Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
0547baa1f2
  1. 1
      iguana/iguana777.h
  2. 6
      iguana/iguana_exchanges.c
  3. 26
      iguana/main.c
  4. 118
      iguana/peggy.c
  5. 8
      iguana/peggy.h
  6. 26
      iguana/peggy_price.c
  7. 17
      iguana/peggy_update.c
  8. 1
      iguana/tests/PAX
  9. 1
      includes/iguana_apideclares.h

1
iguana/iguana777.h

@ -74,6 +74,7 @@ struct supernet_info
struct basilisk_relay relays[BASILISK_MAXRELAYS]; struct basilisk_relay relays[BASILISK_MAXRELAYS];
struct basilisk_spend *spends; int32_t numspends; struct basilisk_spend *spends; int32_t numspends;
int32_t numrelays,RELAYID; int32_t numrelays,RELAYID;
struct peggy_info *PEGS;
// compatibility // compatibility
bits256 pangea_category,instantdex_category; bits256 pangea_category,instantdex_category;
uint8_t logs[256],exps[510]; uint8_t logs[256],exps[510];

6
iguana/iguana_exchanges.c

@ -720,8 +720,8 @@ void exchanges777_loop(void *ptr)
myinfo = SuperNET_MYINFO(0); myinfo = SuperNET_MYINFO(0);
if ( strcmp(exchange->name,"PAX") == 0 ) if ( strcmp(exchange->name,"PAX") == 0 )
{ {
PEGS = calloc(1,sizeof(*PEGS)); PEGS = myinfo->PEGS; //calloc(1,sizeof(*PEGS));
PAX_init(PEGS); //PAX_init(PEGS);
exchange->privatedata = PEGS; exchange->privatedata = PEGS;
peggyflag = 1; peggyflag = 1;
_crypto_update(PEGS,PEGS->cryptovols,&PEGS->data,1,peggyflag); _crypto_update(PEGS,PEGS->cryptovols,&PEGS->data,1,peggyflag);
@ -934,7 +934,7 @@ char *exchanges777_Qprices(struct exchange_info *exchange,char *base,char *rel,i
else else
{ {
req->func = 'M'; req->func = 'M';
printf("Monitor.%s (%s %s) invert.%d\n",exchange->name,base,rel,req->invert); //printf("Monitor.%s (%s %s) invert.%d\n",exchange->name,base,rel,req->invert);
queue_enqueue("pricesQ",&exchange->pricesQ,&req->DL,0); queue_enqueue("pricesQ",&exchange->pricesQ,&req->DL,0);
return(clonestr("{\"result\":\"start monitoring\"}")); return(clonestr("{\"result\":\"start monitoring\"}"));
} }

26
iguana/main.c

@ -1576,19 +1576,19 @@ void iguana_main(void *arg)
iguana_urlinit(myinfo,ismainnet,usessl); iguana_urlinit(myinfo,ismainnet,usessl);
//category_init(myinfo); //category_init(myinfo);
#if LIQUIDITY_PROVIDER #if LIQUIDITY_PROVIDER
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("bitcoin",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("bitcoin"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("poloniex",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("poloniex"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("bittrex",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("bittrex"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("btc38",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("btc38"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("huobi",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("huobi"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("instaforex",0); //myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("instaforex"),0);
//myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("bitfinex",0); //myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("bitfinex"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("coinbase",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("coinbase"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("lakebtc",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("lakebtc"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("quadriga",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("quadriga"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("okcoin",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("okcoin"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("btce",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("btce"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create("bitstamp",0); myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("bitstamp"),0);
#endif #endif
//argjson = arg != 0 ? cJSON_Parse(arg) : cJSON_Parse("{}"); //argjson = arg != 0 ? cJSON_Parse(arg) : cJSON_Parse("{}");
//iguana_coinadd("BTC",argjson); dont do this here, coin args not set //iguana_coinadd("BTC",argjson); dont do this here, coin args not set

118
iguana/peggy.c

@ -280,7 +280,7 @@ struct peggy *peggy_createpair(struct peggy_info *PEGS,int64_t quorum,int64_t de
return(PEG); return(PEG);
} }
struct peggy_info *peggy_init(char *path,int32_t maxdays,char *maincurrency,uint64_t maincurrencyunitsize,uint64_t quorum,uint64_t decisionthreshold,struct price_resolution spread,uint32_t dailyrate,int32_t interesttenths,int32_t posboost,int32_t negpenalty,int32_t feediv,int32_t feemult,uint32_t firsttimestamp,uint32_t BTCD_price0) struct peggy_info *peggy_init(int32_t maxdays,char *maincurrency,uint64_t maincurrencyunitsize,uint64_t quorum,uint64_t decisionthreshold,struct price_resolution spread,uint32_t dailyrate,int32_t interesttenths,int32_t posboost,int32_t negpenalty,int32_t feediv,int32_t feemult,uint32_t firsttimestamp,uint32_t BTCD_price0)
{ {
//struct peggy_limits limits = { { PERCENTAGE(10), PERCENTAGE(25), PERCENTAGE(33), PERCENTAGE(50) }, SATOSHIDEN * 10000, SATOSHIDEN * 1000, { 0, 30, 90, 180 }, 4 }; //struct peggy_limits limits = { { PERCENTAGE(10), PERCENTAGE(25), PERCENTAGE(33), PERCENTAGE(50) }, SATOSHIDEN * 10000, SATOSHIDEN * 1000, { 0, 30, 90, 180 }, 4 };
struct peggy_lock default_lockparms = { 7, 365, 7, 0, 180, 0, -1 }; struct peggy_lock default_lockparms = { 7, 365, 7, 0, 180, 0, -1 };
@ -288,7 +288,7 @@ struct peggy_info *peggy_init(char *path,int32_t maxdays,char *maincurrency,uint
//if ( default_limits != 0 ) //if ( default_limits != 0 )
// limits = *default_limits; // limits = *default_limits;
spread.Pval = PERCENTAGE(1); spread.Pval = PERCENTAGE(1);
OS_ensure_directory(path); //OS_ensure_directory(path);
strcpy(PEGS->maincurrency,maincurrency); strcpy(PEGS->maincurrency,maincurrency);
PEGS->mainbits = stringbits(maincurrency), PEGS->mainunitsize = maincurrencyunitsize, PEGS->quorum = quorum, PEGS->decisionthreshold = decisionthreshold; PEGS->mainbits = stringbits(maincurrency), PEGS->mainunitsize = maincurrencyunitsize, PEGS->quorum = quorum, PEGS->decisionthreshold = decisionthreshold;
PEGS->default_lockparms = default_lockparms, PEGS->default_lockparms.maxlockdays = maxdays; PEGS->default_lockparms = default_lockparms, PEGS->default_lockparms.maxlockdays = maxdays;
@ -324,48 +324,11 @@ long hdecode_varint(uint64_t *valp,uint8_t *ptr,long offset,long mappedsize)
return(offset); return(offset);
} }
struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct peggy_info *PEGS,char *path,uint32_t firsttimestamp,char *opreturnstr) void peggy_priceinits(struct peggy_info *PEGS,uint32_t firsttimestamp,uint32_t *allprices)
{
//struct peggy_limits limits = { { PERCENTAGE(10), PERCENTAGE(25), PERCENTAGE(33), PERCENTAGE(50) }, SATOSHIDEN * 10000, SATOSHIDEN * 1000, { 0, 30, 90, 180 }, 4 };
char name[64],base[64],rel[64]; uint8_t opret[1024]; struct peggy_tx Ptx; struct peggy *PEG;
struct price_resolution mindenom,spread,price; uint64_t len; long offset; uint64_t maxsupply=0,maxnetbalance=0;
int32_t i,c,baseid,relid,peggymils=0,signedcount,datalen,n=0,maxmargin=0,numprices,err=-1; uint32_t pval = 0;
numprices = 1;
datalen = (int32_t)strlen(opreturnstr) / 2;
decode_hex(opret,datalen,opreturnstr);
printf("peggy_genesis(%s)\n",opreturnstr);
if ( opret[0] == OP_RETURN_OPCODE )
{
offset = hdecode_varint(&len,opret,1,sizeof(opret));
if ( opret[offset] == 'P' && opret[offset+1] == 'A' && opret[offset+2] == 'X' )
{ {
printf("deser\n"); char name[64],base[64],rel[64]; struct peggy *PEG;
if ( (n= serdes777_deserialize(&signedcount,&Ptx,firsttimestamp,opret+offset+3,(int32_t)len-3)) > 0 ) struct price_resolution mindenom,spread,price; uint64_t maxsupply=0,maxnetbalance=0;
{ int32_t i,c,baseid,relid,peggymils=0,n=0,maxmargin=0; uint32_t pval = 0;
err = 0;
for (i=0; i<Ptx.details.price.num; i++)
if ( Ptx.details.price.feed[i] == 0 )
break;
if ( i == Ptx.details.price.num )
{
printf("GENESIS.(%s)\n",opreturnstr);
for (i=0; i<Ptx.details.price.num; i++)
printf("%u ",Ptx.details.price.feed[i]);
printf("prices\n");
lookbacks[0] = 0, lookbacks[1] = 1000;
if ( PEGS == 0 )
{
spread.Pval = PERCENTAGE(1);
PEGS = peggy_init(path,PEGGY_MAXLOCKDAYS,"BTCD",SATOSHIDEN/100,1,1,spread,PEGGY_RATE_777,40,10,2,5,2,Ptx.timestamp,Ptx.details.price.feed[0]);
//EGS->accts = accts777_init(path,0);
PEGS->genesis = opreturnstr, opreturnstr = 0;
}
} else printf("i.%d vs %d\n",i,Ptx.details.price.num);
} else printf("deser got n.%d\n",n);
} else printf("illegal opret.(%c%c%c)\n",opret[offset],opret[offset+1],opret[offset+2]);
} else printf("opret[0] %d\n",opret[0]);
if ( err < 0 || PEGS == 0 )
return(0);
mindenom.Pval = PRICE_RESOLUTION; mindenom.Pval = PRICE_RESOLUTION;
spread.Pval = PERCENTAGE(1); spread.Pval = PERCENTAGE(1);
for (i=1; i<sizeof(peggy_bases)/sizeof(*peggy_bases)+28; i++) for (i=1; i<sizeof(peggy_bases)/sizeof(*peggy_bases)+28; i++)
@ -376,7 +339,7 @@ struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct pe
if ( peggy_bases[i] == 0 ) if ( peggy_bases[i] == 0 )
continue; continue;
peggy_mapname(base,rel,i); peggy_mapname(base,rel,i);
price.Pval = Ptx.details.price.feed[i]; price.Pval = allprices[i];
if ( i <= 8 ) if ( i <= 8 )
maxmargin = 25; maxmargin = 25;
else if ( i < 16 ) else if ( i < 16 )
@ -391,9 +354,9 @@ struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct pe
maxsupply = SATOSHIDEN * 10000, maxnetbalance = SATOSHIDEN * 1000; maxsupply = SATOSHIDEN * 10000, maxnetbalance = SATOSHIDEN * 1000;
if ( strcmp(base,"BTC") == 0 || strcmp(base,"NXT") == 0 || strcmp(base,"USD") == 0 || strcmp(base,"CNY") == 0 ) if ( strcmp(base,"BTC") == 0 || strcmp(base,"NXT") == 0 || strcmp(base,"USD") == 0 || strcmp(base,"CNY") == 0 )
maxsupply *= 10, maxnetbalance *= 10; maxsupply *= 10, maxnetbalance *= 10;
price.Pval = Ptx.details.price.feed[i]; price.Pval = allprices[i];
peggy_mapname(base,rel,i); peggy_mapname(base,rel,i);
pval = Ptx.details.price.feed[i]; pval = allprices[i];
} }
else if ( i-sizeof(peggy_bases)/sizeof(*peggy_bases) < PEGGY_MAXPAIREDPEGS ) else if ( i-sizeof(peggy_bases)/sizeof(*peggy_bases) < PEGGY_MAXPAIREDPEGS )
{ {
@ -406,11 +369,11 @@ struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct pe
baseid = Contract_base[c]+1, relid = Contract_rel[c]+1; baseid = Contract_base[c]+1, relid = Contract_rel[c]+1;
peggymils = (PEGS->contracts[baseid]->peggymils * 10000) / PEGS->contracts[relid]->peggymils; peggymils = (PEGS->contracts[baseid]->peggymils * 10000) / PEGS->contracts[relid]->peggymils;
if ( strcmp(PEGS->contracts[baseid]->name.base,base) == 0 && strcmp(PEGS->contracts[relid]->name.base,rel) == 0 ) if ( strcmp(PEGS->contracts[baseid]->name.base,base) == 0 && strcmp(PEGS->contracts[relid]->name.base,rel) == 0 )
price.Pval = (PRICE_RESOLUTION * Ptx.details.price.feed[baseid]) / Ptx.details.price.feed[relid]; price.Pval = (PRICE_RESOLUTION * allprices[baseid]) / allprices[relid];
else printf("mismatched %p base.(%s) baseid.%d (%s) or %p rel.(%s) relid.%d (%s)\n",PEGS->contracts[baseid],PEGS->contracts[baseid]->name.base,baseid,base,PEGS->contracts[relid],PEGS->contracts[relid]->name.base,relid,rel); else printf("mismatched %p base.(%s) baseid.%d (%s) or %p rel.(%s) relid.%d (%s)\n",PEGS->contracts[baseid],PEGS->contracts[baseid]->name.base,baseid,base,PEGS->contracts[relid],PEGS->contracts[relid]->name.base,relid,rel);
pval = (uint32_t)price.Pval; pval = (uint32_t)price.Pval;
} else printf("peggy_genesis RAN out of space\n"); } else printf("peggy_genesis RAN out of space\n");
if ( (PEG= peggy_createpair(PEGS,0,0,name,base,rel,maxsupply,maxnetbalance,0,SATOSHIDEN*10,PEGGY_RATE_777,firsttimestamp,&price,numprices,spread,maxmargin,mindenom,i,i<sizeof(peggy_bases)/sizeof(*peggy_bases),peggymils)) != 0 ) if ( (PEG= peggy_createpair(PEGS,0,0,name,base,rel,maxsupply,maxnetbalance,0,SATOSHIDEN*10,PEGGY_RATE_777,firsttimestamp,&price,1,spread,maxmargin,mindenom,i,i<sizeof(peggy_bases)/sizeof(*peggy_bases),peggymils)) != 0 )
{ {
price = peggy_scaleprice(price,peggymils); price = peggy_scaleprice(price,peggymils);
struct price_resolution x = peggy_price(PEG,0); struct price_resolution x = peggy_price(PEG,0);
@ -418,6 +381,50 @@ struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct pe
n++; n++;
} }
} }
}
struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct peggy_info *PEGS,char *path,uint32_t firsttimestamp,char *opreturnstr)
{
//struct peggy_limits limits = { { PERCENTAGE(10), PERCENTAGE(25), PERCENTAGE(33), PERCENTAGE(50) }, SATOSHIDEN * 10000, SATOSHIDEN * 1000, { 0, 30, 90, 180 }, 4 };
uint8_t opret[1024]; struct peggy_tx Ptx; struct price_resolution spread; uint64_t len;
long offset; int32_t i,signedcount,datalen,n=0,numprices,err=-1;
numprices = 1;
datalen = (int32_t)strlen(opreturnstr) / 2;
decode_hex(opret,datalen,opreturnstr);
printf("peggy_genesis(%s)\n",opreturnstr);
if ( opret[0] == OP_RETURN_OPCODE )
{
offset = hdecode_varint(&len,opret,1,sizeof(opret));
if ( opret[offset] == 'P' && opret[offset+1] == 'A' && opret[offset+2] == 'X' )
{
printf("deser\n");
if ( (n= serdes777_deserialize(&signedcount,&Ptx,firsttimestamp,opret+offset+3,(int32_t)len-3)) > 0 )
{
err = 0;
for (i=0; i<Ptx.details.price.num; i++)
if ( Ptx.details.price.feed[i] == 0 )
break;
if ( i == Ptx.details.price.num )
{
printf("GENESIS.(%s)\n",opreturnstr);
for (i=0; i<Ptx.details.price.num; i++)
printf("%u ",Ptx.details.price.feed[i]);
printf("prices\n");
lookbacks[0] = 0, lookbacks[1] = 1000;
if ( PEGS == 0 )
{
spread.Pval = PERCENTAGE(1);
PEGS = peggy_init(PEGGY_MAXLOCKDAYS,"BTCD",SATOSHIDEN/100,1,1,spread,PEGGY_RATE_777,40,10,2,5,2,Ptx.timestamp,Ptx.details.price.feed[0]);
//PEGS->accts = accts777_init(path,0);
PEGS->genesis = opreturnstr, opreturnstr = 0;
}
} else printf("i.%d vs %d\n",i,Ptx.details.price.num);
} else printf("deser got n.%d\n",n);
} else printf("illegal opret.(%c%c%c)\n",opret[offset],opret[offset+1],opret[offset+2]);
} else printf("opret[0] %d\n",opret[0]);
if ( err < 0 || PEGS == 0 )
return(0);
peggy_priceinits(PEGS,firsttimestamp,Ptx.details.price.feed);
printf("genesis prices t%u vs %u\n",Ptx.timestamp,firsttimestamp); printf("genesis prices t%u vs %u\n",Ptx.timestamp,firsttimestamp);
return(PEGS); return(PEGS);
} }
@ -662,7 +669,7 @@ struct peggy_info *peggy_lchain(struct txinds777_info *opreturns,char *path)
int32_t peggy_init_contexts(struct txinds777_info *opreturns,uint32_t RTblocknum,uint32_t RTblocktimestamp,char *path,void *globals[OPRETURNS_CONTEXTS],int32_t lookbacks[OPRETURNS_CONTEXTS],int32_t maxcontexts) int32_t peggy_init_contexts(struct txinds777_info *opreturns,uint32_t RTblocknum,uint32_t RTblocktimestamp,char *path,void *globals[OPRETURNS_CONTEXTS],int32_t lookbacks[OPRETURNS_CONTEXTS],int32_t maxcontexts)
{ {
double startmilli; char buf[512]; struct price_resolution spread; struct peggy_info *PEGS=0,*PEGS2=0; /* double startmilli; char buf[512]; struct price_resolution spread; struct peggy_info *PEGS=0,*PEGS2=0;
if ( maxcontexts != 2 ) if ( maxcontexts != 2 )
{ {
printf("peggy needs 2 contexts\n"); printf("peggy needs 2 contexts\n");
@ -684,6 +691,17 @@ int32_t peggy_init_contexts(struct txinds777_info *opreturns,uint32_t RTblocknum
globals[1] = PEGS2 = peggy_init(buf,PEGGY_MAXLOCKDAYS,"BTCD",SATOSHIDEN/100,1,1,spread,PEGGY_RATE_777,40,10,2,5,2,PEGS->genesistime,PEGS->BTCD_price0); globals[1] = PEGS2 = peggy_init(buf,PEGGY_MAXLOCKDAYS,"BTCD",SATOSHIDEN/100,1,1,spread,PEGGY_RATE_777,40,10,2,5,2,PEGS->genesistime,PEGS->BTCD_price0);
startmilli = OS_milliseconds(); startmilli = OS_milliseconds();
peggy_clone(buf,PEGS2,PEGS); peggy_clone(buf,PEGS2,PEGS);
printf("cloned %d in %.3f millis per opreturn\n",PEGS->numopreturns,(OS_milliseconds() - startmilli)/PEGS->numopreturns); sleep(3); printf("cloned %d in %.3f millis per opreturn\n",PEGS->numopreturns,(OS_milliseconds() - startmilli)/PEGS->numopreturns); sleep(3);*/
return(2); return(2);
} }
void peggy_indsinit()
{
if ( sizeof(Peggy_inds)/sizeof(*Peggy_inds) != PEGGY_NUMCOEFFS )
{
peggy_geninds();
printf("need to update Peggy_inds with above\n");
exit(-1);
}
peggy_dailyrates();
}

8
iguana/peggy.h

@ -235,7 +235,7 @@ struct peggy_info
int32_t default_dailyrate,interesttenths,posboost,negpenalty,feediv,feemult; int32_t default_dailyrate,interesttenths,posboost,negpenalty,feediv,feemult;
int32_t numpegs,numpairedpegs,numpricedpegs,numopreturns,numvoters; int32_t numpegs,numpairedpegs,numpricedpegs,numopreturns,numvoters;
struct accts777_info *accts; struct accts777_info *accts;
struct PAX_data data,tmp; double cryptovols[2][8][2],btcusd,btcdbtc,cnyusd; struct PAX_data data,tmp; double cryptovols[2][9][2],btcusd,btcdbtc,cnyusd;
char path[512],*genesis; uint32_t genesistime,BTCD_price0,lastupdate; char path[512],*genesis; uint32_t genesistime,BTCD_price0,lastupdate;
struct PAX_spline splines[128]; struct PAX_spline splines[128];
struct peggy_vote votes[PEGGY_MAXPRICEDPEGS][PEGGY_MAXVOTERS]; struct peggy_vote votes[PEGGY_MAXPRICEDPEGS][PEGGY_MAXVOTERS];
@ -307,13 +307,13 @@ extern int32_t MINDENOMS[],Peggy_inds[],dailyrates[];
struct price_resolution peggy_scaleprice(struct price_resolution price,int64_t peggymils); struct price_resolution peggy_scaleprice(struct price_resolution price,int64_t peggymils);
char *peggy_tx(char *jsonstr); char *peggy_tx(char *jsonstr);
void _crypto_update(struct peggy_info *PEGS,double cryptovols[2][8][2],struct PAX_data *dp,int32_t selector,int32_t peggyflag); void _crypto_update(struct peggy_info *PEGS,double cryptovols[2][9][2],struct PAX_data *dp,int32_t selector,int32_t peggyflag);
int32_t PAX_idle(struct peggy_info *PEGS,int32_t peggyflag,int32_t idlegap); int32_t PAX_idle(struct peggy_info *PEGS,int32_t peggyflag,int32_t idlegap);
int32_t PAX_genspline(struct PAX_spline *spline,int32_t splineid,char *name,uint32_t *utc32,double *splinevals,int32_t maxsplines,double *refvals); int32_t PAX_genspline(struct PAX_spline *spline,int32_t splineid,char *name,uint32_t *utc32,double *splinevals,int32_t maxsplines,double *refvals);
int32_t PAX_contractnum(char *base,char *rel); int32_t PAX_contractnum(char *base,char *rel);
int32_t PAX_basenum(char *base); int32_t PAX_basenum(char *base);
int32_t PAX_ispair(char *base,char *rel,char *contract); int32_t PAX_ispair(char *base,char *rel,char *contract);
void PAX_init(struct peggy_info *PEGS); struct peggy_info *PAX_init();
uint32_t peggy_mils(int32_t i); uint32_t peggy_mils(int32_t i);
void calc_smooth_code(int32_t smoothwidth,int32_t _maxprimes); void calc_smooth_code(int32_t smoothwidth,int32_t _maxprimes);
struct peggy *peggy_find(struct peggy_entry *entry,struct peggy_info *PEGS,char *name,int32_t polarity); struct peggy *peggy_find(struct peggy_entry *entry,struct peggy_info *PEGS,char *name,int32_t polarity);
@ -368,10 +368,12 @@ int32_t peggy_init_contexts(struct txinds777_info *opreturns,uint32_t blocknum,u
uint32_t peggy_clone(char *path,void *dest,void *src); uint32_t peggy_clone(char *path,void *dest,void *src);
void *peggy_replay(char *path,struct txinds777_info *opreturns,void *_PEGS,uint32_t blocknum,char *opreturnstr,uint8_t *data,int32_t datalen); void *peggy_replay(char *path,struct txinds777_info *opreturns,void *_PEGS,uint32_t blocknum,char *opreturnstr,uint8_t *data,int32_t datalen);
uint32_t peggy_currentblock(void *globals); uint32_t peggy_currentblock(void *globals);
struct peggy_info *peggy_init(int32_t maxdays,char *maincurrency,uint64_t maincurrencyunitsize,uint64_t quorum,uint64_t decisionthreshold,struct price_resolution spread,uint32_t dailyrate,int32_t interesttenths,int32_t posboost,int32_t negpenalty,int32_t feediv,int32_t feemult,uint32_t firsttimestamp,uint32_t BTCD_price0);
struct peggy_unit *peggy_match(struct accts777_info *accts,int32_t peg,uint64_t nxt64bits,bits256 lockhash,uint16_t lockdays); struct peggy_unit *peggy_match(struct accts777_info *accts,int32_t peg,uint64_t nxt64bits,bits256 lockhash,uint16_t lockdays);
int32_t peggy_addunit(struct accts777_info *accts,struct peggy_unit *U,bits256 lockhash); int32_t peggy_addunit(struct accts777_info *accts,struct peggy_unit *U,bits256 lockhash);
FILE *myfopen(char *fname,char *mode); FILE *myfopen(char *fname,char *mode);
int32_t myfclose(FILE *fp); int32_t myfclose(FILE *fp);
void peggy_priceinits(struct peggy_info *PEGS,uint32_t firsttimestamp,uint32_t *allprices);
#endif #endif

26
iguana/peggy_price.c

@ -76,7 +76,7 @@ short Currency_contractothers[NUM_CURRENCIES+1][NUM_CURRENCIES] = // buggy!
int32_t MINDENOMS[] = { 1000, 1000, 100000, 1000, 1000, 1000, 1000, 1000, // major currencies int32_t MINDENOMS[] = { 1000, 1000, 100000, 1000, 1000, 1000, 1000, 1000, // major currencies
10000, 100000, 10000, 1000, 100000, 10000, 1000, 10000, 1000, 10000, 10000, 10000, 10000, 100000, 1000, 1000000, 1000, 10000, 1000, 1000, 10000, 1000, 10000000, 10000, // end of currencies 10000, 100000, 10000, 1000, 100000, 10000, 1000, 10000, 1000, 10000, 10000, 10000, 10000, 100000, 1000, 1000000, 1000, 10000, 1000, 1000, 10000, 1000, 10000000, 10000, // end of currencies
1, 100, 1, 1, // metals, gold must be first 1, 100, 1, 1, // metals, gold must be first
1, 10, 100000, 100, 100, 10000000, 10000, 1000, 1000, 1000, 100000, 100000, 1000000 // cryptos 100, 1, 10000, 100, 100, 1000, 100000, 1000, 1000, 1000
}; };
int32_t PAX_mindenomination(int32_t base) int32_t PAX_mindenomination(int32_t base)
@ -195,14 +195,14 @@ uint32_t peggy_mils(int32_t i)
minmils = 10; minmils = 10;
else if ( strcmp(peggy_bases[i],"BUND") == 0 || strcmp(peggy_bases[i],"UKOIL") == 0 || strcmp(peggy_bases[i],"USOIL") == 0 ) else if ( strcmp(peggy_bases[i],"BUND") == 0 || strcmp(peggy_bases[i],"UKOIL") == 0 || strcmp(peggy_bases[i],"USOIL") == 0 )
minmils = 100; minmils = 100;
else if ( strncmp(peggy_bases[i],"LTC",3) == 0 || strcmp(peggy_bases[i],"SuperNET") == 0 || strncmp(peggy_bases[i],"XAG",3) == 0 || strncmp(peggy_bases[i],"ETH",3) == 0 || strncmp(peggy_bases[i],"XCP",3) == 0 ) else if ( strncmp(peggy_bases[i],"ETC",3) == 0 || strcmp(peggy_bases[i],"SuperNET") == 0 || strncmp(peggy_bases[i],"XAG",3) == 0 || strncmp(peggy_bases[i],"ETH",3) == 0 || strncmp(peggy_bases[i],"XCP",3) == 0 )
minmils = 1000; minmils = 1000;
else if ( strncmp(peggy_bases[i],"XMR",3) == 0 ) else if ( strncmp(peggy_bases[i],"XMR",3) == 0 )
minmils = 10000; minmils = 10000;
else if ( strncmp(peggy_bases[i],"NXT",3) == 0 || strncmp(peggy_bases[i],"BTS",3) == 0 ) else if ( strncmp(peggy_bases[i],"NXT",3) == 0 || strncmp(peggy_bases[i],"BTS",3) == 0 )
minmils = 1000000; minmils = 1000000;
else if ( strncmp(peggy_bases[i],"DOGE",3) == 0 ) else if ( strncmp(peggy_bases[i],"STEEM",5) == 0 )
minmils = 100000000; minmils = 1000;
else minmils = 10000; else minmils = 10000;
} }
return(minmils); return(minmils);
@ -825,13 +825,27 @@ double PAX_getprice(char *retbuf,char *base,char *rel,char *contract,struct pegg
#include "../includes/iguana_apidefs.h" #include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h" #include "../includes/iguana_apideclares.h"
void PAX_init(struct peggy_info *PEGS) struct peggy_info *PAX_init()
{ {
double commission = 0.; void peggy_indsinit();
struct peggy_info *PEGS; struct price_resolution spread; double commission = 0.;
init_Currencymasks(); init_Currencymasks();
//calc_smooth_code(127,7);
peggy_indsinit();
tradebot_monitorall(0,0,0,0,"fxcm",commission); tradebot_monitorall(0,0,0,0,"fxcm",commission);
tradebot_monitorall(0,0,0,0,"truefx",commission); tradebot_monitorall(0,0,0,0,"truefx",commission);
tradebot_monitorall(0,0,0,0,"instaforex",commission); tradebot_monitorall(0,0,0,0,"instaforex",commission);
spread.Pval = PERCENTAGE(1);
PEGS = peggy_init(PEGGY_MAXLOCKDAYS,"BTCD",SATOSHIDEN/100,100,10,spread,PEGGY_RATE_777,40,10,2,5,2,0,0);
exchange_create("PAX",0);
//peggy_priceinits(PEGS,(uint32_t)time(NULL),allprices);
return(PEGS);
}
ZERO_ARGS(pax,start)
{
myinfo->PEGS = PAX_init();
return(clonestr("{\"result\":\"success\"}"));
} }
#include "../includes/iguana_apiundefs.h" #include "../includes/iguana_apiundefs.h"

17
iguana/peggy_update.c

@ -47,7 +47,7 @@ static char *Yahoo_metals[] = { YAHOO_METALS };
char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies
"CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", // end of currencies "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", // end of currencies
"XAU", "XAG", "XPT", "XPD", // metals, gold must be first "XAU", "XAG", "XPT", "XPD", // metals, gold must be first
"BTCD", "BTC", "NXT", "LTC", "ETH", "DOGE", "BTS", "MAID", "XCP", "XMR" // cryptos "BTCD", "BTC", "NXT", "ETC", "ETH", "STEEM", "BTS", "MAID", "XCP", "XMR" // cryptos
}; };
char CONTRACTS[][16] = { "NZDUSD", "NZDCHF", "NZDCAD", "NZDJPY", "GBPNZD", "EURNZD", "AUDNZD", "CADJPY", "CADCHF", "USDCAD", "EURCAD", "GBPCAD", "AUDCAD", "USDCHF", "CHFJPY", "EURCHF", "GBPCHF", "AUDCHF", "EURUSD", "EURAUD", "EURJPY", "EURGBP", "GBPUSD", "GBPJPY", "GBPAUD", "USDJPY", "AUDJPY", "AUDUSD", "USDCNY", "USDHKD", "USDMXN", "USDZAR", "USDTRY", "EURTRY", "TRYJPY", "USDSGD", "EURNOK", "USDNOK","USDSEK","USDDKK","EURSEK","EURDKK","NOKJPY","SEKJPY","USDPLN","EURPLN","USDILS", // no more currencies char CONTRACTS[][16] = { "NZDUSD", "NZDCHF", "NZDCAD", "NZDJPY", "GBPNZD", "EURNZD", "AUDNZD", "CADJPY", "CADCHF", "USDCAD", "EURCAD", "GBPCAD", "AUDCAD", "USDCHF", "CHFJPY", "EURCHF", "GBPCHF", "AUDCHF", "EURUSD", "EURAUD", "EURJPY", "EURGBP", "GBPUSD", "GBPJPY", "GBPAUD", "USDJPY", "AUDJPY", "AUDUSD", "USDCNY", "USDHKD", "USDMXN", "USDZAR", "USDTRY", "EURTRY", "TRYJPY", "USDSGD", "EURNOK", "USDNOK","USDSEK","USDDKK","EURSEK","EURDKK","NOKJPY","SEKJPY","USDPLN","EURPLN","USDILS", // no more currencies
@ -518,12 +518,12 @@ double blend_price(double *volp,double wtA,cJSON *jsonA,double wtB,cJSON *jsonB)
return(price); return(price);
} }
void _crypto_update(struct peggy_info *PEGS,double cryptovols[2][8][2],struct PAX_data *dp,int32_t selector,int32_t peggyflag) void _crypto_update(struct peggy_info *PEGS,double cryptovols[2][9][2],struct PAX_data *dp,int32_t selector,int32_t peggyflag)
{ {
char *cryptonatorA = "https://www.cryptonator.com/api/full/%s-%s"; //unity-btc char *cryptonatorA = "https://www.cryptonator.com/api/full/%s-%s"; //unity-btc
char *cryptocoinchartsB = "http://api.cryptocoincharts.info/tradingPair/%s_%s"; //bts_btc char *cryptocoinchartsB = "http://api.cryptocoincharts.info/tradingPair/%s_%s"; //bts_btc
char *cryptostrs[9] = { "btc", "nxt", "unity", "eth", "ltc", "xmr", "bts", "xcp", "etc" }; char *cryptostrs[9] = { "btc", "nxt", "unity", "eth", "steem", "xmr", "bts", "xcp", "etc" };
int32_t iter,i,j; double btcusd,btcdbtc,cnyusd,prices[8][2],volumes[8][2]; int32_t iter,i,j; double btcusd,btcdbtc,cnyusd,prices[9][2],volumes[9][2];
char base[16],rel[16],url[512],*str; cJSON *jsonA,*jsonB; char base[16],rel[16],url[512],*str; cJSON *jsonA,*jsonB;
if ( peggyflag != 0 ) if ( peggyflag != 0 )
{ {
@ -541,12 +541,13 @@ void _crypto_update(struct peggy_info *PEGS,double cryptovols[2][8][2],struct PA
for (j=0; j<sizeof(cryptostrs)/sizeof(*cryptostrs); j++) for (j=0; j<sizeof(cryptostrs)/sizeof(*cryptostrs); j++)
{ {
str = cryptostrs[j]; str = cryptostrs[j];
if ( strcmp(str,"etc") == 0 ) /*if ( strcmp(str,"etc") == 0 )
{ {
if ( prices[3][0] > SMALLVAL ) if ( prices[3][0] > SMALLVAL )
break; break;
i = 3; i = 3;
} else i = j; } else*/
i = j;
for (iter=0; iter<1; iter++) for (iter=0; iter<1; iter++)
{ {
if ( i == 0 && iter == 0 ) if ( i == 0 && iter == 0 )
@ -582,9 +583,9 @@ void _crypto_update(struct peggy_info *PEGS,double cryptovols[2][8][2],struct PA
} }
} }
void PAX_RTupdate(struct peggy_info *PEGS,double cryptovols[2][8][2],double RTmetals[4],double *RTprices,struct PAX_data *dp) void PAX_RTupdate(struct peggy_info *PEGS,double cryptovols[2][9][2],double RTmetals[4],double *RTprices,struct PAX_data *dp)
{ {
char *cryptostrs[8] = { "btc", "nxt", "unity", "eth", "ltc", "xmr", "bts", "xcp" }; char *cryptostrs[9] = { "btc", "nxt", "unity", "eth", "etc", "steem", "xmr", "bts", "xcp" };
int32_t iter,i,c,baserel,basenum,relnum; double cnyusd,btcusd,btcdbtc,bid,ask,price,vol,prices[8][2],volumes[8][2]; int32_t iter,i,c,baserel,basenum,relnum; double cnyusd,btcusd,btcdbtc,bid,ask,price,vol,prices[8][2],volumes[8][2];
char base[16],rel[16]; char base[16],rel[16];
PAX_update(PEGS,&btcusd,&btcdbtc); PAX_update(PEGS,&btcusd,&btcdbtc);

1
iguana/tests/PAX

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"pax\",\"method\":\"start\"}"

1
includes/iguana_apideclares.h

@ -13,6 +13,7 @@
* * * *
******************************************************************************/ ******************************************************************************/
ZERO_ARGS(pax,start);
INT_AND_ARRAY(iguana,rates,unused,quotes); INT_AND_ARRAY(iguana,rates,unused,quotes);
TWO_STRINGS(iguana,rate,base,rel); TWO_STRINGS(iguana,rate,base,rel);
THREE_STRINGS_AND_THREE_INTS(iguana,prices,exchange,base,rel,period,start,end); THREE_STRINGS_AND_THREE_INTS(iguana,prices,exchange,base,rel,period,start,end);

Loading…
Cancel
Save