Browse Source

test

etomic
jl777 8 years ago
parent
commit
cda56fa901
  1. 19
      iguana/exchanges/poloniex.c
  2. 19
      iguana/iguana_exchanges.c
  3. 2
      iguana/tests/rate

19
iguana/exchanges/poloniex.c

@ -72,20 +72,29 @@ int32_t SUPPORTS(struct exchange_info *exchange,char *base,char *rel,cJSON *argj
{ {
//char *baserels[][2] = { {"btc","usd"} }; //char *baserels[][2] = { {"btc","usd"} };
//return(baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel)); //return(baserel_polarity(baserels,(int32_t)(sizeof(baserels)/sizeof(*baserels)),base,rel));
if ( strlen(base) > 5 || strlen(rel) > 5 || strcmp(rel,"CNY") == 0 || strcmp(base,"CNY") == 0 || strcmp(rel,"USD") == 0 || strcmp(base,"USD") == 0 ) if ( strlen(base) > 5 || strlen(rel) > 5 || strcmp(rel,"CNY") == 0 || strcmp(base,"CNY") == 0 )
return(0); return(0);
if ( strcmp(rel,"BTC") == 0 ) if ( strcmp(base,"BTC") == 0 && strcmp(rel,"USD") == 0 )
return(1);
else if ( strcmp(rel,"BTC") == 0 && strcmp(base,"USD") == 0 )
return(-1);
else if ( strcmp(rel,"BTC") == 0 )
return(1); return(1);
else if ( strcmp(base,"BTC") == 0 ) else if ( strcmp(base,"BTC") == 0 )
return(-1); return(-1);
else return(0); else return(0);
} }
double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert) double UPDATE(struct exchange_info *exchange,char *_base,char *_rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert)
{ {
char market[128],url[1024]; char market[128],url[1024],base[16],rel[16];
sprintf(market,"%s_%s",rel,base); strcpy(base,_base), touppercase(base);
strcpy(rel,_rel), touppercase(rel);
if ( strcmp(rel,"USD") == 0 )
sprintf(market,"USDT_%s",base);
else sprintf(market,"%s_%s",rel,base);
sprintf(url,"https://poloniex.com/public?command=returnOrderBook&currencyPair=%s&depth=%d",market,maxdepth); sprintf(url,"https://poloniex.com/public?command=returnOrderBook&currencyPair=%s&depth=%d",market,maxdepth);
//printf("URL.(%s)\n",url);
return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0,invert)); return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0,invert));
} }

19
iguana/iguana_exchanges.c

@ -25,7 +25,7 @@
int32_t instantdex_updatesources(struct exchange_info *exchange,struct exchange_quote *sortbuf,int32_t n,int32_t max,int32_t ind,int32_t dir,struct exchange_quote *quotes,int32_t numquotes) int32_t instantdex_updatesources(struct exchange_info *exchange,struct exchange_quote *sortbuf,int32_t n,int32_t max,int32_t ind,int32_t dir,struct exchange_quote *quotes,int32_t numquotes)
{ {
int32_t i; struct exchange_quote *quote; int32_t i; struct exchange_quote *quote;
//printf("instantdex_updatesources.%s update dir.%d numquotes.%d\n",exchange->name,dir,numquotes); printf("instantdex_updatesources.%s update dir.%d numquotes.%d\n",exchange->name,dir,numquotes);
for (i=0; i<numquotes; i++) for (i=0; i<numquotes; i++)
{ {
quote = &quotes[i << 1]; quote = &quotes[i << 1];
@ -86,6 +86,13 @@ double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *s
} }
} }
} }
for (i=0; i<num; i++)
{
if ( active[i]->numbids > 0 && active[i]->numasks > 0 )
{
}
}
for (i=n=0; i<num; i++) for (i=n=0; i<num; i++)
{ {
if ( dir < 0 && active[i]->numbids > 0 ) if ( dir < 0 && active[i]->numbids > 0 )
@ -93,19 +100,19 @@ double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *s
else if ( dir > 0 && active[i]->numasks > 0 ) else if ( dir > 0 && active[i]->numasks > 0 )
n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,-1,&active[i]->bidasks[1],active[i]->numasks); n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,-1,&active[i]->bidasks[1],active[i]->numasks);
} }
//printf("numexchanges.%d dir.%d %s/%s numX.%d n.%d\n",myinfo->numexchanges,dir,base,rel,num,n); printf("numexchanges.%d dir.%d %s/%s numX.%d n.%d\n",myinfo->numexchanges,dir,base,rel,num,n);
if ( dir < 0 ) if ( dir < 0 )
revsort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf)); revsort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf));
else sort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf)); else sort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf));
for (totalvol=pricesum=i=0; i<n && totalvol < basevolume; i++) for (totalvol=pricesum=i=0; i<n; i++)// && totalvol < basevolume; i++)
{ {
quote = sortbuf[i]; quote = sortbuf[i];
printf("n.%d i.%d price %.8f %.8f %.8f\n",n,i,dstr(sortbuf[i].satoshis),sortbuf[i].price,quote.volume); printf("dir.%d n.%d i.%d price %.8f %.8f %.8f\n",dir,n,i,dstr(sortbuf[i].satoshis),sortbuf[i].price,quote.volume);
if ( quote.satoshis != 0 ) if ( quote.satoshis != 0 )
{ {
pricesum += (quote.price * quote.volume); pricesum += (quote.price * quote.volume);
totalvol += quote.volume; totalvol += quote.volume;
//printf("i.%d of %d %12.8f vol %.8f %s | aveprice %.8f total vol %.8f\n",i,n,sortbuf[i].price,quote.volume,active[quote.val]->exchange->name,pricesum/totalvol,totalvol); printf("dir.%d i.%d of %d %12.8f vol %.8f %s | aveprice %.8f total vol %.8f\n",dir,i,n,sortbuf[i].price,quote.volume,active[quote.val]->exchange->name,pricesum/totalvol,totalvol);
} }
} }
if ( totalvol > 0. ) if ( totalvol > 0. )
@ -821,7 +828,7 @@ void exchanges777_loop(void *ptr)
for (i=req->numasks=0; i<req->depth; i++) for (i=req->numasks=0; i<req->depth; i++)
if ( req->bidasks[(i << 1) + 1].price > SMALLVAL ) if ( req->bidasks[(i << 1) + 1].price > SMALLVAL )
req->numasks++; req->numasks++;
//printf("%-10s %s/%s numbids.%d numasks.%d\n",exchange->name,req->base,req->rel,req->numbids,req->numasks); //printf("%-10s %s/%s numbids.%d numasks.%d\n",exchange->name,req->base,req->rel,req->numbids,req->numasks);
prices777_processprice(exchange,req->base,req->rel,req->bidasks,req->depth); prices777_processprice(exchange,req->base,req->rel,req->bidasks,req->depth);
} }
queue_enqueue("pricesQ",&exchange->pricesQ,&req->DL); queue_enqueue("pricesQ",&exchange->pricesQ,&req->DL);

2
iguana/tests/rate

@ -1,2 +1,2 @@
#!/bin/bash #!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"rate\",\"base\":\"BTCD\",\"rel\":\"BTC\"}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"rate\",\"base\":\"BTC\",\"rel\":\"USD\"}"

Loading…
Cancel
Save