Browse Source

Test

etomic
jl777 7 years ago
parent
commit
f8f99cc7ef
  1. 8
      iguana/exchanges/LP_nativeDEX.c
  2. 9
      iguana/exchanges/LP_portfolio.c
  3. 41
      iguana/exchanges/LP_tradebots.c

8
iguana/exchanges/LP_nativeDEX.c

@ -994,7 +994,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching queue_loop for port.%u\n",myport); printf("error launching queue_loop for port.%u\n",myport);
exit(-1); exit(-1);
} }
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,(void *)myipaddr) != 0 ) if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 )
{ {
printf("error launching prices_loop for port.%u\n",myport); printf("error launching prices_loop for port.%u\n",myport);
exit(-1); exit(-1);
@ -1029,11 +1029,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching LP_swapsloop for port.%u\n",myport); printf("error launching LP_swapsloop for port.%u\n",myport);
exit(-1); exit(-1);
} }
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_tradebot_timeslices,ctx) != 0 )
{
printf("error launching LP_tradebot_timeslices\n");
exit(-1);
}
int32_t nonz; int32_t nonz;
while ( 1 ) while ( 1 )
{ {
@ -1117,7 +1112,6 @@ void LP_fromjs_iter()
{ {
LP_notify_pubkeys(ctx,LP_mypubsock); LP_notify_pubkeys(ctx,LP_mypubsock);
LP_privkey_updates(ctx,LP_mypubsock,0); LP_privkey_updates(ctx,LP_mypubsock,0);
prices_loop(0);
if ( (retstr= basilisk_swapentry(0,0)) != 0 ) if ( (retstr= basilisk_swapentry(0,0)) != 0 )
free(retstr); free(retstr);
} }

9
iguana/exchanges/LP_portfolio.c

@ -586,15 +586,14 @@ int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *a
return(n); return(n);
} }
void prices_loop(void *arg) void prices_loop(void *ctx)
{ {
char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx(); char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp;
while ( 1 ) while ( 1 )
{ {
LP_tradebots_timeslice(ctx);
if ( (btcpp= LP_priceinfofind("BTC")) == 0 ) if ( (btcpp= LP_priceinfofind("BTC")) == 0 )
{ {
if ( arg == 0 )
return;
sleep(60); sleep(60);
continue; continue;
} }
@ -628,8 +627,6 @@ void prices_loop(void *arg)
} }
free(retstr); free(retstr);
} }
if ( arg == 0 )
return;
sleep(60); sleep(60);
} }
} }

41
iguana/exchanges/LP_tradebots.c

@ -320,39 +320,36 @@ void LP_tradebot_finished(uint32_t tradeid,uint32_t requestid,uint32_t quoteid)
} }
} }
void LP_tradebot_timeslices(void *ctx) void LP_tradebots_timeslice(void *ctx)
{ {
struct LP_tradebot_trade *tp; struct iguana_info *relcoin; struct LP_tradebot *bot,*tmp; int32_t i,lastnumfinished = 0; static uint32_t lastnumfinished = 0;
while ( 1 ) struct LP_tradebot_trade *tp; struct iguana_info *relcoin; struct LP_tradebot *bot,*tmp; int32_t i;
DL_FOREACH_SAFE(LP_tradebots,bot,tmp)
{ {
DL_FOREACH_SAFE(LP_tradebots,bot,tmp) if ( (relcoin= LP_coinfind(bot->rel)) != 0 )
LP_listunspent_issue(bot->rel,relcoin->smartaddr,1);
if ( bot->numpending > 0 && LP_numfinished > lastnumfinished )
{ {
if ( (relcoin= LP_coinfind(bot->rel)) != 0 ) // expire pending trades and see if any still need their requestid/quoteid
LP_listunspent_issue(bot->rel,relcoin->smartaddr,1); for (i=0; i<bot->numtrades; i++)
if ( bot->numpending > 0 && LP_numfinished > lastnumfinished )
{ {
// expire pending trades and see if any still need their requestid/quoteid if ( (tp= bot->trades[i]) != 0 && tp->finished == 0 )
for (i=0; i<bot->numtrades; i++)
{ {
if ( (tp= bot->trades[i]) != 0 && tp->finished == 0 ) if ( time(NULL) > tp->started+INSTANTDEX_LOCKTIME*2 )
{ {
if ( time(NULL) > tp->started+INSTANTDEX_LOCKTIME*2 ) bot->pendbasesum -= tp->basevol;
{ bot->pendrelsum -= tp->relvol;
bot->pendbasesum -= tp->basevol; bot->numpending--;
bot->pendrelsum -= tp->relvol; tp->finished = (uint32_t)time(NULL);
bot->numpending--; printf("%s trade.%d of %d expired\n",bot->name,i,bot->numtrades);
tp->finished = (uint32_t)time(NULL);
printf("%s trade.%d of %d expired\n",bot->name,i,bot->numtrades);
}
} }
} }
} }
else if ( bot->numpending == 0 )
LP_tradebot_timeslice(ctx,bot);
} }
lastnumfinished = LP_numfinished; else if ( bot->numpending == 0 )
sleep(60); LP_tradebot_timeslice(ctx,bot);
} }
lastnumfinished = LP_numfinished;
} }
char *LP_tradebot_list(void *ctx,int32_t pubsock,cJSON *argjson) char *LP_tradebot_list(void *ctx,int32_t pubsock,cJSON *argjson)

Loading…
Cancel
Save