diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 12ec548f2..6e2410209 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -309,7 +309,7 @@ getprice(base, rel)\n\ if ( (utxo= LP_utxofind(txid,vout)) == 0 ) return(clonestr("{\"error\":\"txid/vout not found\"}")); if ( strcmp(method,"candidates") == 0 ) - return(jprint(LP_tradecandidates(utxo,coin),1)); + return(jprint(LP_tradecandidates(coin),1)); else return(jprint(LP_autotrade(utxo,coin,jdouble(argjson,"maxprice")),1)); } } diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index e418c6899..b75202a12 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -205,5 +205,6 @@ char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *meth uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx,uint32_t nextbits,int32_t suppress_swapsend); double LP_query(char *method,struct LP_quoteinfo *qp,char *ipaddr,uint16_t port,char *base,char *rel,bits256 mypub); int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys); +void LP_quotesinit(char *base,char *rel); #endif diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 31a558aab..92134e254 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -356,6 +356,8 @@ char *LP_orderbook(char *base,char *rel) jaddstr(retjson,"base",base); jaddstr(retjson,"rel",rel); jaddnum(retjson,"timestamp",now); + if ( numbids == 0 && numasks == 0 ) + LP_quotesinit(base,rel); return(jprint(retjson,1)); } diff --git a/iguana/exchanges/LP_quotes.c b/iguana/exchanges/LP_quotes.c index de9407ea8..86a8a7966 100644 --- a/iguana/exchanges/LP_quotes.c +++ b/iguana/exchanges/LP_quotes.c @@ -196,14 +196,14 @@ int32_t LP_arrayfind(cJSON *array,bits256 txid,int32_t vout) return(-1); } -cJSON *LP_tradecandidates(struct LP_utxoinfo *myutxo,char *base) +cJSON *LP_tradecandidates(char *base) { struct LP_peerinfo *peer,*tmp; struct LP_quoteinfo Q; char *utxostr,coinstr[16]; cJSON *array,*retarray=0,*item; int32_t i,n,totaladded,added; double price; - if ( (price= LP_price(base,myutxo->coin)) == .0 ) + /*if ( (price= LP_price(base,myutxo->coin)) == .0 ) { printf("no LP_price (%s -> %s)\n",base,myutxo->coin); return(0); - } + }*/ totaladded = 0; HASH_ITER(hh,LP_peerinfos,peer,tmp) { @@ -248,6 +248,30 @@ cJSON *LP_tradecandidates(struct LP_utxoinfo *myutxo,char *base) return(retarray); } +void LP_quotesinit(char *base,char *rel) +{ + cJSON *array,*item; struct LP_quoteinfo Q; bits256 zero; int32_t i,n,iter; + memset(&zero,0,sizeof(zero)); + for (iter=0; iter<2; iter++) + if ( (array= LP_tradecandidates(iter == 0 ? base : rel)) != 0 ) + { + //printf("candidates.(%s)\nn.%d\n",jprint(array,0),cJSON_GetArraySize(array)); + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + memset(&Q,0,sizeof(Q)); + for (i=0; ilasttime = now; - LP_query("price",&Q,utxo->ipaddr,utxo->port,utxo->coin,"KMD",utxo->mypub); } } } // else printf("skip.(%s)\n",jprint(item,0));