|
@ -20,8 +20,10 @@ |
|
|
|
|
|
|
|
|
struct LP_metricinfo |
|
|
struct LP_metricinfo |
|
|
{ |
|
|
{ |
|
|
|
|
|
double metric; |
|
|
|
|
|
double price,balance,minvol; |
|
|
bits256 pubkey; |
|
|
bits256 pubkey; |
|
|
double metric,price,balance,minvol,maxvol; |
|
|
double maxvol; |
|
|
int32_t ind,numutxos,age,pendingswaps; |
|
|
int32_t ind,numutxos,age,pendingswaps; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -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); |
|
|
int32_t n; double metric,origmetric = (mp->price / bestprice); |
|
|
metric = origmetric; |
|
|
metric = origmetric; |
|
|
if ( mp->numutxos == 0 || relvolume == 0. || mp->maxvol == 0. || mp->balance == 0. ) |
|
|
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.); |
|
|
return(metric * 100.); |
|
|
|
|
|
} |
|
|
if ( relvolume < mp->minvol ) |
|
|
if ( relvolume < mp->minvol ) |
|
|
{ |
|
|
{ |
|
|
metric *= (mp->minvol / relvolume); |
|
|
metric *= (mp->minvol / relvolume); |
|
@ -205,8 +210,8 @@ double _LP_RTmetric_calc(struct LP_metricinfo *mp,double bestprice,double maxpri |
|
|
if ( (n= mp->pendingswaps) > 0 ) |
|
|
if ( (n= mp->pendingswaps) > 0 ) |
|
|
while ( n-- > 0 ) |
|
|
while ( n-- > 0 ) |
|
|
metric *= 1.1; |
|
|
metric *= 1.1; |
|
|
if ( metric != origmetric ) |
|
|
//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); |
|
|
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); |
|
|
return(metric); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -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 *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; |
|
|
groupi = -1; |
|
|
bestprice = 0.; |
|
|
bestprice = 0.; |
|
|
for (num=i=0; i<numasks; i++) |
|
|
for (num=i=0; i<numasks; i++) |
|
@ -241,7 +246,7 @@ cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,dou |
|
|
groupi = i; |
|
|
groupi = i; |
|
|
num++; |
|
|
num++; |
|
|
} |
|
|
} |
|
|
if ( 0 && groupi > 0 ) |
|
|
if ( groupi > 0 ) |
|
|
{ |
|
|
{ |
|
|
sortbuf = calloc(groupi+1,sizeof(*sortbuf)); |
|
|
sortbuf = calloc(groupi+1,sizeof(*sortbuf)); |
|
|
prevdepth = 0.; |
|
|
prevdepth = 0.; |
|
@ -255,7 +260,7 @@ cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,dou |
|
|
array = cJSON_CreateArray(); |
|
|
array = cJSON_CreateArray(); |
|
|
for (i=0; i<=groupi; i++) |
|
|
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); |
|
|
item = jitem(rawasks,sortbuf[i].ind); |
|
|
jaddi(array,jduplicate(item)); |
|
|
jaddi(array,jduplicate(item)); |
|
|
} |
|
|
} |
|
@ -263,6 +268,6 @@ cJSON *LP_RTmetrics_sort(char *base,char *rel,cJSON *rawasks,int32_t numasks,dou |
|
|
jaddi(array,jduplicate(jitem(rawasks,i))); |
|
|
jaddi(array,jduplicate(jitem(rawasks,i))); |
|
|
printf("new ask order for %d of %d, capped at num.%d\n",groupi,numasks,num); |
|
|
printf("new ask order for %d of %d, capped at num.%d\n",groupi,numasks,num); |
|
|
free(sortbuf); |
|
|
free(sortbuf); |
|
|
} else array = rawasks; |
|
|
} |
|
|
return(array); |
|
|
return(array); |
|
|
} |
|
|
} |
|
|