Browse Source

Test

etomic
jl777 8 years ago
parent
commit
996fba765e
  1. 2
      iguana/exchanges/LP_coins.c
  2. 2
      iguana/exchanges/LP_include.h
  3. 2
      iguana/exchanges/LP_rpc.c
  4. 33
      iguana/exchanges/LP_tradebots.c

2
iguana/exchanges/LP_coins.c

@ -198,7 +198,7 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
if ( coin->userpass[0] != 0 ) if ( coin->userpass[0] != 0 )
{ {
jaddnum(item,"height",LP_getheight(coin)); jaddnum(item,"height",LP_getheight(coin));
balance = LP_smartbalance(coin); balance = LP_RTsmartbalance(coin);
jaddnum(item,"balance",dstr(balance)); jaddnum(item,"balance",dstr(balance));
jaddnum(item,"KMDvalue",dstr(LP_KMDvalue(coin,balance))); jaddnum(item,"KMDvalue",dstr(LP_KMDvalue(coin,balance)));
} }

2
iguana/exchanges/LP_include.h

@ -356,7 +356,7 @@ uint16_t LP_psock_get(char *connectaddr,char *connectaddr2,char *publicaddr,int3
//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); //void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
int32_t LP_coinbus(uint16_t coin_busport); int32_t LP_coinbus(uint16_t coin_busport);
int32_t LP_nanomsg_recvs(void *ctx); int32_t LP_nanomsg_recvs(void *ctx);
uint64_t LP_smartbalance(struct iguana_info *coin); uint64_t LP_RTsmartbalance(struct iguana_info *coin);
int32_t LP_getheight(struct iguana_info *coin); int32_t LP_getheight(struct iguana_info *coin);
int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg); int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg);
struct iguana_info *LP_coinfind(char *symbol); struct iguana_info *LP_coinfind(char *symbol);

2
iguana/exchanges/LP_rpc.c

@ -397,7 +397,7 @@ int32_t LP_getheight(struct iguana_info *coin)
return(height); return(height);
} }
uint64_t LP_smartbalance(struct iguana_info *coin) uint64_t LP_RTsmartbalance(struct iguana_info *coin)
{ {
cJSON *array,*item; char buf[512],*retstr; int32_t i,n; uint64_t valuesum,value; cJSON *array,*item; char buf[512],*retstr; int32_t i,n; uint64_t valuesum,value;
valuesum = 0; valuesum = 0;

33
iguana/exchanges/LP_tradebots.c

@ -399,7 +399,7 @@ char *LP_tradebot_list(void *ctx,int32_t pubsock,cJSON *argjson)
char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,double relvolume) char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,double relvolume)
{ {
struct LP_tradebot *bot; int32_t i,n; cJSON *array,*item,*retjson; uint64_t txfees,balance=0; struct iguana_info *basecoin,*relcoin; struct LP_tradebot *bot; double shortfall; int32_t i,n; cJSON *array,*item,*retjson; uint64_t txfees,balance=0,abalance=0; struct iguana_info *basecoin,*relcoin;
basecoin = LP_coinfind(base); basecoin = LP_coinfind(base);
relcoin = LP_coinfind(rel); relcoin = LP_coinfind(rel);
if ( basecoin == 0 || relcoin == 0 || basecoin->inactive != 0 || relcoin->inactive != 0 ) if ( basecoin == 0 || relcoin == 0 || basecoin->inactive != 0 || relcoin->inactive != 0 )
@ -412,22 +412,43 @@ char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,doubl
{ {
item = jitem(array,i); item = jitem(array,i);
//valuesum += j64bits(item,"value") + j64bits(item,"value2"); //valuesum += j64bits(item,"value") + j64bits(item,"value2");
balance += j64bits(item,"satoshis"); abalance += j64bits(item,"satoshis");
} }
} }
free_json(array); free_json(array);
} }
txfees = 10 * relcoin->txfee; txfees = 10 * relcoin->txfee;
if ( dstr(balance) < relvolume + dstr(txfees) ) if ( dstr(abalance) < relvolume + dstr(txfees) )
{ {
printf("%s inventory balance only %.8f, less than relvolume %.8f + txfees %.8f\n",rel,dstr(balance),relvolume,dstr(txfees)); printf("%s inventory balance only %.8f, less than relvolume %.8f + txfees %.8f\n",rel,dstr(abalance),relvolume,dstr(txfees));
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
jaddstr(retjson,"error","not enough funds"); jaddstr(retjson,"error","not enough funds");
jaddstr(retjson,"coin",rel); jaddstr(retjson,"coin",rel);
jaddnum(retjson,"balance",dstr(balance)); jaddnum(retjson,"balance",dstr(abalance));
jaddnum(retjson,"relvolume",relvolume); jaddnum(retjson,"relvolume",relvolume);
jaddnum(retjson,"txfees",dstr(txfees)); jaddnum(retjson,"txfees",dstr(txfees));
jaddnum(retjson,"shortfall",(relvolume + dstr(txfees)) - dstr(balance)); shortfall = (relvolume + dstr(txfees)) - dstr(balance);
jaddnum(retjson,"shortfall",shortfall);
if ( (balance= LP_RTsmartbalance(relcoin)) > abalance+SATOSHIDEN*shortfall )
{
char *withdrawstr; cJSON *outputjson,*withdrawjson,*outputs,*item;
outputjson = cJSON_CreateObject();
outputs = cJSON_CreateArray();
item = cJSON_CreateObject();
jaddnum(item,relcoin->smartaddr,relvolume+dstr(txfees));
jaddi(outputs,item);
item = cJSON_CreateObject();
jaddnum(item,relcoin->smartaddr,(relvolume+dstr(txfees))/777);
jaddi(outputs,item);
jadd(outputjson,"outputs",outputs);
if ( (withdrawstr= LP_withdraw(relcoin,outputjson)) != 0 )
{
if ( (withdrawjson= cJSON_Parse(withdrawstr)) != 0 )
jadd(retjson,"withdraw",withdrawjson);
free(withdrawstr);
}
free_json(outputjson);
}
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
printf("disp.%d tradebot_buy(%s / %s) maxprice %.8f relvolume %.8f\n",dispdir,base,rel,maxprice,relvolume); printf("disp.%d tradebot_buy(%s / %s) maxprice %.8f relvolume %.8f\n",dispdir,base,rel,maxprice,relvolume);

Loading…
Cancel
Save