Browse Source

Initial fomoflag

jl777
jl777 7 years ago
parent
commit
17cdf87074
  1. 20
      iguana/exchanges/LP_commands.c
  2. 23
      iguana/exchanges/LP_ordermatch.c
  3. 2
      iguana/exchanges/LP_portfolio.c
  4. 24
      iguana/exchanges/LP_prices.c
  5. 2
      iguana/exchanges/LP_tradebots.c
  6. 2
      iguana/exchanges/coins

20
iguana/exchanges/LP_commands.c

@ -477,18 +477,30 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
}
else if ( strcmp(method,"buy") == 0 )
{
//*
int32_t fomo = 0; double vol;
if ( jobj(argjson,"fomo") != 0 )
{
fomo = 1;
price = 1.;
vol = jdouble(argjson,"fomo");
} else vol = jdouble(argjson,"relvolume");
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,base,rel,price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
else if ( strcmp(method,"sell") == 0 )
{
//*
int32_t fomo = 0; double vol;
if ( jobj(argjson,"dump") != 0 )
{
fomo = 1;
price = 1.;
vol = jdouble(argjson,"fomo");
} else vol = jdouble(argjson,"basevolume");
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,rel,base,1./price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
}

23
iguana/exchanges/LP_ordermatch.c

@ -1444,7 +1444,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
return(retval);
}
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,uint32_t tradeid)
char *LP_autobuy(void *ctx,int32_t fomoflag,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,uint32_t tradeid)
{
uint64_t desttxfee,txfee; uint32_t lastnonce; int64_t bestsatoshis=0,destsatoshis; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,B,A; struct LP_quoteinfo Q; bits256 pubkeys[100]; struct LP_address_utxo *utxos[4096]; int32_t num=0,maxiters=100,i,max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
basecoin = LP_coinfind(base);
@ -1483,14 +1483,6 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
jaddnum(retjson,"wait",Alice_expiration-time(NULL));
return(jprint(retjson,1));
} else LP_alicequery_clear();
if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 )
return(clonestr("{\"error\":\"invalid parameter\"}"));
if ( strcmp("BTC",rel) == 0 )
maxprice *= 1.01;
else maxprice *= 1.001;
memset(pubkeys,0,sizeof(pubkeys));
LP_txfees(&txfee,&desttxfee,base,rel);
destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee;
LP_address_utxo_reset(&num,relcoin);
if ( num <= 1 )
{
@ -1501,6 +1493,19 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
}
return(clonestr("{\"error\":\"not enough utxo, please make more deposits\"}"));
}
if ( fomoflag != 0 )
{
// fomo -> price is 1. and needs to be set
maxprice = LP_fomoprice(base,rel,relvolume);
}
if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 )
return(clonestr("{\"error\":\"invalid parameter\"}"));
if ( strcmp("BTC",rel) == 0 )
maxprice *= 1.01;
else maxprice *= 1.001;
memset(pubkeys,0,sizeof(pubkeys));
LP_txfees(&txfee,&desttxfee,base,rel);
destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee;
autxo = 0;
for (i=0; i<maxiters; i++)
{

2
iguana/exchanges/LP_portfolio.c

@ -763,7 +763,7 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str
//if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 )
{
memset(zero.bytes,0,sizeof(zero));
if ( (retstr2= LP_autobuy(ctx,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600,gui,LP_lastnonce+1,zero,1)) != 0 )
if ( (retstr2= LP_autobuy(ctx,0,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600,gui,LP_lastnonce+1,zero,1)) != 0 )
{
if ( (retjson2= cJSON_Parse(retstr2)) != 0 )
{

24
iguana/exchanges/LP_prices.c

@ -969,6 +969,30 @@ char *LP_orderbook(char *base,char *rel,int32_t duration)
return(jprint(retjson,1));
}
double LP_fomoprice(char *base,char *rel,double relvolume)
{
char *retstr; cJSON *retjson,*asks; int32_t i,numasks; double biggest,price,fomoprice = 0.;
if ( (retstr= LP_orderbook(base,rel,0)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (asks= jarray(&numasks,retjson,"asks")) != 0 && numasks > 0 )
{
for (i=0; i<numasks; i++)
{
item = jitem(asks,i);
biggest = jdouble(item,"maxvolume");
price = jdouble(item,"price");
printf("fomoprice i.%d %.8f vol %.8f\n",i,biggest,price);
}
}
free_json(retjson);
}
free(retstr);
}
return(fomoprice);
}
int64_t LP_KMDvalue(struct iguana_info *coin,int64_t balance)
{
double price = 0.; int64_t KMDvalue=0;

2
iguana/exchanges/LP_tradebots.c

@ -338,7 +338,7 @@ void LP_tradebot_timeslice(void *ctx,struct LP_tradebot *bot)
{
if ( remaining < 0.001 )
break;
if ( (retstr= LP_autobuy(ctx,LP_myipaddr,LP_mypubsock,bot->base,bot->rel,bot->maxprice,remaining/i,0,0,G.gui,0,destpubkey,tradeid)) != 0 )
if ( (retstr= LP_autobuy(ctx,0,LP_myipaddr,LP_mypubsock,bot->base,bot->rel,bot->maxprice,remaining/i,0,0,G.gui,0,destpubkey,tradeid)) != 0 )
{
if ( (retjson2= cJSON_Parse(retstr)) != 0 )
{

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save