Browse Source

Test

etomic
jl777 7 years ago
parent
commit
bdf651e6f8
  1. 17
      iguana/exchanges/LP_tradebots.c

17
iguana/exchanges/LP_tradebots.c

@ -36,7 +36,7 @@ struct LP_tradebot
char name[128],base[32],rel[32]; char name[128],base[32],rel[32];
int32_t numtrades,numpending,completed,dispdir; int32_t numtrades,numpending,completed,dispdir;
double maxprice,totalrelvolume,totalbasevolume,basesum,relsum,pendbasesum,pendrelsum; double maxprice,totalrelvolume,totalbasevolume,basesum,relsum,pendbasesum,pendrelsum;
uint32_t dead,pause,started,id; uint32_t dead,pause,userpause,started,id;
struct LP_tradebot_trade *trades[LP_TRADEBOTS_MAXTRADES]; struct LP_tradebot_trade *trades[LP_TRADEBOTS_MAXTRADES];
} *LP_tradebots; } *LP_tradebots;
@ -134,8 +134,8 @@ cJSON *LP_tradebot_json(struct LP_tradebot *bot)
jaddstr(json,"name",bot->name); jaddstr(json,"name",bot->name);
jaddnum(json,"botid",bot->id); jaddnum(json,"botid",bot->id);
jaddnum(json,"started",bot->started); jaddnum(json,"started",bot->started);
if ( bot->pause != 0 ) if ( bot->pause != 0 || bot->userpause != 0 )
jaddnum(json,"paused",bot->pause); jaddnum(json,"paused",bot->userpause != 0 ? bot->userpause : bot->pause);
if ( bot->dead != 0 ) if ( bot->dead != 0 )
jaddnum(json,"stopped",bot->dead); jaddnum(json,"stopped",bot->dead);
if ( bot->dispdir > 0 ) if ( bot->dispdir > 0 )
@ -293,7 +293,7 @@ void LP_tradebot_timeslice(void *ctx,struct LP_tradebot *bot)
{ {
double remaining,maxrel; struct LP_tradebot_trade *tp; int32_t i,maxiters = 10; uint32_t tradeid; bits256 destpubkey; char *retstr,*liststr; cJSON *retjson,*retjson2,*pending; double remaining,maxrel; struct LP_tradebot_trade *tp; int32_t i,maxiters = 10; uint32_t tradeid; bits256 destpubkey; char *retstr,*liststr; cJSON *retjson,*retjson2,*pending;
memset(destpubkey.bytes,0,sizeof(destpubkey)); memset(destpubkey.bytes,0,sizeof(destpubkey));
if ( bot->dead == 0 && bot->pause == 0 && bot->numtrades < sizeof(bot->trades)/sizeof(*bot->trades) ) if ( bot->dead == 0 && bot->pause == 0 && bot->userpause == 0 && bot->numtrades < sizeof(bot->trades)/sizeof(*bot->trades) )
{ {
if ( (liststr= LP_recent_swaps(0)) != 0 ) if ( (liststr= LP_recent_swaps(0)) != 0 )
{ {
@ -427,7 +427,8 @@ void LP_tradebots_timeslice(void *ctx)
bot->dead = (uint32_t)time(NULL); bot->dead = (uint32_t)time(NULL);
else if ( (bot->pendrelsum+bot->relsum) >= 0.99*bot->totalrelvolume-SMALLVAL || (bot->basesum+bot->pendbasesum) >= 0.99*bot->totalbasevolume-SMALLVAL ) else if ( (bot->pendrelsum+bot->relsum) >= 0.99*bot->totalrelvolume-SMALLVAL || (bot->basesum+bot->pendbasesum) >= 0.99*bot->totalbasevolume-SMALLVAL )
bot->pause = (uint32_t)time(NULL); bot->pause = (uint32_t)time(NULL);
else bot->pause = 0; else if ( bot->userpause == 0 )
bot->pause = 0;
if ( bot->numpending == 0 ) if ( bot->numpending == 0 )
LP_tradebot_timeslice(ctx,bot); LP_tradebot_timeslice(ctx,bot);
} }
@ -629,7 +630,7 @@ char *LP_tradebot_pause(void *ctx,int32_t pubsock,cJSON *argjson,uint32_t botid)
{ {
if ( bot->dead != 0 ) if ( bot->dead != 0 )
return(clonestr("{\"error\":\"botid aleady stopped\"}")); return(clonestr("{\"error\":\"botid aleady stopped\"}"));
bot->pause = (uint32_t)time(NULL); bot->userpause = (uint32_t)time(NULL);
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));
} }
return(clonestr("{\"error\":\"couldnt find botid\"}")); return(clonestr("{\"error\":\"couldnt find botid\"}"));
@ -642,9 +643,9 @@ char *LP_tradebot_resume(void *ctx,int32_t pubsock,cJSON *argjson,uint32_t botid
{ {
if ( bot->dead != 0 ) if ( bot->dead != 0 )
return(clonestr("{\"error\":\"botid aleady stopped\"}")); return(clonestr("{\"error\":\"botid aleady stopped\"}"));
if ( bot->pause == 0 ) if ( bot->userpause == 0 )
return(clonestr("{\"result\":\"success\",\"status\":\"botid not paused\"}")); return(clonestr("{\"result\":\"success\",\"status\":\"botid not paused\"}"));
bot->pause = 0; bot->userpause = 0;
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));
} }
return(clonestr("{\"error\":\"couldnt find botid\"}")); return(clonestr("{\"error\":\"couldnt find botid\"}"));

Loading…
Cancel
Save