Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
9385714d72
  1. 41
      iguana/iguana_exchanges.c
  2. 1
      iguana/peggy.h
  3. 18
      iguana/peggy_price.c
  4. 6
      iguana/peggy_update.c
  5. 1
      iguana/tests/paxrates
  6. 2
      iguana/tests/rates

41
iguana/iguana_exchanges.c

@ -54,6 +54,11 @@ double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *s
if ( basevolume < 0. )
basevolume = -basevolume, dir = -1;
else dir = 1;
if ( rel == 0 || rel[0] == 0 )
{
*totalvolp = 1.;
return(PAX_aveprice(myinfo,base));
}
memset(sortbuf,0,sizeof(*sortbuf) * max);
if ( base != 0 && rel != 0 && basevolume > SMALLVAL )
{
@ -113,11 +118,13 @@ double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *s
double instantdex_avehbla(struct supernet_info *myinfo,double retvals[4],char *_base,char *_rel,double basevolume)
{
double avebid,aveask,bidvol,askvol; struct exchange_quote sortbuf[2560]; cJSON *argjson; char base[64],rel[64];
int32_t basenum,relnum; double baseval,relval,avebid,aveask,bidvol,askvol; struct exchange_quote sortbuf[2560]; cJSON *argjson; char base[64],rel[64];
if ( retvals == 0 )
return(0);
strcpy(base,_base);
strcpy(rel,_rel);
if ( _rel == 0 )
strcpy(rel,"");
else strcpy(rel,_rel);
if ( myinfo == 0 )
myinfo = SuperNET_MYINFO(0);
argjson = cJSON_CreateObject();
@ -125,6 +132,11 @@ double instantdex_avehbla(struct supernet_info *myinfo,double retvals[4],char *_
avebid = instantdex_aveprice(myinfo,sortbuf,sizeof(sortbuf)/(4*sizeof(*sortbuf)),&bidvol,base,rel,-basevolume,argjson);
free_json(argjson);
retvals[0] = avebid, retvals[1] = bidvol, retvals[2] = aveask, retvals[3] = askvol;
if ( (basenum= PAX_basenum(base)) >= 0 && (relnum= PAX_basenum(rel)) >= 0 )
{
if ( myinfo->PEGS != 0 && (baseval= myinfo->PEGS->data.RTmatrix[basenum][basenum]) != 0. && (relval= myinfo->PEGS->data.RTmatrix[relnum][relnum]) != 0. )
return(baseval / relval);
}
if ( avebid > SMALLVAL && aveask > SMALLVAL )
return((avebid + aveask) * .5);
else return(0);
@ -733,7 +745,7 @@ void exchanges777_loop(void *ptr)
{
if ( peggyflag != 0 && PEGS != 0 )
{
printf("nonz peggy\n");
//printf("nonz peggy\n");
PAX_idle(PEGS,peggyflag,3);
if ( time(NULL) > PEGS->lastupdate+100 )
{
@ -1361,10 +1373,12 @@ THREE_STRINGS_AND_THREE_INTS(iguana,prices,exchange,base,rel,period,start,end)
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();
int32_t i,n,len,j,haveslash,nonz; char *str,*retstr,*quote,base[64][64],rel[64][64],field[64]; double aveprice; cJSON *tmpjson,*item,*array=0,*retjson = cJSON_CreateObject();
if ( myinfo->PEGS != 0 && (str= peggy_emitprices(&nonz,myinfo->PEGS,(uint32_t)time(NULL),PEGGY_MAXLOCKDAYS)) != 0 )
free(str);
if ( is_cJSON_Array(quotes) != 0 && (n= cJSON_GetArraySize(quotes)) > 0 )
{
if ( n > 16 )
if ( n > 64 )
{
jaddstr(retjson,"error","only 16 quotes at a time");
return(jprint(retjson,1));
@ -1383,9 +1397,11 @@ INT_AND_ARRAY(iguana,rates,unused,quotes)
jaddstr(retjson,"error","quote too long");
return(jprint(retjson,1));
}
for (j=0; j<len; j++)
for (j=haveslash=0; j<len; j++)
{
if ( quote[j] == '/' )
{
haveslash = 1;
if ( j > 0 && j < len-1 )
{
memcpy(base[i],quote,j);
@ -1402,25 +1418,30 @@ INT_AND_ARRAY(iguana,rates,unused,quotes)
return(jprint(retjson,1));
}
}
if ( j < len )
}
if ( j < len || haveslash == 0 )
{
if ( haveslash == 0 )
strcpy(base[i],quote);
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");
printf("(%s) ",jprint(tmpjson,0));
//printf("(%s) ",jprint(tmpjson,0));
free_json(tmpjson);
} else printf("error parsing.(%s)\n",retstr);
sprintf(field,"%s/%s",base[i],rel[i]);
if ( haveslash == 0 )
strcpy(field,base[i]);
else 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);
printf(" <- aveprice %f\n",aveprice);
//printf(" <- aveprice %f\n",aveprice);
} else printf("no return from aveprice\n");
}
else

1
iguana/peggy.h

@ -375,5 +375,6 @@ int32_t peggy_addunit(struct accts777_info *accts,struct peggy_unit *U,bits256 l
FILE *myfopen(char *fname,char *mode);
int32_t myfclose(FILE *fp);
void peggy_priceinits(struct peggy_info *PEGS,uint32_t firsttimestamp,uint32_t *allprices);
double PAX_aveprice(struct supernet_info *myinfo,char *base);
#endif

18
iguana/peggy_price.c

@ -682,9 +682,9 @@ int32_t PAX_getmatrix(double *basevals,struct peggy_info *PEGS,double Hmatrix[32
RTprices[i] = PEGS->data.cryptos[7];
else if ( i < 32 )
{
basevals[i] = Hmatrix[i][i];
PEGS->data.RTmatrix[i][i] = basevals[i] = Hmatrix[i][i];
//if ( Debuglevel > 2 )
printf("(%s %f).%d ",CURRENCIES[i],basevals[i],i);
//printf("(%s %f).%d ",CURRENCIES[i],basevals[i],i);
}
else if ( (c= PAX_contractnum(contracts[i],0)) >= 0 )
{
@ -716,10 +716,12 @@ char *peggy_emitprices(int32_t *nonzp,struct peggy_info *PEGS,uint32_t blocktime
double matrix[32][32],RTmatrix[32][32],cprices[64],basevals[64]; struct price_resolution prices[256];
cJSON *json,*array; char *jsonstr,*opreturnstr = 0; int32_t i,nonz = 0;
memset(cprices,0,sizeof(cprices));
//printf("peggy_emitprices\n");
printf("peggy_emitprices\n");
if ( PAX_getmatrix(basevals,PEGS,matrix,cprices+1,peggy_bases+1,sizeof(peggy_bases)/sizeof(*peggy_bases)-1,blocktimestamp) > 0 )
{
cprices[0] = PEGS->btcdbtc;
for (i=0; i<32; i++)
PEGS->data.RTmatrix[i][i] = basevals[i];
/*for (i=0; i<32; i++)
printf("%f ",basevals[i]);
printf("basevals\n");
@ -825,6 +827,16 @@ double PAX_getprice(char *retbuf,char *base,char *rel,char *contract,struct pegg
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
double PAX_aveprice(struct supernet_info *myinfo,char *base)
{
struct peggy_info *PEGS; int32_t basenum;
if ( (PEGS= myinfo->PEGS) != 0 && (basenum= PAX_basenum(base)) >= 0 )
{
return(PEGS->data.RTmatrix[basenum][basenum]);
}
return(0.);
}
struct peggy_info *PAX_init()
{
void peggy_indsinit();

6
iguana/peggy_update.c

@ -91,9 +91,11 @@ int32_t PAX_ispair(char *base,char *rel,char *contract)
return(-1);
}
int32_t PAX_basenum(char *base)
int32_t PAX_basenum(char *_base)
{
int32_t i,j;
int32_t i,j; char base[64];
strcpy(base,_base);
touppercase(base);
if ( 1 )
{
for (i=0; i<sizeof(CURRENCIES)/sizeof(*CURRENCIES); i++)

1
iguana/tests/paxrates

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"rates\",\"quotes\":[\"USD\", \"EUR\", \"JPY\", \"GBP\", \"AUD\", \"CAD\", \"CHF\", \"NZD\", \"CNY\", \"RUB\", \"MXN\", \"BRL\", \"INR\", \"HKD\", \"TRY\", \"ZAR\", \"PLN\", \"NOK\", \"SEK\", \"DKK\", \"CZK\", \"HUF\", \"ILS\", \"KRW\", \"MYR\", \"PHP\", \"RON\", \"SGD\", \"THB\", \"BGN\", \"IDR\", \"HRK\"]}"

2
iguana/tests/rates

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"rates\",\"quotes\":[\"BTCD/BTC\", \"BTC/USD\", \"EUR/USD\"]}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"rates\",\"quotes\":[\"BTCD/BTC\", \"BTC/USD\", \"EUR/USD\", \"THB/BRL\"]}"

Loading…
Cancel
Save