|
|
@ -258,7 +258,7 @@ char *LP_portfolio_goal(char *symbol,double goal) |
|
|
|
return(-1); |
|
|
|
}*/ |
|
|
|
|
|
|
|
void LP_autopriceset(void *ctx,int32_t dir,struct LP_priceinfo *basepp,struct LP_priceinfo *relpp,double price,char *refbase,char *refrel) |
|
|
|
void LP_autopriceset(int32_t ind,void *ctx,int32_t dir,struct LP_priceinfo *basepp,struct LP_priceinfo *relpp,double price,char *refbase,char *refrel) |
|
|
|
{ |
|
|
|
static uint32_t lasttime; |
|
|
|
double margin,minprice,newprice,oppomargin,fixedprice,factor,offset; double bid,ask; int32_t changed; |
|
|
@ -296,8 +296,15 @@ void LP_autopriceset(void *ctx,int32_t dir,struct LP_priceinfo *basepp,struct LP |
|
|
|
else newprice = (price * (1. + margin)); |
|
|
|
if ( (minprice= basepp->minprices[relpp->ind]) == 0. || price >= minprice ) |
|
|
|
{ |
|
|
|
if ( ind >= 0 ) |
|
|
|
{ |
|
|
|
if ( LP_autorefs[ind].lastask < SMALLVAL ) |
|
|
|
LP_autorefs[ind].lastask = newprice; |
|
|
|
else LP_autorefs[ind].lastask = (LP_autorefs[ind].lastask * 0.9) + (0.1 *newprice); |
|
|
|
newprice = LP_autorefs[ind].lastask; |
|
|
|
//printf("autopriceset %s/%s <- %.8f %.8f (%.8f %.8f)\n",basepp->symbol,relpp->symbol,price,newprice,LP_autorefs[ind].lastbid,LP_autorefs[ind].lastask);
|
|
|
|
} |
|
|
|
LP_mypriceset(&changed,relpp->symbol,basepp->symbol,newprice); |
|
|
|
//printf("autoprice changed.%d %s/%s <- %.8f\n",changed,basepp->symbol,relpp->symbol,price);
|
|
|
|
if ( changed != 0 || time(NULL) > lasttime+LP_ORDERBOOK_DURATION*.777) |
|
|
|
{ |
|
|
|
lasttime = (uint32_t)time(NULL); |
|
|
@ -384,8 +391,8 @@ double LP_pricesparse(void *ctx,int32_t trexflag,char *retstr,struct LP_priceinf |
|
|
|
//printf("have trex: iter.%d trexflag.%d %s %.8f %.8f\n",iter,trexflag,symbol,coinpp->bid[1],coinpp->ask[1]);
|
|
|
|
continue; |
|
|
|
} |
|
|
|
LP_autopriceset(ctx,1,coinpp,refpp,price,0,0); |
|
|
|
LP_autopriceset(ctx,-1,refpp,coinpp,price,0,0); |
|
|
|
LP_autopriceset(-1,ctx,1,coinpp,refpp,price,0,0); |
|
|
|
LP_autopriceset(-1,ctx,-1,refpp,coinpp,price,0,0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -470,8 +477,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
{ |
|
|
|
//printf("(%s %.8f %.8f) ",CURRENCIES[i],jdouble(retjson,"price"),jdouble(retjson,"invprice"));
|
|
|
|
price = jdouble(retjson,"price"); |
|
|
|
LP_autopriceset(ctx,1,fiatpp,kmdpp,price,0,0); |
|
|
|
LP_autopriceset(ctx,-1,kmdpp,fiatpp,price,0,0); |
|
|
|
LP_autopriceset(-1,ctx,1,fiatpp,kmdpp,price,0,0); |
|
|
|
LP_autopriceset(-1,ctx,-1,kmdpp,fiatpp,price,0,0); |
|
|
|
free_json(retjson); |
|
|
|
} |
|
|
|
} |
|
|
@ -494,8 +501,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
if ( bidsatoshis != 0 && asksatoshis != 0 ) |
|
|
|
price = 0.5 * dstr(bidsatoshis + asksatoshis) * nxtkmd; |
|
|
|
} |
|
|
|
LP_autopriceset(ctx,1,nxtpp,kmdpp,price,0,0); |
|
|
|
LP_autopriceset(ctx,-1,kmdpp,nxtpp,price,0,0); |
|
|
|
LP_autopriceset(-1,ctx,1,nxtpp,kmdpp,price,0,0); |
|
|
|
LP_autopriceset(-1,ctx,-1,kmdpp,nxtpp,price,0,0); |
|
|
|
//printf("%s %s -> (%s) nxtkmd %.8f %.8f %.8f\n",assetids[i][1],assetids[i][0],jprint(retjson,0),nxtkmd,0.5*dstr(bidsatoshis + asksatoshis),price);
|
|
|
|
free_json(retjson); |
|
|
|
} |
|
|
@ -534,7 +541,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
newprice = (1. / price) * (1. + margin); |
|
|
|
if ( LP_autorefs[i].lastbid < SMALLVAL ) |
|
|
|
LP_autorefs[i].lastbid = newprice; |
|
|
|
else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.5) + (0.5 *newprice); |
|
|
|
else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.9) + (0.1 *newprice); |
|
|
|
newprice = LP_autorefs[i].lastbid; |
|
|
|
LP_mypriceset(&changed,rel,base,newprice); |
|
|
|
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); |
|
|
@ -547,7 +554,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
newprice = (price * (1. + margin)); |
|
|
|
if ( LP_autorefs[i].lastask < SMALLVAL ) |
|
|
|
LP_autorefs[i].lastask = newprice; |
|
|
|
else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.5) + (0.5 *newprice); |
|
|
|
else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 *newprice); |
|
|
|
newprice = LP_autorefs[i].lastask; |
|
|
|
LP_mypriceset(&changed,base,rel,newprice); |
|
|
|
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); |
|
|
@ -573,10 +580,18 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
if ( factor > 0. ) |
|
|
|
price = (price * factor) + offset; |
|
|
|
newprice = (price * (1. + margin)); |
|
|
|
if ( LP_autorefs[i].lastbid < SMALLVAL ) |
|
|
|
LP_autorefs[i].lastbid = newprice; |
|
|
|
else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.9) + (0.1 *newprice); |
|
|
|
newprice = LP_autorefs[i].lastbid; |
|
|
|
LP_mypriceset(&changed,rel,base,newprice); |
|
|
|
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); |
|
|
|
//printf("price %.8f margin %.8f newprice %.8f %.8f\n",price,margin,newprice,(1. / price) * (1. + margin));
|
|
|
|
newprice = (1. / price) * (1. + margin); |
|
|
|
if ( LP_autorefs[i].lastask < SMALLVAL ) |
|
|
|
LP_autorefs[i].lastask = newprice; |
|
|
|
else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 *newprice); |
|
|
|
newprice = LP_autorefs[i].lastask; |
|
|
|
LP_mypriceset(&changed,base,rel,newprice); |
|
|
|
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); |
|
|
|
} |
|
|
@ -587,8 +602,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
relpp = LP_priceinfofind(rel); |
|
|
|
if ( basepp != 0 && relpp != 0 ) |
|
|
|
{ |
|
|
|
//printf("check ref-autoprice %s/%s %f %f\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel,relpp->fixedprices[basepp->ind],basepp->fixedprices[relpp->ind]);
|
|
|
|
LP_autopriceset(ctx,1,basepp,relpp,0.,LP_autorefs[i].refbase,LP_autorefs[i].refrel); |
|
|
|
//printf("check ref-autoprice %s/%s %f %f (%.8f %.8f)\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel,relpp->fixedprices[basepp->ind],basepp->fixedprices[relpp->ind],LP_autorefs[i].lastbid,LP_autorefs[i].lastask);
|
|
|
|
LP_autopriceset(i,ctx,1,basepp,relpp,0.,LP_autorefs[i].refbase,LP_autorefs[i].refrel); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -596,7 +611,32 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
|
|
|
|
void LP_autoprices_update(char *method,char *base,double basevol,char *rel,double relvol) |
|
|
|
{ |
|
|
|
//printf("%s: autoprice update %s/%s %.8f\n",method,base,rel,relvol/basevol);
|
|
|
|
int32_t i; double price,newprice; |
|
|
|
if ( basevol > 0. && relvol > 0. ) |
|
|
|
{ |
|
|
|
price = relvol/basevol; |
|
|
|
for (i=0; i<num_LP_autorefs; i++) |
|
|
|
{ |
|
|
|
if ( strcmp(LP_autorefs[i].rel,rel) == 0 && strcmp(base,LP_autorefs[i].base) == 0 ) |
|
|
|
{ |
|
|
|
newprice = (LP_autorefs[i].lastask * 0.99) + (0.01 * price); |
|
|
|
if ( LP_autorefs[i].lastask > 0 ) |
|
|
|
{ |
|
|
|
printf("%s: autoprice ask update %s/%s %.8f vs myprice %.8f/%.8f -> %.8f\n",method,base,rel,price,LP_autorefs[i].lastbid,LP_autorefs[i].lastask,newprice); |
|
|
|
LP_autorefs[i].lastask = newprice; |
|
|
|
} // else printf("%s: autoprice ask skip update %s/%s %.8f vs myprice %.8f/%.8f -> %.8f\n",method,base,rel,price,LP_autorefs[i].lastbid,LP_autorefs[i].lastask,newprice);
|
|
|
|
} |
|
|
|
else if ( strcmp(LP_autorefs[i].rel,base) == 0 && strcmp(rel,LP_autorefs[i].base) == 0 ) |
|
|
|
{ |
|
|
|
newprice = (LP_autorefs[i].lastbid * 0.99) + (0.01 * price); |
|
|
|
if ( LP_autorefs[i].lastbid > 0 ) |
|
|
|
{ |
|
|
|
printf("%s: autoprice bid update %s/%s %.8f vs myprice %.8f/%.8f -> %.8f\n",method,base,rel,price,LP_autorefs[i].lastbid,LP_autorefs[i].lastask,newprice); |
|
|
|
LP_autorefs[i].lastbid = newprice; |
|
|
|
} // else printf("%s: autoprice bid skip update %s/%s %.8f vs myprice %.8f/%.8f -> %.8f\n",method,base,rel,price,LP_autorefs[i].lastbid,LP_autorefs[i].lastask,newprice);
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) |
|
|
|