Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
bc2afd67ab
  1. 8
      iguana/exchanges/bitcoin.c
  2. 4
      iguana/exchanges777.h
  3. 4
      iguana/iguana_bundles.c
  4. 87
      iguana/iguana_instantdex.c
  5. 174
      iguana/index.html
  6. 2
      iguana/js/imgAPI.js
  7. 1
      includes/iguana_apideclares.h

8
iguana/exchanges/bitcoin.c

@ -339,7 +339,7 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
cJSON *retjson,*bids,*asks; double hbla;
bids = cJSON_CreateArray();
asks = cJSON_CreateArray();
instantdex_offerfind(SuperNET_MYINFO(0),exchange,bids,asks,0,base,rel,1);
instantdex_offerfind(SuperNET_MYINFO(0),exchange,bids,asks,0,base,rel,1,0);
//printf("bids.(%s) asks.(%s)\n",jprint(bids,0),jprint(asks,0));
retjson = cJSON_CreateObject();
cJSON_AddItemToObject(retjson,"bids",bids);
@ -470,7 +470,7 @@ char *ORDERSTATUS(struct exchange_info *exchange,uint64_t orderid,cJSON *argjson
struct supernet_info *myinfo = SuperNET_accountfind(argjson);
if ( (swap= instantdex_statemachinefind(myinfo,exchange,orderid,1)) != 0 )
jadd(retjson,"result",instantdex_statemachinejson(swap));
else if ( (ap= instantdex_offerfind(myinfo,exchange,0,0,orderid,"*","*",1)) != 0 )
else if ( (ap= instantdex_offerfind(myinfo,exchange,0,0,orderid,"*","*",1,0)) != 0 )
jadd(retjson,"result",instantdex_acceptjson(ap));
else if ( (swap= instantdex_historyfind(myinfo,exchange,orderid)) != 0 )
jadd(retjson,"result",instantdex_historyjson(swap));
@ -483,7 +483,7 @@ char *CANCELORDER(struct exchange_info *exchange,uint64_t orderid,cJSON *argjson
struct instantdex_accept *ap = 0; cJSON *retjson; struct bitcoin_swapinfo *swap=0;
struct supernet_info *myinfo = SuperNET_accountfind(argjson);
retjson = cJSON_CreateObject();
if ( (ap= instantdex_offerfind(myinfo,exchange,0,0,orderid,"*","*",1)) != 0 )
if ( (ap= instantdex_offerfind(myinfo,exchange,0,0,orderid,"*","*",1,0)) != 0 )
{
ap->dead = (uint32_t)time(NULL);
jadd(retjson,"orderid",instantdex_acceptjson(ap));
@ -502,7 +502,7 @@ char *OPENORDERS(struct exchange_info *exchange,cJSON *argjson)
cJSON *retjson,*bids,*asks; struct supernet_info *myinfo = SuperNET_accountfind(argjson);
bids = cJSON_CreateArray();
asks = cJSON_CreateArray();
instantdex_offerfind(myinfo,exchange,bids,asks,0,"*","*",1);
instantdex_offerfind(myinfo,exchange,bids,asks,0,"*","*",1,0);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jadd(retjson,"bids",bids);

4
iguana/exchanges777.h

@ -117,7 +117,7 @@ struct instantdex_accept
{
struct queueitem DL; uint8_t peerhas[IGUANA_MAXPEERS/8];
uint64_t pendingvolume64,orderid;
uint32_t dead; int32_t didstate;
uint32_t dead; int32_t didstate:31,reported:1;
struct instantdex_offer offer;
};
@ -157,7 +157,7 @@ struct instantdex_stateinfo
#define instantdex_isbob(swap) (swap)->mine.offer.myside
struct instantdex_accept *instantdex_offerfind(struct supernet_info *myinfo,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel,int32_t requeue);
struct instantdex_accept *instantdex_offerfind(struct supernet_info *myinfo,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel,int32_t requeue,int32_t report);
cJSON *instantdex_acceptjson(struct instantdex_accept *ap);
cJSON *instantdex_historyjson(struct bitcoin_swapinfo *swap);
struct bitcoin_swapinfo *instantdex_historyfind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid);

4
iguana/iguana_bundles.c

@ -1410,8 +1410,8 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag)
static FILE *logfp;
if ( logfp == 0 )
logfp = fopen("debug.log","wb");
if ( logfp != 0 )
fprintf(logfp,"%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,queue_size(&bundlesQ),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck);
//if ( logfp != 0 )
printf("%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,queue_size(&bundlesQ),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck);
strcpy(coin->lastdispstr,str);
//if ( (rand() % 100) == 0 )
// myallocated(0,0);

87
iguana/iguana_instantdex.c

@ -694,7 +694,7 @@ struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinf
return(retswap);
}
struct instantdex_accept *instantdex_offerfind(struct supernet_info *ignore,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel,int32_t requeue)
struct instantdex_accept *instantdex_offerfind(struct supernet_info *ignore,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel,int32_t requeue,int32_t report)
{
struct instantdex_accept PAD,*ap,*retap = 0; uint32_t now; cJSON *item,*offerobj; char *type;
if ( exchange == 0 )
@ -707,28 +707,30 @@ struct instantdex_accept *instantdex_offerfind(struct supernet_info *ignore,stru
if ( now < ap->offer.expiration && ap->dead == 0 )
{
//printf("%d %d find cmps %d %d %d %d %d %d me.%llu vs %llu o.%llu | vs %llu\n",instantdex_bidaskdir(&ap->offer),ap->offer.expiration-now,strcmp(base,"*") == 0,strcmp(base,ap->offer.base) == 0,strcmp(rel,"*") == 0,strcmp(rel,ap->offer.rel) == 0,orderid == 0,orderid == ap->orderid,(long long)myinfo->myaddr.nxt64bits,(long long)ap->offer.offer64,(long long)ap->orderid,(long long)orderid);
if ( (strcmp(base,"*") == 0 || strcmp(base,ap->offer.base) == 0) && (strcmp(rel,"*") == 0 || strcmp(rel,ap->offer.rel) == 0) && (orderid == 0 || orderid == ap->orderid) )
if ( (report == 0 || ap->reported == 0) && (strcmp(base,"*") == 0 || strcmp(base,ap->offer.base) == 0) && (strcmp(rel,"*") == 0 || strcmp(rel,ap->offer.rel) == 0) && (orderid == 0 || orderid == ap->orderid) )
{
if ( report != 0 )
ap->reported = 1;
if ( requeue == 0 && retap != 0 )
queue_enqueue("acceptableQ",&exchange->acceptableQ,&retap->DL,0);
retap = ap;
}
if ( (item= instantdex_acceptjson(ap)) != 0 )
{
//printf("item.(%s)\n",jprint(item,0));
if ( (offerobj= jobj(item,"offer")) != 0 && (type= jstr(offerobj,"type")) != 0 )
if ( (item= instantdex_acceptjson(ap)) != 0 )
{
//printf("item.(%s)\n",jprint(item,0));
if ( (offerobj= jobj(item,"offer")) != 0 && (type= jstr(offerobj,"type")) != 0 )
{
if ( bids != 0 && strcmp(type,"bid") == 0 )
jaddi(bids,jduplicate(offerobj));
else if ( asks != 0 && strcmp(type,"ask") == 0 )
jaddi(asks,jduplicate(offerobj));
}
free_json(item);
} else printf("error generating acceptjson.%llu\n",(long long)ap->orderid);
if ( ap != retap || requeue != 0 )
{
if ( bids != 0 && strcmp(type,"bid") == 0 )
jaddi(bids,jduplicate(offerobj));
else if ( asks != 0 && strcmp(type,"ask") == 0 )
jaddi(asks,jduplicate(offerobj));
//printf("requeue.%p\n",ap);
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
}
free_json(item);
} else printf("error generating acceptjson.%llu\n",(long long)ap->orderid);
if ( ap != retap || requeue != 0 )
{
//printf("requeue.%p\n",ap);
queue_enqueue("acceptableQ",&exchange->acceptableQ,&ap->DL,0);
}
} else free(ap);
}
@ -841,7 +843,7 @@ struct instantdex_accept *instantdex_quotefind(struct supernet_info *myinfo,stru
char base[9],rel[9]; int64_t pricetoshis; uint64_t orderid,offer64;
orderid = instantdex_decodehash(base,rel,&pricetoshis,&offer64,encodedhash);
printf("search for orderid.%llu (%s/%s) %.8f from %llu\n",(long long)orderid,base,rel,dstr(pricetoshis),(long long)offer64);
return(instantdex_offerfind(myinfo,exchanges777_find("bitcoin"),0,0,orderid,base,rel,1));
return(instantdex_offerfind(myinfo,exchanges777_find("bitcoin"),0,0,orderid,base,rel,1,0));
}
struct iguana_bundlereq *instantdex_recvquotes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *quotes,int32_t n)
@ -1245,7 +1247,7 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
else
{
printf("no matching trade for %s %llu -> InstantDEX_minaccept isbob.%d\n",cmdstr,(long long)A.orderid,A.offer.myside);
if ( instantdex_offerfind(myinfo,exchange,0,0,A.orderid,"*","*",1) == 0 )
if ( instantdex_offerfind(myinfo,exchange,0,0,A.orderid,"*","*",1,0) == 0 )
{
ap = calloc(1,sizeof(*ap));
*ap = A;
@ -1493,5 +1495,52 @@ THREE_STRINGS_AND_DOUBLE(tradebot,aveprice,comment,base,rel,basevolume)
return(jprint(retjson,1));
}
cJSON *instantdex_reportjson(cJSON *item,char *name)
{
cJSON *newjson = cJSON_CreateObject(); uint64_t dateval;
dateval = juint(item,"timestamp"), dateval *= 1000;
newjson = cJSON_CreateObject();
jadd(newjson,name,jduplicate(jobj(item,"price")));
jadd(newjson,"volume",jduplicate(jobj(item,"volume")));
jadd(newjson,"orderid",jduplicate(jobj(item,"orderid")));
jaddnum(newjson,"date",dateval);
jaddnum(newjson,"s",dateval % 60);
jaddnum(newjson,"h",(dateval / 60) % 60);
return(newjson);
}
TWO_STRINGS(InstantDEX,events,base,rel)
{
cJSON *bids,*asks,*array,*item; int32_t i,n; struct exchange_info *exchange;
array = cJSON_CreateArray();
if ( (exchange= exchanges777_find("bitcoin")) != 0 )
{
bids = cJSON_CreateArray();
asks = cJSON_CreateArray();
instantdex_offerfind(myinfo,exchange,bids,asks,0,base,rel,1,1);
if ( (n= cJSON_GetArraySize(bids)) > 0 )
{
for (i=0; i<n; i++)
{
item = jobj(jitem(bids,i),"offer");
jaddi(array,instantdex_reportjson(item,"bid"));
}
}
if ( (n= cJSON_GetArraySize(asks)) > 0 )
{
for (i=0; i<n; i++)
{
item = jobj(jitem(asks,i),"offer");
jaddi(array,instantdex_reportjson(item,"ask"));
}
}
free_json(bids);
free_json(asks);
}
return(jprint(array,1));
//return(clonestr("[{\"h\":14,\"m\":44,\"s\":32,\"date\":1407877200000,\"bid\":30,\"ask\":35},{\"date\":1407877200000,\"bid\":40,\"ask\":44},{\"date\":1407877200000,\"bid\":49,\"ask\":45},{\"date\":1407877200000,\"ask\":28},{\"date\":1407877200000,\"ask\":52}]"));
}
#include "../includes/iguana_apiundefs.h"

174
iguana/index.html

@ -25,66 +25,136 @@
<script>
AmCharts.ready(function () { createStockChart(); });
var interval,BASE= "BTCD",REL = "BTC";
function createStockChart() {
var chartData = [];
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"dataDateFormat": "YYYY-MM-DD",
"valueAxes": [{ "id": "v1", "position": "left"}],
"graphs": [{
"id": "g1",
"bullet": "round",
"valueField": "value",
"balloonText": "[[category]]: [[value]]"
}],
"categoryField": "date",
"categoryAxis": {
"parseDates": true,
"equalSpacing": true,
"dashLength": 1,
"minorGridEnabled": true
},
"dataProvider": chartData
});
var chart = AmCharts.makeChart("chartdiv",
{
"type": "serial",
"theme": "dark",
"valueAxes": [
{ "title":"BTC", "id": "vert", "axisAlpha": 0, "dashLength": 1, "position": "left"},
{ "id": "horiz", "axisAlpha": 0, "dashLength": 1, "position": "bottom", "labelFunction": function (value) {
var date = new Date(value);
return AmCharts.formatDate(date, "MMM DD HH:NN:SS");
}}
],
"graphs": [
{ "id": "g1", "lineColor": "#00FFFF", "bullet": "round", "valueField": "bid", "balloonText": "[[category]] [[h]]:[[m]]:[[s]] bid:[[bid]] ask:[[ask]]" },
{ "id": "g2", "lineColor": "#FF8800", "bullet": "round", "valueField": "ask", "balloonText": "[[category]] [[h]]:[[m]]:[[s]] bid:[[bid]] ask:[[ask]]" }],
"categoryField": "date",
"categoryAxis": { "parseDates": true, "equalSpacing": true, "dashLength": 1, "minorGridEnabled": true },
"chartScrollbar": {},
"chartCursor": {},
"dataProvider": chartData
});
var startButton = document.getElementById('start');
var endButton = document.getElementById('stop');
/*
var BTCbutton = document.getElementById('BTC');
var CNYbutton = document.getElementById('CNY');
var USDbutton = document.getElementById('USD');
var EURbutton = document.getElementById('EUR');
var JPYbutton = document.getElementById('JPY');
var GBPbutton = document.getElementById('GBP');
var AUDbutton = document.getElementById('AUD');
var CADbutton = document.getElementById('CAD');
var CHFbutton = document.getElementById('CHF');
var NZDbutton = document.getElementById('NZD');
USDbutton.addEventListener('click', USDrel);
EURbutton.addEventListener('click', EURrel);
JPYbutton.addEventListener('click', JPYrel);
GBPbutton.addEventListener('click', GBPrel);
AUDbutton.addEventListener('click', AUDrel);
CADbutton.addEventListener('click', CADrel);
CHFbutton.addEventListener('click', CHFrel);
NZDbutton.addEventListener('click', NZDrel);
CNYbutton.addEventListener('click', CNYrel);
BTCbutton.addEventListener('click', BTCrel);
*/
var BTCDbutton = document.getElementById('BTCD');
var VPNbutton = document.getElementById('VPN');
var VRCbutton = document.getElementById('VRC');
var SYSbutton = document.getElementById('SYS');
var SuperNETbutton = document.getElementById('SuperNET');
var crypto777button = document.getElementById('crypto777');
var pangeabutton = document.getElementById('Pangea');
var InstantDEXbutton = document.getElementById('InstantDEX');
var Tradebotsbutton = document.getElementById('Tradebots');
var NXTprivacybutton = document.getElementById('NXTprivacy');
startButton.addEventListener('click', startDemo);
endButton.addEventListener('click', endDemo);
var interval;
BTCDbutton.addEventListener('click', BTCDbase);
VPNbutton.addEventListener('click', VPNbase);
SYSbutton.addEventListener('click', SYSbase);
SuperNETbutton.addEventListener('click', SuperNETbase);
crypto777button.addEventListener('click', crypto777base);
pangeabutton.addEventListener('click', Pangeabase);
InstantDEXbutton.addEventListener('click', InstantDEXbase);
Tradebotsbutton.addEventListener('click', Tradebotsbase);
NXTprivacybutton.addEventListener('click', NXTprivacybase);
function BTCDbase() { BASE = "BTCD"; }
function VPNbase() { BASE = "VPN"; }
function SYSbase() { BASE = "SYS"; }
function SuperNETbase() { BASE = "SuperNET"; }
function crypto777base() { BASE = "crypto777"; }
function Pangeabase() { BASE = "Pangea"; }
function InstantDEXbase() { BASE = "InstantDEX"; }
function Tradebotsbase() { BASE = "Tradebots"; }
function NXTprivacybase() { BASE = "NXTprivacy"; }
function USDrel() { REL = "USD"; }
function EURrel() { REL = "EUR"; }
function JPYrel() { REL = "JPY"; }
function GBPrel() { REL = "GBP"; }
function AUDrel() { REL = "AUD"; }
function CADrel() { REL = "CAD"; }
function CHFrel() { REL = "CHF"; }
function NZDrel() { REL = "NZD"; }
function CNYrel() { REL = "CNY"; }
function BTCrel() { REL = "CNY"; }
function startDemo() {
startButton.disabled = "disabled";
endButton.disabled = "";
interval = setInterval(getDataFromServer, 2000);
alert("start");
interval = setInterval(getDataFromServer, 1000);
}
function endDemo() {
startButton.disabled = "";
endButton.disabled = "disabled";
clearInterval(interval);
alert("stop");
}
function getDataFromServer()
{
var i,newDate,newValue,newData = [];
var newDataSize = Math.round(Math.random() + 3) + 1;
if (chartData.length)
newDate = new Date(chartData[chartData.length - 1].date);
else newDate = new Date();
for (i = 0; i < newDataSize; ++i)
{
newValue = Math.round(Math.random() * (40 + i)) + 10 + i;
newDate.setDate(newDate.getDate() + 1);
newData.push({ date: newDate, value: newValue });
}
chartData.push.apply(chartData, newData);
if (chartData.length > 500)
chartData.splice(0, chartData.length - 500);
chart.validateData(); //call to redraw the chart with new data
var i,newData = [];
var request='{"agent":"InstantDEX","method":"events","base":"'+BASE+'","rel":"'+REL+'"}';
SPNAPI.makeRequest(request,
function(request,response)
{
newData = JSON.parse(response);
if ( newData.length > 0 )
{
chartData.push.apply(chartData, newData);
if (chartData.length > 50)
chartData.splice(0, chartData.length - 50);
chart.validateData(); //call to redraw the chart with new data
}
});
// newData = JSON.parse("[{\"h\":14,\"m\":44,\"s\":32,\"date\":1407877200000,\"bid\":30,\"ask\":35},{\"date\":1407877200000,\"bid\":40,\"ask\":44},{\"date\":1407877200000,\"bid\":49,\"ask\":45},{\"date\":1407877200000,\"ask\":28},{\"date\":1407877200000,\"ask\":52}]");
}
}
@ -623,7 +693,24 @@ data-path="{tc}/{config}">
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">
<h3>Instandex tab</h3>
<h3>InstantDEX</h3>
<div class="chart">
<button id="start">Start</button>
<button id="stop" disabled="disabled">Stop </button>
<button id="BTCD"> BTCD</button>
<button id="VPN">VPN</button>
<button id="SYS">SYS</button>
<button id="VRC">VRC</button>
<button id="SuperNET">SuperNET</button>
<button id="crypto777">crypto777</button>
<button id="InstantDEX">InstantDEX</button>
<button id="Tradebots">Tradebots</button>
<button id="Pangea">Pangea</button>
<button id="NXTprivacy">NXTprivacy</button>
<div id="chartdiv"></div>
</div>
</div><div class="pre-scrollable">
<div class="panel-body center">
<button class="btn xyz_button_click btn-primary instantdex_set_method_table" data-method="orderbook" >orderbook</button>
@ -658,11 +745,6 @@ data-path="{tc}/{config}">
</table>
</div></div>
<div class="chart">
<button id="start">Start</button>
<button id="stop" disabled="disabled">Stop</button>
<div id="chartdiv"></div>
</div>
</div>
<style type="text/css">
#Blockexplorer_page .center {

2
iguana/js/imgAPI.js

@ -8,7 +8,7 @@ var prevXY={"X":0,"Y":0};
var prevID=0;
$(document).ready(function() {
loadImages();
// loadImages(); caused internal error with local storage
$('.imagAPI').click(function(e){

1
includes/iguana_apideclares.h

@ -118,6 +118,7 @@ TWO_STRINGS(InstantDEX,cancelorder,exchange,orderid);
STRING_ARG(InstantDEX,openorders,exchange);
STRING_ARG(InstantDEX,tradehistory,exchange);
STRING_AND_INT(InstantDEX,pollgap,exchange,pollgap);
TWO_STRINGS(InstantDEX,events,base,rel);
ZERO_ARGS(InstantDEX,allexchanges);
STRING_ARG(InstantDEX,allpairs,exchange);

Loading…
Cancel
Save