From 49dd22bd017374fe402c9a962d639ae9f9ef4c73 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:21:07 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_ordermatch.c | 3 --- iguana/exchanges/LP_prices.c | 26 ++++++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 786b05f0c..255ac95ca 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -718,13 +718,10 @@ char *LP_ordermatch(char *base,int64_t txfee,double maxprice,double maxvolume,ch desttxfee = LP_txfeecalc(LP_coinfind(rel),desttxfee); if ( (autxo= LP_utxopairfind(0,txid,vout,feetxid,feevout)) == 0 ) return(clonestr("{\"error\":\"cant find alice utxopair\"}")); - printf("call LP_bestutxo\n"); if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*maxvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); - printf("call LP_quoteinfoinit\n"); if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); - printf("call LP_quotedestinfo\n"); if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); return(jprint(LP_quotejson(&Q),1)); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 1d6971004..84f91ce0e 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -18,7 +18,7 @@ // marketmaker // -struct LP_orderbookentry { bits256 pubkey; double price; uint64_t basesatoshis,maxsatoshis; uint32_t timestamp; int32_t numutxos; char coinaddr[64]; }; +struct LP_orderbookentry { bits256 pubkey; double price; uint64_t minsatoshis,maxsatoshis; uint32_t timestamp; int32_t numutxos; char coinaddr[64]; }; #define LP_MAXPRICEINFOS 256 struct LP_priceinfo @@ -539,8 +539,10 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) jaddstr(item,"address",op->coinaddr); jaddnum(item,"price",op->price); jaddnum(item,"numutxos",op->numutxos); - jaddnum(item,"minvolume",dstr(op->basesatoshis)); - jaddnum(item,"maxvolume",dstr(op->maxsatoshis)); + if ( op->minsatoshis != 0 ) + jaddnum(item,"minvolume",1./dstr(op->minsatoshis)); + if ( op->maxsatoshis != 0 ) + jaddnum(item,"maxvolume",1./dstr(op->maxsatoshis)); //jaddbits256(item,"txid",op->txid); //jaddnum(item,"vout",op->vout); jaddbits256(item,"pubkey",op->pubkey); @@ -549,7 +551,7 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) return(item); } -struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t basesatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp) +struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t minsatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp) { struct LP_orderbookentry *op; if ( (op= calloc(1,sizeof(*op))) != 0 ) @@ -561,7 +563,7 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d safecopy(op->coinaddr,address,sizeof(op->coinaddr)); op->price = price; op->numutxos = numutxos; - op->basesatoshis = basesatoshis; + op->minsatoshis = minsatoshis; op->maxsatoshis = maxsatoshis; op->pubkey = pubkey; op->timestamp = timestamp; @@ -580,7 +582,7 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *rel,struct LP_orderbookentry *(**arrayp),int32_t num,int32_t cachednum,int32_t duration) { - char coinaddr[64]; uint8_t zeroes[20]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; uint64_t basesatoshis,maxsatoshis; + char coinaddr[64]; uint8_t zeroes[20]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; uint64_t minsatoshis,maxsatoshis; if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) baseid = basepp->ind; else return(num); @@ -596,25 +598,25 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 ) continue; bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - basesatoshis = maxsatoshis = n = 0; + minsatoshis = maxsatoshis = n = 0; ap = 0; //char str[65],str2[65]; printf("check utxo.%s/v%d from %s\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,utxo->pubkey)); //if ( strcmp(base,utxo->coin) == 0 && LP_isavailable(utxo) > 0 && pubp != 0 && (price= pubp->matrix[baseid][relid]) > SMALLVAL ) //if ( polarity > 0 ) - // basesatoshis = utxo->S.satoshis; - //else basesatoshis = utxo->S.satoshis * price; + // minsatoshis = utxo->S.satoshis; + //else minsatoshis = utxo->S.satoshis * price; if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL ) { if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { - n = LP_address_minmax(&basesatoshis,&maxsatoshis,ap); + n = LP_address_minmax(&minsatoshis,&maxsatoshis,ap); if ( polarity < 0 ) { - basesatoshis *= price; + minsatoshis *= price; maxsatoshis *= price; } } - if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,basesatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp)) != 0 ) + if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,minsatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp)) != 0 ) { *arrayp = realloc(*arrayp,sizeof(*(*arrayp)) * (num+1)); (*arrayp)[num++] = op;