From 0c993985df7bb8c9120e1fd85270e0d6321844e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Jun 2017 16:38:16 +0300 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 23 ++++++++++++++++++++++- iguana/exchanges/LP_quotes.c | 21 --------------------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 542f04704..48ae74b70 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -286,7 +286,7 @@ forward(pubkey,hexstr)\n\ { HASH_ITER(hh,LP_utxoinfos[1],utxo,tmp) { - if ( LP_ismine(utxo) > 0 && (strcmp(utxo->coin,base) == 0 || strcmp(utxo->coin,rel) == 0) ) + if ( LP_ismine(utxo) > 0 && strcmp(utxo->coin,base) == 0 )//|| strcmp(utxo->coin,rel) == 0) ) LP_priceping(LP_mypubsock,utxo,rel,LP_profitratio - 1.); //else printf("notmine.(%s %s)\n",utxo->coin,bits256_str(str,utxo->txid)); } diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index dd2422cdf..3648309f7 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -218,5 +218,6 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3 double LP_query(char *method,struct LP_quoteinfo *qp,char *base,char *rel,bits256 mypub); int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys); void LP_quotesinit(char *base,char *rel); +int32_t LP_priceping(int32_t pubsock,struct LP_utxoinfo *utxo,char *rel,double profitmargin); #endif diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a174c3c7c..a9f2cf819 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -138,6 +138,27 @@ int32_t LP_subsock_check(struct LP_peerinfo *peer) return(nonz); } +int32_t LP_priceping(int32_t pubsock,struct LP_utxoinfo *utxo,char *rel,double profitmargin) +{ + double price,bid,ask; uint32_t now; cJSON *retjson; struct LP_quoteinfo Q; char *retstr; + if ( (now= (uint32_t)time(NULL)) > utxo->T.swappending ) + utxo->T.swappending = 0; + if ( now > utxo->T.published+60 && utxo->T.swappending == 0 && utxo->S.swap == 0 && (price= LP_myprice(&bid,&ask,utxo->coin,rel)) != 0. ) + { + if ( LP_quoteinfoinit(&Q,utxo,rel,price) < 0 ) + return(-1); + Q.timestamp = (uint32_t)time(NULL); + retjson = LP_quotejson(&Q); + jaddstr(retjson,"method","quote"); + retstr = jprint(retjson,1); + //printf("PING.(%s)\n",retstr); + LP_send(pubsock,retstr,1); + utxo->T.published = now; + return(0); + } + return(-1); +} + void LP_utxo_spentcheck(int32_t pubsock,struct LP_utxoinfo *utxo,double profitmargin) { struct _LP_utxoinfo u; char str[65]; uint32_t now = (uint32_t)time(NULL); @@ -173,7 +194,7 @@ void LP_utxo_updates(int32_t pubsock,char *passphrase,double profitmargin) void LP_mainloop(char *myipaddr,struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,char *pushaddr,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin,cJSON *coins,char *seednode) { - char *retstr,*lpnode; uint8_t r; int32_t i,n,j,counter=0,nonz,lastn; struct LP_peerinfo *peer,*tmp; uint32_t now,lastforward = 0; cJSON *item; struct LP_utxoinfo *utxo,*utmp; + char *retstr; uint8_t r; int32_t i,n,j,counter=0,nonz,lastn; struct LP_peerinfo *peer,*tmp; uint32_t now,lastforward = 0; cJSON *item; struct LP_utxoinfo *utxo,*utmp; if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); diff --git a/iguana/exchanges/LP_quotes.c b/iguana/exchanges/LP_quotes.c index 7f7b7ade9..5d31ae262 100644 --- a/iguana/exchanges/LP_quotes.c +++ b/iguana/exchanges/LP_quotes.c @@ -373,27 +373,6 @@ cJSON *LP_autotrade(struct LP_utxoinfo *myutxo,char *base,double maxprice) return(bestitem); } -int32_t LP_priceping(int32_t pubsock,struct LP_utxoinfo *utxo,char *rel,double profitmargin) -{ - double price,bid,ask; uint32_t now; cJSON *retjson; struct LP_quoteinfo Q; char *retstr; - if ( (now= (uint32_t)time(NULL)) > utxo->T.swappending ) - utxo->T.swappending = 0; - if ( now > utxo->T.published+60 && utxo->T.swappending == 0 && utxo->S.swap == 0 && (price= LP_myprice(&bid,&ask,utxo->coin,rel)) != 0. ) - { - if ( LP_quoteinfoinit(&Q,utxo,rel,price) < 0 ) - return(-1); - Q.timestamp = (uint32_t)time(NULL); - retjson = LP_quotejson(&Q); - jaddstr(retjson,"method","quote"); - retstr = jprint(retjson,1); - //printf("PING.(%s)\n",retstr); - LP_send(pubsock,retstr,1); - utxo->T.published = now; - return(0); - } - return(-1); -} -