|
|
@ -531,7 +531,7 @@ char *LP_connectedalice(cJSON *argjson) // alice |
|
|
|
|
|
|
|
int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag) |
|
|
|
{ |
|
|
|
int32_t i,v,height,n=0; uint64_t value; bits256 txid; char buf[512]; cJSON *array,*item; struct iguana_info *coin = LP_coinfind(symbol); |
|
|
|
int32_t i,v,numconfs,height,n=0; uint64_t value; bits256 txid; char buf[512]; cJSON *array,*item; struct iguana_info *coin = LP_coinfind(symbol); |
|
|
|
if ( coin != 0 )//&& (IAMLP != 0 || coin->inactive == 0) )
|
|
|
|
{ |
|
|
|
if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) <= 0 ) |
|
|
@ -543,8 +543,11 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag) |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if ( strcmp(symbol,"BTC") == 0 ) |
|
|
|
numconfs = 0; |
|
|
|
else numconfs = 1; |
|
|
|
//printf("my coin electrum.%p\n",coin->electrum);
|
|
|
|
sprintf(buf,"[1, 99999999, [\"%s\"]]",coinaddr); |
|
|
|
sprintf(buf,"[%d, 99999999, [\"%s\"]]",numconfs,coinaddr); |
|
|
|
if ( (array= bitcoin_json(coin,"listunspent",buf)) != 0 ) |
|
|
|
{ |
|
|
|
if ( (n= cJSON_GetArraySize(array)) > 0 ) |
|
|
@ -761,7 +764,7 @@ struct LP_utxoinfo *LP_ordermatch_iter(struct LP_address_utxo **utxos,int32_t ma |
|
|
|
return(0); |
|
|
|
} |
|
|
|
|
|
|
|
struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,char *gui,bits256 *avoids,int32_t numavoids) |
|
|
|
struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,char *gui,bits256 *avoids,int32_t numavoids,bits256 destpubkey) |
|
|
|
{ |
|
|
|
bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t maxiters,i,j,numasks,max; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; uint64_t asatoshis; struct iguana_info *basecoin; struct LP_utxoinfo *bestutxo = 0; |
|
|
|
maxiters = 100; |
|
|
@ -790,27 +793,23 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i |
|
|
|
price = jdouble(item,"price"); |
|
|
|
price *= 1.005; |
|
|
|
pubkey = jbits256(item,"pubkey"); |
|
|
|
if ( bits256_nonz(destpubkey) != 0 && bits256_cmp(destpubkey,pubkey) != 0 ) |
|
|
|
continue; |
|
|
|
//printf("[%d/%d] %s pubcmp %d price %.8f vs maxprice %.8f\n",i,numasks,jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519),price,maxprice);
|
|
|
|
if ( LP_pricevalid(price) > 0 && price <= maxprice ) |
|
|
|
{ |
|
|
|
if ( bits256_nonz(destpubkey) == 0 ) |
|
|
|
{ |
|
|
|
for (j=0; j<numavoids; j++) |
|
|
|
if ( bits256_cmp(pubkey,avoids[j]) == 0 ) |
|
|
|
break; |
|
|
|
if ( j != numavoids ) |
|
|
|
continue; |
|
|
|
} |
|
|
|
if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) |
|
|
|
{ |
|
|
|
bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); |
|
|
|
asatoshis = autxo->S.satoshis; |
|
|
|
/*if ( basecoin->electrum != 0 )
|
|
|
|
{ |
|
|
|
price *= 1.01; |
|
|
|
*ordermatchpricep = price; |
|
|
|
*bestsatoshisp = LP_basesatoshis(dstr(asatoshis),price,txfee,desttxfee); |
|
|
|
*bestdestsatoshisp = asatoshis; |
|
|
|
} |
|
|
|
else*/ |
|
|
|
{ |
|
|
|
LP_listunspent_query(base,coinaddr); |
|
|
|
LP_listunspent_both(base,coinaddr,1); |
|
|
|
for (j=0; j<maxiters; j++) |
|
|
@ -824,7 +823,6 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i |
|
|
|
} |
|
|
|
if ( j < maxiters ) |
|
|
|
break; |
|
|
|
} |
|
|
|
} else printf("self trading or blacklisted peer\n"); |
|
|
|
} |
|
|
|
else |
|
|
@ -847,7 +845,7 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i |
|
|
|
return(bestutxo); |
|
|
|
} |
|
|
|
|
|
|
|
char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration,char *gui,uint32_t nonce) |
|
|
|
char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration,char *gui,uint32_t nonce,bits256 destpubkey) |
|
|
|
{ |
|
|
|
uint64_t desttxfee,txfee; uint32_t lastnonce; int32_t i,maxiters,numpubs = 0; int64_t bestsatoshis=0,destsatoshis,bestdestsatoshis=0; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; bits256 pubkeys[100]; |
|
|
|
basecoin = LP_coinfind(base); |
|
|
@ -904,7 +902,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel |
|
|
|
} |
|
|
|
while ( 1 ) |
|
|
|
{ |
|
|
|
if ( (bestutxo= LP_buyutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,gui,pubkeys,numpubs)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) |
|
|
|
if ( (bestutxo= LP_buyutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,gui,pubkeys,numpubs,destpubkey)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) |
|
|
|
{ |
|
|
|
printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); |
|
|
|
return(clonestr("{\"error\":\"cant find ordermatch utxo, need to change relvolume to be closer to available\"}")); |
|
|
@ -934,12 +932,13 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel |
|
|
|
if ( i == maxiters || qprice > maxprice ) |
|
|
|
{ |
|
|
|
printf("i.%d maxiters.%d qprice %.8f vs maxprice %.8f, no acceptable quote for this pubkey\n",i,maxiters,dstr(qprice),dstr(maxprice)); |
|
|
|
if ( bits256_nonz(destpubkey) == 0 ) |
|
|
|
continue; |
|
|
|
else return(clonestr("{\"error\":\"cant ordermatch to destpubkey\"}")); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
//printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1));
|
|
|
|
return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); |
|
|
|
} |
|
|
|
return(clonestr("{\"error\":\"cant get here\"}")); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|