From 2f93b99037cc61a5f0428b3be9ed40aad6b41497 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 13:40:50 +0300 Subject: [PATCH 01/13] Test --- iguana/exchanges/LP_portfolio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 8dd603178..6dac2a7e8 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -582,7 +582,10 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) price = 1. / price_btc; else continue; if ( factor > 0. ) + { + printf("price %.8f -> factor %.8f %.8f\n",price,factor,(price * factor) + offset); price = (price * factor) + offset; + } newprice = (price * (1. + buymargin)); if ( LP_autorefs[i].lastbid < SMALLVAL ) LP_autorefs[i].lastbid = newprice; From 47665d696803454dfeeaec86a5401c6b8b061bfa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 13:47:29 +0300 Subject: [PATCH 02/13] Test --- iguana/exchanges/LP_portfolio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 6dac2a7e8..34423f068 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -576,6 +576,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) { if ( strcmp(rel,"KMD") == 0 && kmd_btc > SMALLVAL ) price = kmd_btc / price_btc; + else if ( strcmp(rel,"USD") == 0 && price_usd > SMALLVAL ) + price = 1. / price_usd; else if ( strcmp(rel,"BCH") == 0 && bch_btc > SMALLVAL ) price = bch_btc / price_btc; else if ( strcmp(rel,"BTC") == 0 ) @@ -583,22 +585,26 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) else continue; if ( factor > 0. ) { - printf("price %.8f -> factor %.8f %.8f\n",price,factor,(price * factor) + offset); + printf("USD %.8f KMDBTC %.8f pricebtc %.8f price %.8f -> factor %.8f %.8f\n",price_usd,kmd_btc,price_btc,price,factor,(price * factor) + offset); price = (price * factor) + offset; } newprice = (price * (1. + buymargin)); + printf("b newprice %.8f\n",newprice); if ( LP_autorefs[i].lastbid < SMALLVAL ) LP_autorefs[i].lastbid = newprice; else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.99) + (0.01 * newprice); newprice = LP_autorefs[i].lastbid; + printf("b2 newprice %.8f\n",newprice); LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); //printf("%s/%s price %.8f margin %.8f/%.8f newprice %.8f %.8f\n",base,rel,price,buymargin,sellmargin,newprice,(1. / newprice) * (1. + sellmargin)); newprice = (1. / price) * (1. + sellmargin); + printf("a newprice %.8f\n",newprice); if ( LP_autorefs[i].lastask < SMALLVAL ) LP_autorefs[i].lastask = newprice; else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.99) + (0.01 * newprice); newprice = LP_autorefs[i].lastask; + printf("a2 newprice %.8f\n",newprice); LP_mypriceset(&changed,base,rel,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); } From 5c2533605af095fe8eef235c4fdfaa96ee01f4ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 13:54:59 +0300 Subject: [PATCH 03/13] Test --- iguana/exchanges/LP_portfolio.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 34423f068..1cce71093 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -22,7 +22,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]; + char refbase[65],refrel[65],base[65],rel[65],fundbid[16],fundask[16],usdpeg; double buymargin,sellmargin,factor,offset,lastbid,lastask; cJSON *fundvalue; uint32_t count; @@ -574,15 +574,22 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) //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 && kmd_btc > SMALLVAL ) - price = kmd_btc / price_btc; - else if ( strcmp(rel,"USD") == 0 && price_usd > SMALLVAL ) - price = 1. / price_usd; - 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 ( LP_autorefs[i].usdpeg != 0 ) + { + if ( price_usd > SMALLVAL ) + price = 1. / price_usd; + else continue; + } + else + { + if ( strcmp(rel,"KMD") == 0 && kmd_btc > SMALLVAL ) + price = kmd_btc / price_btc; + 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. ) { printf("USD %.8f KMDBTC %.8f pricebtc %.8f price %.8f -> factor %.8f %.8f\n",price_usd,kmd_btc,price_btc,price,factor,(price * factor) + offset); @@ -728,8 +735,9 @@ 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[i].buymargin = buymargin; - LP_autorefs[i].sellmargin = sellmargin; + LP_autorefs[num_LP_autorefs].usdpeg = juint(argjson,"usdpeg"); + LP_autorefs[num_LP_autorefs].buymargin = buymargin; + LP_autorefs[num_LP_autorefs].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)); From b0b0db064f68cb856c42c370992f50877bcfec3d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 13:58:31 +0300 Subject: [PATCH 04/13] Test --- iguana/exchanges/LP_portfolio.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 1cce71093..ee8a77d58 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -577,7 +577,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) if ( LP_autorefs[i].usdpeg != 0 ) { if ( price_usd > SMALLVAL ) - price = 1. / price_usd; + price = price_usd; else continue; } else @@ -592,26 +592,22 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) } if ( factor > 0. ) { - printf("USD %.8f KMDBTC %.8f pricebtc %.8f price %.8f -> factor %.8f %.8f\n",price_usd,kmd_btc,price_btc,price,factor,(price * factor) + offset); + //printf("USD %.8f KMDBTC %.8f pricebtc %.8f price %.8f -> factor %.8f %.8f\n",price_usd,kmd_btc,price_btc,price,factor,(price * factor) + offset); price = (price * factor) + offset; } newprice = (price * (1. + buymargin)); - printf("b newprice %.8f\n",newprice); if ( LP_autorefs[i].lastbid < SMALLVAL ) LP_autorefs[i].lastbid = newprice; else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.99) + (0.01 * newprice); newprice = LP_autorefs[i].lastbid; - printf("b2 newprice %.8f\n",newprice); LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); //printf("%s/%s price %.8f margin %.8f/%.8f newprice %.8f %.8f\n",base,rel,price,buymargin,sellmargin,newprice,(1. / newprice) * (1. + sellmargin)); newprice = (1. / price) * (1. + sellmargin); - printf("a newprice %.8f\n",newprice); if ( LP_autorefs[i].lastask < SMALLVAL ) LP_autorefs[i].lastask = newprice; else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.99) + (0.01 * newprice); newprice = LP_autorefs[i].lastask; - printf("a2 newprice %.8f\n",newprice); LP_mypriceset(&changed,base,rel,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); } From c9d27a4e0d3fe4fbc0583ba4c83f4c94c482911c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 14:01:34 +0300 Subject: [PATCH 05/13] Test --- iguana/exchanges/LP_portfolio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index ee8a77d58..b2240a642 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -592,7 +592,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) } if ( factor > 0. ) { - //printf("USD %.8f KMDBTC %.8f pricebtc %.8f price %.8f -> factor %.8f %.8f\n",price_usd,kmd_btc,price_btc,price,factor,(price * factor) + offset); + printf("USD %.8f KMDBTC %.8f pricebtc %.8f price %.8f -> factor %.8f %.8f\n",price_usd,kmd_btc,price_btc,price,factor,(price * factor) + offset); price = (price * factor) + offset; } newprice = (price * (1. + buymargin)); From 8542d6870a3adf976a269f1c14ff098ae1d8c91c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 14:06:48 +0300 Subject: [PATCH 06/13] Test --- iguana/exchanges/LP_portfolio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index b2240a642..9bd158908 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -577,7 +577,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) if ( LP_autorefs[i].usdpeg != 0 ) { if ( price_usd > SMALLVAL ) - price = price_usd; + price = 1. / price_usd; else continue; } else From 4b6e001e6da0c8a57ddf2d9772596cec047df17a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 14:15:07 +0300 Subject: [PATCH 07/13] Autoprice with USD pegs --- iguana/exchanges/LP_portfolio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 9bd158908..73d621e1e 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -592,7 +592,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) } if ( factor > 0. ) { - printf("USD %.8f KMDBTC %.8f pricebtc %.8f price %.8f -> factor %.8f %.8f\n",price_usd,kmd_btc,price_btc,price,factor,(price * factor) + offset); + //printf("USD %.8f KMDBTC %.8f pricebtc %.8f price %.8f -> factor %.8f %.8f\n",price_usd,kmd_btc,price_btc,price,factor,(price * factor) + offset); price = (price * factor) + offset; } newprice = (price * (1. + buymargin)); From e9e75f440a8b82b75cc2bcb8206b4e1743eb5275 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 14:15:58 +0300 Subject: [PATCH 08/13] auto_usd script --- iguana/exchanges/auto_usd | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 iguana/exchanges/auto_usd diff --git a/iguana/exchanges/auto_usd b/iguana/exchanges/auto_usd new file mode 100644 index 000000000..3dfa13808 --- /dev/null +++ b/iguana/exchanges/auto_usd @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"OOT\",\"factor\":0.15,\"buymargin\":0.0001,\"sellmargin\":0.2,\"refbase\":\"komodo\",\"refrel\":\"coinmarketcap\",\"usdpeg\":1}" From 3a6702de3da5c0a204806c54ccd271b649b667ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 15:40:19 +0300 Subject: [PATCH 09/13] Test --- iguana/exchanges/LP_portfolio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 73d621e1e..6224c527f 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -571,7 +571,7 @@ 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/%.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,buymargin,sellmargin); + 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 ( LP_autorefs[i].usdpeg != 0 ) @@ -610,7 +610,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) newprice = LP_autorefs[i].lastask; LP_mypriceset(&changed,base,rel,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); - } + } else printf("null return from CMC\n"); } else { From aecefe88b24281a04c148932341838de75d139f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 15:41:37 +0300 Subject: [PATCH 10/13] Test --- iguana/exchanges/LP_prices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 12e409dda..f2d6aa91a 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -1230,7 +1230,7 @@ double LP_CMCbtcprice(double *price_usdp,char *symbol) item = jitem(ticker,0); price_btc = jdouble(item,"price_btc"); *price_usdp = jdouble(item,"price_usd"); - //printf("%.8f item.(%s)\n",price_btc,jprint(item,0)); +printf("%.8f item.(%s)\n",price_btc,jprint(item,0)); free_json(ticker); } free(retstr); From 6e71bf2b4748c9ef4ecb55c2088e8e63361f69de Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 16:22:00 +0300 Subject: [PATCH 11/13] Test --- iguana/exchanges/LP_portfolio.c | 7 ++++--- iguana/exchanges/LP_prices.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 6224c527f..7f0654d50 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -571,7 +571,7 @@ 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/%.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,buymargin,sellmargin); + //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 ( LP_autorefs[i].usdpeg != 0 ) @@ -871,14 +871,15 @@ void prices_loop(void *ctx) char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; strcpy(prices_loop_stats.name,"prices_loop"); prices_loop_stats.threshold = 600000.; + printf("start prices_loop\n"); while ( LP_STOP_RECEIVED == 0 ) { + printf("G.initializing.%d prices loop autoprices.%d autorefs.%d\n",G.initializing,LP_autoprices,num_LP_autorefs); if ( G.initializing != 0 ) { - sleep(1); + sleep(30); continue; } - //printf("prices loop autoprices.%d autorefs.%d\n",LP_autoprices,num_LP_autorefs); LP_millistats_update(&prices_loop_stats); LP_tradebots_timeslice(ctx); if ( (btcpp= LP_priceinfofind("BTC")) == 0 ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index f2d6aa91a..453825a44 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -1230,7 +1230,7 @@ double LP_CMCbtcprice(double *price_usdp,char *symbol) item = jitem(ticker,0); price_btc = jdouble(item,"price_btc"); *price_usdp = jdouble(item,"price_usd"); -printf("%.8f item.(%s)\n",price_btc,jprint(item,0)); +//printf("%.8f item.(%s)\n",price_btc,jprint(item,0)); free_json(ticker); } free(retstr); From d19918f5fe5ce3570b96a21c6968add5663a3bcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 16:50:59 +0300 Subject: [PATCH 12/13] Fix autopsic when error getting central prices --- iguana/exchanges/LP_portfolio.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 7f0654d50..67247e392 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -463,19 +463,25 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 ) { printf("trex error getting marketsummaries\n"); - sleep(60); - return; + sleep(40); + //return; + } + else + { + nxtkmd = LP_pricesparse(ctx,1,retstr,btcpp); + free(retstr); } - nxtkmd = LP_pricesparse(ctx,1,retstr,btcpp); - free(retstr); if ( (retstr= issue_curlt("https://www.cryptopia.co.nz/api/GetMarkets",LP_HTTP_TIMEOUT*10)) == 0 ) { printf("cryptopia error getting marketsummaries\n"); - sleep(60); - return; + sleep(40); + //return; + } + else + { + LP_pricesparse(ctx,0,retstr,btcpp); + free(retstr); } - LP_pricesparse(ctx,0,retstr,btcpp); - free(retstr); if ( (kmdpp= LP_priceinfofind("KMD")) != 0 ) { for (i=0; i<32; i++) From 6831c382417a626fbdfa6f97f8d9d0b0d0b8fa13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 31 Mar 2018 16:55:28 +0300 Subject: [PATCH 13/13] Test --- iguana/exchanges/LP_portfolio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 67247e392..c7c32cdef 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -616,7 +616,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) newprice = LP_autorefs[i].lastask; LP_mypriceset(&changed,base,rel,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); - } else printf("null return from CMC\n"); + } //else printf("null return from CMC\n"); } else { @@ -880,7 +880,7 @@ void prices_loop(void *ctx) printf("start prices_loop\n"); while ( LP_STOP_RECEIVED == 0 ) { - printf("G.initializing.%d prices loop autoprices.%d autorefs.%d\n",G.initializing,LP_autoprices,num_LP_autorefs); + //printf("G.initializing.%d prices loop autoprices.%d autorefs.%d\n",G.initializing,LP_autoprices,num_LP_autorefs); if ( G.initializing != 0 ) { sleep(30);