Browse Source

Test

etomic
jl777 7 years ago
parent
commit
18b5c793b0
  1. 2
      iguana/exchanges/DEXstats.h
  2. 8
      iguana/exchanges/LP_commands.c
  3. 19
      iguana/exchanges/LP_forwarding.c
  4. 2
      iguana/exchanges/LP_include.h
  5. 2
      iguana/exchanges/LP_nativeDEX.c
  6. 18
      iguana/exchanges/LP_quotes.c
  7. 2
      iguana/exchanges/mm.c
  8. 7
      iguana/exchanges/stats.c

2
iguana/exchanges/DEXstats.h

@ -927,7 +927,7 @@ char *stats_prices(char *symbol,char *dest,struct DEXstats_disp *prices,int32_t
}
#ifndef FROM_MARKETMAKER
char *stats_JSON(cJSON *argjson,char *remoteaddr,uint16_t port)
char *stats_JSON(char *myipaddr,int32_t mypubsock,double profitmargin,cJSON *argjson,char *remoteaddr,uint16_t port)
{
char *method,*agent,*retstr,*source,*dest; struct tai T; uint32_t endtimestamp; struct DEXstats_disp prices[365]; int32_t leftdatenum,seconds,numdates;
if ( (method= jstr(argjson,"method")) == 0 )

8
iguana/exchanges/LP_commands.c

@ -19,7 +19,7 @@
//
char *stats_JSON(int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
char *stats_JSON(char *myipaddr,int32_t pubsock,double profitmargin,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
{
char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport,pushport,subport; int32_t otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson; struct iguana_info *ptr;
if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 )
@ -100,7 +100,7 @@ forwardhex(pubkey,hex)\n\
{
if ( LP_mypriceset(base,rel,price) < 0 )
return(clonestr("{\"error\":\"couldnt set price\"}"));
else return(LP_pricepings(LP_mypubsock,base,rel,price * LP_profitratio));
else return(LP_pricepings(myipaddr,LP_mypubsock,profitmargin,base,rel,price * LP_profitratio));
} else return(clonestr("{\"error\":\"no price\"}"));
}
else if ( strcmp(method,"myprice") == 0 )
@ -117,7 +117,7 @@ forwardhex(pubkey,hex)\n\
} else return(clonestr("{\"error\":\"no price set\"}"));
}
else if ( strcmp(method,"autotrade") == 0 )
return(LP_autotrade(base,rel,jdouble(argjson,"price"),jdouble(argjson,"volume")));
return(LP_autotrade(myipaddr,pubsock,profitmargin,base,rel,jdouble(argjson,"price"),jdouble(argjson,"volume")));
}
else if ( (coin= jstr(argjson,"coin")) != 0 )
{
@ -189,7 +189,7 @@ forwardhex(pubkey,hex)\n\
printf("FORWARDED.(%s)\n",jprint(argjson,0));
if ( (reqjson= LP_dereference(argjson,"forward")) != 0 )
{
if ( LP_forward(jbits256(argjson,"pubkey"),jprint(reqjson,1),1) > 0 )
if ( LP_forward(myipaddr,pubsock,profitmargin,jbits256(argjson,"pubkey"),jprint(reqjson,1),1) > 0 )
retstr = clonestr("{\"result\":\"success\"}");
else retstr = clonestr("{\"error\":\"error forwarding\"}");
} else retstr = clonestr("{\"error\":\"cant recurse forwards\"}");

19
iguana/exchanges/LP_forwarding.c

@ -180,14 +180,25 @@ char *LP_forwardhex(int32_t pubsock,bits256 pubkey,char *hexstr)
return(retstr);
}
int32_t LP_forward(bits256 pubkey,char *jsonstr,int32_t freeflag)
int32_t LP_forward(char *myipaddr,int32_t pubsock,double profitmargin,bits256 pubkey,char *jsonstr,int32_t freeflag)
{
struct LP_forwardinfo *ptr; struct LP_peerinfo *peer,*tmp; char *hexstr,*retstr; int32_t len,retval = -1; cJSON *retjson,*reqjson;
struct LP_forwardinfo *ptr; struct LP_peerinfo *peer,*tmp; char *hexstr,*retstr; int32_t len,retval = -1; cJSON *retjson,*reqjson,*argjson;
if ( jsonstr == 0 || jsonstr[0] == 0 )
return(-1);
if ( bits256_nonz(pubkey) != 0 )
{
if ( IAMLP != 0 && (ptr= LP_forwardfind(pubkey)) != 0 && ptr->pushsock >= 0 && ptr->lasttime > time(NULL)-LP_KEEPALIVE )
if ( bits256_cmp(pubkey,LP_mypubkey) == 0 )
{
printf("GOT FORWARDED.(%s)\n",jsonstr);
if ( (argjson= cJSON_Parse(jsonstr)) != 0 )
{
if ( (retstr= LP_command_process(myipaddr,pubsock,argjson,0,0,profitmargin)) != 0 )
free(retstr);
free_json(argjson);
}
return(1);
}
else if ( IAMLP != 0 && (ptr= LP_forwardfind(pubkey)) != 0 && ptr->pushsock >= 0 && ptr->lasttime > time(NULL)-LP_KEEPALIVE )
{
return(LP_send(ptr->pushsock,jsonstr,1));
}
@ -207,7 +218,7 @@ int32_t LP_forward(bits256 pubkey,char *jsonstr,int32_t freeflag)
free(retstr);
}
} else retval = 0;
if ( retval == 0 && peer->pushsock >= 0 )
if ( retval >= 0 && peer->pushsock >= 0 )
{
//printf("found LPnode.(%s) forward.(%s)\n",peer->ipaddr,jsonstr);
len = (int32_t)strlen(jsonstr) + 1;

2
iguana/exchanges/LP_include.h

@ -221,7 +221,7 @@ 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_forward(bits256 pubkey,char *jsonstr,int32_t freeflag);
int32_t LP_forward(char *myipaddr,int32_t pubsock,double profitmargin,bits256 pubkey,char *jsonstr,int32_t freeflag);
int32_t LP_ismine(struct LP_utxoinfo *utxo);
int32_t LP_isavailable(struct LP_utxoinfo *utxo);
struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port);

