From 9efc70d9715b5a254b0b2301a62961c9aad943b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 15:49:51 +0200 Subject: [PATCH 01/19] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 59dc9cf86..103dd6dea 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -913,7 +913,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru return(0); if ( p >= qprice ) break; - price *= 0.99777; + price /= 0.99777; i++; } printf("i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",i,qprice,myprice,price,p); From c7b73c2bc8be919bb8e9889a3015abc3ed7b208b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 15:56:13 +0200 Subject: [PATCH 02/19] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 103dd6dea..9ac3d1396 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -913,7 +913,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru return(0); if ( p >= qprice ) break; - price /= 0.99777; + price /= 0.995; i++; } printf("i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",i,qprice,myprice,price,p); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 04bc97462..c4c75180e 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -665,7 +665,7 @@ again: if ( coin->electrum != 0 ) rate *= 1.5; if ( fabs(rate - coin->rate) > SMALLVAL ) - printf("t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->ratetime,coin->symbol,retstr,rate,coin->rate); + printf("%u t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",(uint32_t)time(NULL),coin->ratetime,coin->symbol,retstr,rate,coin->rate); coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); } @@ -683,7 +683,7 @@ again: double LP_getestimatedrate(struct iguana_info *coin) { - double rate = 0.00000020; + double rate = 0.00000005; if ( coin == 0 ) return(rate); if ( (rate= _LP_getestimatedrate(coin)) <= 0. ) From 5bb888b217b746d725bbf3ab7766d631f73295b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 16:07:13 +0200 Subject: [PATCH 03/19] Test --- iguana/exchanges/LP_rpc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index c4c75180e..7e7fca334 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -678,6 +678,7 @@ again: } } else rate = coin->rate; } else rate = coin->rate; + coin->rate = rate; return(rate); } From 0ac8c910950c35134c14453baa3ea6fb5f4e8d7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 16:07:55 +0200 Subject: [PATCH 04/19] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9ac3d1396..56fc7617b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -887,7 +887,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru //LP_address_utxo_reset(coin); //printf("done LP_address_utxo_reset.%s\n",coin->symbol); i = 0; - while ( i < 100 && price >= myprice ) + while ( i < 33 && price >= myprice ) { if ( (butxo= LP_address_myutxopair(butxo,1,utxos,max,LP_coinfind(qp->srccoin),qp->coinaddr,qp->txfee,dstr(qp->destsatoshis),price,qp->desttxfee)) != 0 ) { @@ -913,7 +913,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru return(0); if ( p >= qprice ) break; - price /= 0.995; + price /= 0.99; i++; } printf("i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",i,qprice,myprice,price,p); From d6ef95125934335a36055d2c1b4c24c479d3432f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 16:17:09 +0200 Subject: [PATCH 05/19] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 56fc7617b..22cdb0b97 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -73,7 +73,7 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen) coin->rate = LP_getestimatedrate(coin); if ( (txfee= SATOSHIDEN * coin->rate * txlen) <= 10000 ) { - coin->rate = -1.; + //coin->rate = -1.; coin->rate = _LP_getestimatedrate(coin); if ( (txfee= SATOSHIDEN * coin->rate * txlen) <= 10000 ) txfee = 10000; diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 7e7fca334..41f568652 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -668,6 +668,7 @@ again: printf("%u t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",(uint32_t)time(NULL),coin->ratetime,coin->symbol,retstr,rate,coin->rate); coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); + printf("set rate %.8f t%u\n",rate,coin->ratetime); } free(retstr); if ( err == 1 && coin->electrum == 0 && strcmp("BTC",coin->symbol) == 0 ) From 18485cf4be237b65fdbc92a79ddc91fcc962764d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 16:18:11 +0200 Subject: [PATCH 06/19] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 41f568652..fa304b3d9 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -671,7 +671,7 @@ again: printf("set rate %.8f t%u\n",rate,coin->ratetime); } free(retstr); - if ( err == 1 && coin->electrum == 0 && strcmp("BTC",coin->symbol) == 0 ) + if ( err == 1 && coin->electrum == 0 && strcmp(coin->estimatefeestr,"estimatefee") == 0 ) { strcpy(coin->estimatefeestr,"estimatesmartfee"); err = 2; From 4928c884ce74308cbca816b373d74f71c04ae944 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 16:26:38 +0200 Subject: [PATCH 07/19] -prints --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 22cdb0b97..65fcfb593 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -187,7 +187,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str desttxfee = qp->desttxfee; if ( qp->satoshis != 0 ) qprice = ((double)qp->destsatoshis / (qp->satoshis-qp->txfee)); - printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee)); + //printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee)); if ( qp->txfee < LP_REQUIRED_TXFEE*txfee || qp->desttxfee < LP_REQUIRED_TXFEE*desttxfee ) { printf("error -14: txfee %.8f >= %.8f or desttxfee %.8f >= %.8f\n",dstr(qp->txfee),dstr(LP_REQUIRED_TXFEE*txfee),dstr(qp->desttxfee),dstr(LP_REQUIRED_TXFEE*desttxfee)); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index fa304b3d9..6cb26a9fa 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -668,7 +668,7 @@ again: printf("%u t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",(uint32_t)time(NULL),coin->ratetime,coin->symbol,retstr,rate,coin->rate); coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); - printf("set rate %.8f t%u\n",rate,coin->ratetime); + //printf("set rate %.8f t%u\n",rate,coin->ratetime); } free(retstr); if ( err == 1 && coin->electrum == 0 && strcmp(coin->estimatefeestr,"estimatefee") == 0 ) From 157342cf70715ec45f7fe4484113f7127ef6b1bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 16:39:47 +0200 Subject: [PATCH 08/19] Test --- iguana/exchanges/LP_rpc.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 6cb26a9fa..52a4ab85a 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -616,6 +616,17 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag) } else return(cJSON_Parse("{\"result\":\"success\"}")); } +cJSON *LP_bitcoinfees() +{ + char *retstr; cJSON *retjson = 0; + if ( (retstr= issue_curlt("https://bitcoinfees.earn.com/api/v1/fees/recommended",LP_HTTP_TIMEOUT)) != 0 ) + { + retjson = cJSON_Parse(retstr); + free(retstr); + } + return(retjson); +} + double _LP_getestimatedrate(struct iguana_info *coin) { char buf[512],*retstr=0; int32_t numblocks,err=0; cJSON *errjson,*retjson; double rate = 0.00000005; @@ -632,12 +643,29 @@ again: } else { - if ( (retjson= electrum_estimatefee(coin->symbol,coin->electrum,&retjson,numblocks)) != 0 ) + // {"fastestFee":70,"halfHourFee":70,"hourFee":10} + if ( (retjson= LP_bitcoinfees()) != 0 ) + { + int32_t fastest,half,hour,best=0; + fastest = jint(retjson,"fastestFee"); + half = jint(retjson,"halfHourFee"); + hour = jint(retjson,"hourFee"); + if ( hour*2 > half ) + best = hour*2; + else best = half; + if ( fastest < best ) + best = fastest; + retstr = calloc(1,16); + sprintf(retstr,"%0.8f",(double)best * 1024); + printf("LP_getestimatedrate (%s) -> %s\n",jprint(retjson,0),retstr); + free(retjson); + } + /*if ( (retjson= electrum_estimatefee(coin->symbol,coin->electrum,&retjson,numblocks)) != 0 ) { retstr = jprint(retjson,1); //free_json(retjson), retjson = 0; causes crash? printf("estfee numblocks.%d (%s)\n",numblocks,retstr); - } + }*/ } if ( retstr != 0 ) { From 5c145e93df6707c0faa574369963a4636f7e8fe6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 16:42:57 +0200 Subject: [PATCH 09/19] Test --- iguana/exchanges/LP_rpc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 52a4ab85a..973b5a20a 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -687,11 +687,11 @@ again: rate = atof(retstr) / 1024.; if ( rate != 0. ) { - rate *= 1.5; + rate *= 1.25; if ( rate < 0.00000005 ) rate = 0.00000005; - if ( coin->electrum != 0 ) - rate *= 1.5; + //if ( coin->electrum != 0 ) + // rate *= 1.5; if ( fabs(rate - coin->rate) > SMALLVAL ) printf("%u t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",(uint32_t)time(NULL),coin->ratetime,coin->symbol,retstr,rate,coin->rate); coin->rate = rate; From 59f2677b61320e1c7bcecb054f1f3b435e2b9d06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 16:45:02 +0200 Subject: [PATCH 10/19] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 973b5a20a..fa1ed2799 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -656,7 +656,7 @@ again: if ( fastest < best ) best = fastest; retstr = calloc(1,16); - sprintf(retstr,"%0.8f",(double)best * 1024); + sprintf(retstr,"%0.8f",((double)best * 1024)/SATOSHIDEN); printf("LP_getestimatedrate (%s) -> %s\n",jprint(retjson,0),retstr); free(retjson); } From 9d1ce395e8238aff3665423e9115e8c5eda06dde Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 17:11:25 +0200 Subject: [PATCH 11/19] Inuse api --- iguana/exchanges/LP_commands.c | 5 +++++ iguana/exchanges/LP_utxo.c | 21 +++++++++++++++++++++ iguana/exchanges/inuse | 3 +++ 3 files changed, 29 insertions(+) create mode 100755 iguana/exchanges/inuse diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index eb4dc1456..2def1e92d 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -140,6 +140,7 @@ balances(address)\n\ fundvalue(address="", holdings=[], divisor=0)\n\ orderbook(base, rel, duration=3600)\n\ getprices()\n\ +inuse()\n\ getmyprice(base, rel)\n\ getprice(base, rel)\n\ //sendmessage(base=coin, rel="", pubkey=zero, )\n\ @@ -527,6 +528,10 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ { return(LP_sendrawtransaction(coin,jstr(argjson,"signedtx"))); } + else if ( strcmp(method,"inuse") == 0 ) + { + return(jprint(LP_inuse_json(),1)); + } else if ( strcmp(method,"getrawtransaction") == 0 ) { return(jprint(LP_gettx(coin,jbits256(argjson,"txid"),0),1)); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 9e922d95c..71aac774e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -27,6 +27,27 @@ struct LP_inuse_info } LP_inuse[1024]; int32_t LP_numinuse; +cJSON *LP_inuse_json() +{ + int32_t i; cJSON *item,*array; struct LP_inuse_info *lp; + array = cJSON_CreateArray(); + for (i=0; iexpiration != 0 ) + { + item = cJSON_CreateObject(); + jaddnum(item,"expiration",lp->expiration); + jaddbits256(item,"txid",lp->txid); + jaddnum(item,"vout",lp->vout); + if ( bits256_nonz(lp->otherpub) != 0 ) + jaddbits256(item,"otherpub",lp->otherpub); + jaddi(array,item); + } + } + return(array); +} + struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) { int32_t i; diff --git a/iguana/exchanges/inuse b/iguana/exchanges/inuse new file mode 100755 index 000000000..005d91040 --- /dev/null +++ b/iguana/exchanges/inuse @@ -0,0 +1,3 @@ +#!/bin/bash +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"inuse\"}" From f3f883dea4f7599b38fab1c9f69a15bc5bf50572 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 17:14:51 +0200 Subject: [PATCH 12/19] Test --- iguana/exchanges/LP_commands.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 2def1e92d..add8f199f 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -530,6 +530,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ } else if ( strcmp(method,"inuse") == 0 ) { + printf("got inuse method\n"); return(jprint(LP_inuse_json(),1)); } else if ( strcmp(method,"getrawtransaction") == 0 ) From 35e697776f598ea5883846a26f2baed98cbd3be3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 17:16:34 +0200 Subject: [PATCH 13/19] Test --- iguana/exchanges/LP_commands.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index add8f199f..f5f0c8eca 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -364,6 +364,8 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ } return(clonestr("{\"error\":\"cant find address\"}")); } + else if ( strcmp(method,"inuse") == 0 ) + return(jprint(LP_inuse_json(),1)); else if ( (retstr= LP_istradebots_command(ctx,pubsock,method,argjson)) != 0 ) return(retstr); if ( base[0] != 0 && rel[0] != 0 ) @@ -528,11 +530,6 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ { return(LP_sendrawtransaction(coin,jstr(argjson,"signedtx"))); } - else if ( strcmp(method,"inuse") == 0 ) - { - printf("got inuse method\n"); - return(jprint(LP_inuse_json(),1)); - } else if ( strcmp(method,"getrawtransaction") == 0 ) { return(jprint(LP_gettx(coin,jbits256(argjson,"txid"),0),1)); From 275c3915ade41eef4e29687b29fb5b9c493a1100 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 17:24:38 +0200 Subject: [PATCH 14/19] Test --- iguana/exchanges/LP_ordermatch.c | 7 ++++--- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 65fcfb593..bdab99e57 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -443,8 +443,9 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb if ( targetval == 0 || mini < 0 ) break; } - } else printf("no %s %s utxos pass LP_address_utxo_ptrs filter %.8f %.8f\n",coin->symbol,coinaddr,dstr(targetval),dstr(targetval2)); - } else printf("address_myutxopair couldnt find %s %s\n",coin->symbol,coinaddr); + } //else printf("no %s %s utxos pass LP_address_utxo_ptrs filter %.8f %.8f\n",coin->symbol,coinaddr,dstr(targetval),dstr(targetval2)); + } + printf("address_myutxopair couldnt find %s %s targets %.8f %.8f\n",coin->symbol,coinaddr,dstr(targetval),dstr(targetval2)); return(0); } @@ -1401,7 +1402,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel if ( destsatoshis < (autxo->payment.value / LP_MINCLIENTVOL) || autxo->payment.value < desttxfee*LP_MINSIZE_TXFEEMULT ) { printf("destsatoshis %.8f vs utxo %.8f this would have triggered an quote error -13\n",dstr(destsatoshis),dstr(autxo->payment.value)); - return(clonestr("{\"error\":\"cant find a deposit that is close enough in size. make another deposit that is just a bit larger than what you want to trade\"}")); + return(clonestr("{\"error\":\"cant find a deposit that is close enough in size. make another deposit that is a bit larger than what you want to trade\"}")); } bestsatoshis = 1.001 * LP_basesatoshis(dstr(destsatoshis),maxprice,txfee,desttxfee); memset(&B,0,sizeof(B)); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index fa1ed2799..3abf0b8d5 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -644,7 +644,7 @@ again: else { // {"fastestFee":70,"halfHourFee":70,"hourFee":10} - if ( (retjson= LP_bitcoinfees()) != 0 ) + if ( strcmp(coin->symbol,"BTC") == 0 && (retjson= LP_bitcoinfees()) != 0 ) { int32_t fastest,half,hour,best=0; fastest = jint(retjson,"fastestFee"); From 456cd513eb4c1f2939e81421e210094ebeaab01c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 18:14:54 +0200 Subject: [PATCH 15/19] Test --- iguana/exchanges/LP_ordermatch.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index bdab99e57..20dfa6e68 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -865,7 +865,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru } else return(0); if ( qprice >= myprice ) { - r = (LP_rand() % 100); + r = (LP_rand() % 90) + 10; range = (qprice - myprice); price = myprice + ((r * range) / 100.); bestprice = LP_bob_competition(&counter,qp->aliceid,price,0); @@ -941,12 +941,13 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru struct LP_quoteinfo *LP_trades_gotreserved(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp) { - char *retstr; - //char str[65]; printf("alice %s received RESERVED.(%llu) %.8f\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid,(double)qp->destsatoshis/(qp->satoshis+1)); + char *retstr; double qprice; + char str[65]; printf("alice %s received RESERVED.(%llu) %.8f\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid,(double)qp->destsatoshis/(qp->satoshis+1)); *newqp = *qp; qp = newqp; - if ( LP_trades_alicevalidate(ctx,qp) > 0. ) + if ( (qprice= LP_trades_alicevalidate(ctx,qp)) > 0. ) { + printf("got qprice %.8f\n",qprice); LP_aliceid(qp->tradeid,qp->aliceid,"reserved",0,0); if ( (retstr= LP_quotereceived(qp)) != 0 ) free(retstr); From bc514b365d5a8b1a59c71472ca5c9772e8c4cf34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 18:32:42 +0200 Subject: [PATCH 16/19] Test --- iguana/exchanges/LP_ordermatch.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 20dfa6e68..1a1f2054f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -307,7 +307,7 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a } if ( replacei >= 0 ) { - printf("REPLACE bestdist %.8f height %d with dist %.8f height %d\n",dstr(bestdist),bestup->U.height,dstr(utxos[replacei]->U.value - targetval),utxos[replacei]->U.height); + //printf("REPLACE bestdist %.8f height %d with dist %.8f height %d\n",dstr(bestdist),bestup->U.height,dstr(utxos[replacei]->U.value - targetval),utxos[replacei]->U.height); return(replacei); } } @@ -842,7 +842,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[1000]; int32_t i,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos)); *newqp = *qp; qp = newqp; - printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid); + //printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid); if ( (coin= LP_coinfind(qp->srccoin)) == 0 ) return(0); if ( (myprice= LP_trades_bobprice(&bid,&ask,qp)) == 0. ) @@ -920,6 +920,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru printf("i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",i,qprice,myprice,price,p); if ( LP_allocated(qp->txid,qp->vout) == 0 && LP_allocated(qp->txid2,qp->vout2) == 0 ) { + printf("found unallocated txids\n"); reqjson = LP_quotejson(qp); LP_unavailableset(qp->txid,qp->vout,qp->timestamp + LP_RESERVETIME,qp->desthash); LP_unavailableset(qp->txid2,qp->vout2,qp->timestamp + LP_RESERVETIME,qp->desthash); @@ -928,12 +929,12 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru jaddnum(reqjson,"quotetime",qp->quotetime); jaddnum(reqjson,"pending",qp->timestamp + LP_RESERVETIME); jaddstr(reqjson,"method","reserved"); - //LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); + LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); bits256 zero; memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); free_json(reqjson); - //printf("Send RESERVED id.%llu\n",(long long)qp->aliceid); + printf("Send RESERVED id.%llu\n",(long long)qp->aliceid); return(qp); } else printf("request processing selected ineligible utxos?\n"); return(0); From 99ef2b1908207feff44220c4b3db7d910101f8a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 18:36:59 +0200 Subject: [PATCH 17/19] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_transaction.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 3643e3bc8..069263a2c 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -59,7 +59,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_MAXVINS 64 #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) #define LP_AUTOTRADE_TIMEOUT 30 -#define LP_RESERVETIME 600 //(LP_AUTOTRADE_TIMEOUT * 2) +#define LP_RESERVETIME (LP_AUTOTRADE_TIMEOUT * 3) #define ELECTRUM_TIMEOUT 13 #define LP_ELECTRUM_KEEPALIVE 60 #define LP_ELECTRUM_MAXERRORS 777 diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index bd56c6b32..6c53314b0 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1180,7 +1180,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ vp->suppress_pubkeys = suppress_pubkeys; vp->ignore_cltverr = ignore_cltverr; jaddi(vins,LP_inputjson(up->U.txid,up->U.vout,spendscriptstr)); - LP_unavailableset(up->U.txid,up->U.vout,(uint32_t)time(NULL)+LP_RESERVETIME,G.LP_mypub25519); + LP_unavailableset(up->U.txid,up->U.vout,(uint32_t)time(NULL)+LP_RESERVETIME*2,G.LP_mypub25519); if ( remains <= 0 && i >= numpre-1 ) break; if ( numunspents < 0 || n >= LP_MAXVINS ) From 9cd96bd4d7a164ced4d9eb882e9c4d45abcfc25f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 18:40:05 +0200 Subject: [PATCH 18/19] Test --- iguana/exchanges/LP_remember.c | 2 +- iguana/exchanges/LP_signatures.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 7d703616b..4f21bbaf8 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1188,7 +1188,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } LP_txbytes_update("aliceclaim",rswap.bobcoin,rswap.txbytes[BASILISK_ALICECLAIM],&rswap.txids[BASILISK_ALICECLAIM],&rswap.depositspent,&rswap.sentflags[BASILISK_ALICECLAIM]); } - } else printf("now %u before expiration %u\n",(uint32_t)time(NULL),rswap.expiration); + } //else printf("now %u before expiration %u\n",(uint32_t)time(NULL),rswap.expiration); } if ( (rswap.sentflags[BASILISK_ALICEPAYMENT] != 0 || bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0)&& bits256_nonz(rswap.Apaymentspent) == 0 && rswap.sentflags[BASILISK_ALICERECLAIM] == 0 ) { diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 377d9e44c..1c400bf4c 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -681,6 +681,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ if ( bits256_nonz(qp->srchash) != 0 ) LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->srchash,clonestr(msg)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg)); + LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,clonestr(msg)); free(msg); /*portable_mutex_lock(&LP_reservedmutex); if ( num_Reserved_msgs[1] < sizeof(Reserved_msgs[1])/sizeof(*Reserved_msgs[1])-2 ) From cf875e7512967c4513bdefd9897d343804c6963c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 25 Feb 2018 19:36:26 +0200 Subject: [PATCH 19/19] Update estimate fee --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 3abf0b8d5..a134e03c1 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -634,7 +634,7 @@ double _LP_getestimatedrate(struct iguana_info *coin) { if ( coin->estimatefeestr[0] == 0 ) strcpy(coin->estimatefeestr,"estimatefee"); - numblocks = 4;//strcmp(coin->symbol,"BTC") == 0 ? 6 : 2; + numblocks = 2;//strcmp(coin->symbol,"BTC") == 0 ? 6 : 2; again: if ( coin->electrum == 0 ) {