|
|
@ -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("autoprice changed.%d %s/%s <- %.8f %.8f\n",changed,basepp->symbol,relpp->symbol,price,newprice); |
|
|
|
} |
|
|
|
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); |
|
|
|
} |
|
|
@ -596,7 +603,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
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); |
|
|
|
LP_autopriceset(i,ctx,1,basepp,relpp,0.,LP_autorefs[i].refbase,LP_autorefs[i].refrel); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -613,7 +620,7 @@ void LP_autoprices_update(char *method,char *base,double basevol,char *rel,doubl |
|
|
|
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 && price < LP_autorefs[i].lastask ) |
|
|
|
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; |
|
|
@ -623,7 +630,7 @@ void LP_autoprices_update(char *method,char *base,double basevol,char *rel,doubl |
|
|
|
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 && price > LP_autorefs[i].lastbid ) |
|
|
|
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; |
|
|
|