From a06f8a32aa4417201e7750ffd01e68d185ce53c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:20:59 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_ordermatch.c | 5 +-- iguana/exchanges/LP_rpc.c | 64 ++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 70d3f4f97..6ecf8a7c6 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -25,9 +25,8 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) { if ( strcmp(coin->symbol,"BTC") == 0 ) { - if ( coin->rate == 0. || txfee < LP_MIN_TXFEE ) - coin->rate = LP_getestimatedrate(coin); - if ( txfee == 0 && (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) + coin->rate = _LP_getestimatedrate(coin); + if ( (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; } else txfee = coin->txfee; if ( txfee < LP_MIN_TXFEE ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 703e4b40d..b0c4866c1 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -595,39 +595,47 @@ int32_t LP_importaddress(char *symbol,char *address) } } -double LP_getestimatedrate(struct iguana_info *coin) +double _LP_getestimatedrate(struct iguana_info *coin) { char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020; + sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); + if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) + { + if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) + { + if ( jobj(errjson,"error") != 0 ) + rate = 0.; + free_json(errjson); + } + else if ( retstr[0] != '-' ) + { + rate = atof(retstr) / 1024.; + if ( rate < 0.00000020 ) + rate = 0.00000020; + rate *= 1.25; + if ( coin->electrum != 0 ) + rate *= 1.25; + coin->rate = rate; + coin->ratetime = (uint32_t)time(NULL); + printf("estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->symbol,retstr,rate,coin->rate); + } + free(retstr); + } + return(rate); +} + +double LP_getestimatedrate(struct iguana_info *coin) +{ + double rate = 0.00000020; if ( coin == 0 ) return(0.0001); - if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. ) + if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. || time(NULL) > coin->ratetime+60 ) { - if ( coin->rate == 0. || (strcmp(coin->symbol,"BTC") == 0 && coin->txfee == 10000) || time(NULL) > coin->ratetime+6 ) - { - sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); - if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) - { - if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) - { - if ( jobj(errjson,"error") != 0 ) - rate = 0.; - free_json(errjson); - } - else if ( retstr[0] != '-' ) - { - rate = atof(retstr) / 1024.; - if ( rate < 0.00000020 ) - rate = 0.00000020; - rate *= 1.25; - if ( coin->electrum != 0 ) - rate *= 1.25; - coin->rate = rate; - coin->ratetime = (uint32_t)time(NULL); - printf("estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->symbol,retstr,rate,coin->rate); - } - free(retstr); - } - } else rate = coin->rate; + if ( coin->rate == 0. || (strcmp(coin->symbol,"BTC") == 0 && coin->txfee == 10000) ) + rate = _LP_getestimatedrate(coin); + else rate = coin->rate; + if ( rate != 0. ) + coin->txfee = (coin->rate * LP_AVETXSIZE); } else return((double)coin->txfee / LP_AVETXSIZE); return(SATOSHIDEN * rate); }