Browse Source

Auto price

etomic
jl777 8 years ago
parent
commit
fea0b41053
  1. 6
      iguana/exchanges/LP_commands.c
  2. 30
      iguana/exchanges/LP_nativeDEX.c
  3. 31
      iguana/exchanges/LP_network.c
  4. 83
      iguana/exchanges/LP_prices.c
  5. 50
      iguana/exchanges/LP_statemachine.c

6
iguana/exchanges/LP_commands.c

@ -169,6 +169,12 @@ trust(pubkey, trust)\n\
else return(LP_pricepings(ctx,myipaddr,LP_mypubsock,base,rel,price * LP_profitratio));
} else return(clonestr("{\"error\":\"no price\"}"));
}
else if ( strcmp(method,"autoprice") == 0 )
{
if ( LP_autoprice(base,rel,price,jdouble(argjson,"margin")) < 0 )
return(clonestr("{\"error\":\"couldnt set autoprice\"}"));
else return(clonestr("{\"error\":\"autoprice error\"}"));
}
else if ( strcmp(method,"myprice") == 0 )
{
if ( LP_myprice(&bid,&ask,base,rel) > SMALLVAL )

30
iguana/exchanges/LP_nativeDEX.c

@ -19,13 +19,17 @@
//
// new features:
// stats
// auto-utxo creation
// autoprice
// autofill
// autoutxo
// fixes:
// -wiftaddr and no flag for importprivkey (VERGE)
// -avoid redundant importprivkey
// -KMD: z_sendmany to set nLockTime
// -put Atxfee and Btxfee into rememberfiles
// bugs"
// false detection of bobreclaim
// unduplicated bugs:
@ -437,13 +441,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
if ( (counter % 6000) == 10 )
{
LP_myutxo_updates(ctx,pubsock,passphrase);
/*if ( lastforward < now-3600 )
{
if ( (retstr= LP_registerall(0)) != 0 )
free(retstr);
//LP_forwarding_register(LP_mypubkey,pushaddr,pushport,10);
lastforward = now;
}*/
HASH_ITER(hh,LP_utxoinfos[0],utxo,utmp)
{
LP_utxo_spentcheck(pubsock,utxo);
@ -458,18 +455,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
}
}
}
//if ( IAMLP != 0 && (counter % 600) == 42 )
// LP_hellos();
/*if ( 0 && LP_canbind == 0 && (counter % (PSOCK_KEEPALIVE*MAINLOOP_PERSEC/2)) == 13 )
{
char keepalive[128];
sprintf(keepalive,"{\"method\":\"keepalive\"}");
//printf("send keepalive to %s pullsock.%d\n",pushaddr,pullsock);
if ( /LP_send(pullsock,keepalive,(int32_t)strlen(keepalive)+1,0) < 0 )
{
//LP_deadman_switch = 0;
}
}*/
HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht
{
cJSON *obj; int32_t height; bits256 zero;
@ -717,6 +702,11 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching stats rpcloop for port.%u\n",myport);
exit(-1);
}
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,(void *)&myipaddr) != 0 )
{
printf("error launching stats rpcloop for port.%u\n",myport);
exit(-1);
}
//if ( (retstr= basilisk_swapentry(0,0)) != 0 )
// free(retstr);
while ( 1 )

31
iguana/exchanges/LP_network.c

