jl777
9 years ago
10 changed files with 884 additions and 31 deletions
@ -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 "ecb" |
|||
#define UPDATE ecb ## _price |
|||
#define SUPPORTS ecb ## _supports |
|||
#define SIGNPOST ecb ## _signpost |
|||
#define TRADE ecb ## _trade |
|||
#define ORDERSTATUS ecb ## _orderstatus |
|||
#define CANCELORDER ecb ## _cancelorder |
|||
#define OPENORDERS ecb ## _openorders |
|||
#define TRADEHISTORY ecb ## _tradehistory |
|||
#define BALANCES ecb ## _balances |
|||
#define PARSEBALANCE ecb ## _parsebalance |
|||
#define WITHDRAW ecb ## _withdraw |
|||
#define CHECKBALANCE ecb ## _checkbalance |
|||
#define ALLPAIRS ecb ## _allpairs |
|||
#define FUNCS ecb ## _funcs |
|||
#define BASERELS ecb ## _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\":\"ecb is readonly data source\"}"); |
|||
return(cJSON_Parse("{}")); |
|||
} |
|||
|
|||
char *PARSEBALANCE(struct exchange_info *exchange,double *balancep,char *coinstr,cJSON *argjson) |
|||
{ |
|||
return(clonestr("{\"error\":\"ecb is readonly data source\"}")); |
|||
} |
|||
|
|||
cJSON *BALANCES(struct exchange_info *exchange,cJSON *argjson) |
|||
{ |
|||
return(cJSON_Parse("{\"error\":\"ecb 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\":\"ecb is readonly data source\"}")); |
|||
} |
|||
|
|||
char *CANCELORDER(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson) |
|||
{ |
|||
return(clonestr("{\"error\":\"ecb is readonly data source\"}")); |
|||
} |
|||
|
|||
char *OPENORDERS(struct exchange_info *exchange,cJSON *argjson) |
|||
{ |
|||
return(clonestr("{\"error\":\"ecb is readonly data source\"}")); |
|||
} |
|||
|
|||
char *TRADEHISTORY(struct exchange_info *exchange,cJSON *argjson) |
|||
{ |
|||
return(clonestr("{\"error\":\"ecb is readonly data source\"}")); |
|||
} |
|||
|
|||
char *WITHDRAW(struct exchange_info *exchange,char *base,double amount,char *destaddr,cJSON *argjson) |
|||
{ |
|||
return(clonestr("{\"error\":\"ecb is readonly data source\"}")); |
|||
} |
|||
|
|||
struct exchange_funcs ecb_funcs = EXCHANGE_FUNCS(ecb,EXCHANGE_NAME); |
|||
|
|||
#include "exchange_undefs.h" |
@ -0,0 +1,327 @@ |
|||
/******************************************************************************
|
|||
* 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 "fxcm" |
|||
#define UPDATE fxcm ## _price |
|||
#define SUPPORTS fxcm ## _supports |
|||
#define SIGNPOST fxcm ## _signpost |
|||
#define TRADE fxcm ## _trade |
|||
#define ORDERSTATUS fxcm ## _orderstatus |
|||
#define CANCELORDER fxcm ## _cancelorder |
|||
#define OPENORDERS fxcm ## _openorders |
|||
#define TRADEHISTORY fxcm ## _tradehistory |
|||
#define BALANCES fxcm ## _balances |
|||
#define PARSEBALANCE fxcm ## _parsebalance |
|||
#define WITHDRAW fxcm ## _withdraw |
|||
#define CHECKBALANCE fxcm ## _checkbalance |
|||
#define ALLPAIRS fxcm ## _allpairs |
|||
#define FUNCS fxcm ## _funcs |
|||
#define BASERELS fxcm ## _baserels |
|||
|
|||
static char **FXCM_contracts; static int num_FXCM; |
|||
|
|||
char *fxcm_xmlstr() |
|||
{ |
|||
char *xmlstr; int32_t i,j,k; |
|||
if ( (xmlstr= issue_curl("http://rates.fxcm.com/RatesXML")) != 0 ) |
|||
{ |
|||
_stripwhite(xmlstr,0); |
|||
//printf("(%s)\n",xmlstr);
|
|||
i = 0; |
|||
if ( strncmp("<?xml",xmlstr,5) == 0 ) |
|||
for (; xmlstr[i]!='>'&&xmlstr[i]!=0; i++) |
|||
; |
|||
if ( xmlstr[i] == '>' ) |
|||
i++; |
|||
for (j=0; xmlstr[i]!=0; i++) |
|||
{ |
|||
if ( strncmp("<Rates>",&xmlstr[i],strlen("<Rates>")) == 0 ) |
|||
xmlstr[j++] = '[', i += strlen("<Rates>")-1; |
|||
else if ( strncmp("<RateSymbol=",&xmlstr[i],strlen("<RateSymbol=")) == 0 ) |
|||
{ |
|||
if ( j > 1 ) |
|||
xmlstr[j++] = ','; |
|||
memcpy(&xmlstr[j],"{\"Symbol\":",strlen("{\"Symbol\":")), i += strlen("<RateSymbol=")-1, j += strlen("{\"Symbol\":"); |
|||
} |
|||
else |
|||
{ |
|||
char *strpairs[][2] = { { "<Bid>", "\"Bid\":" }, { "<Ask>", "\"Ask\":" }, { "<High>", "\"High\":" }, { "<Low>", "\"Low\":" }, { "<Direction>", "\"Direction\":" }, { "<Last>", "\"Last\":\"" } }; |
|||
for (k=0; k<sizeof(strpairs)/sizeof(*strpairs); k++) |
|||
if ( strncmp(strpairs[k][0],&xmlstr[i],strlen(strpairs[k][0])) == 0 ) |
|||
{ |
|||
memcpy(&xmlstr[j],strpairs[k][1],strlen(strpairs[k][1])); |
|||
i += strlen(strpairs[k][0])-1; |
|||
j += strlen(strpairs[k][1]); |
|||
break; |
|||
} |
|||
if ( k == sizeof(strpairs)/sizeof(*strpairs) ) |
|||
{ |
|||
char *ends[] = { "</Bid>", "</Ask>", "</High>", "</Low>", "</Direction>", "</Last>", "</Rate>", "</Rates>", ">" }; |
|||
for (k=0; k<sizeof(ends)/sizeof(*ends); k++) |
|||
if ( strncmp(ends[k],&xmlstr[i],strlen(ends[k])) == 0 ) |
|||
{ |
|||
i += strlen(ends[k])-1; |
|||
if ( strcmp("</Rate>",ends[k]) == 0 ) |
|||
xmlstr[j++] = '}'; |
|||
else if ( strcmp("</Rates>",ends[k]) == 0 ) |
|||
xmlstr[j++] = ']'; |
|||
else if ( strcmp("</Last>",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 ) |
|||
{ |
|||
/*<Rate Symbol="USDJPY">
|
|||
<Bid>123.763</Bid> |
|||
<Ask>123.786</Ask> |
|||
<High>123.956</High> |
|||
<Low>123.562</Low> |
|||
<Direction>-1</Direction> |
|||
<Last>08:49:15</Last>*/ |
|||
//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<num_FXCM; i++) |
|||
{ |
|||
if ( FXCM_contracts[i] == 0 ) |
|||
break; |
|||
free(FXCM_contracts[i]); |
|||
} |
|||
free(FXCM_contracts); |
|||
} |
|||
FXCM_contracts = calloc(n+1,sizeof(*FXCM_contracts)); |
|||
for (i=0; i<n; i++) |
|||
{ |
|||
obj = jitem(json,i); |
|||
flag = 0; |
|||
if ( (str= jstr(obj,"Symbol")) != 0 && strlen(str) < 15 ) |
|||
{ |
|||
strcpy(name,str); |
|||
touppercase(name); |
|||
if ( strcmp(name,"USDCNH") == 0 ) |
|||
strcpy(name,"USDCNY"); |
|||
FXCM_contracts[num++] = clonestr(name); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
free(xmlstr); |
|||
} |
|||
return(num); |
|||
} |
|||
|
|||
int32_t fxcm_ensure() |
|||
{ |
|||
if ( num_FXCM == 0 || FXCM_contracts == 0 ) |
|||
num_FXCM = fxcm_setcontracts(); |
|||
if ( FXCM_contracts == 0 ) |
|||
return(-1); |
|||
else return(0); |
|||
} |
|||
|
|||
char *ALLPAIRS(struct exchange_info *exchange,cJSON *argjson) |
|||
{ |
|||
int32_t i,c,n; char base[32],rel[32]; cJSON *json,*item,*array = cJSON_CreateArray(); |
|||
if ( fxcm_ensure() == 0 ) |
|||
{ |
|||
for (i=0; i<num_FXCM; i++) |
|||
{ |
|||
if ( strcmp("COPPER",FXCM_contracts[i]) != 0 && (n= (int32_t)strlen(FXCM_contracts[i])) == 6 && ((c= FXCM_contracts[i][n-1]) < '0' || c > '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<num_FXCM; i++) |
|||
{ |
|||
if ( strcmp(contract,FXCM_contracts[i]) == 0 ) |
|||
return(1); |
|||
else if ( strcmp(revcontract,FXCM_contracts[i]) == 0 ) |
|||
return(-1); |
|||
} |
|||
} |
|||
return(0); |
|||
} |
|||
|
|||
void prices777_fxcm(double bids[64],double asks[64],double highs[64],double lows[64]) |
|||
{ |
|||
static char *xmlstr; static uint32_t lasttime; |
|||
char name[64],*str; cJSON *json,*obj; int32_t i,c,flag,n = 0; double bid,ask,high,low; struct destbuf numstr; |
|||
memset(bids,0,sizeof(*bids) * 64), memset(asks,0,sizeof(*asks) * 64); |
|||
memset(highs,0,sizeof(*highs) * 64), memset(lows,0,sizeof(*lows) * 64); |
|||
if ( fxcm_ensure() < 0 ) |
|||
return; |
|||
if ( time(NULL) > 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<n; i++) |
|||
{ |
|||
obj = jitem(json,i); |
|||
flag = 0; |
|||
c = -1; |
|||
if ( (str= jstr(obj,"Symbol")) != 0 && strlen(str) < 15 ) |
|||
{ |
|||
strcpy(name,str); |
|||
if ( strcmp(name,"USDCNH") == 0 ) |
|||
strcpy(name,"USDCNY"); |
|||
copy_cJSON(&numstr,jobj(obj,"Bid")), bid = atof(numstr.buf); |
|||
copy_cJSON(&numstr,jobj(obj,"Ask")), ask = atof(numstr.buf); |
|||
copy_cJSON(&numstr,jobj(obj,"High")), high = atof(numstr.buf); |
|||
copy_cJSON(&numstr,jobj(obj,"Low")), low = atof(numstr.buf); |
|||
if ( (c= strsearch(FXCM_contracts,num_FXCM,name)) >= 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" |
@ -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" |
@ -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" |
@ -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" |
Loading…
Reference in new issue