Browse Source

Test

etomic
jl777 8 years ago
parent
commit
b697da6e6b
  1. 11
      iguana/exchanges/LP_commands.c
  2. 2
      iguana/exchanges/LP_include.h
  3. 67
      iguana/exchanges/LP_portfolio.c
  4. 4
      iguana/exchanges/LP_prices.c
  5. 2
      iguana/exchanges/goals

11
iguana/exchanges/LP_commands.c

@ -96,8 +96,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r
available localhost RPC commands:\n \
setprice(base, rel, price)\n\
autoprice(base, rel, price, margin, type)\n\
autofill(base, rel, price, relvolume)\n\
goal(coin, perc)\n\
goal(coin=*, perc=<autocalc>)\n\
myprice(base, rel)\n\
enable(coin)\n\
disable(coin)\n\
@ -183,12 +182,12 @@ trust(pubkey, trust)\n\
return(clonestr("{\"error\":\"couldnt set autoprice\"}"));
else return(clonestr("{\"result\":\"success\"}"));
}
else if ( strcmp(method,"autofill") == 0 )
/*else if ( strcmp(method,"autofill") == 0 )
{
if ( LP_autofill(base,rel,price,jdouble(argjson,"relvolume")) < 0 )
return(clonestr("{\"error\":\"couldnt set autofill\"}"));
else return(clonestr("{\"result\":\"success\"}"));
}
}*/
else if ( strcmp(method,"myprice") == 0 )
{
if ( LP_myprice(&bid,&ask,base,rel) > SMALLVAL )
@ -268,10 +267,10 @@ trust(pubkey, trust)\n\
}
}
else if ( strcmp(method,"goal") == 0 )
{
return(LP_portfolio_goal(coin,jdouble(argjson,"perc")));
}
}
else if ( strcmp(method,"goal") == 0 )
return(LP_portfolio_goal("*",100.));
else if ( strcmp(method,"swapstatus") == 0 )
{
uint32_t requestid,quoteid;

2
iguana/exchanges/LP_include.h

@ -183,7 +183,7 @@ struct iguana_info
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag;
char symbol[16],smartaddr[64],userpass[1024],serverport[128];
// portfolio
double price_kmd,force,perc,goal,goalperc;
double price_kmd,force,perc,goal,goalperc,relvolume;
uint64_t maxamount,kmd_equiv,balanceA,balanceB,valuesumA,valuesumB;
uint8_t pubkey33[33];
};

67
iguana/exchanges/LP_portfolio.c

