Browse Source

Test

etomic
jl777 8 years ago
parent
commit
aa1b61018c
  1. 92
      iguana/exchanges/LP_portfolio.c

92
iguana/exchanges/LP_portfolio.c

@ -298,70 +298,68 @@ void prices_loop(void *ignore)
char *retstr; cJSON *retjson,*bid,*ask; uint64_t bidsatoshis,asksatoshis; int32_t i; double nxtkmd,price; struct LP_priceinfo *btcpp,*kmdpp,*fiatpp,*nxtpp; void *ctx = bitcoin_ctx(); char *retstr; cJSON *retjson,*bid,*ask; uint64_t bidsatoshis,asksatoshis; int32_t i; double nxtkmd,price; struct LP_priceinfo *btcpp,*kmdpp,*fiatpp,*nxtpp; void *ctx = bitcoin_ctx();
while ( 1 ) while ( 1 )
{ {
if ( LP_autoprices == 0 )
{
sleep(60);
continue;
}
if ( (btcpp= LP_priceinfofind("BTC")) == 0 ) if ( (btcpp= LP_priceinfofind("BTC")) == 0 )
{ {
sleep(60); sleep(60);
continue; continue;
} }
if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 ) if ( LP_autoprices != 0 )
{
printf("error getting marketsummaries\n");
sleep(60);
continue;
}
nxtkmd = LP_pricesparse(ctx,1,retstr,btcpp);
free(retstr);
if ( (retstr= issue_curlt("https://www.cryptopia.co.nz/api/GetMarkets",LP_HTTP_TIMEOUT*10)) == 0 )
{
printf("error getting marketsummaries\n");
sleep(60);
continue;
}
LP_pricesparse(ctx,0,retstr,btcpp);
free(retstr);
if ( (kmdpp= LP_priceinfofind("KMD")) != 0 )
{ {
for (i=0; i<32; i++) if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 )
{ {
if ( (fiatpp= LP_priceinfofind(CURRENCIES[i])) != 0 ) printf("error getting marketsummaries\n");
sleep(60);
continue;
}
nxtkmd = LP_pricesparse(ctx,1,retstr,btcpp);
free(retstr);
if ( (retstr= issue_curlt("https://www.cryptopia.co.nz/api/GetMarkets",LP_HTTP_TIMEOUT*10)) == 0 )
{
printf("error getting marketsummaries\n");
sleep(60);
continue;
}
LP_pricesparse(ctx,0,retstr,btcpp);
free(retstr);
if ( (kmdpp= LP_priceinfofind("KMD")) != 0 )
{
for (i=0; i<32; i++)
{ {
if ( (retjson= LP_paxprice(CURRENCIES[i])) != 0 ) if ( (fiatpp= LP_priceinfofind(CURRENCIES[i])) != 0 )
{ {
//printf("(%s %.8f %.8f) ",CURRENCIES[i],jdouble(retjson,"price"),jdouble(retjson,"invprice")); if ( (retjson= LP_paxprice(CURRENCIES[i])) != 0 )
price = jdouble(retjson,"price"); {
LP_autopriceset(ctx,1,kmdpp,fiatpp,price); //printf("(%s %.8f %.8f) ",CURRENCIES[i],jdouble(retjson,"price"),jdouble(retjson,"invprice"));
LP_autopriceset(ctx,-1,fiatpp,kmdpp,price); price = jdouble(retjson,"price");
free_json(retjson); LP_autopriceset(ctx,1,kmdpp,fiatpp,price);
LP_autopriceset(ctx,-1,fiatpp,kmdpp,price);
free_json(retjson);
}
} }
} }
} }
} if ( nxtkmd > SMALLVAL )
if ( nxtkmd > SMALLVAL )
{
for (i=0; i<sizeof(assetids)/sizeof(*assetids); i++)
{ {
if ( (nxtpp= LP_priceinfofind(assetids[i][1])) != 0 ) for (i=0; i<sizeof(assetids)/sizeof(*assetids); i++)
{ {
price = 0.; if ( (nxtpp= LP_priceinfofind(assetids[i][1])) != 0 )
bidsatoshis = asksatoshis = 0;
if ( (retjson= LP_assethbla(assetids[i][0])) != 0 )
{ {
if ( (bid= jobj(retjson,"bid")) != 0 && (ask= jobj(retjson,"ask")) != 0 ) price = 0.;
bidsatoshis = asksatoshis = 0;
if ( (retjson= LP_assethbla(assetids[i][0])) != 0 )
{ {
bidsatoshis = j64bits(bid,"priceNQT") * atoi(assetids[i][2]); if ( (bid= jobj(retjson,"bid")) != 0 && (ask= jobj(retjson,"ask")) != 0 )
asksatoshis = j64bits(ask,"priceNQT") * atoi(assetids[i][2]); {
if ( bidsatoshis != 0 && asksatoshis != 0 ) bidsatoshis = j64bits(bid,"priceNQT") * atoi(assetids[i][2]);
price = 0.5 * dstr(bidsatoshis + asksatoshis) * nxtkmd; asksatoshis = j64bits(ask,"priceNQT") * atoi(assetids[i][2]);
if ( bidsatoshis != 0 && asksatoshis != 0 )
price = 0.5 * dstr(bidsatoshis + asksatoshis) * nxtkmd;
}
LP_autopriceset(ctx,1,kmdpp,nxtpp,price);
LP_autopriceset(ctx,-1,nxtpp,kmdpp,price);
//printf("%s %s -> (%s) nxtkmd %.8f %.8f %.8f\n",assetids[i][1],assetids[i][0],jprint(retjson,0),nxtkmd,0.5*dstr(bidsatoshis + asksatoshis),price);
free_json(retjson);
} }
LP_autopriceset(ctx,1,kmdpp,nxtpp,price);
LP_autopriceset(ctx,-1,nxtpp,kmdpp,price);
//printf("%s %s -> (%s) nxtkmd %.8f %.8f %.8f\n",assetids[i][1],assetids[i][0],jprint(retjson,0),nxtkmd,0.5*dstr(bidsatoshis + asksatoshis),price);
free_json(retjson);
} }
} }
} }

Loading…
Cancel
Save