Browse Source

Test

etomic
jl777 8 years ago
parent
commit
dbce544813
  1. 9
      iguana/exchanges/LP_commands.c

9
iguana/exchanges/LP_commands.c

@ -159,7 +159,7 @@ cJSON *LP_tradecandidates(struct LP_utxoinfo *myutxo,char *base)
cJSON *LP_bestprice(struct LP_utxoinfo *utxo,char *base)
{
static bits256 zero;
int32_t i,n,besti; cJSON *array,*item,*bestitem=0; double bestmetric,metric,bestprice=0.,price,prices[100]; bits256 otherpubs[100]; uint32_t reserved[100]; uint64_t txfees[100],destsatoshis[100],desttxfees[100];
int32_t i,n,besti; cJSON *array,*item,*bestitem=0; double bestmetric,metric,bestprice=0.,price,prices[100]; bits256 otherpubs[100]; uint32_t reserved[100]; uint64_t txfees[100],destsatoshis[100],desttxfees[100]; quoteinfo struct
bestprice = 0.;
if ( (array= LP_tradecandidates(utxo,base)) != 0 )
{
@ -177,6 +177,7 @@ cJSON *LP_bestprice(struct LP_utxoinfo *utxo,char *base)
item = jitem(array,i);
if ( (price= jdouble(item,"price")) == 0. )
{
horrible, pass in quoteinfo, utxo
price = LP_query("price",&otherpubs[i],&reserved[i],&txfees[i],&destsatoshis[i],&desttxfees[i],jstr(item,"ipaddr"),jint(item,"port"),base,utxo->coin,jbits256(item,"txid"),jint(item,"vout"),zero,0);
if ( destsatoshis[i] != 0 && (double)j64bits(item,"value")/destsatoshis[i] > price )
price = (double)j64bits(item,"value")/destsatoshis[i];
@ -221,6 +222,7 @@ cJSON *LP_bestprice(struct LP_utxoinfo *utxo,char *base)
jaddbits256(bestitem,"otherpub",otherpubs[besti]);
if ( LP_price(base,utxo->coin) > 0.975*price )
{
the same, cleanup
price = LP_query("connect",&otherpubs[i],&reserved[i],&txfees[i],&destsatoshis[i],&desttxfees[i],jstr(item,"ipaddr"),jint(item,"port"),base,utxo->coin,jbits256(item,"txid"),jint(item,"vout"),utxo->mypub,item);
}
}
@ -268,6 +270,7 @@ int32_t LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uin
if ( (price= LP_price(base,rel)) != 0. )
{
price *= (1. + profitmargin);
horror show
retjson = cJSON_CreateObject();
jaddstr(retjson,"base",base);
jaddstr(retjson,"rel",rel);
@ -321,7 +324,7 @@ int32_t LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uin
jaddbits256(argjson,"srchash",srchash);
value = j64bits(argjson,"destsatoshis");
quotetime = juint(argjson,"quotetime");
//if ( timestamp == utxo->swappending-LP_RESERVETIME && quotetime >= timestamp && quotetime < utxo->swappending && bits256_cmp(pubkey,srchash) == 0 && (destsatoshis= LP_txvalue(rel,desttxid,destvout)) > price*(utxo->satoshis-txfee)+desttxfee && value <= destsatoshis-desttxfee )
if ( timestamp == utxo->swappending-LP_RESERVETIME && quotetime >= timestamp && quotetime < utxo->swappending && bits256_cmp(pubkey,srchash) == 0 && (destsatoshis= LP_txvalue(rel,desttxid,destvout)) > price*(utxo->satoshis-txfee)+desttxfee && value <= destsatoshis-desttxfee )
{
destsatoshis = value;
nanomsg_tcpname(pairstr,mypeer->ipaddr,10000+(rand() % 10000));
@ -373,7 +376,7 @@ int32_t LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uin
nn_close(utxo->pair);
utxo->pair = -1;
}
} //else printf("dest %.8f < required %.8f\n",dstr(value),dstr(price*(utxo->satoshis-txfee)));
} else printf("dest %.8f < required %.8f\n",dstr(value),dstr(price*(utxo->satoshis-txfee)));
} else printf("no price for %s/%s\n",base,rel);
} else printf("utxo->pair.%d when connect came in (%s)\n",utxo->pair,jprint(argjson,0));
}

Loading…
Cancel
Save