Browse Source

Bestfit

etomic
jl777 7 years ago
parent
commit
60f74c5a89
  1. 9
      iguana/exchanges/LP_commands.c
  2. 14
      iguana/exchanges/LP_ordermatch.c
  3. 2
      iguana/exchanges/autotrade
  4. 2
      iguana/exchanges/bestfit
  5. 6
      iguana/exchanges/install

9
iguana/exchanges/LP_commands.c

@ -67,6 +67,7 @@ enable(coin)\n\
disable(coin)\n\
inventory(coin)\n\
autotrade(base, rel, price, relvolume, timeout=10, duration=3600)\n\
bestfit(rel, relvolume)\n\
swapstatus()\n\
swapstatus(requestid, quoteid)\n\
public API:\n \
@ -127,13 +128,15 @@ forwardhex(pubkey,hex)\n\
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
else if ( strcmp(method,"autotrade") == 0 )
else if ( strcmp(method,"autotrade") == 0 || strcmp(method,"bestfit") == 0 )
{
if ( price > SMALLVAL )
{
printf("price set (%s/%s) <- %.8f\n",rel,base,1./price);
LP_mypriceset(rel,base,1./price);
return(LP_autotrade(ctx,myipaddr,pubsock,profitmargin,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration")));
if ( strcmp(method,"autotrade") == 0 )
return(LP_autotrade(ctx,myipaddr,pubsock,profitmargin,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration")));
else return(LP_bestfit(rel,jdouble(argjson,"relvolume")));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
}
@ -202,7 +205,7 @@ forwardhex(pubkey,hex)\n\
else if ( strcmp(method,"getprices") == 0 )
return(LP_prices());
else if ( strcmp(method,"orderbook") == 0 )
return(LP_orderbook(base,rel,jint(argjson,"duration")));
return(LP_orderbook(base,rel,jint(argjson,"duration")));
else if ( strcmp(method,"registerall") == 0 )
return(LP_registerall(jint(argjson,"numnodes")));
else if ( strcmp(method,"forward") == 0 )

14
iguana/exchanges/LP_ordermatch.c

@ -560,11 +560,23 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
return(retval);
}
char *LP_bestfit(char *rel,double relvolume)
{
struct LP_utxoinfo *autxo;
if ( relvolume <= 0. || LP_priceinfofind(rel) == 0 )
return(clonestr("{\"error\":\"invalid parameter\"}"));
if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 )
return(clonestr("{\"error\":\"cant find utxo that is big enough\"}"));
return(jprint(LP_utxojson(autxo),1));
}
char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,double profitmargin,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration)
{
int64_t satoshis,destsatoshis,desttxfee,txfee,bestdestsatoshis=0; bits256 txid,pubkey; char *obookstr,*retstr; cJSON *orderbook,*asks,*item,*bestitem=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; int32_t i,vout,numasks,DEXselector=0; uint32_t expiration; double ordermatchprice,bestmetric,metric,bestprice=0.,vol,price; struct LP_quoteinfo Q; struct LP_pubkeyinfo *pubp;
if ( duration <= 0 )
duration = LP_ORDERBOOK_DURATION;
if ( timeout <= 0 )
timeout = LP_AUTOTRADE_TIMEOUT;
if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 )
return(clonestr("{\"error\":\"invalid parameter\"}"));
if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 )
@ -574,8 +586,6 @@ char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,double profitmargi
desttxfee = LP_MIN_TXFEE;
if ( (txfee= LP_getestimatedrate(base) * LP_AVETXSIZE) < LP_MIN_TXFEE )
txfee = LP_MIN_TXFEE;
if ( timeout <= 0 )
timeout = LP_AUTOTRADE_TIMEOUT;
if ( (obookstr= LP_orderbook(base,rel,duration)) != 0 )
{
if ( (orderbook= cJSON_Parse(obookstr)) != 0 )

2
iguana/exchanges/autotrade

@ -1,2 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autotrade\",\"base\":\"REVS\",\"rel\":\"KMD\",\"volume\":1.01,\"price\":1.234}"
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"autotrade\",\"base\":\"REVS\",\"rel\":\"KMD\",\"relvolume\":1.01,\"price\":1.234}"

2
iguana/exchanges/bestfit

@ -0,0 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"bestfit\",\"rel\":\"KMD\",\"relvolume\":1.01}"

6
iguana/exchanges/install

@ -1,4 +1,4 @@
cp orderbook autotrade client run_osx client_osx run coins disable enable forward myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv lookup pub setprice status utxos ../dexscripts
cp bestfit orderbook autotrade client run_osx client_osx run coins disable enable forward myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv lookup pub setprice status utxos ../dexscripts
cd ../dexscripts
cp ../exchanges/passphrase ../exchanges/userpass .
echo you will need to modify passphrase file with your passphrase and userpass file with userpass value
#cp ../exchanges/passphrase ../exchanges/userpass .
echo you will need to have a passphrase file with your passphrase and userpass file with userpass value in dexscripts dir

Loading…
Cancel
Save