diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 987801ba6..de7470a9a 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1507,7 +1507,9 @@ char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,cha { relvolume = dstr(maxutxo) - dstr(desttxfee)*3; printf("maxutxo %.8f relvolume %.8f desttxfee %.8f\n",dstr(maxutxo),relvolume,dstr(desttxfee)); - maxprice = LP_fomoprice(base,rel,relvolume); + maxprice = LP_fomoprice(base,rel,&relvolume); + printf("fomoprice %.8f relvolume %.8f\n",maxprice,relvolume); +maxprice = 0.; } else printf("no utxo available\n"); } if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index a5ca0a46f..d09d13aee 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -969,9 +969,10 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) return(jprint(retjson,1)); } -double LP_fomoprice(char *base,char *rel,double relvolume) +double LP_fomoprice(char *base,char *rel,double *relvolumep) { - char *retstr; cJSON *retjson,*asks,*item; int32_t i,numasks; double biggest,price,fomoprice = 0.; + char *retstr; cJSON *retjson,*asks,*item; int32_t i,numasks; double maxvol=0.,relvolume,biggest,price,fomoprice = 0.; + relvolume = *relvolumep; if ( (retstr= LP_orderbook(base,rel,0)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) @@ -983,13 +984,24 @@ double LP_fomoprice(char *base,char *rel,double relvolume) item = jitem(asks,i); biggest = jdouble(item,"maxvolume"); price = jdouble(item,"price"); - printf("fomoprice (%.8f) i.%d %.8f vol %.8f\n",relvolume,i,price,biggest); + if ( biggest > maxvol ) + { + maxvol = biggest; + fomoprice = price; + } + printf("fomoprice (%.8f) i.%d %.8f vol %.8f [max %.8f @ %.8f]\n",relvolume,i,price,biggest,maxvol,fomoprice); } } free_json(retjson); } free(retstr); } + if ( maxvol > 0. && maxvol < relvolume && fomoprice > 0. ) + { + relvolume = maxvol * 0.98; + fomoprice /= 0.99; + } else *fomoprice = 0.; + *relvolumep = relvolume; return(fomoprice); }