From f71b2b2781e641c201c21a82e52108c04f22f200 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Jan 2016 18:56:12 -0300 Subject: [PATCH] test --- crypto777/OS_portable.h | 1 + crypto777/iguana_utils.c | 13 ++ iguana/exchanges/ecb.c | 94 ++++++++++ iguana/exchanges/fxcm.c | 327 ++++++++++++++++++++++++++++++++++ iguana/exchanges/instaforex.c | 94 ++++++++++ iguana/exchanges/truefx.c | 196 ++++++++++++++++++++ iguana/exchanges/yahoo.c | 94 ++++++++++ iguana/iguana_exchanges.c | 83 +++++---- iguana/iguana_rpc.c | 11 ++ iguana/main.c | 2 +- 10 files changed, 884 insertions(+), 31 deletions(-) create mode 100755 iguana/exchanges/ecb.c create mode 100755 iguana/exchanges/fxcm.c create mode 100755 iguana/exchanges/instaforex.c create mode 100755 iguana/exchanges/truefx.c create mode 100755 iguana/exchanges/yahoo.c diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index d4b7dd21f..11ea1d80a 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -249,6 +249,7 @@ int32_t bitweight(uint64_t x); unsigned char _decode_hex(char *hex); char *uppercase_str(char *buf,char *str); char *lowercase_str(char *buf,char *str); +int32_t strsearch(char *strs[],int32_t num,char *name); 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); diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index f3a100cb2..263c9137d 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -560,6 +560,19 @@ char *lowercase_str(char *buf,char *str) return(buf); } +int32_t strsearch(char *strs[],int32_t num,char *name) +{ + int32_t i; char strA[32],refstr[32]; + strcpy(refstr,name), touppercase(refstr); + for (i=0; i' ) + i++; + for (j=0; xmlstr[i]!=0; i++) + { + if ( strncmp("",&xmlstr[i],strlen("")) == 0 ) + xmlstr[j++] = '[', i += strlen("")-1; + else if ( strncmp(" 1 ) + xmlstr[j++] = ','; + memcpy(&xmlstr[j],"{\"Symbol\":",strlen("{\"Symbol\":")), i += strlen("", "\"Bid\":" }, { "", "\"Ask\":" }, { "", "\"High\":" }, { "", "\"Low\":" }, { "", "\"Direction\":" }, { "", "\"Last\":\"" } }; + for (k=0; k", "", "", "", "", "", "", "", ">" }; + for (k=0; k",ends[k]) == 0 ) + xmlstr[j++] = '}'; + else if ( strcmp("",ends[k]) == 0 ) + xmlstr[j++] = ']'; + else if ( strcmp("",ends[k]) == 0 ) + xmlstr[j++] = '\"'; + else xmlstr[j++] = ','; + break; + } + if ( k == sizeof(ends)/sizeof(*ends) ) + xmlstr[j++] = xmlstr[i]; + } + } + } + xmlstr[j] = 0; + } + return(xmlstr); +} + +int32_t fxcm_setcontracts() +{ + int32_t i,n,flag,num = 0; cJSON *json,*obj; char name[32],*str,*xmlstr = fxcm_xmlstr(); + if ( xmlstr != 0 ) + { + if ( (json= cJSON_Parse(xmlstr)) != 0 ) + { + /* + 123.763 + 123.786 + 123.956 + 123.562 + -1 + 08:49:15*/ + //printf("Parsed stupid XML! (%s)\n",xmlstr); + if ( is_cJSON_Array(json) != 0 && (n= cJSON_GetArraySize(json)) != 0 ) + { + if ( FXCM_contracts != 0 ) + { + for (i=0; i '9') ) + { + strcpy(base,FXCM_contracts[i]); + strcpy(rel,FXCM_contracts[i] + 3); + base[3] = rel[3] = 0; + touppercase(base), touppercase(rel); + } + else if ( strcmp(FXCM_contracts[i],"USDOLLAR") == 0 || strcmp(FXCM_contracts[i],"BUND") == 0 || ((c= FXCM_contracts[i][n-1]) >= '0' && c <= '9') ) + { + strcpy(base,FXCM_contracts[i]), touppercase(base); + rel[0] = 0; + } + else + { + strcpy(base,FXCM_contracts[i]), touppercase(base); + strcpy(rel,"USD"); + } + item = cJSON_CreateArray(); + jaddistr(item,base); + jaddistr(item,rel); + jaddi(array,item); + } + json = cJSON_CreateObject(); + jadd(json,"result",array); + return(jprint(json,1)); + } else return(clonestr("{\"error\":\"cant find FXCM contracts\"}")); +} + +int32_t SUPPORTS(struct exchange_info *exchange,char *_base,char *_rel,cJSON *argjson) +{ + int32_t i; char contract[32],revcontract[32],base[32],rel[32]; + if ( fxcm_ensure() == 0 && num_FXCM > 0 && FXCM_contracts != 0 ) + { + strcpy(base,_base), strcpy(rel,_rel); + touppercase(base), touppercase(rel); + sprintf(contract,"%s%s",base,rel), touppercase(contract); + sprintf(revcontract,"%s%s",rel,base), touppercase(revcontract); + for (i=0; i lasttime ) + { + if ( xmlstr != 0 ) + free(xmlstr); + xmlstr = fxcm_xmlstr(); + lasttime = (uint32_t)time(NULL); + } + if ( xmlstr != 0 ) + { + if ( (json= cJSON_Parse(xmlstr)) != 0 ) + { + if ( is_cJSON_Array(json) != 0 && (n= cJSON_GetArraySize(json)) != 0 ) + { + for (i=0; i= 0 ) + { + bids[c] = bid, asks[c] = ask, highs[c] = high, lows[c] = low; + //printf("c.%d (%s) %f %f\n",c,name,bid,ask); + flag = 1; + } else printf("cant find.%s\n",name);//, getchar(); + } + if ( flag == 0 ) + printf("FXCM: Error finding.(%s) c.%d (%s)\n",name,c,cJSON_Print(obj)); + } + } + free_json(json); + } else printf("couldnt parse.(%s)\n",xmlstr); + } +} + +double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert) +{ + double bid,ask,bids[64],asks[64],highs[64],lows[64]; int32_t numbids,numasks,c; char name[32]; + if ( fxcm_ensure() == 0 ) + { + strcpy(name,base), strcat(name,rel), touppercase(name); + if ( (c= strsearch(FXCM_contracts,num_FXCM,name)) >= 0 ) + { + prices777_fxcm(bids,asks,highs,lows); + numbids = numasks = 0; + printf("invert.%d\n",invert); + bid = exchange_setquote(bidasks,&numbids,&numasks,0,invert,bids[c],1,commission,0,(uint32_t)time(NULL),0); + ask = exchange_setquote(bidasks,&numbids,&numasks,1,invert,asks[c],1,commission,0,(uint32_t)time(NULL),0); + if ( bid > SMALLVAL && ask > SMALLVAL ) + return((bid + ask) * .5); + } + } + return(0); +} + +cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,char *path) +{ + if ( retstrp != 0 ) + *retstrp = clonestr("{\"error\":\"fxcm is readonly data source\"}"); + return(cJSON_Parse("{}")); +} + +char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr,cJSON *argjson) +{ + return(clonestr("{\"error\":\"fxcm is readonly data source\"}")); +} + +cJSON *BALANCES(struct exchange_info *exchange,cJSON *argjson) +{ + return(cJSON_Parse("{\"error\":\"fxcm is readonly data source\"}")); +} + +uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume,cJSON *argjson) +{ + return(0); +} + +char *ORDERSTATUS(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson) +{ + return(clonestr("{\"error\":\"fxcm is readonly data source\"}")); +} + +char *CANCELORDER(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson) +{ + return(clonestr("{\"error\":\"fxcm is readonly data source\"}")); +} + +char *OPENORDERS(struct exchange_info *exchange,cJSON *argjson) +{ + return(clonestr("{\"error\":\"fxcm is readonly data source\"}")); +} + +char *TRADEHISTORY(struct exchange_info *exchange,cJSON *argjson) +{ + return(clonestr("{\"error\":\"fxcm is readonly data source\"}")); +} + +char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *destaddr,cJSON *argjson) +{ + return(clonestr("{\"error\":\"fxcm is readonly data source\"}")); +} + +struct exchange_funcs fxcm_funcs = EXCHANGE_FUNCS(fxcm,EXCHANGE_NAME); + +#include "exchange_undefs.h" diff --git a/iguana/exchanges/instaforex.c b/iguana/exchanges/instaforex.c new file mode 100755 index 000000000..1714684e5 --- /dev/null +++ b/iguana/exchanges/instaforex.c @@ -0,0 +1,94 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#define EXCHANGE_NAME "instaforex" +#define UPDATE instaforex ## _price +#define SUPPORTS instaforex ## _supports +#define SIGNPOST instaforex ## _signpost +#define TRADE instaforex ## _trade +#define ORDERSTATUS instaforex ## _orderstatus +#define CANCELORDER instaforex ## _cancelorder +#define OPENORDERS instaforex ## _openorders +#define TRADEHISTORY instaforex ## _tradehistory +#define BALANCES instaforex ## _balances +#define PARSEBALANCE instaforex ## _parsebalance +#define WITHDRAW instaforex ## _withdraw +#define CHECKBALANCE instaforex ## _checkbalance +#define ALLPAIRS instaforex ## _allpairs +#define FUNCS instaforex ## _funcs +#define BASERELS instaforex ## _baserels + +static char *BASERELS[][2] = { {"btc","nxt"}, {"btc","btcd"}, {"btc","ltc"}, {"btc","vrc"}, {"btc","doge"} }; +#include "exchange_supports.h" + +double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert) +{ + char url[1024],lrel[16],lbase[16]; + strcpy(lrel,rel), strcpy(lbase,base); + tolowercase(lrel), tolowercase(lbase); + sprintf(url,"http://api.quadrigacx.com/v2/order_book?book=%s_%s",lbase,lrel); + return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0,invert)); +} + +cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,char *path) +{ + if ( retstrp != 0 ) + *retstrp = clonestr("{\"error\":\"instaforex is readonly data source\"}"); + return(cJSON_Parse("{}")); +} + +char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr,cJSON *argjson) +{ + return(clonestr("{\"error\":\"instaforex is readonly data source\"}")); +} + +cJSON *BALANCES(struct exchange_info *exchange,cJSON *argjson) +{ + return(cJSON_Parse("{\"error\":\"instaforex is readonly data source\"}")); +} + +uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume,cJSON *argjson) +{ + return(0); +} + +char *ORDERSTATUS(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson) +{ + return(clonestr("{\"error\":\"instaforex is readonly data source\"}")); +} + +char *CANCELORDER(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson) +{ + return(clonestr("{\"error\":\"instaforex is readonly data source\"}")); +} + +char *OPENORDERS(struct exchange_info *exchange,cJSON *argjson) +{ + return(clonestr("{\"error\":\"instaforex is readonly data source\"}")); +} + +char *TRADEHISTORY(struct exchange_info *exchange,cJSON *argjson) +{ + return(clonestr("{\"error\":\"instaforex is readonly data source\"}")); +} + +char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *destaddr,cJSON *argjson) +{ + return(clonestr("{\"error\":\"instaforex is readonly data source\"}")); +} + +struct exchange_funcs instaforex_funcs = EXCHANGE_FUNCS(instaforex,EXCHANGE_NAME); + +#include "exchange_undefs.h" diff --git a/iguana/exchanges/truefx.c b/iguana/exchanges/truefx.c new file mode 100755 index 000000000..aaae4cb28 --- /dev/null +++ b/iguana/exchanges/truefx.c @@ -0,0 +1,196 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#define EXCHANGE_NAME "truefx" +#define UPDATE truefx ## _price +#define SUPPORTS truefx ## _supports +#define SIGNPOST truefx ## _signpost +#define TRADE truefx ## _trade +#define ORDERSTATUS truefx ## _orderstatus +#define CANCELORDER truefx ## _cancelorder +#define OPENORDERS truefx ## _openorders +#define TRADEHISTORY truefx ## _tradehistory +#define BALANCES truefx ## _balances +#define PARSEBALANCE truefx ## _parsebalance +#define WITHDRAW truefx ## _withdraw +#define CHECKBALANCE truefx ## _checkbalance +#define ALLPAIRS truefx ## _allpairs +#define FUNCS truefx ## _funcs +#define BASERELS truefx ## _baserels + +static char *BASERELS[][2] = { {"EUR","USD"},{"USD","JPY"},{"GBP","USD"},{"EUR","GBP"},{"USD","CHF"},{"AUD","NZD"},{"CAD","CHF"},{"CHF","JPY"},{"EUR","AUD"},{"EUR","CAD"},{"EUR","JPY"},{"EUR","CHF"},{"USD","CAD"},{"AUD","USD"},{"GBP","JPY"},{"AUD","CAD"},{"AUD","CHF"},{"AUD","JPY"},{"EUR","NOK"},{"EUR","NZD"},{"GBP","CAD"},{"GBP","CHF"},{"NZD","JPY"},{"NZD","USD"},{"USD","NOK"},{"USD","SEK"} }; +#include "exchange_supports.h" + +uint64_t prices777_truefx(char *reqbase,char *reqrel,uint64_t *millistampp,double *bidp,double *askp,double *openp,double *highp,double *lowp,double *closep,char *username,char *password,uint64_t sessionid) +{ + static uint32_t lasttime; static char *laststr; + char *truefxfmt = "http://webrates.truefx.com/rates/connect.html?f=csv&id=%s:%s:poll:%llu&c=EUR/USD,USD/JPY,GBP/USD,EUR/GBP,USD/CHF,AUD/NZD,CAD/CHF,CHF/JPY,EUR/AUD,EUR/CAD,EUR/JPY,EUR/CHF,USD/CAD,AUD/USD,GBP/JPY,AUD/CAD,AUD/CHF,AUD/JPY,EUR/NOK,EUR/NZD,GBP/CAD,GBP/CHF,NZD/JPY,NZD/USD,USD/NOK,USD/SEK"; + // EUR/USD,1437569931314,1.09,034,1.09,038,1.08922,1.09673,1.09384 USD/JPY,1437569932078,123.,778,123.,781,123.569,123.903,123.860 GBP/USD,1437569929008,1.56,332,1.56,337,1.55458,1.56482,1.55538 EUR/GBP,1437569931291,0.69,742,0.69,750,0.69710,0.70383,0.70338 USD/CHF,1437569932237,0.96,142,0.96,153,0.95608,0.96234,0.95748 EUR/JPY,1437569932237,134.,960,134.,972,134.842,135.640,135.476 EUR/CHF,1437569930233,1.04,827,1.04,839,1.04698,1.04945,1.04843 USD/CAD,1437569929721,1.30,231,1.30,241,1.29367,1.30340,1.29466 AUD/USD,1437569931700,0.73,884,0.73,890,0.73721,0.74395,0.74200 GBP/JPY,1437569931924,193.,500,193.,520,192.298,193.670,192.649 + char url[1024],userpass[1024],buf[128],base[64],rel[64],*str=0; cJSON *array; + int32_t jpyflag,i,n=0; double pre,pre2,bid,ask,openval,high,low; long millistamp; + millistamp = pre = pre2 = bid = ask = openval = high = low = 0; + //printf("truefx.(%s)(%s).%llu\n",username,password,(long long)idnum); + url[0] = 0; + if ( username[0] != 0 && password[0] != 0 ) + { + if ( sessionid == 0 ) + { + sprintf(userpass,"http://webrates.truefx.com/rates/connect.html?f=csv&s=y&u=%s&p=%s&q=poll",username,password); + if ( (str= issue_curl(userpass)) != 0 ) + { + _stripwhite(str,0); + printf("(%s) -> (%s)\n",userpass,str); + sprintf(userpass,"%s:%s:poll:",username,password); + sessionid = calc_nxt64bits(str + strlen(userpass)); + free(str); + //printf("idnum.%llu\n",(long long)sessionid); + } + } + if ( sessionid != 0 ) + sprintf(url,truefxfmt,username,password,(long long)sessionid); + } + if ( url[0] == 0 ) + sprintf(url,"http://webrates.truefx.com/rates/connect.html?f=csv&s=y"); + if ( laststr != 0 && time(NULL) > lasttime ) + { + //printf("free laststr.%p lag.%d\n",laststr,(int32_t)(time(NULL) - lasttime)); + free(laststr); + laststr = 0; + } else str = laststr; + if ( str == 0 ) + { + str = issue_curl(url); + lasttime = (uint32_t)time(NULL); + laststr = str; + } + if ( str != 0 ) + { + //printf("(%s) -> (%s)\n",url,str); + while ( str[n + 0] != 0 && str[n] != '\n' && str[n] != '\r' ) + { + for (i=jpyflag=0; str[n + i]!=' '&&str[n + i]!='\n'&&str[n + i]!='\r'&&str[n + i]!=0; i++) + { + if ( i > 0 && str[n+i] == ',' && str[n+i-1] == '.' ) + str[n+i-1] = ' ', jpyflag = 1; + else if ( i > 0 && str[n+i-1] == ',' && str[n+i] == '0' && str[n+i+1+2] == ',' ) + { + str[n+i] = ' '; + if ( str[n+i+1] == '0' ) + str[n+i+1] = ' ', i++; + } + } + memcpy(base,str+n,3), base[3] = 0; + memcpy(rel,str+n+4,3), rel[3] = 0; + str[n + i] = 0; + //printf("str.(%s) (%s/%s) %d n.%d i.%d\n",str+n,base,rel,str[n],n,i); + sprintf(buf,"[%s]",str+n+7+1); + n += i + 1; + if ( (array= cJSON_Parse(buf)) != 0 ) + { + if ( is_cJSON_Array(array) != 0 ) + { + millistamp = j64bits(jitem(array,0),0); + pre = jdouble(jitem(array,1),0); + bid = jdouble(jitem(array,2),0); + pre2 = jdouble(jitem(array,3),0); + ask = jdouble(jitem(array,4),0); + openval = jdouble(jitem(array,5),0); + high = jdouble(jitem(array,6),0); + low = jdouble(jitem(array,7),0); + if ( jpyflag != 0 ) + bid = pre + (bid / 1000.), ask = pre2 + (ask / 1000.); + else bid = pre + (bid / 100000.), ask = pre2 + (ask / 100000.); + if ( strcmp(base,reqbase) == 0 && strcmp(rel,reqrel) == 0 ) + { + *bidp = bid, *askp = ask, *openp = openval, *highp = high, *lowp = low; + *closep = 0; + *millistampp = millistamp; + break; + } + } + free_json(array); + } else printf("cant parse.(%s)\n",buf); + } + } + return(sessionid); +} + +double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert) +{ + int32_t numbids,numasks; double bid,ask,openval,high,low,closeval,volume=1; uint64_t millistamp; + char *username = "",*password = ""; + if ( exchange->apikey[0] != 0 && exchange->apisecret[0] != 0 ) + username = exchange->apikey, password = exchange->apisecret; + else if ( exchange->userid[0] != 0 && exchange->tradepassword[0] != 0 ) + username = exchange->userid, password = exchange->tradepassword; + exchange->lastnonce = prices777_truefx(base,rel,&millistamp,&bid,&ask,&openval,&high,&low,&closeval,username,password,exchange->lastnonce); + numbids = numasks = 0; + bid = exchange_setquote(bidasks,&numbids,&numasks,0,invert,bid,volume,commission,0,(uint32_t)(millistamp/1000),0); + ask = exchange_setquote(bidasks,&numbids,&numasks,1,invert,ask,volume,commission,0,(uint32_t)(millistamp/1000),0); + if ( bid > SMALLVAL && ask > SMALLVAL ) + return((bid + ask) * .5); + else return(0); +} + +cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,char *path) +{ + if ( retstrp != 0 ) + *retstrp = clonestr("{\"error\":\"truefx is readonly data source\"}"); + return(cJSON_Parse("{}")); +} + +char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr,cJSON *argjson) +{ + return(clonestr("{\"error\":\"truefx is readonly data source\"}")); +} + +cJSON *BALANCES(struct exchange_info *exchange,cJSON *argjson) +{ + return(cJSON_Parse("{\"error\":\"truefx is readonly data source\"}")); +} + +uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume,cJSON *argjson) +{ + return(0); +} + +char *ORDERSTATUS(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson) +{ + return(clonestr("{\"error\":\"truefx is readonly data source\"}")); +} + +char *CANCELORDER(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson) +{ + return(clonestr("{\"error\":\"truefx is readonly data source\"}")); +} + +char *OPENORDERS(struct exchange_info *exchange,cJSON *argjson) +{ + return(clonestr("{\"error\":\"truefx is readonly data source\"}")); +} + +char *TRADEHISTORY(struct exchange_info *exchange,cJSON *argjson) +{ + return(clonestr("{\"error\":\"truefx is readonly data source\"}")); +} + +char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *destaddr,cJSON *argjson) +{ + return(clonestr("{\"error\":\"truefx is readonly data source\"}")); +} + +struct exchange_funcs truefx_funcs = EXCHANGE_FUNCS(truefx,EXCHANGE_NAME); + +#include "exchange_undefs.h" diff --git a/iguana/exchanges/yahoo.c b/iguana/exchanges/yahoo.c new file mode 100755 index 000000000..0d1f5afa1 --- /dev/null +++ b/iguana/exchanges/yahoo.c @@ -0,0 +1,94 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#define EXCHANGE_NAME "yahoo" +#define UPDATE yahoo ## _price +#define SUPPORTS yahoo ## _supports +#define SIGNPOST yahoo ## _signpost +#define TRADE yahoo ## _trade +#define ORDERSTATUS yahoo ## _orderstatus +#define CANCELORDER yahoo ## _cancelorder +#define OPENORDERS yahoo ## _openorders +#define TRADEHISTORY yahoo ## _tradehistory +#define BALANCES yahoo ## _balances +#define PARSEBALANCE yahoo ## _parsebalance +#define WITHDRAW yahoo ## _withdraw +#define CHECKBALANCE yahoo ## _checkbalance +#define ALLPAIRS yahoo ## _allpairs +#define FUNCS yahoo ## _funcs +#define BASERELS yahoo ## _baserels + +static char *BASERELS[][2] = { {"EUR","USD"},{"USD","JPY"},{"GBP","USD"},{"EUR","GBP"},{"USD","CHF"},{"AUD","NZD"},{"CAD","CHF"},{"CHF","JPY"},{"EUR","AUD"},{"EUR","CAD"},{"EUR","JPY"},{"EUR","CHF"},{"USD","CAD"},{"AUD","USD"},{"GBP","JPY"},{"AUD","CAD"},{"AUD","CHF"},{"AUD","JPY"},{"EUR","NOK"},{"EUR","NZD"},{"GBP","CAD"},{"GBP","CHF"},{"NZD","JPY"},{"NZD","USD"},{"USD","NOK"},{"USD","SEK"} }; +#include "exchange_supports.h" + +double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *quotes,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert) +{ + char url[1024],lrel[16],lbase[16]; + strcpy(lrel,rel), strcpy(lbase,base); + tolowercase(lrel), tolowercase(lbase); + sprintf(url,"http://api.quadrigacx.com/v2/order_book?book=%s_%s",lbase,lrel); + return(exchanges777_standardprices(exchange,commission,base,rel,url,quotes,0,0,maxdepth,0,invert)); +} + +cJSON *SIGNPOST(void **cHandlep,int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *payload,char *path) +{ + if ( retstrp != 0 ) + *retstrp = clonestr("{\"error\":\"yahoo is readonly data source\"}"); + return(cJSON_Parse("{}")); +} + +char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr,cJSON *argjson) +{ + return(clonestr("{\"error\":\"yahoo is readonly data source\"}")); +} + +cJSON *BALANCES(struct exchange_info *exchange,cJSON *argjson) +{ + return(cJSON_Parse("{\"error\":\"yahoo is readonly data source\"}")); +} + +uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,char *base,char *rel,int32_t dir,double price,double volume,cJSON *argjson) +{ + return(0); +} + +char *ORDERSTATUS(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson) +{ + return(clonestr("{\"error\":\"yahoo is readonly data source\"}")); +} + +char *CANCELORDER(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson) +{ + return(clonestr("{\"error\":\"yahoo is readonly data source\"}")); +} + +char *OPENORDERS(struct exchange_info *exchange,cJSON *argjson) +{ + return(clonestr("{\"error\":\"yahoo is readonly data source\"}")); +} + +char *TRADEHISTORY(struct exchange_info *exchange,cJSON *argjson) +{ + return(clonestr("{\"error\":\"yahoo is readonly data source\"}")); +} + +char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *destaddr,cJSON *argjson) +{ + return(clonestr("{\"error\":\"yahoo is readonly data source\"}")); +} + +struct exchange_funcs yahoo_funcs = EXCHANGE_FUNCS(yahoo,EXCHANGE_NAME); + +#include "exchange_undefs.h" diff --git a/iguana/iguana_exchanges.c b/iguana/iguana_exchanges.c index cab52dd0b..895beffc6 100755 --- a/iguana/iguana_exchanges.c +++ b/iguana/iguana_exchanges.c @@ -19,7 +19,7 @@ #define EXCHANGE777_ISPENDING 2 #define EXCHANGE777_REQUEUE 3 -char *Exchange_names[] = { "poloniex", "bittrex", "btc38", "huobi", "bitstamp", "bitfinex", "btce", "coinbase", "okcoin", "lakebtc", "quadriga",};// "truefx", "ecb", "instaforex", "fxcm", "yahoo" }; +char *Exchange_names[] = { "poloniex", "bittrex", "btc38", "huobi", "bitstamp", "bitfinex", "btce", "coinbase", "okcoin", "lakebtc", "quadriga", "truefx", "ecb", "instaforex", "fxcm", "yahoo" }; struct exchange_info *Exchanges[sizeof(Exchange_names)/sizeof(*Exchange_names)]; @@ -165,10 +165,39 @@ char *exchanges777_orderbook_jsonstr(struct exchange_info *exchange,char *_base, return(jprint(json,1)); } +double exchange_setquote(struct exchange_quote *bidasks,int32_t *numbidsp,int32_t *numasksp,int32_t bidask,int32_t invert,double price,double volume,double commission,uint64_t orderid,uint32_t timestamp,uint64_t offerNXT) +{ + int32_t slot_ba; struct exchange_quote *quote; + if ( price > SMALLVAL && volume > SMALLVAL ) + { + if ( invert != 0 ) + { + bidask = (1 ^ bidask); + volume *= price; + price = 1. / price; + } + if ( commission != 0. ) + { + //printf("price %f fee %f -> ",price,prices->commission * price); + if ( bidask == 0 ) + price -= commission * price; + else price += commission * price; + //printf("%f\n",price); + } + quote = (bidask == 0) ? &bidasks[(*numbidsp)<<1] : &bidasks[((*numasksp)<<1) + 1]; + quote->price = price, quote->volume = volume, quote->timestamp = timestamp, quote->orderid = orderid, quote->offerNXT = offerNXT; + if ( bidask == 0 ) + slot_ba = ((*numbidsp)++ << 1); + else slot_ba = ((*numasksp)++ << 1) | 1; + quote->satoshis = (price * SATOSHIDEN); + } + return(price); +} + void exchanges777_json_quotes(struct exchange_info *exchange,double commission,char *base,char *rel,double *lastbidp,double *lastaskp,double *hblap,struct exchange_quote *bidasks,cJSON *bids,cJSON *asks,int32_t maxdepth,char *pricefield,char *volfield,uint32_t reftimestamp,int32_t invert) { - int32_t i,slot,ba2,n=0,m=0,dir,bidask,slot_ba,numitems,numbids,numasks; uint64_t orderid,offerNXT; - cJSON *item; struct exchange_quote *quote; uint32_t timestamp; double price,volume,hbla = 0.; + int32_t i,slot,n=0,m=0,dir,bidask,numitems,numbids,numasks; uint64_t orderid,offerNXT; + cJSON *item; uint32_t timestamp; double price,volume,hbla = 0.; *lastbidp = *lastaskp = 0.; numbids = numasks = 0; if ( reftimestamp == 0 ) @@ -214,36 +243,16 @@ void exchanges777_json_quotes(struct exchange_info *exchange,double commission,c else continue; if ( price > SMALLVAL && volume > SMALLVAL ) { - if ( invert != 0 ) - { - ba2 = (1 ^ bidask); - volume *= price; - price = 1. / price; - } - else ba2 = bidask; - if ( commission != 0. ) - { - //printf("price %f fee %f -> ",price,prices->commission * price); - if ( ba2 == 0 ) - price -= commission * price; - else price += commission * price; - //printf("%f\n",price); - } - quote = (ba2 == 0) ? &bidasks[numbids<<1] : &bidasks[(numasks<<1) + 1]; - quote->price = price, quote->volume = volume, quote->timestamp = timestamp, quote->orderid = orderid, quote->offerNXT = offerNXT; - if ( ba2 == 0 ) - slot_ba = (numbids++ << 1); - else slot_ba = (numasks++ << 1) | 1; + price = exchange_setquote(bidasks,&numbids,&numasks,bidask,invert,price,volume,commission,orderid,timestamp,offerNXT); if ( i == 0 ) { - if ( ba2 == 0 ) + if ( (bidask ^ invert) == 0 ) *lastbidp = price; else *lastaskp = price; if ( hbla == 0. ) hbla = price; else hbla = 0.5 * (hbla + price); } - quote->satoshis = (price * SATOSHIDEN); //printf("%d,%d: %-8s %s %5s/%-5s %13.8f vol %13.8f | i %13.8f vol %13.8f | t.%u\n",numbids,numasks,exchange->name,dir>0?"bid":"ask",base,rel,price,volume,1./price,volume*price,timestamp); } } @@ -404,14 +413,16 @@ char *exchange_extractorderid(int32_t historyflag,char *status,uint64_t quoteid, int32_t baserel_polarity(char *pairs[][2],int32_t n,char *_base,char *_rel) { - int32_t i; char base[32],rel[32]; + int32_t i; char base[32],rel[32],cmpbase[32],cmprel[32]; strcpy(base,_base), tolowercase(base); strcpy(rel,_rel), tolowercase(rel); for (i=0; iname,base,rel,pairs[0][0],pairs[0][1],n); @@ -431,6 +442,12 @@ int32_t baserel_polarity(char *pairs[][2],int32_t n,char *_base,char *_rel) #include "exchanges/coinbase.c" #include "exchanges/bitstamp.c" +#include "exchanges/truefx.c" +#include "exchanges/yahoo.c" +#include "exchanges/fxcm.c" +#include "exchanges/instaforex.c" +#include "exchanges/ecb.c" + int32_t exchanges777_orient(struct exchange_info *exchange,char *base,char *rel,double *pricep,double *volumep,struct exchange_request *req) { int32_t polarity = 1; @@ -531,6 +548,8 @@ char *exchanges777_process(struct exchange_info *exchange,int32_t *retvalp,struc retstr = (*exchange->issue.withdraw)(exchange,req->base,req->volume,req->destaddr,req->argjson); break; } + if ( retstr == 0 ) + retstr = clonestr("{\"error\":\"null return\"}"); return(retstr); } @@ -742,9 +761,11 @@ int32_t exchanges777_id(char *exchangestr) int32_t i; for (i=0; iname,exchange->issue.supports,exchange->issue.price,exchange->issue.allpairs); return(exchange); } @@ -981,7 +1004,7 @@ ZERO_ARGS(InstantDEX,allexchanges) STRING_ARG(InstantDEX,allpairs,exchange) { struct exchange_info *ptr; - if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) + if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 && ptr->issue.allpairs != 0 ) return((*ptr->issue.allpairs)(ptr,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); } diff --git a/iguana/iguana_rpc.c b/iguana/iguana_rpc.c index cf689af12..83d5323f7 100755 --- a/iguana/iguana_rpc.c +++ b/iguana/iguana_rpc.c @@ -950,6 +950,17 @@ void iguana_rpcloop(void *args) remains = (int32_t)strlen(retstr); //printf("POSTFLAG.%d\n",postflag); //printf("RETBUF.(%s)\n",retstr); + char hdrs[1024]; + if ( remoteaddr[0] != 0 && strcmp(remoteaddr,"127.0.0.1") != 0 ) + sprintf(hdrs,"Access-Control-Allow-Origin: *\r\n"); + else sprintf(hdrs,"Access-Control-Allow-Origin: null\r\n"); + sprintf(hdrs,"Access-Control-Allow-Credentials: true\r\n"); + sprintf(hdrs,"Access-Control-Allow-Headers: Authorization, Content-Type\r\n"); + sprintf(hdrs,"Access-Control-Allow-Methods: GET, POST\r\n"); + sprintf(hdrs,"Cache-Control: no-cache, no-store, must-revalidate\r\n"); + sprintf(hdrs,"Content-type: text/html\r\n"); + sprintf(hdrs,"Content-Length: %8d\r\n",(int32_t)strlen(retstr)); + send(sock,hdrs,strlen(hdrs),MSG_NOSIGNAL); while ( remains > 0 ) { if ( (numsent= (int32_t)send(sock,&retstr[i],remains,MSG_NOSIGNAL)) < 0 ) diff --git a/iguana/main.c b/iguana/main.c index 3fa0590b3..2fa591ace 100644 --- a/iguana/main.c +++ b/iguana/main.c @@ -295,7 +295,7 @@ void mainloop(struct supernet_info *myinfo) } if ( flag == 0 ) { - sleep(10); + usleep(100000); } } }