From 69c601b27ad7357a69ffa9b7ff6bda4a33a63889 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Aug 2016 16:00:37 -0300 Subject: [PATCH] test --- iguana/iguana_exchanges.c | 77 +++++++++++++++++++++++++++++++++++ iguana/tests/rates | 1 + includes/iguana_apideclares.h | 2 +- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 iguana/tests/rates diff --git a/iguana/iguana_exchanges.c b/iguana/iguana_exchanges.c index 44659d007..657ef83e1 100755 --- a/iguana/iguana_exchanges.c +++ b/iguana/iguana_exchanges.c @@ -1294,4 +1294,81 @@ STRING_ARG(InstantDEX,allpairs,exchange) return((*ptr->issue.allpairs)(ptr,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); } + +INT_AND_ARRAY(iguana,rates,unused,quotes) +{ + int32_t i,n,len,j; char *retstr,*quote,base[16][64],rel[16][64],field[64]; double aveprice; cJSON *tmpjson,*item,*array=0,*retjson = cJSON_CreateObject(); + if ( is_cJSON_Array(quotes) != 0 && (n= cJSON_GetArraySize(quotes)) > 0 ) + { + if ( n > 16 ) + { + jaddstr(retjson,"error","only 16 quotes at a time"); + return(jprint(retjson,1)); + } + memset(base,0,sizeof(base)); + memset(rel,0,sizeof(rel)); + for (i=0; i= 64 ) + { + if ( array != 0 ) + free_json(array); + jaddstr(retjson,"error","quote too long"); + return(jprint(retjson,1)); + } + for (j=0; j 0 && j < len-1 ) + { + memcpy(base[i],quote,j); + base[i][j] = 0; + j++; + strcpy(rel[i],"e[j]); + break; + } + else + { + if ( array != 0 ) + free_json(array); + jaddstr(retjson,"error","no base error in quote item"); + return(jprint(retjson,1)); + } + } + if ( j < len ) + { + aveprice = 0.; + if ( (retstr= tradebot_aveprice(myinfo,coin,json,remoteaddr,"",base[i],rel[i],1)) != 0 ) + { + if ( (tmpjson= cJSON_Parse(retstr)) != 0 ) + { + aveprice = jdouble(tmpjson,"aveprice"); + free_json(tmpjson); + } + sprintf(field,"%s/%s",base[i],rel[i]); + item = cJSON_CreateObject(); + jaddnum(item,field,aveprice); + if ( array == 0 ) + array = cJSON_CreateArray(); + jaddi(array,item); + free(retstr); + } + } + else + { + if ( array != 0 ) + free_json(array); + jaddstr(retjson,"error","syntax error in quote item"); + return(jprint(retjson,1)); + } + } + } + jaddstr(retjson,"result","success"); + jadd(retjson,"rates",array); + } else jaddstr(retjson,"error","no quotes array"); + return(jprint(retjson,1)); +} #include "../includes/iguana_apiundefs.h" diff --git a/iguana/tests/rates b/iguana/tests/rates new file mode 100755 index 000000000..a36a53b10 --- /dev/null +++ b/iguana/tests/rates @@ -0,0 +1 @@ +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"rates\",\"quotes\":[\"BTC/USD\", \"EUR/USD\"]}" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 3231e5b62..d16fa5f0f 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -13,7 +13,7 @@ * * ******************************************************************************/ -//INT_AND_ARRAY(iguana,rates,unused,quotes); +INT_AND_ARRAY(iguana,rates,unused,quotes); ZERO_ARGS(InstantDEX,allcoins); STRING_ARG(InstantDEX,available,source);