Browse Source

Bob side fill

pass-iguana-arg
jl777 7 years ago
parent
commit
0a69b8bf76
  1. 81
      iguana/exchanges/LP_ordermatch.c

81
iguana/exchanges/LP_ordermatch.c

@ -916,7 +916,8 @@ double LP_trades_pricevalidate(struct LP_quoteinfo *qp,struct iguana_info *coin,
struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp,char *pairstr) struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp,char *pairstr)
{ {
double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin,*othercoin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[4096]; int32_t i,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos)); int32_t voliters=10,priceiters=33;
double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin,*othercoin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[4096]; int32_t i,j,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos));
*newqp = *qp; *newqp = *qp;
qp = newqp; qp = newqp;
printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32,qp->fill,qp->gtc); printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32,qp->fill,qp->gtc);
@ -998,45 +999,61 @@ printf("bob %s received REQUEST.(%s) fill.%d gtc.%d\n",bits256_str(str,G.LP_mypu
} }
} }
i = 0; i = 0;
while ( i < 33 && price >= myprice ) while ( i < priceiters && price >= myprice )
{ {
if ( (butxo= LP_address_myutxopair(butxo,1,utxos,max,LP_coinfind(qp->srccoin),qp->coinaddr,qp->txfee,dstr(qp->destsatoshis),price,qp->desttxfee)) != 0 ) for (j=0; j<voliters; j++)
{ {
strcpy(qp->gui,G.gui); if ( (butxo= LP_address_myutxopair(butxo,1,utxos,max,LP_coinfind(qp->srccoin),qp->coinaddr,qp->txfee,dstr(qp->destsatoshis),price,qp->desttxfee)) != 0 )
strcpy(qp->coinaddr,coin->smartaddr); {
qp->srchash = G.LP_mypub25519; strcpy(qp->gui,G.gui);
qp->txid = butxo->payment.txid; strcpy(qp->coinaddr,coin->smartaddr);
qp->vout = butxo->payment.vout; qp->srchash = G.LP_mypub25519;
qp->txid2 = butxo->deposit.txid; qp->txid = butxo->payment.txid;
qp->vout2 = butxo->deposit.vout; qp->vout = butxo->payment.vout;
qp->satoshis = butxo->swap_satoshis;// + qp->txfee; qp->txid2 = butxo->deposit.txid;
qp->quotetime = (uint32_t)time(NULL); qp->vout2 = butxo->deposit.vout;
} qp->satoshis = butxo->swap_satoshis;// + qp->txfee;
else qp->quotetime = (uint32_t)time(NULL);
{ break;
printf("i.%d cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f\n",i,(long long)qp->aliceid,qp->srccoin,qp->destcoin,dstr(LP_basesatoshis(dstr(qp->destsatoshis),price,qp->txfee,qp->desttxfee)),dstr(qp->destsatoshis)); }
return(0); qp->destsatoshis = (qp->destsatoshis * 7) >> 3;
} }
if ( qp->satoshis <= qp->txfee ) if ( j < voliters )
return(0);
p = (double)qp->destsatoshis / (qp->satoshis - qp->txfee);
if ( LP_trades_pricevalidate(qp,coin,p) < 0. )
return(0);
if ( i == 0 && p < myprice )
{ {
price = qprice; if ( qp->satoshis <= qp->txfee )
printf("reset price <- qprice %.8f\n",qprice); return(0);
p = (double)qp->destsatoshis / (qp->satoshis - qp->txfee);
if ( LP_trades_pricevalidate(qp,coin,p) < 0. )
{
if ( qp->fill != 0 )
return(0);
price *= 0.995;
i++;
continue;
}
if ( i == 0 && p < myprice )
{
price = qprice;
printf("reset price <- qprice %.8f\n",qprice);
}
else
{
if ( qprice >= p || qp->fill != 0 )
break;
price *= 0.995;
}
if ( qp->fill != 0 )
break;
i++;
} }
else else if ( qp->fill != 0 || i == priceiters )
{ {
if ( qprice >= p ) printf("i.%d cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f\n",i,(long long)qp->aliceid,qp->srccoin,qp->destcoin,dstr(LP_basesatoshis(dstr(qp->destsatoshis),price,qp->txfee,qp->desttxfee)),dstr(qp->destsatoshis));
break; return(0);
price *= 0.995;
} }
i++;
} }
printf("%s/%s i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",qp->srccoin,qp->destcoin,i,qprice,myprice,price,p); printf("%s/%s i.%d j.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",qp->srccoin,qp->destcoin,i,j,qprice,myprice,price,p);
if ( LP_allocated(qp->txid,qp->vout) == 0 && LP_allocated(qp->txid2,qp->vout2) == 0 ) if ( bits256_nonz(qp->txid) != 0 && bits256_nonz(qp->txid2) != 0 && LP_allocated(qp->txid,qp->vout) == 0 && LP_allocated(qp->txid2,qp->vout2) == 0 )
{ {
//printf("found unallocated txids\n"); //printf("found unallocated txids\n");
reqjson = LP_quotejson(qp); reqjson = LP_quotejson(qp);

Loading…
Cancel
Save