@ -29,6 +29,7 @@ cJSON *LP_portfolio_entry(struct iguana_info *coin)
jaddnum(item,"perc",coin->perc);
jaddnum(item,"goal",coin->goal);
jaddnum(item,"goalperc",coin->goalperc);
jaddnum(item,"relvolume",coin->relvolume);
jaddnum(item,"force",coin->force);
jaddnum(item,"balanceA",dstr(coin->balanceA));
jaddnum(item,"valuesumA",dstr(coin->valuesumA));
@ -90,14 +91,18 @@ char *LP_portfolio()
}
else
{
coin->relvolume = 0.;
if ( kmdsum > SMALLVAL )
coin->perc = 100. * coin->kmd_equiv / kmdsum;
if ( goalsum > SMALLVAL && coin->goal > SMALLVAL )
{
coin->goalperc = 100. * coin->goal / goalsum;
if ( (coin->force= (coin->goalperc - coin->perc)) < 0. )
{
coin->force *= -coin->force;
else coin->force *= coin->force;
if ( coin->price_kmd > SMALLVAL )
coin->relvolume = (coin->kmd_equiv * (coin->goalperc - coin->perc) / 100.) / coin->price_kmd;
} else coin->force *= coin->force;
if ( coin->force > maxval )
{
maxval = coin->force;
@ -131,17 +136,45 @@ char *LP_portfolio()
char *LP_portfolio_goal(char *symbol,double goal)
{
struct iguana_info *coin;
if ( (coin= LP_coinfind(symbol)) != 0 && coin->inactive == 0 )
struct iguana_info *coin,*tmp; int32_t iter,n = 0; double kmdbtc = 50.;
if ( strcmp(symbol,"*") == 0 )
{
if ( (coin= LP_coinfind("KMD")) != 0 )
coin->goal = 25.;
if ( (coin= LP_coinfind("BTC")) != 0 )
coin->goal = 25.;
for (iter=0; iter<2; iter++)
{
HASH_ITER(hh,LP_coins,coin,tmp)
{
if ( iter == 0 )
coin->goal = 0;
if ( coin->inactive == 0 && strcmp(coin->symbol,"KMD") != 0 && strcmp(coin->symbol,"BTC") != 0 )
{
if ( iter == 0 )
n++;
else coin->goal = (100. - kmdbtc) / n;
}
}
if ( n == 0 )
break;
}
if ( (coin= LP_coinfind("KMD")) != 0 )
coin->goal = kmdbtc * 0.5;
if ( (coin= LP_coinfind("BTC")) != 0 )
coin->goal = kmdbtc * 0.5;
return(LP_portfolio());
}
else if ( (coin= LP_coinfind(symbol)) != 0 && coin->inactive == 0 )
{
coin->goal = goal;
return(LP_portfolio());
} else return(clonestr("{\error\":\"cant set goal for inactive coin\"}"));
}
int32_t LP_autoprices,LP_autofills;
int32_t LP_autoprices;
int32_t LP_autofill(char *base,char *rel,double maxprice,double totalrelvolume)
/*int32_t LP_autofill(char *base,char *rel,double maxprice,double totalrelvolume)
{
struct LP_priceinfo *basepp,*relpp;
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
@ -152,7 +185,7 @@ int32_t LP_autofill(char *base,char *rel,double maxprice,double totalrelvolume)
return(0);
}
return(-1);
}
}*/
int32_t LP_autoprice(char *base,char *rel,double minprice,double margin,char *type)
{
@ -361,7 +394,6 @@ void prices_loop(void *ignore)
char *buycoin,*sellcoin,*retstr; struct iguana_info *buy,*sell; cJSON *retjson; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx();
while ( 1 )
{
printf("prices_loop\n");
if ( (btcpp= LP_priceinfofind("BTC")) == 0 )
{
sleep(60);
@ -369,21 +401,20 @@ void prices_loop(void *ignore)
}
if ( LP_autoprices != 0 )
LP_autoprice_iter(ctx,btcpp);
if ( LP_autofills > 0 )
if ( (retstr= LP_portfolio()) != 0 )
{
if ( (retstr= LP_portfolio()) != 0 )
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
if ( (buycoin= jstr(retjson,"buycoin")) != 0 && (buy= LP_coinfind(buycoin)) != 0 && (sellcoin= jstr(retjson,"sellcoin")) != 0 && (sell= LP_coinfind(sellcoin)) != 0 )
{
if ( (buycoin= jstr(retjson,"buycoin")) != 0 && (buy= LP_coinfind(buycoin)) != 0 && (sellcoin= jstr(retjson,"sellcoin")) != 0 && (sell= LP_coinfind(sellcoin)) != 0 )
{
printf("buy.%s force %f, sell.%s force %f\n",buycoin,jdouble(retjson,"buyforce"),sellcoin,jdouble(retjson,"sellforce"));
} else printf("buy or sell missing.(%s)\n",jprint(retjson,0));
free_json(retjson);
}
free(retstr);
printf("base buy.%s force %f, rel sell.%s force %f relvolume %f\n",buycoin,jdouble(retjson,"buyforce"),sellcoin,jdouble(retjson,"sellforce"),sell->relvolume);
//if ( (autxo= LP_utxo_bestfit(sellcoin,SATOSHIDEN * relvolume)) == 0 )
// return(clonestr("{\"error\":\"cant find utxo that is big enough\"}"));
} else printf("buy or sell missing.(%s)\n",jprint(retjson,0));
free_json(retjson);
}
} else printf("LP_autofills.%d\n",LP_autofills);
free(retstr);
}
sleep(60);
}
}

4
iguana/exchanges/LP_prices.c

@ -31,8 +31,8 @@ struct LP_priceinfo
double myprices[LP_MAXPRICEINFOS];
double minprices[LP_MAXPRICEINFOS]; // autoprice
double margins[LP_MAXPRICEINFOS];
double maxprices[LP_MAXPRICEINFOS]; // autofill of base/rel
double relvols[LP_MAXPRICEINFOS];
//double maxprices[LP_MAXPRICEINFOS]; // autofill of base/rel
//double relvols[LP_MAXPRICEINFOS];
FILE *fps[LP_MAXPRICEINFOS];
} LP_priceinfos[LP_MAXPRICEINFOS];
int32_t LP_numpriceinfos;

2
iguana/exchanges/goals

@ -0,0 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"goal\"}"
Loading…
Cancel
Save