2
iguana/exchanges/LP_nativeDEX.c

@ -84,7 +84,7 @@ char *LP_command_process(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *
char *retstr=0;
if ( LP_tradecommand(myipaddr,pubsock,argjson,data,datalen,profitmargin) <= 0 )
{
if ( (retstr= stats_JSON(pubsock,argjson,"127.0.0.1",0)) != 0 )
if ( (retstr= stats_JSON(myipaddr,pubsock,profitmargin,argjson,"127.0.0.1",0)) != 0 )
{
printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr);
if ( pubsock >= 0 )

18
iguana/exchanges/LP_quotes.c

@ -171,7 +171,7 @@ char *LP_quotereceived(cJSON *argjson)
} else return(clonestr("{\"error\":\"nullptr\"}"));
}
char *LP_pricepings(int32_t pubsock,char *base,char *rel,double price)
char *LP_pricepings(char *myipaddr,int32_t pubsock,double profitmargin,char *base,char *rel,double price)
{
bits256 zero; cJSON *reqjson = cJSON_CreateObject();
jaddbits256(reqjson,"pubkey",LP_mypubkey);
@ -189,7 +189,7 @@ char *LP_pricepings(int32_t pubsock,char *base,char *rel,double price)
jaddstr(reqjson,"method","forward");
jaddstr(reqjson,"method2","postprice");
memset(zero.bytes,0,sizeof(zero));
LP_forward(zero,jprint(reqjson,1),1);
LP_forward(myipaddr,pubsock,profitmargin,zero,jprint(reqjson,1),1);
}
return(clonestr("{\"result\":\"success\"}"));
}
@ -229,7 +229,7 @@ int32_t LP_arrayfind(cJSON *array,bits256 txid,int32_t vout)
return(-1);
}
double LP_query(char *method,struct LP_quoteinfo *qp)
double LP_query(char *myipaddr,int32_t mypubsock,double profitmargin,char *method,struct LP_quoteinfo *qp)
{
cJSON *reqjson; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo;
if ( strcmp(method,"request") == 0 )
@ -256,7 +256,7 @@ double LP_query(char *method,struct LP_quoteinfo *qp)
{
jaddstr(reqjson,"method2",method);
jaddstr(reqjson,"method","forward");
LP_forward(qp->srchash,jprint(reqjson,1),1);
LP_forward(myipaddr,mypubsock,profitmargin,qp->srchash,jprint(reqjson,1),1);
}
for (i=0; i<30; i++)
{
@ -320,7 +320,7 @@ int32_t LP_connectstartbob(int32_t pubsock,struct LP_utxoinfo *utxo,cJSON *argjs
retstr = jprint(retjson,1);
if ( pubsock >= 0 )
LP_send(pubsock,retstr,1);
else LP_forward(utxo->S.otherpubkey,retstr,1);
else LP_forward(myipaddr,pubsock,profitmargin,utxo->S.otherpubkey,retstr,1);
retval = 0;
} else printf("error launching swaploop\n");
} else printf("printf error nn_connect to %s\n",pairstr);
@ -427,7 +427,7 @@ int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *d
retstr = jprint(retjson,1);
if ( pubsock >= 0 )
LP_send(pubsock,retstr,1);
else LP_forward(utxo->S.otherpubkey,retstr,1);
else LP_forward(myipaddr,pubsock,profitmargin,utxo->S.otherpubkey,retstr,1);
utxo->T.lasttime = (uint32_t)time(NULL);
} else printf("null price\n");
} else printf("swappending.%u swap.%p\n",utxo->T.swappending,utxo->S.swap);
@ -449,7 +449,7 @@ int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *d
return(retval);
}
char *LP_autotrade(char *base,char *rel,double maxprice,double volume)
char *LP_autotrade(char *myipaddr,int32_t mypubsock,double profitmargin,char *base,char *rel,double maxprice,double volume)
{
uint64_t destsatoshis,asatoshis; bits256 txid,pubkey; char *obookstr; cJSON *orderbook,*asks,*item,*bestitem=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; int32_t i,vout,numasks,DEXselector=0; uint32_t expiration; double ordermatchprice,bestmetric,metric,bestprice=0.,vol,price; struct LP_quoteinfo Q;
if ( maxprice <= 0. || volume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 )
@ -512,11 +512,11 @@ char *LP_autotrade(char *base,char *rel,double maxprice,double volume)
return(clonestr("{\"error\":\"cant set ordermatch quote\"}"));
if ( LP_quotedestinfo(&Q,Q.timestamp+1,asatoshis,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypubkey,autxo->coinaddr) < 0 )
return(clonestr("{\"error\":\"cant set ordermatch quote info\"}"));
price = LP_query("request",&Q);
price = LP_query(myipaddr,mypubsock,profitmargin,"request",&Q);
if ( price <= maxprice )
{
bestitem = LP_quotejson(&Q);
price = LP_query("connect",&Q);
price = LP_query(myipaddr,mypubsock,profitmargin,"connect",&Q);
LP_requestinit(&Q.R,Q.srchash,Q.desthash,base,Q.satoshis,Q.destcoin,Q.destsatoshis,Q.timestamp,Q.quotetime,DEXselector);
expiration = (uint32_t)time(NULL) + 10;
while ( time(NULL) < expiration )

2
iguana/exchanges/mm.c

@ -24,7 +24,7 @@
#include <stdint.h>
#include "OS_portable.h"
#define MAX(a,b) ((a) > (b) ? (a) : (b))
char *stats_JSON(int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port);
char *stats_JSON(char *myipaddr,int32_t pubsock,double profitmargin,cJSON *argjson,char *remoteaddr,uint16_t port);
#include "stats.c"
void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveask,double highbid,double lowask,double PAXPRICES[32]);

7
iguana/exchanges/stats.c

@ -304,8 +304,7 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port)
{
cJSON *tokens,*argjson,*origargjson,*tmpjson=0,*json = 0; long filesize;
char symbol[64],buf[4096],*userpass=0,urlmethod[16],*data,url[8192],furl[8192],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
cJSON *tokens,*argjson,*origargjson,*tmpjson=0,*json = 0; long filesize; double profitmargin = 0.; char *myipaddr="127.0.0.1",symbol[64],buf[4096],*userpass=0,urlmethod[16],*data,url[8192],furl[8192],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
//printf("rpcparse.(%s)\n",urlstr);
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
urlmethod[i] = urlstr[i];
@ -489,7 +488,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
if ( userpass != 0 && jstr(argjson,"userpass") == 0 )
jaddstr(argjson,"userpass",userpass);
//printf("after urlconv.(%s) argjson.(%s)\n",jprint(json,0),jprint(argjson,0));
if ( (retstr= stats_JSON(-1,argjson,remoteaddr,port)) != 0 )
if ( (retstr= stats_JSON(myipaddr,-1,profitmargin,argjson,remoteaddr,port)) != 0 )
{
if ( (retitem= cJSON_Parse(retstr)) != 0 )
jaddi(retarray,retitem);
@ -512,7 +511,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
//printf("ARGJSON.(%s)\n",jprint(arg,0));
if ( userpass != 0 && jstr(arg,"userpass") == 0 )
jaddstr(arg,"userpass",userpass);
retstr = stats_JSON(-1,arg,remoteaddr,port);
retstr = stats_JSON(myipaddr,-1,profitmargin,arg,remoteaddr,port);
}
free_json(argjson);
free_json(json);

Loading…
Cancel
Save