|
|
@ -23,7 +23,7 @@ struct LP_portfoliotrade { double metric; char buycoin[65],sellcoin[65]; }; |
|
|
|
struct LP_autoprice_ref |
|
|
|
{ |
|
|
|
char refbase[65],refrel[65],base[65],rel[65],fundbid[16],fundask[16]; |
|
|
|
double margin,factor,offset,lastbid,lastask; |
|
|
|
double buymargin,sellmargin,factor,offset,lastbid,lastask; |
|
|
|
cJSON *fundvalue; |
|
|
|
uint32_t count; |
|
|
|
} LP_autorefs[1024]; |
|
|
@ -262,8 +262,8 @@ void LP_autopriceset(int32_t ind,void *ctx,int32_t dir,struct LP_priceinfo *base |
|
|
|
{ |
|
|
|
static uint32_t lasttime; |
|
|
|
double margin,minprice,newprice,oppomargin,fixedprice,factor,offset; double bid,ask; int32_t changed; |
|
|
|
margin = basepp->margins[relpp->ind]; |
|
|
|
oppomargin = relpp->margins[basepp->ind]; |
|
|
|
margin = basepp->sellmargins[relpp->ind]; |
|
|
|
oppomargin = basepp->buymargins[relpp->ind]; |
|
|
|
if ( (fixedprice= basepp->fixedprices[relpp->ind]) > SMALLVAL ) |
|
|
|
{ |
|
|
|
LP_mypriceset(&changed,relpp->symbol,basepp->symbol,fixedprice); |
|
|
@ -278,7 +278,7 @@ void LP_autopriceset(int32_t ind,void *ctx,int32_t dir,struct LP_priceinfo *base |
|
|
|
if ( fabs(price) < SMALLVAL && refbase != 0 && refrel != 0 ) |
|
|
|
{ |
|
|
|
price = LP_myprice(&bid,&ask,refbase,refrel); |
|
|
|
//printf("%s/%s USE ref %s/%s %.8f factor %.8f offset %.8f margin %.8f\n",basepp->symbol,relpp->symbol,refbase,refrel,price,factor,offset,margin);
|
|
|
|
//printf("%s/%s USE ref %s/%s %.8f factor %.8f offset %.8f margin %.8f/%.8f\n",basepp->symbol,relpp->symbol,refbase,refrel,price,factor,offset,oppomargin,margin);
|
|
|
|
} |
|
|
|
if ( LP_pricevalid(price) > 0 ) |
|
|
|
{ |
|
|
@ -450,7 +450,7 @@ double LP_tickered_price(int32_t bidask,char *base,char *rel,double price,cJSON |
|
|
|
void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
{ |
|
|
|
static cJSON *tickerjson; static uint32_t lasttime; |
|
|
|
char *retstr,*base,*rel; cJSON *retjson,*bid,*ask,*fundjson,*argjson; uint64_t bidsatoshis,asksatoshis; int32_t i,changed; double bch_usd,bch_btc,nxtkmd,price,factor,offset,newprice,margin,price_btc,price_usd,kmd_btc,kmd_usd; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp,*basepp,*relpp; |
|
|
|
char *retstr,*base,*rel; cJSON *retjson,*bid,*ask,*fundjson,*argjson; uint64_t bidsatoshis,asksatoshis; int32_t i,changed; double bch_usd,bch_btc,nxtkmd,price,factor,offset,newprice,buymargin,sellmargin,price_btc,price_usd,kmd_btc,kmd_usd; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp,*basepp,*relpp; |
|
|
|
if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 ) |
|
|
|
{ |
|
|
|
printf("trex error getting marketsummaries\n"); |
|
|
@ -525,7 +525,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
{ |
|
|
|
rel = LP_autorefs[i].rel; |
|
|
|
base = LP_autorefs[i].base; |
|
|
|
margin = LP_autorefs[i].margin; |
|
|
|
buymargin = LP_autorefs[i].buymargin; |
|
|
|
sellmargin = LP_autorefs[i].sellmargin; |
|
|
|
offset = LP_autorefs[i].offset; |
|
|
|
factor = LP_autorefs[i].factor; |
|
|
|
if ( (argjson= LP_autorefs[i].fundvalue) != 0 ) |
|
|
@ -538,7 +539,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
{ |
|
|
|
if ( tickerjson != 0 && LP_autorefs[i].count == 0 ) |
|
|
|
price = LP_tickered_price(0,base,rel,price,tickerjson); |
|
|
|
newprice = (1. / price) * (1. + margin); |
|
|
|
newprice = (1. / price) * (1. + buymargin); |
|
|
|
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); |
|
|
@ -551,7 +552,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
{ |
|
|
|
if ( tickerjson != 0 && LP_autorefs[i].count == 0 ) |
|
|
|
price = LP_tickered_price(1,base,rel,price,tickerjson); |
|
|
|
newprice = (price * (1. + margin)); |
|
|
|
newprice = (price * (1. + sellmargin)); |
|
|
|
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); |
|
|
@ -567,27 +568,27 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) |
|
|
|
} |
|
|
|
else if ( strcmp(LP_autorefs[i].refrel,"coinmarketcap") == 0 ) |
|
|
|
{ |
|
|
|
//printf("%s/%s for %s/%s margin %.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,margin);
|
|
|
|
//printf("%s/%s for %s/%s margin %.8f/%.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,buymargin,sellmargin);
|
|
|
|
if ( (price_btc= LP_CMCbtcprice(&price_usd,LP_autorefs[i].refbase)) > SMALLVAL ) |
|
|
|
{ |
|
|
|
if ( strcmp(rel,"KMD") == 0 ) |
|
|
|
if ( strcmp(rel,"KMD") == 0 && kmd_btc > SMALLVAL ) |
|
|
|
price = kmd_btc / price_btc; |
|
|
|
else if ( strcmp(rel,"BCH") == 0 ) |
|
|
|
else if ( strcmp(rel,"BCH") == 0 && bch_btc > SMALLVAL ) |
|
|
|
price = bch_btc / price_btc; |
|
|
|
else if ( strcmp(rel,"BTC") == 0 ) |
|
|
|
price = 1. / price_btc; |
|
|
|
else continue; |
|
|
|
if ( factor > 0. ) |
|
|
|
price = (price * factor) + offset; |
|
|
|
newprice = (price * (1. + margin)); |
|
|
|
newprice = (price * (1. + buymargin)); |
|
|
|
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); |
|
|
|
//printf("price %.8f margin %.8f/%.8f newprice %.8f %.8f\n",price,buymargin,sellmargin,newprice,(1. / price) * (1. + buymargin));
|
|
|
|
newprice = (1. / price) * (1. + sellmargin); |
|
|
|
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); |
|
|
@ -642,20 +643,30 @@ void LP_autoprices_update(char *method,char *base,double basevol,char *rel,doubl |
|
|
|
int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) |
|
|
|
{ |
|
|
|
//curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"MNZ\",\"rel\":\"KMD\",\"offset\":0.1,\"refbase\":\"KMD\",\refrel\":\"BTC\",\"factor\":15000,\"margin\":0.01}"
|
|
|
|
struct LP_priceinfo *basepp,*relpp; int32_t i,retval = -1; char *fundvalue_bid,*fundvalue_ask,*refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; cJSON *fundvalue; |
|
|
|
struct LP_priceinfo *basepp,*relpp; int32_t i,retval = -1; char *fundvalue_bid,*fundvalue_ask,*refbase="",*refrel=""; double margin,minprice,buymargin,sellmargin,offset,factor,fixedprice; cJSON *fundvalue; |
|
|
|
//printf("autoprice.(%s %s) %s\n",base,rel,jprint(argjson,0));
|
|
|
|
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 ) |
|
|
|
{ |
|
|
|
if ( jobj(argjson,"minprice") != 0 ) |
|
|
|
minprice = jdouble(argjson,"minprice"); |
|
|
|
else minprice = 0.; |
|
|
|
margin = jdouble(argjson,"margin"); |
|
|
|
if ( (margin= jdouble(argjson,"margin")) == 0. ) |
|
|
|
{ |
|
|
|
buymargin = jdouble(argjson,"buymargin"); |
|
|
|
sellmargin = jdouble(argjson,"sellmargin"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
buymargin = margin; |
|
|
|
sellmargin = margin; |
|
|
|
} |
|
|
|
offset = jdouble(argjson,"offset"); |
|
|
|
factor = jdouble(argjson,"factor"); |
|
|
|
fixedprice = jdouble(argjson,"fixed"); |
|
|
|
basepp->fixedprices[relpp->ind] = fixedprice; |
|
|
|
basepp->minprices[relpp->ind] = minprice; |
|
|
|
basepp->margins[relpp->ind] = margin; |
|
|
|
basepp->buymargins[relpp->ind] = buymargin; |
|
|
|
basepp->sellmargins[relpp->ind] = sellmargin; |
|
|
|
basepp->offsets[relpp->ind] = offset; |
|
|
|
basepp->factors[relpp->ind] = factor; |
|
|
|
refbase = jstr(argjson,"refbase"); |
|
|
@ -682,7 +693,8 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) |
|
|
|
safecopy(LP_autorefs[i].fundbid,fundvalue_bid,sizeof(LP_autorefs[i].fundbid)); |
|
|
|
safecopy(LP_autorefs[i].fundask,fundvalue_ask,sizeof(LP_autorefs[i].fundask)); |
|
|
|
} |
|
|
|
LP_autorefs[i].margin = margin; |
|
|
|
LP_autorefs[i].buymargin = buymargin; |
|
|
|
LP_autorefs[i].sellmargin = sellmargin; |
|
|
|
LP_autorefs[i].factor = factor; |
|
|
|
LP_autorefs[i].offset = offset; |
|
|
|
safecopy(LP_autorefs[i].refbase,refbase,sizeof(LP_autorefs[i].refbase)); |
|
|
@ -702,14 +714,15 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) |
|
|
|
safecopy(LP_autorefs[num_LP_autorefs].fundbid,fundvalue_bid,sizeof(LP_autorefs[num_LP_autorefs].fundbid)); |
|
|
|
safecopy(LP_autorefs[num_LP_autorefs].fundask,fundvalue_ask,sizeof(LP_autorefs[num_LP_autorefs].fundask)); |
|
|
|
} |
|
|
|
LP_autorefs[num_LP_autorefs].margin = margin; |
|
|
|
LP_autorefs[i].buymargin = buymargin; |
|
|
|
LP_autorefs[i].sellmargin = sellmargin; |
|
|
|
LP_autorefs[num_LP_autorefs].factor = factor; |
|
|
|
LP_autorefs[num_LP_autorefs].offset = offset; |
|
|
|
safecopy(LP_autorefs[num_LP_autorefs].refbase,refbase,sizeof(LP_autorefs[num_LP_autorefs].refbase)); |
|
|
|
safecopy(LP_autorefs[num_LP_autorefs].refrel,refrel,sizeof(LP_autorefs[num_LP_autorefs].refrel)); |
|
|
|
safecopy(LP_autorefs[num_LP_autorefs].base,base,sizeof(LP_autorefs[num_LP_autorefs].base)); |
|
|
|
safecopy(LP_autorefs[num_LP_autorefs].rel,rel,sizeof(LP_autorefs[num_LP_autorefs].rel)); |
|
|
|
printf("%d Using ref %s/%s for %s/%s factor %.8f, offset %.8f, margin %.8f fixed %.8f\n",num_LP_autorefs,refbase,refrel,base,rel,factor,offset,margin,fixedprice); |
|
|
|
printf("%d Using ref %s/%s for %s/%s factor %.8f, offset %.8f, margin %.8f/%.8f fixed %.8f\n",num_LP_autorefs,refbase,refrel,base,rel,factor,offset,buymargin,sellmargin,fixedprice); |
|
|
|
num_LP_autorefs++; |
|
|
|
} |
|
|
|
} |
|
|
|