@ -71,12 +71,12 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen)
if ( txlen = = 0 )
if ( txlen = = 0 )
txlen = LP_AVETXSIZE ;
txlen = LP_AVETXSIZE ;
coin - > rate = LP_getestimatedrate ( coin ) ;
coin - > rate = LP_getestimatedrate ( coin ) ;
if ( ( txfee = SATOSHIDEN * coin - > rate * txlen ) < = LP_MIN_TXFEE )
if ( ( txfee = SATOSHIDEN * coin - > rate * txlen ) < = 10000 )
{
{
coin - > rate = - 1. ;
//coin->rate = -1.;
coin - > rate = _LP_getestimatedrate ( coin ) ;
coin - > rate = _LP_getestimatedrate ( coin ) ;
if ( ( txfee = SATOSHIDEN * coin - > rate * txlen ) < = LP_MIN_TXFEE )
if ( ( txfee = SATOSHIDEN * coin - > rate * txlen ) < = 10000 )
txfee = LP_MIN_TXFEE ;
txfee = 10000 ;
}
}
} else txfee = coin - > txfee ;
} else txfee = coin - > txfee ;
if ( txfee < LP_MIN_TXFEE )
if ( txfee < LP_MIN_TXFEE )
@ -180,16 +180,19 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str
printf ( " srcvalue %.8f [%.8f] satoshis %.8f is too small txfee %.8f? \n " , dstr ( srcvalue ) , dstr ( srcvalue ) - dstr ( qp - > txfee + qp - > satoshis ) , dstr ( qp - > satoshis ) , dstr ( qp - > txfee ) ) ;
printf ( " srcvalue %.8f [%.8f] satoshis %.8f is too small txfee %.8f? \n " , dstr ( srcvalue ) , dstr ( srcvalue ) - dstr ( qp - > txfee + qp - > satoshis ) , dstr ( qp - > satoshis ) , dstr ( qp - > txfee ) ) ;
return ( - 33 ) ;
return ( - 33 ) ;
}
}
if ( qp - > satoshis ! = 0 )
qprice = ( ( double ) qp - > destsatoshis / ( qp - > satoshis - qp - > txfee ) ) ;
LP_txfees ( & txfee , & desttxfee , qp - > srccoin , qp - > destcoin ) ;
LP_txfees ( & txfee , & desttxfee , qp - > srccoin , qp - > destcoin ) ;
if ( txfee < qp - > txfee )
if ( txfee < qp - > txfee )
txfee = qp - > txfee ;
txfee = qp - > txfee ;
if ( desttxfee < qp - > desttxfee )
if ( desttxfee < qp - > desttxfee )
desttxfee = qp - > desttxfee ;
desttxfee = qp - > desttxfee ;
if ( qp - > satoshis ! = 0 )
qprice = ( ( double ) qp - > destsatoshis / ( qp - > satoshis - qp - > txfee ) ) ;
//printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee));
//printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee));
if ( qp - > txfee < LP_REQUIRED_TXFEE * txfee | | qp - > desttxfee < LP_REQUIRED_TXFEE * desttxfee )
if ( qp - > txfee < LP_REQUIRED_TXFEE * txfee | | qp - > desttxfee < LP_REQUIRED_TXFEE * desttxfee )
{
printf ( " error -14: txfee %.8f >= %.8f or desttxfee %.8f >= %.8f \n " , dstr ( qp - > txfee ) , dstr ( LP_REQUIRED_TXFEE * txfee ) , dstr ( qp - > desttxfee ) , dstr ( LP_REQUIRED_TXFEE * desttxfee ) ) ;
return ( - 14 ) ;
return ( - 14 ) ;
}
if ( butxo ! = 0 )
if ( butxo ! = 0 )
{
{
if ( qp - > satoshis < ( srcvalue / LP_MINVOL ) | | srcvalue < qp - > txfee * LP_MINSIZE_TXFEEMULT )
if ( qp - > satoshis < ( srcvalue / LP_MINVOL ) | | srcvalue < qp - > txfee * LP_MINSIZE_TXFEEMULT )
@ -304,7 +307,7 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_a
}
}
if ( replacei > = 0 )
if ( replacei > = 0 )
{
{
printf ( " REPLACE bestdist %.8f height %d with dist %.8f height %d \n " , dstr ( bestdist ) , bestup - > U . height , dstr ( utxos [ replacei ] - > U . value - targetval ) , utxos [ replacei ] - > U . height ) ;
//printf(" REPLACE bestdist %.8f height %d with dist %.8f height %d\n",dstr(bestdist),bestup->U.height,dstr(utxos[replacei]->U.value - targetval),utxos[replacei]->U.height);
return ( replacei ) ;
return ( replacei ) ;
}
}
}
}
@ -440,8 +443,9 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
if ( targetval = = 0 | | mini < 0 )
if ( targetval = = 0 | | mini < 0 )
break ;
break ;
}
}
} else printf ( " no %s %s utxos pass LP_address_utxo_ptrs filter %.8f %.8f \n " , coin - > symbol , coinaddr , dstr ( targetval ) , dstr ( targetval2 ) ) ;
} //else printf("no %s %s utxos pass LP_address_utxo_ptrs filter %.8f %.8f\n",coin->symbol,coinaddr,dstr(targetval),dstr(targetval2));
} else printf ( " address_myutxopair couldnt find %s %s \n " , coin - > symbol , coinaddr ) ;
}
printf ( " address_myutxopair couldnt find %s %s targets %.8f %.8f \n " , coin - > symbol , coinaddr , dstr ( targetval ) , dstr ( targetval2 ) ) ;
return ( 0 ) ;
return ( 0 ) ;
}
}
@ -827,7 +831,7 @@ double LP_trades_pricevalidate(struct LP_quoteinfo *qp,struct iguana_info *coin,
}
}
if ( qprice < ( price - 0.00000001 ) * 0.998 )
if ( qprice < ( price - 0.00000001 ) * 0.998 )
{
{
printf ( " quote price %.8f too low vs %.8f for %s/%s %.8f < %.8f \n " , qprice , price , qp - > srccoin , qp - > destcoin , q price, ( price - 0.00000001 ) * 0.998 ) ;
printf ( " quote price %.8f (%llu/%llu %.8f) too low vs %.8f for %s/%s price %.8f %.8f \n " , qprice , ( long long ) qp - > destsatoshis , ( long long ) ( qp - > satoshis - qp - > txfee ) , ( double ) qp - > destsatoshis / ( qp - > satoshis - qp - > txfee ) , price , qp - > srccoin , qp - > destcoin , price , ( price - 0.00000001 ) * 0.998 ) ;
return ( - 77 ) ;
return ( - 77 ) ;
}
}
return ( qprice ) ;
return ( qprice ) ;
@ -835,7 +839,7 @@ 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 , qprice , myprice , bestprice , range , bid , ask ; struct iguana_info * coin ; struct LP_utxoinfo A , B , * autxo , * butxo ; cJSON * reqjson ; char str [ 65 ] ; struct LP_address_utxo * utxos [ 1000 ] ; int32_t r , counter , max = ( int32_t ) ( sizeof ( utxos ) / sizeof ( * utxos ) ) ;
double price = 0. , p = 0. , qprice , myprice , bestprice , range , bid , ask ; struct iguana_info * coin ; struct LP_utxoinfo A , B , * autxo , * butxo ; cJSON * reqjson ; char str [ 65 ] ; struct LP_address_utxo * utxos [ 1000 ] ; int32_t i , r , counter , max = ( int32_t ) ( sizeof ( utxos ) / sizeof ( * utxos ) ) ;
* newqp = * qp ;
* newqp = * qp ;
qp = newqp ;
qp = newqp ;
//printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
//printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
@ -859,16 +863,21 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
memset ( & qp - > txid2 , 0 , sizeof ( qp - > txid2 ) ) ;
memset ( & qp - > txid2 , 0 , sizeof ( qp - > txid2 ) ) ;
qp - > vout = qp - > vout2 = - 1 ;
qp - > vout = qp - > vout2 = - 1 ;
} else return ( 0 ) ;
} else return ( 0 ) ;
if ( qprice > myprice )
if ( qprice > = myprice )
{
{
r = ( LP_rand ( ) % 100 ) ;
r = ( LP_rand ( ) % 90 ) + 10 ;
range = ( qprice - myprice ) ;
range = ( qprice - myprice ) ;
price = myprice + ( r * range ) / 100. ;
price = myprice + ( ( r * range ) / 100. ) ;
bestprice = LP_bob_competition ( & counter , qp - > aliceid , price , 0 ) ;
bestprice = LP_bob_competition ( & counter , qp - > aliceid , price , 0 ) ;
printf ( " %llu >>>>>>> qprice %.8f r.%d range %.8f -> %.8f, bestprice %.8f counter.%d \n " , ( long long ) qp - > aliceid , qprice , r , range , price , bestprice , counter ) ;
printf ( " %llu >>>>>>> myprice %.8f qprice %.8f r.%d range %.8f -> %.8f, bestprice %.8f counter.%d \n " , ( long long ) qp - > aliceid , myprice , qprice , r , range , price , bestprice , counter ) ;
if ( counter > 3 & & price > bestprice + SMALLVAL ) // skip if late or bad price
if ( counter > 3 & & price > bestprice + SMALLVAL ) // skip if late or bad price
return ( 0 ) ;
return ( 0 ) ;
} else return ( 0 ) ;
}
else
{
printf ( " ignore as qprice %.8f vs myprice %.8f \n " , qprice , myprice ) ;
return ( 0 ) ;
}
//LP_RTmetrics_update(qp->srccoin,qp->destcoin);
//LP_RTmetrics_update(qp->srccoin,qp->destcoin);
if ( LP_RTmetrics_blacklisted ( qp - > desthash ) > = 0 )
if ( LP_RTmetrics_blacklisted ( qp - > desthash ) > = 0 )
{
{
@ -878,27 +887,40 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
//printf("LP_address_utxo_reset.%s\n",coin->symbol);
//printf("LP_address_utxo_reset.%s\n",coin->symbol);
//LP_address_utxo_reset(coin);
//LP_address_utxo_reset(coin);
//printf("done LP_address_utxo_reset.%s\n",coin->symbol);
//printf("done LP_address_utxo_reset.%s\n",coin->symbol);
if ( ( butxo = LP_address_myutxopair ( butxo , 1 , utxos , max , LP_coinfind ( qp - > srccoin ) , qp - > coinaddr , qp - > txfee , dstr ( qp - > destsatoshis ) , price , qp - > desttxfee ) ) ! = 0 )
i = 0 ;
while ( i < 33 & & price > = myprice )
{
{
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 ) ;
{
}
//printf("cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f\n",(long long)qp->aliceid,qp->srccoin,qp->destcoin,dstr(LP_basesatoshis(dstr(qp->destsatoshis),price,qp->txfee,qp->desttxfee)),dstr(qp->destsatoshis));
else
return ( 0 ) ;
{
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 ) ;
}
if ( qp - > satoshis < = qp - > txfee )
return ( 0 ) ;
p = ( double ) qp - > destsatoshis / ( qp - > satoshis - qp - > txfee ) ;
if ( LP_trades_pricevalidate ( qp , coin , p ) < 0. )
return ( 0 ) ;
if ( p > = qprice )
break ;
price / = 0.99 ;
i + + ;
}
}
if ( ( qprice = LP_trades_pricevalidate ( qp , coin , myprice ) ) < 0. )
printf ( " i.%d qprice %.8f myprice %.8f price %.8f [%.8f] \n " , i , qprice , myprice , price , p ) ;
return ( 0 ) ;
if ( LP_allocated ( qp - > txid , qp - > vout ) = = 0 & & LP_allocated ( qp - > txid2 , qp - > vout2 ) = = 0 )
if ( LP_allocated ( qp - > txid , qp - > vout ) = = 0 & & LP_allocated ( qp - > txid2 , qp - > vout2 ) = = 0 )
{
{
printf ( " found unallocated txids \n " ) ;
reqjson = LP_quotejson ( qp ) ;
reqjson = LP_quotejson ( qp ) ;
LP_unavailableset ( qp - > txid , qp - > vout , qp - > timestamp + LP_RESERVETIME , qp - > desthash ) ;
LP_unavailableset ( qp - > txid , qp - > vout , qp - > timestamp + LP_RESERVETIME , qp - > desthash ) ;
LP_unavailableset ( qp - > txid2 , qp - > vout2 , qp - > timestamp + LP_RESERVETIME , qp - > desthash ) ;
LP_unavailableset ( qp - > txid2 , qp - > vout2 , qp - > timestamp + LP_RESERVETIME , qp - > desthash ) ;
@ -907,12 +929,12 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
jaddnum ( reqjson , " quotetime " , qp - > quotetime ) ;
jaddnum ( reqjson , " quotetime " , qp - > quotetime ) ;
jaddnum ( reqjson , " pending " , qp - > timestamp + LP_RESERVETIME ) ;
jaddnum ( reqjson , " pending " , qp - > timestamp + LP_RESERVETIME ) ;
jaddstr ( reqjson , " method " , " reserved " ) ;
jaddstr ( reqjson , " method " , " reserved " ) ;
//LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
LP_reserved_msg ( 1 , qp - > srccoin , qp - > destcoin , qp - > desthash , jprint ( reqjson , 0 ) ) ;
bits256 zero ;
bits256 zero ;
memset ( zero . bytes , 0 , sizeof ( zero ) ) ;
memset ( zero . bytes , 0 , sizeof ( zero ) ) ;
LP_reserved_msg ( 1 , qp - > srccoin , qp - > destcoin , zero , jprint ( reqjson , 0 ) ) ;
LP_reserved_msg ( 1 , qp - > srccoin , qp - > destcoin , zero , jprint ( reqjson , 0 ) ) ;
free_json ( reqjson ) ;
free_json ( reqjson ) ;
//printf("Send RESERVED id.%llu\n",(long long)qp->aliceid);
printf ( " Send RESERVED id.%llu \n " , ( long long ) qp - > aliceid ) ;
return ( qp ) ;
return ( qp ) ;
} else printf ( " request processing selected ineligible utxos? \n " ) ;
} else printf ( " request processing selected ineligible utxos? \n " ) ;
return ( 0 ) ;
return ( 0 ) ;
@ -920,12 +942,13 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
struct LP_quoteinfo * LP_trades_gotreserved ( void * ctx , struct LP_quoteinfo * qp , struct LP_quoteinfo * newqp )
struct LP_quoteinfo * LP_trades_gotreserved ( void * ctx , struct LP_quoteinfo * qp , struct LP_quoteinfo * newqp )
{
{
char * retstr ;
char * retstr ; double qprice ;
//char str[65]; printf("alice %s received RESERVED.(%llu) %.8f\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid,(double)qp->destsatoshis/(qp->satoshis+1));
char str [ 65 ] ; printf ( " alice %s received RESERVED.(%llu) %.8f \n " , bits256_str ( str , G . LP_mypub25519 ) , ( long long ) qp - > aliceid , ( double ) qp - > destsatoshis / ( qp - > satoshis + 1 ) ) ;
* newqp = * qp ;
* newqp = * qp ;
qp = newqp ;
qp = newqp ;
if ( LP_trades_alicevalidate ( ctx , qp ) > 0. )
if ( ( qprice = LP_trades_alicevalidate ( ctx , qp ) ) > 0. )
{
{
printf ( " got qprice %.8f \n " , qprice ) ;
LP_aliceid ( qp - > tradeid , qp - > aliceid , " reserved " , 0 , 0 ) ;
LP_aliceid ( qp - > tradeid , qp - > aliceid , " reserved " , 0 , 0 ) ;
if ( ( retstr = LP_quotereceived ( qp ) ) ! = 0 )
if ( ( retstr = LP_quotereceived ( qp ) ) ! = 0 )
free ( retstr ) ;
free ( retstr ) ;
@ -956,7 +979,7 @@ struct LP_quoteinfo *LP_trades_gotconnect(void *ctx,struct LP_quoteinfo *qp,stru
struct LP_quoteinfo * LP_trades_gotconnected ( void * ctx , struct LP_quoteinfo * qp , struct LP_quoteinfo * newqp , char * pairstr )
struct LP_quoteinfo * LP_trades_gotconnected ( void * ctx , struct LP_quoteinfo * qp , struct LP_quoteinfo * newqp , char * pairstr )
{
{
char * retstr ;
char * retstr ; int32_t changed ;
//char str[65]; printf("alice %s received CONNECTED.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
//char str[65]; printf("alice %s received CONNECTED.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
* newqp = * qp ;
* newqp = * qp ;
qp = newqp ;
qp = newqp ;
@ -966,6 +989,8 @@ struct LP_quoteinfo *LP_trades_gotconnected(void *ctx,struct LP_quoteinfo *qp,st
LP_aliceid ( qp - > tradeid , qp - > aliceid , " connected " , 0 , 0 ) ;
LP_aliceid ( qp - > tradeid , qp - > aliceid , " connected " , 0 , 0 ) ;
if ( ( retstr = LP_connectedalice ( qp , pairstr ) ) ! = 0 )
if ( ( retstr = LP_connectedalice ( qp , pairstr ) ) ! = 0 )
free ( retstr ) ;
free ( retstr ) ;
LP_mypriceset ( & changed , qp - > destcoin , qp - > srccoin , 0. ) ;
LP_alicequery_clear ( ) ;
return ( qp ) ;
return ( qp ) ;
}
}
//printf("LP_trades_alicevalidate error\n");
//printf("LP_trades_alicevalidate error\n");
@ -1193,6 +1218,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
if ( ( method = jstr ( argjson , " method " ) ) ! = 0 & & ( strcmp ( method , " reserved " ) = = 0 | | strcmp ( method , " connected " ) = = 0 | | strcmp ( method , " request " ) = = 0 | | strcmp ( method , " connect " ) = = 0 ) )
if ( ( method = jstr ( argjson , " method " ) ) ! = 0 & & ( strcmp ( method , " reserved " ) = = 0 | | strcmp ( method , " connected " ) = = 0 | | strcmp ( method , " request " ) = = 0 | | strcmp ( method , " connect " ) = = 0 ) )
{
{
LP_quoteparse ( & Q , argjson ) ;
LP_quoteparse ( & Q , argjson ) ;
if ( Q . satoshis < Q . txfee )
return ( 1 ) ;
LP_requestinit ( & Q . R , Q . srchash , Q . desthash , Q . srccoin , Q . satoshis - Q . txfee , Q . destcoin , Q . destsatoshis - Q . desttxfee , Q . timestamp , Q . quotetime , DEXselector ) ;
LP_requestinit ( & Q . R , Q . srchash , Q . desthash , Q . srccoin , Q . satoshis - Q . txfee , Q . destcoin , Q . destsatoshis - Q . desttxfee , Q . timestamp , Q . quotetime , DEXselector ) ;
LP_tradecommand_log ( argjson ) ;
LP_tradecommand_log ( argjson ) ;
rq = ( ( uint64_t ) Q . R . requestid < < 32 ) | Q . R . quoteid ;
rq = ( ( uint64_t ) Q . R . requestid < < 32 ) | Q . R . quoteid ;
@ -1201,11 +1228,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
printf ( " aliceid.%llu is expired by %d \n " , ( long long ) Q . aliceid , ( uint32_t ) time ( NULL ) - ( Q . timestamp + LP_AUTOTRADE_TIMEOUT * 20 ) ) ;
printf ( " aliceid.%llu is expired by %d \n " , ( long long ) Q . aliceid , ( uint32_t ) time ( NULL ) - ( Q . timestamp + LP_AUTOTRADE_TIMEOUT * 20 ) ) ;
return ( 1 ) ;
return ( 1 ) ;
}
}
qprice = ( double ) Q . destsatoshis / ( Q . satoshis - Q . txfee ) ; //jdouble(argjson,"price");
//printf("%s\n",jprint(argjson,0));
//printf("%s\n",jprint(argjson,0));
printf ( " %-4d (%-10u %10u) %12s id.%-20llu %5s/%-5s %12.8f -> %12.8f (%11.8f) | RT.%d %d n%d \n " , ( uint32_t ) time ( NULL ) % 3600 , Q . R . requestid , Q . R . quoteid , method , ( long long ) Q . aliceid , Q . srccoin , Q . destcoin , dstr ( Q . satoshis ) , dstr ( Q . destsatoshis ) , ( double ) Q . destsatoshis / Q . satoshis , LP_RTcount , LP_swapscount , G . netid ) ;
printf ( " %-4d (%-10u %10u) %12s id.%-20llu %5s/%-5s %12.8f -> %12.8f (%11.8f) | RT.%d %d n%d \n " , ( uint32_t ) time ( NULL ) % 3600 , Q . R . requestid , Q . R . quoteid , method , ( long long ) Q . aliceid , Q . srccoin , Q . destcoin , dstr ( Q . satoshis ) , dstr ( Q . destsatoshis ) , qprice , LP_RTcount , LP_swapscount , G . netid ) ;
retval = 1 ;
retval = 1 ;
aliceid = j64bits ( argjson , " aliceid " ) ;
aliceid = j64bits ( argjson , " aliceid " ) ;
qprice = jdouble ( argjson , " price " ) ;
if ( strcmp ( method , " reserved " ) = = 0 )
if ( strcmp ( method , " reserved " ) = = 0 )
{
{
bestprice = LP_bob_competition ( & counter , aliceid , qprice , 1 ) ;
bestprice = LP_bob_competition ( & counter , aliceid , qprice , 1 ) ;
@ -1377,7 +1404,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
if ( destsatoshis < ( autxo - > payment . value / LP_MINCLIENTVOL ) | | autxo - > payment . value < desttxfee * LP_MINSIZE_TXFEEMULT )
if ( destsatoshis < ( autxo - > payment . value / LP_MINCLIENTVOL ) | | autxo - > payment . value < desttxfee * LP_MINSIZE_TXFEEMULT )
{
{
printf ( " destsatoshis %.8f vs utxo %.8f this would have triggered an quote error -13 \n " , dstr ( destsatoshis ) , dstr ( autxo - > payment . value ) ) ;
printf ( " destsatoshis %.8f vs utxo %.8f this would have triggered an quote error -13 \n " , dstr ( destsatoshis ) , dstr ( autxo - > payment . value ) ) ;
return ( clonestr ( " { \" error \" : \" cant find a deposit that is close enough in size. make another deposit that is just a bit larger than what you want to trade \" } " ) ) ;
return ( clonestr ( " { \" error \" : \" cant find a deposit that is close enough in size. make another deposit that is a bit larger than what you want to trade \" } " ) ) ;
}
}
bestsatoshis = 1.001 * LP_basesatoshis ( dstr ( destsatoshis ) , maxprice , txfee , desttxfee ) ;
bestsatoshis = 1.001 * LP_basesatoshis ( dstr ( destsatoshis ) , maxprice , txfee , desttxfee ) ;
memset ( & B , 0 , sizeof ( B ) ) ;
memset ( & B , 0 , sizeof ( B ) ) ;
@ -1387,6 +1414,8 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
if ( LP_quotedestinfo ( & Q , autxo - > payment . txid , autxo - > payment . vout , autxo - > fee . txid , autxo - > fee . vout , G . LP_mypub25519 , autxo - > coinaddr ) < 0 )
if ( LP_quotedestinfo ( & Q , autxo - > payment . txid , autxo - > payment . vout , autxo - > fee . txid , autxo - > fee . vout , G . LP_mypub25519 , autxo - > coinaddr ) < 0 )
return ( clonestr ( " { \" error \" : \" cant set ordermatch quote info \" } " ) ) ;
return ( clonestr ( " { \" error \" : \" cant set ordermatch quote info \" } " ) ) ;
int32_t changed ;
int32_t changed ;
if ( strcmp ( base , " BTC " ) = = 0 | | strcmp ( " BTC " , rel ) = = 0 )
printf ( " %s/%s maxprice %.8f qprice %.8f txfee %.8f desttxfee %.8f \n " , base , rel , maxprice , ( double ) destsatoshis / ( bestsatoshis - txfee ) , dstr ( txfee ) , dstr ( desttxfee ) ) ;
LP_mypriceset ( & changed , autxo - > coin , base , 1. / maxprice ) ;
LP_mypriceset ( & changed , autxo - > coin , base , 1. / maxprice ) ;
LP_mypriceset ( & changed , base , autxo - > coin , 0. ) ;
LP_mypriceset ( & changed , base , autxo - > coin , 0. ) ;
return ( LP_trade ( ctx , myipaddr , mypubsock , & Q , maxprice , timeout , duration , tradeid , destpubkey ) ) ;
return ( LP_trade ( ctx , myipaddr , mypubsock , & Q , maxprice , timeout , duration , tradeid , destpubkey ) ) ;