diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 54a1eea6a..d4b7dd21f 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -250,6 +250,8 @@ unsigned char _decode_hex(char *hex); char *uppercase_str(char *buf,char *str); char *lowercase_str(char *buf,char *str); int32_t OS_getline(int32_t waitflag,char *line,int32_t max,char *dispstr); +int32_t sort64s(uint64_t *buf,uint32_t num,int32_t size); +int32_t revsort64s(uint64_t *buf,uint32_t num,int32_t size); long _stripwhite(char *buf,int accept); int32_t is_DST(int32_t datenum); diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 6cae9dc08..de04b819b 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -295,7 +295,7 @@ void *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * *cHandlep = cHandle = curl_easy_init(); else curl_easy_reset(cHandle); //#ifdef DEBUG - //curl_easy_setopt(cHandle,CURLOPT_VERBOSE, 1); + curl_easy_setopt(cHandle,CURLOPT_VERBOSE, 1); //#endif curl_easy_setopt(cHandle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); curl_easy_setopt(cHandle,CURLOPT_SSL_VERIFYPEER,0); diff --git a/crypto777/hmac_sha512.c b/crypto777/hmac_sha512.c index d9bebaca4..43d92030c 100755 --- a/crypto777/hmac_sha512.c +++ b/crypto777/hmac_sha512.c @@ -506,8 +506,8 @@ char *hmac_sha512_str(char *dest,char *key,int32_t key_size,char *message) hmac_memory(&sha512_desc,(void *)key,key_size,(void *)message,strlen(message),checkbuf,&size); init_hexbytes_noT(dest,mac,SHA512_DIGEST_SIZE); init_hexbytes_noT(dest2,checkbuf,SHA512_DIGEST_SIZE); - if ( memcmp(checkbuf,mac,SHA512_DIGEST_SIZE) != 0 ) - printf("hmac_512 error: %s vs %s\n",dest,dest2); + //if ( memcmp(checkbuf,mac,SHA512_DIGEST_SIZE) != 0 ) + printf("hmac_512 : %s vs %s\n",dest,dest2); return(dest); } diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index 1227f525b..2cb2db3a4 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -454,12 +454,49 @@ static int _increasing_double(const void *a,const void *b) #undef double_b } +int _increasing_uint64(const void *a,const void *b) +{ +#define uint64_a (*(uint64_t *)a) +#define uint64_b (*(uint64_t *)b) + if ( uint64_b > uint64_a ) + return(-1); + else if ( uint64_b < uint64_a ) + return(1); + return(0); +#undef uint64_a +#undef uint64_b +} + +static int _decreasing_uint64(const void *a,const void *b) +{ +#define uint64_a (*(uint64_t *)a) +#define uint64_b (*(uint64_t *)b) + if ( uint64_b > uint64_a ) + return(1); + else if ( uint64_b < uint64_a ) + return(-1); + return(0); +#undef uint64_a +#undef uint64_b +} + int32_t sortds(double *buf,uint32_t num,int32_t size) { qsort(buf,num,size,_increasing_double); return(0); } +int32_t sort64s(uint64_t *buf,uint32_t num,int32_t size) +{ + qsort(buf,num,size,_increasing_uint64); + return(0); +} + +int32_t revsort64s(uint64_t *buf,uint32_t num,int32_t size) +{ + qsort(buf,num,size,_decreasing_uint64); + return(0); +} /*int32_t iguana_sortbignum(void *buf,int32_t size,uint32_t num,int32_t structsize,int32_t dir) { int32_t retval = 0; diff --git a/iguana/SuperNET.h b/iguana/SuperNET.h index fd9262f28..0260952d8 100644 --- a/iguana/SuperNET.h +++ b/iguana/SuperNET.h @@ -160,6 +160,7 @@ struct category_chain *category_chain_functions(struct supernet_info *myinfo,bit #define category_default_latest() (*cchain->default_func)(cchain,'L',0,0,0,0,zero) void category_init(struct supernet_info *myinfo); char *SuperNET_keysinit(struct supernet_info *myinfo,char *jsonstr); +double instantdex_aveprice(struct supernet_info *myinfo,char *base,char *rel,double volume,cJSON *argjson); #endif diff --git a/iguana/SuperNET_keys.c b/iguana/SuperNET_keys.c index a50dc7333..97ebe9a99 100644 --- a/iguana/SuperNET_keys.c +++ b/iguana/SuperNET_keys.c @@ -43,7 +43,7 @@ bits256 SuperNET_wallet2priv(char *wallet2fname,bits256 wallethash) char *SuperNET_parsemainargs(struct supernet_info *myinfo,bits256 *wallethashp,bits256 *wallet2privp,char *argjsonstr) { - cJSON *exchanges,*json = 0; char *wallet2fname,*coinargs=0,*secret,*filestr; + cJSON *exchanges=0,*json = 0; char *wallet2fname,*coinargs=0,*secret,*filestr; long allocsize; bits256 wallethash,wallet2priv; int32_t n,len; uint8_t secretbuf[8192]; wallethash = wallet2priv = GENESIS_PRIVKEY; if ( argjsonstr != 0 ) @@ -71,13 +71,13 @@ char *SuperNET_parsemainargs(struct supernet_info *myinfo,bits256 *wallethashp,b if ( (wallet2fname= jstr(json,"2fafile")) != 0 ) wallet2priv = SuperNET_wallet2priv(wallet2fname,wallethash); } - if ( (exchanges= jarray(&n,json,"exchanges")) != 0 ) - exchanges777_init(myinfo,exchanges,0); + exchanges = jarray(&n,json,"exchanges"); if ( jobj(json,"coins") != 0 ) coinargs = argjsonstr; free_json(json); } } + exchanges777_init(myinfo,exchanges,0); *wallethashp = wallethash, *wallet2privp = wallet2priv; return(coinargs); } @@ -147,6 +147,7 @@ int32_t SuperNET_savejsonfile(char *fname,bits256 privkey,bits256 destpubkey,cJS int32_t SuperNET_userkeys(char *passphrase,int32_t passsize,char *fname2fa,int32_t fnamesize) { + return(0); #ifndef __PNACL //if ( (bits256_nonz(*wallethashp) == 0 || bits256_cmp(*wallethashp,GENESIS_PRIVKEY) == 0) && (bits256_nonz(*wallet2privp) == 0 || bits256_cmp(*wallet2privp,GENESIS_PRIVKEY) == 0) ) { diff --git a/iguana/exchanges777.h b/iguana/exchanges777.h index 837369263..7683fb85c 100755 --- a/iguana/exchanges777.h +++ b/iguana/exchanges777.h @@ -63,7 +63,7 @@ struct instantdex_msghdr struct exchange_request { struct queueitem DL; - cJSON *argjson; char **retstrp; + cJSON *argjson; char **retstrp; struct exchange_info *exchange; double price,volume,hbla,lastbid,lastask,commission; uint64_t orderid; uint32_t timedout,expiration,dead,timestamp; int32_t dir,depth,func,numbids,numasks; diff --git a/iguana/iguana_exchanges.c b/iguana/iguana_exchanges.c index 00fec1dac..68f705eb0 100755 --- a/iguana/iguana_exchanges.c +++ b/iguana/iguana_exchanges.c @@ -19,8 +19,9 @@ #define EXCHANGE777_ISPENDING 2 #define EXCHANGE777_REQUEUE 3 -char *Exchange_names[] = { "bitfinex", "btc38", "bitstamp", "btce", "poloniex", "bittrex", "huobi", "coinbase", "okcoin", "lakebtc", "quadriga", "truefx", "ecb", "instaforex", "fxcm", "yahoo" }; -struct exchange_info *Exchanges[sizeof(Exchange_names)/sizeof(*Exchange_names)]; +char *Exchange_names[] = { "poloniex" };// "bitfinex", "btc38", "bitstamp", "btce", "bittrex", "huobi", "coinbase", "okcoin", "lakebtc", "quadriga",};// "truefx", "ecb", "instaforex", "fxcm", "yahoo" }; + + struct exchange_info *Exchanges[sizeof(Exchange_names)/sizeof(*Exchange_names)]; void prices777_processprice(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth) { @@ -405,7 +406,7 @@ int32_t baserel_polarity(char *pairs[][2],int32_t n,char *_base,char *_rel) else if ( strcmp(pairs[i][0],rel) == 0 && strcmp(pairs[i][1],base) == 0 ) return(-1); } - printf("cant find.(%s/%s) [%s/%s].%d\n",base,rel,pairs[0][0],pairs[0][1],n); + //printf("%s cant find.(%s/%s) [%s/%s].%d\n",exchange->name,base,rel,pairs[0][0],pairs[0][1],n); return(0); } @@ -429,48 +430,65 @@ char *exchanges777_process(struct exchange_info *exchange,int32_t *retvalp,struc switch ( req->func ) { case 'Q': case 'M': - memset(req->bidasks,0,req->depth * sizeof(*req->bidasks) * 2); - (*exchange->issue.price)(exchange,req->base,req->rel,req->bidasks,req->depth,req->commission,req->argjson); - retstr = exchanges777_orderbook_jsonstr(exchange,req->base,req->rel,req->bidasks,req->depth,req->invert,req->allflag); + if ( exchange->issue.price != 0 ) + { + memset(req->bidasks,0,req->depth * sizeof(*req->bidasks) * 2); + (*exchange->issue.price)(exchange,req->base,req->rel,req->bidasks,req->depth,req->commission,req->argjson); + retstr = exchanges777_orderbook_jsonstr(exchange,req->base,req->rel,req->bidasks,req->depth,req->invert,req->allflag); + } break; case 'S': - dir = (*exchange->issue.supports)(exchange,req->base,req->rel,req->argjson); - retjson = cJSON_CreateObject(); - jaddnum(retjson,"result",dir); - retstr = jprint(retjson,1); - break; - case 'T': - orderid = (*exchange->issue.trade)(req->dotrade,&retstr,exchange,req->base,req->rel,req->dir,req->price,req->volume,req->argjson); - if ( retstr == 0 ) + if ( exchange->issue.supports != 0 ) { + dir = (*exchange->issue.supports)(exchange,req->base,req->rel,req->argjson); retjson = cJSON_CreateObject(); - if ( orderid != 0 ) - jadd64bits(retjson,"result",orderid); - else jaddstr(retjson,"error","no return value from trade call"); + jaddnum(retjson,"result",dir); retstr = jprint(retjson,1); } break; + case 'T': + if ( exchange->issue.trade != 0 ) + { + orderid = (*exchange->issue.trade)(req->dotrade,&retstr,exchange,req->base,req->rel,req->dir,req->price,req->volume,req->argjson); + if ( retstr == 0 ) + { + retjson = cJSON_CreateObject(); + if ( orderid != 0 ) + jadd64bits(retjson,"result",orderid); + else jaddstr(retjson,"error","no return value from trade call"); + retstr = jprint(retjson,1); + } + } + break; case 'B': - if ( (balancejson= (*exchange->issue.balances)(exchange,req->argjson)) != 0 ) + if ( exchange->issue.balances != 0 && exchange->issue.parsebalance != 0 ) { - retstr = (*exchange->issue.parsebalance)(exchange,&balance,req->base,balancejson); - free_json(balancejson); + if ( (balancejson= (*exchange->issue.balances)(exchange,req->argjson)) != 0 ) + { + retstr = (*exchange->issue.parsebalance)(exchange,&balance,req->base,balancejson); + free_json(balancejson); + } } break; case 'P': - retstr = (*exchange->issue.orderstatus)(exchange,req->orderid,req->argjson); + if ( exchange->issue.orderstatus != 0 ) + retstr = (*exchange->issue.orderstatus)(exchange,req->orderid,req->argjson); break; case 'C': - retstr = (*exchange->issue.cancelorder)(exchange,req->orderid,req->argjson); + if ( exchange->issue.cancelorder != 0 ) + retstr = (*exchange->issue.cancelorder)(exchange,req->orderid,req->argjson); break; case 'O': - retstr = (*exchange->issue.openorders)(exchange,req->argjson); + if ( exchange->issue.openorders != 0 ) + retstr = (*exchange->issue.openorders)(exchange,req->argjson); break; case 'H': - retstr = (*exchange->issue.tradehistory)(exchange,req->argjson); + if ( exchange->issue.tradehistory != 0 ) + retstr = (*exchange->issue.tradehistory)(exchange,req->argjson); break; case 'W': - retstr = (*exchange->issue.withdraw)(exchange,req->base,req->volume,req->destaddr,req->argjson); + if ( exchange->issue.withdraw != 0 ) + retstr = (*exchange->issue.withdraw)(exchange,req->base,req->volume,req->destaddr,req->argjson); break; } return(retstr); @@ -486,9 +504,9 @@ void exchanges777_loop(void *ptr) retstr = 0; if ( (req= queue_dequeue(&exchange->requestQ,0)) != 0 ) { + printf("dequeued %s.%c\n",exchange->name,req->func); if ( req->dead == 0 ) { - //printf("dequeued %s.%c\n",exchange->name,req->func); retstr = exchanges777_process(exchange,&retval,req); if ( retval == EXCHANGE777_DONE ) { @@ -527,16 +545,17 @@ void exchanges777_loop(void *ptr) } if ( (bot= queue_dequeue(&exchange->tradebotsQ,0)) != 0 ) tradebot_timeslice(exchange,bot); - if ( flag == 0 && time(NULL) > exchange->lastpoll+exchange->pollgap ) + if ( time(NULL) > exchange->lastpoll+exchange->pollgap ) { if ( (req= queue_dequeue(&exchange->pricesQ,0)) != 0 ) { + printf("check %s pricesQ (%s %s)\n",exchange->name,req->base,req->rel); if ( req->dead == 0 ) { if ( req->base[0] != 0 ) { - //printf("check %s pricesQ (%s %s)\n",exchange->name,req->base,req->rel); req->timestamp = exchange->lastpoll = (uint32_t)time(NULL); + req->exchange = exchange; req->hbla = (*exchange->issue.price)(exchange,req->base,req->rel,req->bidasks,req->depth,req->commission,req->argjson); for (i=req->numbids=0; idepth; i++) if ( req->bidasks[i << 1].price > SMALLVAL ) @@ -570,7 +589,7 @@ struct exchange_request *exchanges777_baserelfind(struct exchange_info *exchange { if ( ((strcmp(base,req->base) == 0 && strcmp(rel,req->rel) == 0) || (strcmp(rel,req->base) == 0 && strcmp(base,req->rel) == 0)) && (func < 0 || req->func == func) ) retreq = req; - else queue_enqueue("pricesQ",&exchange->pricesQ,&req->DL,0); + queue_enqueue("pricesQ",&exchange->pricesQ,&req->DL,0); } return(retreq); } @@ -609,6 +628,8 @@ char *exchanges777_submit(struct exchange_info *exchange,char **retstrp,struct e char *exchanges777_Qtrade(struct exchange_info *exchange,char *base,char *rel,int32_t maxseconds,int32_t dotrade,int32_t dir,double price,double volume,cJSON *argjson) { struct exchange_request *req; int32_t polarity; char *retstr = 0; + if ( exchange->issue.supports == 0 ) + return(clonestr("{\"error\":\"no supports function\"}")); if ( base[0] == 0 || rel[0] == 0 || (polarity= (*exchange->issue.supports)(exchange,base,rel,argjson)) == 0 || price < SMALLVAL || volume < SMALLVAL ) return(clonestr("{\"error\":\"invalid base or rel\"}")); req = calloc(1,sizeof(*req)); @@ -625,6 +646,8 @@ char *exchanges777_Qtrade(struct exchange_info *exchange,char *base,char *rel,in char *exchanges777_Qprices(struct exchange_info *exchange,char *base,char *rel,int32_t maxseconds,int32_t allfields,int32_t depth,cJSON *argjson,int32_t monitor,double commission) { struct exchange_request *req; char *retstr = 0; int32_t polarity; + if ( exchange->issue.supports == 0 ) + return(clonestr("{\"error\":\"no supports function\"}")); if ( base[0] == 0 || rel[0] == 0 || (polarity= (*exchange->issue.supports)(exchange,base,rel,argjson)) == 0 ) return(clonestr("{\"error\":\"invalid base or rel\"}")); if ( depth <= 0 ) @@ -642,6 +665,7 @@ char *exchanges777_Qprices(struct exchange_info *exchange,char *base,char *rel,i else { req->func = 'M'; + printf("Monitor.%s (%s %s)\n",exchange->name,base,rel); queue_enqueue("pricesQ",&exchange->pricesQ,&req->DL,0); return(clonestr("{\"result\":\"start monitoring\"}")); } @@ -752,7 +776,7 @@ struct exchange_info *exchanges777_info(char *exchangestr,int32_t sleepflag,cJSO void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sleepflag) { int32_t i,n; cJSON *argjson,*item; bits256 instantdexhash; struct exchange_info *exchange; - if ( exchanges != 0 ) + if ( 0 && exchanges != 0 ) { n = cJSON_GetArraySize(exchanges); for (i=0; itradingexchanges[myinfo->numexchanges++] = exchange; free_json(argjson); } instantdexhash = calc_categoryhashes(0,"InstantDEX",0); diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 5eac14ca0..f1a3643fc 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -78,54 +78,98 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,cJSON *argjson,char *cmdst } } -void instantdex_updatesources(int32_t dir,struct exchange_quote *quotes,int32_t numquotes) +int32_t instantdex_updatesources(uint64_t *sortbuf,int32_t n,int32_t ind,int32_t dir,struct exchange_quote *quotes,int32_t numquotes) { int32_t i; struct exchange_quote *quote; for (i=0; iprice,quote->volume); + if ( quote->price > SMALLVAL ) + { + quote->val = ind; + sortbuf[n*2] = quote->price * SATOSHIDEN; + //printf("sortbuf[%d] <-\n",n*2); + memcpy(&sortbuf[n*2 + 1],"e,sizeof(quote)); + n++; + } } + return(n); } -char *instantdex_request(struct supernet_info *myinfo,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *data,int32_t datalen) +double instantdex_aveprice(struct supernet_info *myinfo,char *base,char *rel,double volume,cJSON *argjson) { - char *base,*rel,*request,*str; double volume; int32_t i,num,depth = 30; + char *str; double totalvol,pricesum; uint32_t timestamp; + uint64_t sortbuf[64*32][2]; int32_t i,n,num,depth = 30; struct exchange_quote *quote; struct exchange_info *exchange; struct exchange_request *req,*active[64]; - if ( argjson != 0 ) + timestamp = (uint32_t)time(NULL); + //InstantDEX_supports(myinfo,0,argjson,0,"poloniex",base,rel); + if ( base != 0 && rel != 0 && volume > SMALLVAL ) { - num = 0; - request = jstr(argjson,"request"); - base = jstr(argjson,"base"); - rel = jstr(argjson,"rel"); - volume = jdouble(argjson,"volume"); - if ( base != 0 && rel != 0 && volume > SMALLVAL ) + for (i=num=0; inumexchanges && num < sizeof(active)/sizeof(*active); i++) { - for (i=0; inumexchanges; i++) + if ( (exchange= myinfo->tradingexchanges[i]) != 0 ) { - if ( (exchange= myinfo->tradingexchanges[i]) != 0 ) + if ( (req= exchanges777_baserelfind(exchange,base,rel,'M')) == 0 ) + { + if ( (str= exchanges777_Qprices(exchange,base,rel,30,1,depth,argjson,1,exchange->commission)) != 0 ) + free(str); + req = exchanges777_baserelfind(exchange,base,rel,'M'); + } + if ( req == 0 ) + { + if ( (*exchange->issue.supports)(exchange,base,rel,argjson) != 0 ) + printf("unexpected null req.(%s %s) %s\n",base,rel,exchange->name); + } + else { - if ( (req= exchanges777_baserelfind(exchange,base,rel,'M')) == 0 ) - { - if ( (str= exchanges777_Qprices(exchange,base,rel,30,1,depth,argjson,1,exchange->commission)) != 0 ) - free(str); - req = exchanges777_baserelfind(exchange,base,rel,'M'); - } - if ( req == 0 ) - { - if ( (*exchange->issue.supports)(exchange,base,rel,argjson) != 0 ) - printf("unexpected null req.(%s %s) %s\n",base,rel,exchange->name); - } else active[num++] = req; + active[num++] = req; } } - for (i=0; itimestamp > timestamp-30 ) { if ( volume < 0. && active[i]->numbids > 0 ) - instantdex_updatesources(1,active[i]->bidasks,active[i]->numbids); + n = instantdex_updatesources(&sortbuf[0][0],n,i,1,active[i]->bidasks,active[i]->numbids); else if ( volume > 0. && active[i]->numasks > 0 ) - instantdex_updatesources(-1,&active[i]->bidasks[1],active[i]->numasks); + n = instantdex_updatesources(&sortbuf[0][0],n,i,-1,&active[i]->bidasks[1],active[i]->numasks); } - return(clonestr("{\"result\":\"reqprice response sent\"}")); } + if ( volume < 0. ) + revsort64s(&sortbuf[0][0],n,sizeof(*sortbuf) * 2); + else sort64s(&sortbuf[0][0],n,sizeof(*sortbuf) * 2); + for (totalvol=pricesum=i=0; iprice * quote->volume); + totalvol += quote->volume; + printf("i.%d %12.8f vol %.8f %s | aveprice %.8f total vol %.8f\n",i,dstr(sortbuf[i][0]),quote->volume,active[quote->val]->exchange->name,pricesum/totalvol,totalvol); + } + } + if ( totalvol > 0. ) + return(pricesum / totalvol); + } + return(0); +} + +char *instantdex_request(struct supernet_info *myinfo,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *data,int32_t datalen) +{ + char *base,*rel,*request; double volume,aveprice; int32_t num,depth; + if ( argjson != 0 ) + { + num = 0; + depth = 30; + request = jstr(argjson,"request"); + base = jstr(argjson,"base"); + rel = jstr(argjson,"rel"); + volume = jdouble(argjson,"volume"); + aveprice = instantdex_aveprice(myinfo,base,rel,volume,argjson); + return(clonestr("{\"result\":\"request calculated aveprice\"}")); return(clonestr("{\"error\":\"request missing parameter\"}")); } else return(clonestr("{\"error\":\"request needs argjson\"}")); } diff --git a/iguana/iguana_json.c b/iguana/iguana_json.c index 15e0f0da7..f6183acfa 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -734,7 +734,7 @@ TWO_STRINGS(SuperNET,html,agentform,htmlfile) #undef IGUANA_ARGS #include "../includes/iguana_apiundefs.h" -char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSON *json,char *remoteaddr) +char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,cJSON *json,char *remoteaddr) { char *coinstr; struct iguana_info *coin = 0; if ( remoteaddr != 0 && (remoteaddr[0] == 0 || strcmp(remoteaddr,"127.0.0.1") == 0) ) @@ -743,53 +743,53 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSO coinstr = myinfo->rpcsymbol; if ( coinstr != 0 && coinstr[0] != 0 ) coin = iguana_coinfind(coinstr); - if ( strcmp(agent,"ramchain") == 0 && coin == 0 ) + if ( strcmp(agentstr,"ramchain") == 0 && coin == 0 ) return(clonestr("{\"error\":\"ramchain needs coin\"}")); #define IGUANA_ARGS myinfo,coin,json,remoteaddr -#define IGUANA_DISPATCH0(agent,name) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS)) -#define IGUANA_DISPATCH_S(agent,name,str) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str))) -#define IGUANA_DISPATCH_SS(agent,name,str,str2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2))) -#define IGUANA_DISPATCH_SSS(agent,name,str,str2,str3) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3))) -#define IGUANA_DISPATCH_SSSD(agent,name,str,str2,str3,amount) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3),jdouble(json,#amount))) -#define IGUANA_DISPATCH_SSSDDD(agent,name,str,str2,str3,val,val2,val3) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3),jdouble(json,#val),jdouble(json,#val2),jdouble(json,#val3))) -#define IGUANA_DISPATCH_SSSIII(agent,name,str,str2,str3,val,val2,val3) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3),jint(json,#val),jint(json,#val2),jint(json,#val3))) - -#define IGUANA_DISPATCH_SSH(agent,name,str,str2,hash) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash))) -#define IGUANA_DISPATCH_SSHI(agent,name,str,str2,hash,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash),juint(json,#val))) -#define IGUANA_DISPATCH_SSHII(agent,name,str,str2,hash,val,val2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash),juint(json,#val),juint(json,#val2))) -#define IGUANA_DISPATCH_SSHHII(agent,name,str,str2,hash,hash2,val,val2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash),jbits256(json,#hash2),juint(json,#val),juint(json,#val2))) -#define IGUANA_DISPATCH_SI(agent,name,str,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val))) -#define IGUANA_DISPATCH_SII(agent,name,str,val,val2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val),juint(json,#val2))) -#define IGUANA_DISPATCH_SSI(agent,name,str,str2,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),juint(json,#val))) -#define IGUANA_DISPATCH_SA(agent,name,str,array) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jobj(json,#array))) -#define IGUANA_DISPATCH_SAA(agent,name,str,array,array2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jobj(json,#array),jobj(json,#array2))) -#define IGUANA_DISPATCH_SIII(agent,name,str,val,val2,val3) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val),juint(json,#val2),juint(json,#val3))) - -#define IGUANA_DISPATCH_I(agent,name,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val))) -#define IGUANA_DISPATCH_II(agent,name,val,val2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),juint(json,#val2))) -#define IGUANA_DISPATCH_IIA(agent,name,val,val2,array) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),juint(json,#val2),jobj(json,#array))) -#define IGUANA_DISPATCH_III(agent,name,val,val2,val3) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),juint(json,#val2),juint(json,#val3))) -#define IGUANA_DISPATCH_IA(agent,name,val,array) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),jobj(json,#array))) -#define IGUANA_DISPATCH_IAS(agent,name,val,array,str) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),jobj(json,#array),jstr(json,#str))) +#define IGUANA_DISPATCH0(agent,name) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS)) +#define IGUANA_DISPATCH_S(agent,name,str) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str))) +#define IGUANA_DISPATCH_SS(agent,name,str,str2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2))) +#define IGUANA_DISPATCH_SSS(agent,name,str,str2,str3) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3))) +#define IGUANA_DISPATCH_SSSD(agent,name,str,str2,str3,amount) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3),jdouble(json,#amount))) +#define IGUANA_DISPATCH_SSSDDD(agent,name,str,str2,str3,val,val2,val3) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3),jdouble(json,#val),jdouble(json,#val2),jdouble(json,#val3))) +#define IGUANA_DISPATCH_SSSIII(agent,name,str,str2,str3,val,val2,val3) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jstr(json,#str3),jint(json,#val),jint(json,#val2),jint(json,#val3))) + +#define IGUANA_DISPATCH_SSH(agent,name,str,str2,hash) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash))) +#define IGUANA_DISPATCH_SSHI(agent,name,str,str2,hash,val) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash),juint(json,#val))) +#define IGUANA_DISPATCH_SSHII(agent,name,str,str2,hash,val,val2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash),juint(json,#val),juint(json,#val2))) +#define IGUANA_DISPATCH_SSHHII(agent,name,str,str2,hash,hash2,val,val2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jbits256(json,#hash),jbits256(json,#hash2),juint(json,#val),juint(json,#val2))) +#define IGUANA_DISPATCH_SI(agent,name,str,val) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val))) +#define IGUANA_DISPATCH_SII(agent,name,str,val,val2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val),juint(json,#val2))) +#define IGUANA_DISPATCH_SSI(agent,name,str,str2,val) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),juint(json,#val))) +#define IGUANA_DISPATCH_SA(agent,name,str,array) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jobj(json,#array))) +#define IGUANA_DISPATCH_SAA(agent,name,str,array,array2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jobj(json,#array),jobj(json,#array2))) +#define IGUANA_DISPATCH_SIII(agent,name,str,val,val2,val3) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),juint(json,#val),juint(json,#val2),juint(json,#val3))) + +#define IGUANA_DISPATCH_I(agent,name,val) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val))) +#define IGUANA_DISPATCH_II(agent,name,val,val2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),juint(json,#val2))) +#define IGUANA_DISPATCH_IIA(agent,name,val,val2,array) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),juint(json,#val2),jobj(json,#array))) +#define IGUANA_DISPATCH_III(agent,name,val,val2,val3) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),juint(json,#val2),juint(json,#val3))) +#define IGUANA_DISPATCH_IA(agent,name,val,array) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),jobj(json,#array))) +#define IGUANA_DISPATCH_IAS(agent,name,val,array,str) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,juint(json,#val),jobj(json,#array),jstr(json,#str))) -#define IGUANA_DISPATCH_64A(agent,name,j64,array) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,j64bits(json,#j64),jobj(json,#array))) -#define IGUANA_DISPATCH_AA(agent,name,array,array2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jobj(json,#array),jobj(json,#array2))) +#define IGUANA_DISPATCH_64A(agent,name,j64,array) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,j64bits(json,#j64),jobj(json,#array))) +#define IGUANA_DISPATCH_AA(agent,name,array,array2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jobj(json,#array),jobj(json,#array2))) -#define IGUANA_DISPATCH_D(agent,name,amount) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jdouble(json,#amount))) +#define IGUANA_DISPATCH_D(agent,name,amount) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jdouble(json,#amount))) -#define IGUANA_DISPATCH_H(agent,name,hash) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash))) -#define IGUANA_DISPATCH_HI(agent,name,hash,val) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),juint(json,#val))) -#define IGUANA_DISPATCH_HH(agent,name,hash,hash2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jbits256(json,#hash2))) -#define IGUANA_DISPATCH_HA(agent,name,hash,array) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jobj(json,#array))) -#define IGUANA_DISPATCH_HS(agent,name,hash,str) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jstr(json,#str))) -#define IGUANA_DISPATCH_HII(agent,name,hash,val,val2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),juint(json,#val),juint(json,#val2))) -#define IGUANA_DISPATCH_HHS(agent,name,hash,hash2,str) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jbits256(json,#hash2),jstr(json,#str))) -#define IGUANA_DISPATCH_HAS(agent,name,hash,array,str) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jobj(json,#array),jstr(json,#str))) - -#define IGUANA_DISPATCH_SSDIS(agent,name,str,str2,amount,val,str3) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jdouble(json,#amount),juint(json,#val),jstr(json,#str3))) -#define IGUANA_DISPATCH_SSDISS(agent,name,str,str2,amount,val,str3,str4) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jdouble(json,#amount),juint(json,#val),jstr(json,#str3),jstr(json,#str4))) -#define IGUANA_DISPATCH_SAIS(agent,name,str,array,val,str2) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jobj(json,#array),juint(json,#val),jstr(json,#str2))) -#define IGUANA_DISPATCH_SDSS(agent,name,str,amount,str2,str3) else if ( strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jdouble(json,#amount),jstr(json,#str2),jstr(json,#str3))) +#define IGUANA_DISPATCH_H(agent,name,hash) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash))) +#define IGUANA_DISPATCH_HI(agent,name,hash,val) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),juint(json,#val))) +#define IGUANA_DISPATCH_HH(agent,name,hash,hash2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jbits256(json,#hash2))) +#define IGUANA_DISPATCH_HA(agent,name,hash,array) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jobj(json,#array))) +#define IGUANA_DISPATCH_HS(agent,name,hash,str) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jstr(json,#str))) +#define IGUANA_DISPATCH_HII(agent,name,hash,val,val2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),juint(json,#val),juint(json,#val2))) +#define IGUANA_DISPATCH_HHS(agent,name,hash,hash2,str) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jbits256(json,#hash2),jstr(json,#str))) +#define IGUANA_DISPATCH_HAS(agent,name,hash,array,str) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jobj(json,#array),jstr(json,#str))) + +#define IGUANA_DISPATCH_SSDIS(agent,name,str,str2,amount,val,str3) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jdouble(json,#amount),juint(json,#val),jstr(json,#str3))) +#define IGUANA_DISPATCH_SSDISS(agent,name,str,str2,amount,val,str3,str4) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jstr(json,#str2),jdouble(json,#amount),juint(json,#val),jstr(json,#str3),jstr(json,#str4))) +#define IGUANA_DISPATCH_SAIS(agent,name,str,array,val,str2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jobj(json,#array),juint(json,#val),jstr(json,#str2))) +#define IGUANA_DISPATCH_SDSS(agent,name,str,amount,str2,str3) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jstr(json,#str),jdouble(json,#amount),jstr(json,#str2),jstr(json,#str3))) // API functions #define ZERO_ARGS IGUANA_DISPATCH0 diff --git a/iguana/main.c b/iguana/main.c index c0e4a1386..24e3d3f3f 100644 --- a/iguana/main.c +++ b/iguana/main.c @@ -294,7 +294,13 @@ void mainloop(struct supernet_info *myinfo) else pangea_queues(SuperNET_MYINFO(0)); } if ( flag == 0 ) - sleep(1); + { + //double avebid,aveask; cJSON *argjson = cJSON_Parse("{}"); + //avebid = instantdex_aveprice(myinfo,"NXT","BTC",10000,argjson); + //aveask = instantdex_aveprice(myinfo,"NXT","BTC",-10000,argjson); + //printf("avebid %.8f aveask %.8f\n",avebid,aveask); + sleep(10); + } } }