Browse Source

Test

etomic
jl777 8 years ago
parent
commit
270a0eb173
  1. 9
      iguana/exchanges/LP_commands.c
  2. 1
      iguana/exchanges/LP_include.h
  3. 16
      iguana/exchanges/LP_prices.c

9
iguana/exchanges/LP_commands.c

@ -34,7 +34,7 @@ char *LP_numutxos()
char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
{
char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr;
char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr;
//printf("stats_JSON(%s)\n",jprint(argjson,0));
if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 )
{
@ -165,9 +165,10 @@ trust(pubkey, trust)\n\
{
if ( price > SMALLVAL )
{
if ( LP_mypriceset(base,rel,price) < 0 )
if ( LP_mypriceset(&changed,base,rel,price) < 0 )
return(clonestr("{\"error\":\"couldnt set price\"}"));
else return(LP_pricepings(ctx,myipaddr,LP_mypubsock,base,rel,price * LP_profitratio));
else if ( changed != 0 )
return(LP_pricepings(ctx,myipaddr,LP_mypubsock,base,rel,price * LP_profitratio));
} else return(clonestr("{\"error\":\"no price\"}"));
}
else if ( strcmp(method,"autoprice") == 0 )
@ -208,7 +209,7 @@ trust(pubkey, trust)\n\
if ( price > SMALLVAL )
{
printf("price set (%s/%s) <- %.8f\n",rel,base,1./price);
LP_mypriceset(rel,base,1./price);
LP_mypriceset(&changed,rel,base,1./price);
return(LP_autotrade(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration")));
} else return(clonestr("{\"error\":\"no price set\"}"));
}

1
iguana/exchanges/LP_include.h

@ -269,6 +269,7 @@ void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
int32_t LP_coinbus(uint16_t coin_busport);
struct iguana_info *LP_coinfind(char *symbol);
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32);
char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price);
#endif

16
iguana/exchanges/LP_prices.c

@ -327,11 +327,14 @@ char *LP_myprices()
return(jprint(array,1));
}
int32_t LP_mypriceset(char *base,char *rel,double price)
int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
{
struct LP_priceinfo *basepp,*relpp; struct LP_pubkeyinfo *pubp;
*changedp = 0;
if ( base != 0 && rel != 0 && price > SMALLVAL && (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
{
if ( fabs(basepp->myprices[relpp->ind] - price) > SMALLVAL )
*changedp = 1;
basepp->myprices[relpp->ind] = price; // ask
//relpp->myprices[basepp->ind] = (1. / price); // bid
if ( (pubp= LP_pubkeyadd(LP_mypub25519)) != 0 )
@ -670,7 +673,7 @@ int32_t LP_autoprice(char *base,char *rel,double minprice,double margin)
void prices_loop(void *ignore)
{
//{"success":true,"message":"","result":[{"MarketName":"BTC-KMD","High":0.00040840,"Low":0.00034900,"Volume":328042.46061669,"Last":0.00037236,"BaseVolume":123.36439511,"TimeStamp":"2017-07-15T13:50:21.87","Bid":0.00035721,"Ask":0.00037069,"OpenBuyOrders":343,"OpenSellOrders":1690,"PrevDay":0.00040875,"Created":"2017-02-11T23:04:01.853"},
int32_t i,n; double margin,price; struct LP_priceinfo *coinpp,*btcpp; char *retstr,*name; cJSON *retjson,*array,*item;
int32_t i,n,changed; double margin,price; struct LP_priceinfo *coinpp,*btcpp; char *retstr,*name; cJSON *retjson,*array,*item; void *ctx = bitcoin_ctx();
while ( 1 )
{
if ( LP_autoprices == 0 )
@ -715,14 +718,15 @@ void prices_loop(void *ignore)
coinpp->prevday = jdouble(item,"PrevDay");
if ( (margin= coinpp->margins[btcpp->ind]) > SMALLVAL )
{
price = coinpp->bid * (1. - margin);
LP_mypriceset("BTC",name,1. / price);
price = 1. / coinpp->bid * (1. - margin);
LP_mypriceset(&changed,"BTC",name,price);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,"BTC",name,price);
}
if ( (margin= btcpp->margins[coinpp->ind]) > SMALLVAL )
{
price = coinpp->ask * (1. + margin);
LP_mypriceset(name,"BTC",price);
LP_mypriceset(&changed,name,"BTC",price);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,name,"BTC",price);
}
}
}

Loading…
Cancel
Save