From ff093b08e380059cde986e31ec3630206e45a24e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 4 Jun 2017 21:26:08 +0300 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 28 ++++------------------------ iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_utxos.c | 6 +++++- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 6390f541d..b75ae40f6 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -228,7 +228,7 @@ int32_t LP_sizematch(uint64_t mysatoshis,uint64_t othersatoshis) cJSON *LP_tradecandidates(struct LP_utxoinfo *myutxo,char *base) { - struct LP_peerinfo *peer,*tmp; struct LP_quoteinfo Q; char *utxostr,coinstr[16]; cJSON *array,*icopy,*retarray=0,*item; int32_t i,n; double price; int64_t satoshis; + struct LP_peerinfo *peer,*tmp; struct LP_quoteinfo Q; char *utxostr,coinstr[16]; cJSON *array,*retarray=0,*item; int32_t i,n; double price; if ( (price= LP_price(base,myutxo->coin)) == .0 ) { printf("no LP_price (%s -> %s)\n",base,myutxo->coin); @@ -250,23 +250,7 @@ cJSON *LP_tradecandidates(struct LP_utxoinfo *myutxo,char *base) LP_quoteparse(&Q,item); safecopy(coinstr,jstr(item,"base"),sizeof(coinstr)); if ( strcmp(coinstr,base) == 0 ) - { - icopy = 0; - if ( (price= LP_pricecache(&Q,base,myutxo->coin,jbits256(item,"txid"),jint(item,"vout"))) != 0. ) - { - if ( Q.destsatoshis == 0 ) - Q.destsatoshis = Q.satoshis * price; - if ( LP_sizematch(myutxo->satoshis,Q.destsatoshis) == 0 ) - icopy = jduplicate(item); - } else icopy = jduplicate(item); - if ( icopy != 0 ) - { - if ( price != 0. ) - jaddnum(icopy,"price",price); - jaddi(retarray,icopy); - } - printf(">>>> i.%d %.8f %.8f Q: price %.8f -> %.8f\n",i,dstr(myutxo->satoshis),dstr(Q.destsatoshis),price,price * dstr(Q.satoshis)); - } + jaddi(retarray,jduplicate(item)); } } free_json(array); @@ -300,11 +284,7 @@ cJSON *LP_autotrade(struct LP_utxoinfo *myutxo,char *base,double maxprice) if ( (price= jdouble(item,"price")) == 0. ) { price = LP_query("price",&Q[i],jstr(item,"ipaddr"),jint(item,"port"),base,myutxo->coin,zero); - if ( Q[i].destsatoshis != 0 && (double)j64bits(item,"satoshis")/Q[i].destsatoshis > price ) - { - printf("adjustprice %.8f -> %.8f\n",price,(double)j64bits(item,"satoshis")/Q[i].destsatoshis); - price = (double)j64bits(item,"satoshis")/Q[i].destsatoshis; - } + Q[i].destsatoshis = price * Q[i].satoshis; } if ( (prices[i]= price) != 0. && (bestprice == 0. || price < bestprice) ) bestprice = price; @@ -316,7 +296,7 @@ cJSON *LP_autotrade(struct LP_utxoinfo *myutxo,char *base,double maxprice) besti = -1; for (i=0; isatoshis > Q[i].destsatoshis ) { metric = price / bestprice; printf("%f %f %f %f ",price,metric,dstr(Q[i].destsatoshis),metric * metric * metric); diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 9dc21ab9b..cef33e7b0 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -164,6 +164,7 @@ struct LP_utxoinfo UT_hash_handle hh; bits256 txid,txid2,feetxid,otherpubkey,mypub; void *swap; + double value; uint64_t satoshis,satoshis2; uint8_t key[sizeof(bits256) + sizeof(int32_t)]; int32_t vout,vout2,pair; diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index b10a7d93f..2a3d74ec7 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -116,7 +116,11 @@ struct LP_utxoinfo *LP_addutxo(int32_t amclient,struct LP_peerinfo *mypeer,int32 safecopy(utxo->spendscript,spendscript,sizeof(utxo->spendscript)); utxo->txid = txid; utxo->vout = vout; - utxo->satoshis = satoshis; + utxo->value = dstr(satoshis); + if ( IAMCLIENT == 0 ) + utxo->satoshis = satoshis; + else if ( depositsatoshis < 9 * (satoshis >> 3) ) + utxo->satoshis = (depositsatoshis / 9) << 3; utxo->txid2 = deposittxid; utxo->vout2 = depositvout; utxo->satoshis2 = depositsatoshis;