@ -576,37 +576,6 @@ char *LP_psock(char *myipaddr,int32_t ispaired)
*/
/*int32_t nn_tests(void *ctx,int32_t pullsock,char *pushaddr,int32_t nnother)
{
int32_t sock,n,m,timeout,retval = -1; char msg[512],*retstr;
printf("nn_tests.(%s)\n",pushaddr);
if ( (sock= nn_socket(AF_SP,nnother)) >= 0 )
{
if ( nn_connect(sock,pushaddr) < 0 )
printf("connect error %s\n",nn_strerror(nn_errno()));
else
{
sleep(3);
timeout = 1;
nn_setsockopt(sock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
sprintf(msg,"{\"method\":\"nn_tests\",\"ipaddr\":\"%s\"}",pushaddr);
n = /LP_send(sock,msg,(int32_t)strlen(msg)+1,0);
sleep(3);
LP_pullsock_check(ctx,&retstr,"127.0.0.1",-1,pullsock,0.);
sprintf(msg,"{\"method\":\"nn_tests2\",\"ipaddr\":\"%s\"}",pushaddr);
m = /LP_send(pullsock,msg,(int32_t)strlen(msg)+1,0);
printf(">>>>>>>>>>>>>>>>>>>>>> sent %d+%d bytes -> pullsock.%d retstr.(%s)\n",n,m,pullsock,retstr!=0?retstr:"");
if ( retstr != 0 )
{
free(retstr);
retval = 0;
}
}
nn_close(sock);
}
return(retval);
}*/
int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired)
{
int32_t nntype,pullsock,timeout; char bindaddr[128],connectaddr[128];

83
iguana/exchanges/LP_prices.c

@ -26,9 +26,11 @@ struct LP_priceinfo
char symbol[16];
uint64_t coinbits;
int32_t ind,pad;
double diagval;
double diagval,high,low,volume,btcvolume,last,bid,ask,prevday; // mostly bittrex info
double relvals[LP_MAXPRICEINFOS];
double myprices[LP_MAXPRICEINFOS];
double minprices[LP_MAXPRICEINFOS];
double margins[LP_MAXPRICEINFOS];
} LP_priceinfos[LP_MAXPRICEINFOS];
int32_t LP_numpriceinfos;
@ -650,7 +652,84 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
} else printf("error finding %s/%s %.8f\n",base,rel,price);
}
int32_t LP_autoprices;
int32_t LP_autoprice(char *base,char *rel,double minprice,double margin)
{
struct LP_priceinfo *basepp,*relpp;
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
{
basepp->minprices[relpp->ind] = minprice;
basepp->margins[relpp->ind] = margin;
LP_autoprices++;
return(0);
}
return(-1);
}
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;
while ( 1 )
{
if ( LP_autoprices == 0 )
{
sleep(60);
continue;
}
if ( (btcpp= LP_priceinfofind("BTC")) == 0 )
{
sleep(60);
continue;
}
if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 )
{
sleep(60);
continue;
}
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (array= jarray(&n,retjson,"result")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( (name= jstr(item,"MarketName")) != 0 )
{
if ( strncmp("BTC-",name,4) == 0 )
{
name += 4;
if ( (coinpp= LP_priceinfofind(name)) != 0 )
{
coinpp->high = jdouble(item,"High");
coinpp->low = jdouble(item,"Low");
coinpp->volume = jdouble(item,"Volume");
coinpp->btcvolume = jdouble(item,"BaseVolume");
coinpp->last = jdouble(item,"Last");
coinpp->bid = jdouble(item,"Bid");
coinpp->ask = jdouble(item,"Ask");
coinpp->prevday = jdouble(item,"PrevDay");
if ( (margin= coinpp->margins[btcpp->ind]) > SMALLVAL )
{
price = coinpp->bid * (1. - margin);
LP_mypriceset("BTC",name,1. / price);
}
if ( (margin= btcpp->margins[coinpp->ind]) > SMALLVAL )
{
price = coinpp->ask * (1. + margin);
LP_mypriceset(name,"BTC",price);
}
}
}
}
}
}
free_json(retjson);
}
free(retstr);
sleep(60);
}
}

50
iguana/exchanges/LP_statemachine.c

@ -113,6 +113,56 @@ FILE *basilisk_swap_save(struct basilisk_swap *swap,bits256 privkey,struct basil
}*/
return(fp);
}
/*if ( lastforward < now-3600 )
{
if ( (retstr= LP_registerall(0)) != 0 )
free(retstr);
//LP_forwarding_register(LP_mypubkey,pushaddr,pushport,10);
lastforward = now;
}*/
//if ( IAMLP != 0 && (counter % 600) == 42 )
// LP_hellos();
/*if ( 0 && LP_canbind == 0 && (counter % (PSOCK_KEEPALIVE*MAINLOOP_PERSEC/2)) == 13 )
{
char keepalive[128];
sprintf(keepalive,"{\"method\":\"keepalive\"}");
//printf("send keepalive to %s pullsock.%d\n",pushaddr,pullsock);
if ( /LP_send(pullsock,keepalive,(int32_t)strlen(keepalive)+1,0) < 0 )
{
//LP_deadman_switch = 0;
}
}*/
/*int32_t nn_tests(void *ctx,int32_t pullsock,char *pushaddr,int32_t nnother)
{
int32_t sock,n,m,timeout,retval = -1; char msg[512],*retstr;
printf("nn_tests.(%s)\n",pushaddr);
if ( (sock= nn_socket(AF_SP,nnother)) >= 0 )
{
if ( nn_connect(sock,pushaddr) < 0 )
printf("connect error %s\n",nn_strerror(nn_errno()));
else
{
sleep(3);
timeout = 1;
nn_setsockopt(sock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
sprintf(msg,"{\"method\":\"nn_tests\",\"ipaddr\":\"%s\"}",pushaddr);
n = /LP_send(sock,msg,(int32_t)strlen(msg)+1,0);
sleep(3);
LP_pullsock_check(ctx,&retstr,"127.0.0.1",-1,pullsock,0.);
sprintf(msg,"{\"method\":\"nn_tests2\",\"ipaddr\":\"%s\"}",pushaddr);
m = /LP_send(pullsock,msg,(int32_t)strlen(msg)+1,0);
printf(">>>>>>>>>>>>>>>>>>>>>> sent %d+%d bytes -> pullsock.%d retstr.(%s)\n",n,m,pullsock,retstr!=0?retstr:"");
if ( retstr != 0 )
{
free(retstr);
retval = 0;
}
}
nn_close(sock);
}
return(retval);
}*/
int32_t basilisk_swap_load(uint32_t requestid,uint32_t quoteid,bits256 *privkeyp,struct basilisk_request *rp,uint32_t *statebitsp,int32_t *optiondurationp)
{

Loading…
Cancel
Save