Skip to content

Commit

Permalink
Merge pull request jl777#414 from jl777/spvdex
Browse files Browse the repository at this point in the history
fix RTmetrics crash
  • Loading branch information
jl777 authored Oct 30, 2017
2 parents d2ac59e + 065998a commit 42e8d9f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
19 changes: 12 additions & 7 deletions iguana/exchanges/LP_RTmetrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

struct LP_metricinfo
{
double metric;
double price,balance,minvol;
bits256 pubkey;
double metric,price,balance,minvol,maxvol;
double maxvol;
int32_t ind,numutxos,age,pendingswaps;
};

Expand Down Expand Up @@ -181,7 +183,10 @@ double _LP_RTmetric_calc(struct LP_metricinfo *mp,double bestprice,double maxpri
int32_t n; double metric,origmetric = (mp->price / bestprice);
metric = origmetric;
if ( mp->numutxos == 0 || relvolume == 0. || mp->maxvol == 0. || mp->balance == 0. )
{
printf("skip i.%d as no info\n",mp->ind);
return(metric * 100.);
}
if ( relvolume < mp->minvol )
{
metric *= (mp->minvol / relvolume);
Expand All @@ -205,8 +210,8 @@ double _LP_RTmetric_calc(struct LP_metricinfo *mp,double bestprice,double maxpri
if ( (n= mp->pendingswaps) > 0 )
while ( n-- > 0 )
metric *= 1.1;
if ( metric != origmetric )
printf("price %.8f orig %.8f -> %.8f relvol %.8f min %.8f max %.8f bal %.8f age.%d pend.%d\n",mp->price,origmetric,metric,relvolume,mp->minvol,mp->maxvol,mp->balance,mp->age,mp->pendingswaps);
//if ( metric != origmetric )
printf("i.%d price %.8f orig %.8f -> %.8f relvol %.8f min %.8f max %.8f bal %.8f age.%d pend.%d\n",mp->ind,mp->price,origmetric,metric,relvolume,mp->minvol,mp->maxvol,mp->balance,mp->age,mp->pendingswaps);
return(metric);
}

Expand All @@ -226,7 +231,7 @@ void LP_RTmetric_calc(struct LP_metricinfo *sortbuf,int32_t ind,cJSON *item,doub

cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,double maxprice,double relvolume)
{
cJSON *array,*item; int32_t i,num,groupi; double price,prevdepth,bestprice; struct LP_metricinfo *sortbuf;
cJSON *array=rawasks,*item; int32_t i,num,groupi; double price,prevdepth,bestprice; struct LP_metricinfo *sortbuf;
groupi = -1;
bestprice = 0.;
for (num=i=0; i<numasks; i++)
Expand All @@ -241,7 +246,7 @@ cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,dou
groupi = i;
num++;
}
if ( 0 && groupi > 0 )
if ( groupi > 0 )
{
sortbuf = calloc(groupi+1,sizeof(*sortbuf));
prevdepth = 0.;
Expand All @@ -255,14 +260,14 @@ cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,dou
array = cJSON_CreateArray();
for (i=0; i<=groupi; i++)
{
printf("(%d -> %d) ",i,sortbuf[i].ind);
printf("(%d -> %d %.3f) ",i,sortbuf[i].ind,sortbuf[i].metric);
item = jitem(rawasks,sortbuf[i].ind);
jaddi(array,jduplicate(item));
}
for (; i<numasks; i++)
jaddi(array,jduplicate(jitem(rawasks,i)));
printf("new ask order for %d of %d, capped at num.%d\n",groupi,numasks,num);
free(sortbuf);
} else array = rawasks;
}
return(array);
}
2 changes: 1 addition & 1 deletion iguana/exchanges/LP_nativeDEX.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
}
else
{
printf("packet not for this node %u\n",crc32);
//printf("packet not for this node %u\n",crc32);
}
} else printf("error (%s) method is %s\n",jsonstr,method);
}
Expand Down
6 changes: 3 additions & 3 deletions iguana/exchanges/LP_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,10 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
if ( rawtx->I.redeemlen > 0 && rawtx->I.redeemlen < 0x100 )
{
memcpy(rawtx->redeemscript,&data[datalen],rawtx->I.redeemlen);
for (i=0; i<rawtx->I.redeemlen; i++)
printf("%02x",rawtx->redeemscript[i]);
//for (i=0; i<rawtx->I.redeemlen; i++)
// printf("%02x",rawtx->redeemscript[i]);
bitcoin_address(redeemaddr,rawtx->coin->taddr,rawtx->coin->p2shtype,rawtx->redeemscript,rawtx->I.redeemlen);
printf(" received redeemscript.(%s) %s taddr.%d\n",redeemaddr,rawtx->coin->symbol,rawtx->coin->taddr);
//printf(" received redeemscript.(%s) %s taddr.%d\n",redeemaddr,rawtx->coin->symbol,rawtx->coin->taddr);
LP_swap_coinaddr(rawtx->coin,checkaddr,0,data,datalen,0);
if ( strcmp(redeemaddr,checkaddr) != 0 )
{
Expand Down

0 comments on commit 42e8d9f

Please sign in to comment.