From 19b93b1706563e91a75f571de5b893f131679a2c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Feb 2018 02:11:25 +0200 Subject: [PATCH] Tweak margins --- iguana/exchanges/LP_portfolio.c | 4 ++-- iguana/exchanges/LP_prices.c | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 14a60c5d5..70a1d7f0e 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -542,12 +542,12 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) bidprice = (1. / price * (1. + buymargin)); if ( LP_autorefs[i].lastbid < SMALLVAL ) LP_autorefs[i].lastbid = bidprice; - else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.99) + (0.01 * bidprice); + else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.9) + (0.1 * bidprice); bidprice = LP_autorefs[i].lastbid; askprice = price * (1. + sellmargin); if ( LP_autorefs[i].lastask < SMALLVAL ) LP_autorefs[i].lastask = askprice; - else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.99) + (0.01 * askprice); + else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 * askprice); askprice = LP_autorefs[i].lastask; LP_mypriceset(&changed,rel,base,bidprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,bidprice); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index a887331da..38c431ea9 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -512,7 +512,7 @@ char *LP_myprices() int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) { - struct LP_priceinfo *basepp,*relpp; struct LP_pubkey_info *pubp; double minprice,maxprice; + struct LP_priceinfo *basepp,*relpp; struct LP_pubkey_info *pubp; double minprice,maxprice,margin,buymargin,sellmargin; *changedp = 0; //if ( strcmp("DEX",base) == 0 || strcmp("DEX",rel) == 0 ) // printf("%s/%s setprice %.8f\n",base,rel,price); @@ -521,6 +521,9 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) if ( price == 0. || fabs(basepp->myprices[relpp->ind] - price)/price > 0.001 ) *changedp = 1; + sellmargin = relpp->sellmargins[basepp->ind]; + buymargin = relpp->buymargins[basepp->ind]; + margin = (sellmargin + buymargin) * 0.5; if ( price == 0. ) { relpp->minprices[basepp->ind] = 0.; @@ -529,18 +532,19 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) relpp->sellmargins[basepp->ind] = 0.; relpp->offsets[basepp->ind] = 0.; relpp->factors[basepp->ind] = 0.; + margin = 0.; } else if ( (minprice= basepp->minprices[relpp->ind]) > SMALLVAL && price < minprice ) { printf("%s/%s price %.8f less than minprice %.8f\n",base,rel,price,minprice); - price = minprice; + price = minprice * (1. - margin); } else if ( (maxprice= relpp->minprices[basepp->ind]) > SMALLVAL ) { if ( price > (1. / maxprice) ) { printf("%s/%s price %.8f less than maxprice %.8f, more than %.8f\n",base,rel,price,maxprice,1./maxprice); - price = (1. / maxprice); + price = (1. / maxprice) * (1. + margin); } } /*else if ( basepp->myprices[relpp->ind] > SMALLVAL )