Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
f3236330bc
  1. 16
      basilisk/basilisk.c
  2. 20
      basilisk/basilisk_DEX.c
  3. 67
      basilisk/basilisk_tradebot.c
  4. 2
      iguana/coins/genbtc
  5. 1
      iguana/exchanges777.h
  6. 5
      iguana/iguana777.h
  7. 18
      iguana/iguana_tradebots.c
  8. 3
      includes/iguana_apideclares.h
  9. 1
      includes/iguana_funcs.h

16
basilisk/basilisk.c

@ -24,6 +24,13 @@ int32_t basilisk_specialcmd(char *cmd)
else return(1); else return(1);
} }
int32_t basilisk_specialrelay_CMD(char *CMD)
{
if ( strcmp(CMD,"OUT") == 0 || strcmp(CMD,"MSG") == 0 || strcmp(CMD,"BLK") == 0 || strcmp(CMD,"MEM") == 0 || strcmp(CMD,"GTX") == 0 || strcmp(CMD,"RID") == 0 )
return(1);
else return(0);
}
uint32_t basilisk_calcnonce(struct supernet_info *myinfo,uint8_t *data,int32_t datalen,uint32_t nBits) uint32_t basilisk_calcnonce(struct supernet_info *myinfo,uint8_t *data,int32_t datalen,uint32_t nBits)
{ {
int32_t i,numiters = 0; bits256 hash,hash2,threshold; uint32_t basilisktag; int32_t i,numiters = 0; bits256 hash,hash2,threshold; uint32_t basilisktag;
@ -137,13 +144,6 @@ struct basilisk_item *basilisk_itemcreate(struct supernet_info *myinfo,char *CMD
return(ptr); return(ptr);
} }
int32_t basilisk_specialrelay_CMD(char *CMD)
{
if ( strcmp(CMD,"OUT") == 0 || strcmp(CMD,"MSG") == 0 )//|| strcmp(CMD,"BLK") == 0 || strcmp(CMD,"MEM") == 0 || strcmp(CMD,"GTX") == 0 || strcmp(CMD,"RID") == 0 )
return(1);
else return(0);
}
int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits) // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag) int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits) // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag)
{ {
int32_t i,r,l,s,val,n=0,retval = -1; char cmd[12]; struct iguana_info *coin,*tmp; struct iguana_peer *addr; bits256 hash; uint32_t *alreadysent; int32_t i,r,l,s,val,n=0,retval = -1; char cmd[12]; struct iguana_info *coin,*tmp; struct iguana_peer *addr; bits256 hash; uint32_t *alreadysent;
@ -199,7 +199,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
printf("%s %s s.%d vs n.%d iguana.%d\n",coin->symbol,addr->ipaddr,s,n,addr->supernet); printf("%s %s s.%d vs n.%d iguana.%d\n",coin->symbol,addr->ipaddr,s,n,addr->supernet);
if ( addr->usock >= 0 ) if ( addr->usock >= 0 )
{ {
if ( basilisk_specialrelay_CMD(type) > 0 ) if ( basilisk_specialcmd(type) != 0 )
{ {
for (s=0; s<myinfo->numrelays; s++) for (s=0; s<myinfo->numrelays; s++)
if ( addr->ipbits != myinfo->myaddr.myipbits && myinfo->relays[s].ipbits == addr->ipbits ) if ( addr->ipbits != myinfo->myaddr.myipbits && myinfo->relays[s].ipbits == addr->ipbits )

20
basilisk/basilisk_DEX.c

@ -158,7 +158,7 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *rp,ui
} }
else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}"));
} }
else if ( myinfo->RELAYID >= 0 ) else if ( myinfo->IAMLP != 0 )
{ {
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
jaddstr(retjson,"result","basilisk node needs to start atomic thread locally"); jaddstr(retjson,"result","basilisk node needs to start atomic thread locally");
@ -492,9 +492,9 @@ INT_ARG(InstantDEX,incoming,requestid)
{ {
cJSON *vals; char *retstr; cJSON *vals; char *retstr;
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
if ( myinfo->RELAYID >= 0 ) //if ( myinfo->IAMLP != 0 )
return(basilisk_respond_requests(myinfo,myinfo->myaddr.persistent,requestid,0)); // return(basilisk_respond_requests(myinfo,myinfo->myaddr.persistent,requestid,0));
else //else
{ {
vals = cJSON_CreateObject(); vals = cJSON_CreateObject();
jaddnum(vals,"requestid",(uint32_t)requestid); jaddnum(vals,"requestid",(uint32_t)requestid);
@ -509,9 +509,9 @@ TWO_INTS(InstantDEX,swapstatus,requestid,quoteid)
{ {
cJSON *vals; char *retstr; cJSON *vals; char *retstr;
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
if ( myinfo->RELAYID >= 0 ) //if ( myinfo->IAMLP != 0 )
return(basilisk_respond_swapstatus(myinfo,myinfo->myaddr.persistent,requestid,quoteid)); // return(basilisk_respond_swapstatus(myinfo,myinfo->myaddr.persistent,requestid,quoteid));
else //else
{ {
vals = cJSON_CreateObject(); vals = cJSON_CreateObject();
jaddnum(vals,"requestid",(uint32_t)requestid); jaddnum(vals,"requestid",(uint32_t)requestid);
@ -527,9 +527,9 @@ TWO_INTS(InstantDEX,accept,requestid,quoteid)
{ {
cJSON *vals; char *retstr; cJSON *vals; char *retstr;
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
if ( myinfo->RELAYID >= 0 ) //if ( myinfo->IAMLP != 0 )
return(basilisk_respond_accept(myinfo,requestid,quoteid)); // return(basilisk_respond_accept(myinfo,requestid,quoteid));
else //else
{ {
vals = cJSON_CreateObject(); vals = cJSON_CreateObject();
jaddnum(vals,"quoteid",(uint32_t)quoteid); jaddnum(vals,"quoteid",(uint32_t)quoteid);

67
basilisk/basilisk_tradebot.c

@ -109,6 +109,51 @@ int32_t basilisk_request_cmpref(struct basilisk_request *ref,struct basilisk_req
} else return(0); } else return(0);
} }
void tradebot_liquidity_command(struct supernet_info *myinfo,char *base,bits256 hash,cJSON *vals)
{
struct liquidity_info li,refli; int32_t i;
memset(&li,0,sizeof(li));
strcpy(li.base,base), strcpy(li.rel,"BTC");
li.profit = jdouble(vals,"profit");
li.refprice = jdouble(vals,"refprice");
for (i=0; i<sizeof(myinfo->linfos)/sizeof(*myinfo->linfos); i++)
{
refli = myinfo->linfos[i];
if ( strcmp(li.rel,refli.base) == 0 && strcmp(li.base,refli.rel) == 0 )
{
strcpy(li.base,refli.base);
strcpy(li.rel,refli.rel);
li.refprice = (1. / li.refprice);
printf("Set rev linfo[%d] (%s/%s) %.6f %.8f\n",i,li.base,li.rel,li.profit,li.refprice);
myinfo->linfos[i] = li;
return;
}
else if ( refli.base[0] == 0 || (strcmp(li.base,refli.base) == 0 && strcmp(li.rel,refli.rel) == 0) )
{
myinfo->linfos[i] = li;
printf("Set linfo[%d] (%s/%s) %.6f %.8f\n",i,li.base,li.rel,li.profit,li.refprice);
return;
}
}
printf("ERROR: too many linfos %d\n",i);
}
double tradebot_liquidity_active(struct supernet_info *myinfo,double *refpricep,char *base,char *rel)
{
int32_t i; struct liquidity_info refli;
*refpricep = 0.;
for (i=0; i<sizeof(myinfo->linfos)/sizeof(*myinfo->linfos); i++)
{
refli = myinfo->linfos[i];
if ( (strcmp(base,refli.base) == 0 && strcmp(rel,refli.rel) == 0) || (strcmp(rel,refli.base) == 0 && strcmp(base,refli.rel) == 0 ))
{
*refpricep = refli.refprice;
return(refli.profit);
}
}
return(0.);
}
double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk_request *issueR,struct basilisk_request *list,int32_t n) double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk_request *issueR,struct basilisk_request *list,int32_t n)
{ {
int32_t i,noquoteflag=0,havequoteflag=0,myrequest=0,maxi=-1; uint64_t destamount,minamount = 0,maxamount = 0; uint32_t pendingid=0; struct basilisk_swap *active; double metric = 0.; int32_t i,noquoteflag=0,havequoteflag=0,myrequest=0,maxi=-1; uint64_t destamount,minamount = 0,maxamount = 0; uint32_t pendingid=0; struct basilisk_swap *active; double metric = 0.;
@ -142,13 +187,23 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
} else noquoteflag++; } else noquoteflag++;
} }
printf("myrequest.%d pendingid.%u noquoteflag.%d havequoteflag.%d maxi.%d %.8f\n",myrequest,pendingid,noquoteflag,havequoteflag,maxi,dstr(maxamount)); printf("myrequest.%d pendingid.%u noquoteflag.%d havequoteflag.%d maxi.%d %.8f\n",myrequest,pendingid,noquoteflag,havequoteflag,maxi,dstr(maxamount));
if ( myrequest == 0 && pendingid == 0 && noquoteflag != 0 ) double retvals[4],refprice,profitmargin,aveprice,balance=0.; cJSON *retjson; char *retstr;
if ( myinfo->IAMLP != 0 && myrequest == 0 && pendingid == 0 && noquoteflag != 0 && (profitmargin= tradebot_liquidity_active(myinfo,&refprice,list[0].src,list[0].dest)) > 0. )
{
if ( (aveprice= instantdex_avehbla(myinfo,retvals,list[0].src,list[0].dest,1.3 * dstr(list[0].srcamount))) == 0. || refprice > aveprice )
aveprice = refprice;
destamount = (1.0 - profitmargin) * aveprice * list[0].srcamount;
if ( (retstr= InstantDEX_available(myinfo,iguana_coinfind(list[0].dest),0,0,list[0].dest)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{ {
double retvals[4],aveprice; balance = jdouble(retjson,"result");
aveprice = instantdex_avehbla(myinfo,retvals,list[0].src,list[0].dest,1.3 * dstr(list[0].srcamount)); free_json(retjson);
destamount = 0.99 * aveprice * list[0].srcamount; }
printf("destamount %.8f aveprice %.8f minamount %.8f\n",dstr(destamount),aveprice,dstr(minamount)); free(retstr);
if ( destamount > 0 && destamount >= maxamount && destamount >= minamount ) }
printf("balance %.8f destamount %.8f aveprice %.8f minamount %.8f\n",balance,dstr(destamount),aveprice,dstr(minamount));
if ( balance > destamount && destamount > 0 && destamount >= maxamount && destamount >= minamount )
{ {
metric = 1.; metric = 1.;
*issueR = list[0]; *issueR = list[0];

2
iguana/coins/genbtc

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":5,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":16,\"endpend\":16,\"services\":128,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}" curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":5,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}"

1
iguana/exchanges777.h

@ -133,7 +133,6 @@ struct instantdex_accept
struct instantdex_offer offer; struct instantdex_offer offer;
}; };
struct instantdex_stateinfo struct instantdex_stateinfo
{ {
char name[24]; int16_t ind,initialstate; char name[24]; int16_t ind,initialstate;

5
iguana/iguana777.h

@ -54,6 +54,8 @@ struct supernet_address
char NXTADDR[32],BTC[64],BTCD[64]; char NXTADDR[32],BTC[64],BTCD[64];
}; };
struct liquidity_info { char base[64],rel[64]; double profit,refprice; };
struct supernet_info struct supernet_info
{ {
struct supernet_address myaddr; struct supernet_address myaddr;
@ -61,7 +63,7 @@ struct supernet_info
uint8_t persistent_pubkey33[33]; uint8_t persistent_pubkey33[33];
char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024]; char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024];
char *decryptstr; char *decryptstr;
int32_t maxdelay,IAMRELAY,publicRPC,basilisk_busy,genesisresults; int32_t maxdelay,IAMRELAY,IAMLP,publicRPC,basilisk_busy,genesisresults;
uint32_t expiration,dirty,DEXactive; uint32_t expiration,dirty,DEXactive;
uint16_t argport,rpcport; uint16_t argport,rpcport;
struct basilisk_info basilisks; struct basilisk_info basilisks;
@ -79,6 +81,7 @@ struct supernet_info
struct basilisk_spend *spends; int32_t numspends; struct basilisk_spend *spends; int32_t numspends;
int32_t numrelays,RELAYID; int32_t numrelays,RELAYID;
struct peggy_info *PEGS; struct peggy_info *PEGS;
struct liquidity_info linfos[64];
// compatibility // compatibility
bits256 pangea_category,instantdex_category; bits256 pangea_category,instantdex_category;
uint8_t logs[256],exps[510]; uint8_t logs[256],exps[510];

18
iguana/iguana_tradebots.c

@ -221,6 +221,24 @@ char *tradebot_control(struct supernet_info *myinfo,char *exchangestr,char *boti
#include "../includes/iguana_apidefs.h" #include "../includes/iguana_apidefs.h"
HASH_ARRAY_STRING(tradebot,liquidity,hash,vals,targetcoin)
{
tradebot_liquidity_command(myinfo,targetcoin,hash,vals);
return(clonestr("{\"result\":\"targetcoin updated\"}"));
}
ZERO_ARGS(tradebot,amlp)
{
myinfo->IAMLP = 1;
return(clonestr("{\"result\":\"liquidity provider active\"}"));
}
ZERO_ARGS(tradebot,notlp)
{
myinfo->IAMLP = 0;
return(clonestr("{\"result\":\"not liquidity provider\"}"));
}
THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission) THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission)
{ {
int32_t allfields = 1,depth = 50; struct exchange_info *ptr; int32_t allfields = 1,depth = 50; struct exchange_info *ptr;

3
includes/iguana_apideclares.h

@ -16,6 +16,9 @@
#ifdef INCLUDE_PAX #ifdef INCLUDE_PAX
ZERO_ARGS(pax,start); ZERO_ARGS(pax,start);
#endif #endif
HASH_ARRAY_STRING(tradebot,liquidity,hash,vals,targetcoin);
ZERO_ARGS(tradebot,amlp);
ZERO_ARGS(tradebot,notlp);
INT_AND_ARRAY(iguana,rates,unused,quotes); INT_AND_ARRAY(iguana,rates,unused,quotes);
TWO_STRINGS(iguana,rate,base,rel); TWO_STRINGS(iguana,rate,base,rel);

1
includes/iguana_funcs.h

@ -359,6 +359,7 @@ void iguana_RTdataset_free(struct iguana_info *coin);
void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp); void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp);
//void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp); //void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp);
void iguana_coinpurge(struct iguana_info *coin); void iguana_coinpurge(struct iguana_info *coin);
void tradebot_liquidity_command(struct supernet_info *myinfo,char *targetcoin,bits256 hash,cJSON *vals);
int32_t iguana_setmaxbundles(struct iguana_info *coin); int32_t iguana_setmaxbundles(struct iguana_info *coin);
void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp); void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp);
uint32_t iguana_sparseaddtx(uint8_t *bits,int32_t width,uint32_t tablesize,bits256 txid,struct iguana_txid *T,uint32_t txidind,struct iguana_ramchain *ramchain); uint32_t iguana_sparseaddtx(uint8_t *bits,int32_t width,uint32_t tablesize,bits256 txid,struct iguana_txid *T,uint32_t txidind,struct iguana_ramchain *ramchain);

Loading…
Cancel
Save