Browse Source

Gettradestatus

etomic
jl777 7 years ago
parent
commit
c5a60493b4
  1. 2
      iguana/exchanges/LP_include.h
  2. 27
      iguana/exchanges/LP_stats.c

2
iguana/exchanges/LP_include.h

@ -385,7 +385,7 @@ struct LP_swapstats
bits256 bobdeposit,alicepayment,bobpayment,paymentspent,Apaymentspent,depositspent;
double qprice;
uint64_t aliceid;
uint32_t ind,methodind,finished,expired;
uint32_t ind,methodind,finished,expired,lasttime;
char alicegui[32],bobgui[32];
};

27
iguana/exchanges/LP_stats.c

@ -170,6 +170,7 @@ bits256 LP_swapstats_txid(cJSON *argjson,char *name,bits256 oldtxid)
int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSON *lineobj)
{
char *statusstr,*base,*rel,gui[64]; uint32_t requestid,quoteid; uint64_t satoshis,destsatoshis;
sp->lasttime = (uint32_t)time(NULL);
safecopy(gui,sp->Q.gui,sizeof(gui));
if ( strcmp(LP_stats_methods[sp->methodind],"tradestatus") == 0 )
{
@ -304,6 +305,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj)
sp->qprice = qprice;
sp->methodind = methodind;
sp->ind = LP_aliceids++;
sp->lasttime = (uint32_t)time(NULL);
strcpy(sp->bobgui,"nogui");
strcpy(sp->alicegui,"nogui");
if ( sp->finished == 0 && sp->expired == 0 )
@ -360,8 +362,10 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp)
char *LP_swapstatus_recv(cJSON *argjson)
{
struct LP_swapstats *sp; int32_t methodind;
printf("swapstatus.(%s)\n",jprint(argjson,0));
if ( (sp= LP_swapstats_find(j64bits(argjson,"aliceid"))) != 0 )
{
sp->lasttime = (uint32_t)time(NULL);
if ( (methodind= jint(argjson,"ind")) > sp->methodind && methodind < sizeof(LP_stats_methods)/sizeof(*LP_stats_methods) )
{
sp->methodind = methodind;
@ -376,7 +380,8 @@ char *LP_swapstatus_recv(cJSON *argjson)
char *LP_gettradestatus(uint64_t aliceid)
{
struct LP_swapstats *sp; cJSON *reqjson; bits256 zero;
if ( (sp= LP_swapstats_find(aliceid)) != 0 )
printf("gettradestatus.(%llu)\n",(long long)aliceid);
if ( (sp= LP_swapstats_find(aliceid)) != 0 && time(NULL) > sp->lasttime+60 )
{
if ( (reqjson= LP_swapstats_json(sp)) != 0 )
{
@ -422,7 +427,10 @@ int32_t LP_stats_dispiter(cJSON *array,struct LP_swapstats *sp,uint32_t starttim
cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256 refpubkey,char *refbase,char *refrel)
{
cJSON *retjson,*array,*item; struct LP_swapstats *sp,*tmp; int32_t i,n,numtrades[LP_MAXPRICEINFOS]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS];
static int32_t rval;
cJSON *retjson,*array,*item,*reqjson; bits256 zero; uint32_t now; struct LP_swapstats *sp,*tmp; int32_t i,n,numtrades[LP_MAXPRICEINFOS]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS];
if ( rval == 0 )
rval = (LP_rand() % 300) + 60;
if ( starttime > endtime )
starttime = endtime;
n = LP_statslog_parse();
@ -434,13 +442,26 @@ cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256
jaddnum(retjson,"newlines",n);
array = cJSON_CreateArray();
LP_RTcount = LP_swapscount = 0;
now = (uint32_t)time(NULL);
HASH_ITER(hh,LP_RTstats,sp,tmp)
{
if ( LP_stats_dispiter(array,sp,starttime,endtime,refbase,refrel,refgui,refpubkey) > 0 )
{
HASH_DELETE(hh,LP_RTstats,sp);
HASH_ADD(hh,LP_swapstats,aliceid,sizeof(sp->aliceid),sp);
} else LP_RTcount++;
}
else
{
LP_RTcount++;
if ( now > sp->lasttime+rval )
{
reqjson = cJSON_CreateObject();
jaddstr(reqjson,"method","gettradestatus");
jadd64bits(reqjson,"aliceid",sp->aliceid);
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
}
}
}
HASH_ITER(hh,LP_swapstats,sp,tmp)
{

Loading…
Cancel
Save