Browse Source

pricefeed

dPoW2
jl777 8 years ago
parent
commit
493ef27e94
  1. 2
      iguana/dpow/dpow_fsm.c
  2. 1859
      iguana/dpow/dpow_prices.c
  3. 5
      iguana/exchanges/fxcm.c
  4. 2
      iguana/exchanges/instaforex.c
  5. 17
      iguana/exchanges/truefx.c
  6. 1
      iguana/exchanges777.h
  7. 3
      iguana/iguana777.h
  8. 22
      iguana/iguana_exchanges.c
  9. 5
      iguana/iguana_notary.c
  10. 10
      iguana/peggy.c
  11. 10
      iguana/peggy.h
  12. 54
      iguana/peggy_price.c
  13. 116
      iguana/peggy_update.c
  14. 6
      iguana/ramchain_api.c
  15. 2
      includes/iguana_apideclares.h

2
iguana/dpow/dpow_fsm.c

@ -111,7 +111,7 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,uint32_t channel,uint32_t
if ( (bp= dpow_heightfind(myinfo,height)) == 0 )
{
if ( (rand() % 100) == 0 )
printf("couldnt find height.%d\n",height);
printf("couldnt find height.%d | if you just started notary dapp this is normal\n",height);
return(-1);
}
dpow_notaryfind(myinfo,bp,&myind,myinfo->DPOW.minerkey33);

1859
iguana/dpow/dpow_prices.c

File diff suppressed because it is too large

5
iguana/exchanges/fxcm.c

@ -131,6 +131,7 @@ int32_t fxcm_setcontracts()
if ( strcmp(name,"USDCNH") == 0 )
strcpy(name,"USDCNY");
FXCM_contracts[num++] = clonestr(name);
printf("FXCM[%d] = %s\n",num-1,name);
}
}
}
@ -235,6 +236,7 @@ void prices777_fxcm(double bids[64],double asks[64],double highs[64],double lows
{
bids[c] = bid, asks[c] = ask, highs[c] = high, lows[c] = low;
//printf("c.%d (%s) %f %f\n",c,name,bid,ask);
dpow_price("fxcm",name,bid,ask);
flag = 1;
} else printf("cant find.%s\n",name);//, getchar();
}
@ -261,7 +263,10 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
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 )
{
//printf("%d.{%.6f %.6f}.%s ",c,bid,ask,name);
return((bid + ask) * .5);
}
}
}
return(0);

2
iguana/exchanges/instaforex.c

@ -44,7 +44,7 @@ void prices777_instaforex(uint32_t timestamps[NUM_INSTAFOREX],double bids[NUM_IN
jsonstr = issue_curl("https://quotes.instaforex.com/get_quotes.php?q=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,XAUUSD&m=json");
if ( jsonstr != 0 )
{
// printf("(%s)\n",jsonstr);
printf("(%s)\n",jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
for (i=0; i<NUM_INSTAFOREX; i++)

17
iguana/exchanges/truefx.c

@ -38,11 +38,13 @@ uint64_t prices777_truefx(char *reqbase,char *reqrel,uint64_t *millistampp,doubl
// 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;
char url[1024],userpass[1024],buf[128],name[16],base[64],rel[64],*str=0; cJSON *array;
int32_t maxlen,count,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;
*millistampp = 0;
*bidp = *askp = *openp = *highp = *lowp = *closep = 0.;
if ( username[0] != 0 && password[0] != 0 )
{
if ( sessionid == 0 )
@ -79,6 +81,8 @@ uint64_t prices777_truefx(char *reqbase,char *reqrel,uint64_t *millistampp,doubl
if ( str != 0 )
{
//printf("(%s) -> (%s)\n",url,str);
maxlen = (int32_t)strlen(str);
count = 0;
/*EUR/USD,1454354222037,1.08,997,1.09,000,1.08142,1.09130,1.08333
USD/JPY,1454354221120,121.,049,121.,053,120.676,121.496,121.289
GBP/USD,1454354221048,1.44,242,1.44,254,1.42280,1.44305,1.42483
@ -91,7 +95,7 @@ uint64_t prices777_truefx(char *reqbase,char *reqrel,uint64_t *millistampp,doubl
GBP/JPY,1454354221581,174.,602,174.,621,172.408,174.730,172.805
*/
while ( str[n + 0] != 0 && str[n] != '\n' && str[n] != '\r' )
while ( str[n + 0] != 0 && str[n] != '\n' && str[n] != '\r' && count++ < 10 )
{
for (i=jpyflag=0; str[n + i]!=' '&&str[n + i]!='\n'&&str[n + i]!='\r'&&str[n + i]!=0; i++)
{
@ -108,7 +112,7 @@ uint64_t prices777_truefx(char *reqbase,char *reqrel,uint64_t *millistampp,doubl
memcpy(rel,str+n+4,3), rel[3] = 0;
str[n + i] = 0;
sprintf(buf,"[%s]",str+n+7+1);
//printf("str.(%s) (%s/%s) %d n.%d i.%d |%s|\n",str+n,base,rel,str[n],n,i,buf);
//printf("%d: str.(%s) (%s/%s) %d n.%d i.%d |%s|\n",count,str+n,base,rel,str[n],n,i,buf);
n += i + 1;
if ( (array= cJSON_Parse(buf)) != 0 )
{
@ -130,7 +134,9 @@ uint64_t prices777_truefx(char *reqbase,char *reqrel,uint64_t *millistampp,doubl
*bidp = bid, *askp = ask, *openp = openval, *highp = high, *lowp = low;
*closep = 0;
*millistampp = millistamp;
//printf("(%f %f)\n ",bid,ask);
sprintf(name,"%s%s",reqbase,reqrel);
dpow_price("truefx",name,bid,ask);
//printf("[%s%s %f %f] buf.(%s) (%ld)\n ",base,rel,bid,ask,buf,strlen(&str[n]));
break;
}
}
@ -154,6 +160,7 @@ double UPDATE(struct exchange_info *exchange,char *base,char *rel,struct exchang
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);
//printf("[%s/%s %.6f %.6f] ",base,rel,bid,ask);
if ( bid > SMALLVAL && ask > SMALLVAL )
return((bid + ask) * .5);
else return(0);

1
iguana/exchanges777.h

@ -195,5 +195,6 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n);
struct bitcoin_statetx *instantdex_feetx(struct supernet_info *myinfo,struct instantdex_accept *A,struct bitcoin_swapinfo *swap,struct iguana_info *coin);
void instantdex_statemachine_iter(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap);
void instantdex_historyadd(struct exchange_info *exchange,struct bitcoin_swapinfo *swap);
void dpow_price(char *exchange,char *name,double bid,double ask);
#endif

3
iguana/iguana777.h

@ -99,7 +99,8 @@ struct supernet_info
struct dpow_info DPOW;
struct delayedPoW_info dPoW;
struct basilisk_spend *spends; int32_t numspends;
struct peggy_info *PEGS;
//struct peggy_info *PEGS;
void *PAXDATA;
struct liquidity_info linfos[64];
struct komodo_notaries NOTARY;
// compatibility

22
iguana/iguana_exchanges.c

@ -736,7 +736,7 @@ void exchanges777_loop(void *ptr)
int32_t flag,retval,i; struct exchange_request *req; char *retstr;
myinfo = SuperNET_MYINFO(0);
#ifdef INCLUDE_PAX
struct peggy_info *PEGS=0; int32_t peggyflag = 0;
/*struct peggy_info *PEGS=0; int32_t peggyflag = 0;
if ( strcmp(exchange->name,"PAX") == 0 )
{
if ( (PEGS= myinfo->PEGS) != 0 )
@ -746,23 +746,12 @@ void exchanges777_loop(void *ptr)
_crypto_update(PEGS,PEGS->cryptovols,&PEGS->data,1,peggyflag);
PEGS->lastupdate = (uint32_t)time(NULL);
}
}
}*/
#endif
printf("exchanges loop.(%s)\n",exchange->name);
while ( 1 )
{
#ifdef INCLUDE_PAX
if ( peggyflag != 0 && PEGS != 0 )
{
//printf("nonz peggy\n");
PAX_idle(PEGS,peggyflag,3);
if ( time(NULL) > PEGS->lastupdate+100 )
{
_crypto_update(PEGS,PEGS->cryptovols,&PEGS->data,1,peggyflag);
PEGS->lastupdate = (uint32_t)time(NULL);
}
}
#endif
PAX_idle(myinfo);
flag = retval = 0;
retstr = 0;
if ( (req= queue_dequeue(&exchange->requestQ,0)) != 0 )
@ -1133,8 +1122,11 @@ void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sle
for (i=0; i<sizeof(Exchange_funcs)/sizeof(*Exchange_funcs); i++)
if ( (exchange= exchanges777_find(Exchange_funcs[i]->name)) == 0 )
{
if ( strcmp(Exchange_funcs[i]->name,"PAX") == 0 || strcmp(Exchange_funcs[i]->name,"truefx") == 0 || strcmp(Exchange_funcs[i]->name,"fxcm") == 0 || strcmp(Exchange_funcs[i]->name,"instaforx") == 0 )
if ( strcmp(Exchange_funcs[i]->name,"PAX") == 0 || strcmp(Exchange_funcs[i]->name,"truefx") == 0 || strcmp(Exchange_funcs[i]->name,"fxcm") == 0 || strcmp(Exchange_funcs[i]->name,"instaforex") == 0 )
{
exchange->pollgap = 10;
continue;
}
if ( ((exchange= exchanges777_find(Exchange_funcs[i]->name)) == 0 && (exchange= exchange_create(Exchange_funcs[i]->name,0)) != 0) || (exchange= exchanges777_info(Exchange_funcs[i]->name,sleepflag,argjson,0)) != 0 )
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange;
}

5
iguana/iguana_notary.c

@ -15,10 +15,6 @@
// Todo list:
// ht specific notarized ht
// a) award 5% APR for utxo older than a week when they are spent
// q) investigate if rebroadcast reorged local chain notary tx and scanning mempool is needed
#define CHECKSIG 0xac
@ -32,6 +28,7 @@ int32_t dpow_datahandler(struct supernet_info *myinfo,uint32_t channel,uint32_t
#include "dpow/dpow_rpc.c"
#include "dpow/dpow_tx.c"
#include "dpow/dpow_fsm.c"
#include "dpow/dpow_prices.c"
void dpow_fifoupdate(struct supernet_info *myinfo,struct dpow_checkpoint *fifo,struct dpow_checkpoint tip)
{

10
iguana/peggy.c

@ -280,7 +280,7 @@ struct peggy *peggy_createpair(struct peggy_info *PEGS,int64_t quorum,int64_t de
return(PEG);
}
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_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 KMD_price0)
{
//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 };
@ -297,8 +297,8 @@ struct peggy_info *peggy_init(int32_t maxdays,char *maincurrency,uint64_t maincu
PEGS->interesttenths = interesttenths, PEGS->posboost = posboost, PEGS->negpenalty = negpenalty, PEGS->feediv = feediv, PEGS->feemult = feemult;
mindenom.Pval = PRICE_RESOLUTION;
PEGS->genesistime = firsttimestamp;
price.Pval = PEGS->BTCD_price0 = BTCD_price0;
printf("set genesistime.%u BTCD0.%u\n",firsttimestamp,BTCD_price0);
price.Pval = PEGS->KMD_price0 = KMD_price0;
printf("set genesistime.%u BTCD0.%u\n",firsttimestamp,KMD_price0);
peggy_createpair(PEGS,0,0,"BTCD","BTCD",0,SATOSHIDEN*1000000,SATOSHIDEN*100000,0,SATOSHIDEN,PEGGY_RATE_777,firsttimestamp,&price,1,spread,0,mindenom,0,1,peggy_mils(0));
//PEGS->accts = accts777_init(path,0);
return(PEGS);
@ -414,7 +414,7 @@ struct peggy_info *peggy_genesis(int32_t lookbacks[OPRETURNS_CONTEXTS],struct pe
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 = peggy_init(PEGGY_MAXLOCKDAYS,"KMD",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;
}
@ -688,7 +688,7 @@ int32_t peggy_init_contexts(struct txinds777_info *opreturns,uint32_t RTblocknum
PEGS = peggy_init(path,PEGGY_MAXLOCKDAYS,"BTCD",SATOSHIDEN/100,100,10,spread,PEGGY_RATE_777,40,10,2,5,2,0,0);
globals[0] = PEGS;
sprintf(buf,"%s_PERM",path);
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->KMD_price0);
startmilli = OS_milliseconds();
peggy_clone(buf,PEGS2,PEGS);
printf("cloned %d in %.3f millis per opreturn\n",PEGS->numopreturns,(OS_milliseconds() - startmilli)/PEGS->numopreturns); sleep(3);*/

10
iguana/peggy.h

@ -222,7 +222,7 @@ struct PAX_data
uint32_t itimestamps[128]; double ibids[128],iasks[128];
char edate[128]; double ecbmatrix[32][32],dailyprices[MAX_CURRENCIES * MAX_CURRENCIES],metals[4];
int32_t ecbdatenum,ecbyear,ecbmonth,ecbday; double RTmatrix[32][32],RTprices[128],RTmetals[4];
double btcusd,btcdbtc,cryptos[8];
double btcusd,kmdbtc,cryptos[8];
};
struct PAX_spline { char name[64]; int32_t splineid,lasti,basenum,num,firstx,dispincr,spline32[MAX_SPLINES][4]; uint32_t utc32[MAX_SPLINES]; int64_t spline64[MAX_SPLINES][4]; double dSplines[MAX_SPLINES][4],pricevals[MAX_SPLINES+MAX_LOOKAHEAD],lastutc,lastval,aveslopeabs; };
@ -235,8 +235,8 @@ struct peggy_info
int32_t default_dailyrate,interesttenths,posboost,negpenalty,feediv,feemult;
int32_t numpegs,numpairedpegs,numpricedpegs,numopreturns,numvoters;
struct accts777_info *accts;
struct PAX_data data,tmp; double cryptovols[2][9][2],btcusd,btcdbtc,cnyusd;
char path[512],*genesis; uint32_t genesistime,BTCD_price0,lastupdate;
struct PAX_data data,tmp; double cryptovols[2][9][2],btcusd,kmdbtc,cnyusd;
char path[512],*genesis; uint32_t genesistime,KMD_price0,lastupdate;
struct PAX_spline splines[128];
struct peggy_vote votes[PEGGY_MAXPRICEDPEGS][PEGGY_MAXVOTERS];
struct peggy *contracts[PEGGY_MAXPEGS];
@ -308,7 +308,7 @@ extern int32_t MINDENOMS[],Peggy_inds[],dailyrates[];
struct price_resolution peggy_scaleprice(struct price_resolution price,int64_t peggymils);
char *peggy_tx(char *jsonstr);
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 supernet_info *myinfo);//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_contractnum(char *base,char *rel);
int32_t PAX_basenum(char *base);
@ -368,7 +368,7 @@ int32_t peggy_init_contexts(struct txinds777_info *opreturns,uint32_t blocknum,u
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);
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_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 KMD_price0);
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);

54
iguana/peggy_price.c

@ -201,17 +201,17 @@ uint32_t peggy_mils(int32_t i)
minmils = 10000;
else if ( strncmp(peggy_bases[i],"NXT",3) == 0 || strncmp(peggy_bases[i],"BTS",3) == 0 )
minmils = 1000000;
else if ( strncmp(peggy_bases[i],"STEEM",5) == 0 )
else if ( strncmp(peggy_bases[i],"KMD",5) == 0 )
minmils = 1000;
else minmils = 10000;
}
return(minmils);
}
int32_t peggy_prices(struct price_resolution prices[64],double btcusd,double btcdbtc,char *contracts[],int32_t num,double *cprices,double *basevals)
int32_t peggy_prices(struct price_resolution prices[64],double btcusd,double kmdbtc,char *contracts[],int32_t num,double *cprices,double *basevals)
{
double btcdusd,price_in_btcd,dprice,usdcny,usdrub,btccny,btcrub,xauusd,usdprice=0.,usdval,btcprice=0.; int32_t contractnum,base,nonz = 0;
if ( btcusd > SMALLVAL && btcdbtc > SMALLVAL && (usdval= basevals[0]) > SMALLVAL )
double kmdusd,price_in_kmd,dprice,usdcny,usdrub,btccny,btcrub,xauusd,usdprice=0.,usdval,btcprice=0.; int32_t contractnum,base,nonz = 0;
if ( btcusd > SMALLVAL && kmdbtc > SMALLVAL && (usdval= basevals[0]) > SMALLVAL )
{
xauusd = usdcny = usdrub = btccny = btcrub = 0.;
for (contractnum=0; contractnum<num; contractnum++)
@ -230,9 +230,9 @@ int32_t peggy_prices(struct price_resolution prices[64],double btcusd,double btc
usdrub = (basevals[0] * peggy_mils(9)) / (basevals[9] * peggy_mils(0));
btcrub = 1000 * btcusd * usdrub;
}
btcdusd = (btcusd * btcdbtc);
printf("xauusd %f usdval %f %f %f usdcny %f usdrub %f btcusd %f btcdbtc %f btcdusd %f btccny %f btcrub %f\n",xauusd,usdval,basevals[8],basevals[9],usdcny,usdrub,btcusd,btcdbtc,btcdusd,btccny,btcrub);
prices[0].Pval = (PRICE_RESOLUTION * 100. * btcdbtc);
kmdusd = (btcusd * kmdbtc);
printf("xauusd %f usdval %f %f %f usdcny %f usdrub %f btcusd %f kmdbtc %f kmdusd %f btccny %f btcrub %f\n",xauusd,usdval,basevals[8],basevals[9],usdcny,usdrub,btcusd,kmdbtc,kmdusd,btccny,btcrub);
prices[0].Pval = (PRICE_RESOLUTION * 100. * kmdbtc);
for (base=0,contractnum=1; base<32; base++,contractnum++)
{
if ( strcmp(contracts[contractnum],CURRENCIES[base]) == 0 )
@ -241,17 +241,17 @@ int32_t peggy_prices(struct price_resolution prices[64],double btcusd,double btc
{
nonz++;
if ( base == 0 )
usdprice = price_in_btcd = (1. / btcdusd);
else price_in_btcd = (dprice / (btcdusd * usdval));
prices[contractnum].Pval = (PRICE_RESOLUTION * price_in_btcd);
usdprice = price_in_kmd = (1. / kmdusd);
else price_in_kmd = (dprice / (kmdusd * usdval));
prices[contractnum].Pval = (PRICE_RESOLUTION * price_in_kmd);
}
} else printf("unexpected list entry %s vs %s at %d\n",contracts[contractnum],CURRENCIES[base],contractnum);
}
if ( strcmp(contracts[contractnum],"BTCUSD") != 0 )
printf("unexpected contract (%s) at %d\n",contracts[contractnum],contractnum);
btcprice = (1. / btcdbtc);
prices[contractnum++].Pval = (PRICE_RESOLUTION / btcdbtc) / 1000.;
printf("btcprice %f = 1/%f %llu\n",btcprice,1./btcdbtc,(long long)prices[contractnum-1].Pval);
btcprice = (1. / kmdbtc);
prices[contractnum++].Pval = (PRICE_RESOLUTION / kmdbtc) / 1000.;
printf("btcprice %f = 1/%f %llu\n",btcprice,1./kmdbtc,(long long)prices[contractnum-1].Pval);
for (; contractnum<64; contractnum++)
{
//dprice = 0;
@ -628,7 +628,7 @@ int32_t PAX_calcmatrix(double matrix[32][32])
int32_t PAX_getmatrix(double *basevals,struct peggy_info *PEGS,double Hmatrix[32][32],double *RTprices,char *contracts[],int32_t num,uint32_t timestamp)
{
int32_t i,j,c; char name[16]; double btcusd,btcdbtc;
int32_t i,j,c; char name[16]; double btcusd,kmdbtc;
memcpy(Hmatrix,PEGS->data.ecbmatrix,sizeof(PEGS->data.ecbmatrix));
PAX_calcmatrix(Hmatrix);
/*for (i=0; i<32; i++)
@ -638,11 +638,11 @@ int32_t PAX_getmatrix(double *basevals,struct peggy_info *PEGS,double Hmatrix[32
printf("%s\n",CURRENCIES[i]);
}*/
btcusd = PEGS->data.btcusd;
btcdbtc = PEGS->data.btcdbtc;
kmdbtc = PEGS->data.kmdbtc;
if ( btcusd > SMALLVAL )
dxblend(&PEGS->btcusd,btcusd,.9);
if ( btcdbtc > SMALLVAL )
dxblend(&PEGS->btcdbtc,btcdbtc,.9);
if ( kmdbtc > SMALLVAL )
dxblend(&PEGS->kmdbtc,kmdbtc,.9);
// char *cryptostrs[8] = { "btc", "nxt", "unity", "eth", "ltc", "xmr", "bts", "xcp" };
// "BTCUSD", "NXTBTC", "SuperNET", "ETHBTC", "LTCBTC", "XMRBTC", "BTSBTC", "XCPBTC", // BTC priced
for (i=0; i<num; i++)
@ -705,7 +705,7 @@ int32_t PAX_getmatrix(double *basevals,struct peggy_info *PEGS,double Hmatrix[32
}
}
//if ( Debuglevel > 2 )
printf("(%f %f) i.%d num.%d %s %f\n",PEGS->btcusd,PEGS->btcdbtc,i,num,contracts[i],RTprices[i]);
printf("(%f %f) i.%d num.%d %s %f\n",PEGS->btcusd,PEGS->kmdbtc,i,num,contracts[i],RTprices[i]);
//printf("RT.(%s %f) ",contracts[i],RTprices[i]);
}
return(PEGS->data.ecbdatenum);
@ -719,7 +719,7 @@ char *peggy_emitprices(int32_t *nonzp,struct peggy_info *PEGS,uint32_t blocktime
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;
cprices[0] = PEGS->kmdbtc;
for (i=0; i<32; i++)
PEGS->data.RTmatrix[i][i] = basevals[i];
/*for (i=0; i<32; i++)
@ -732,7 +732,7 @@ char *peggy_emitprices(int32_t *nonzp,struct peggy_info *PEGS,uint32_t blocktime
memset(prices,0,sizeof(prices));
memset(matrix,0,sizeof(matrix));
memset(RTmatrix,0,sizeof(RTmatrix));
peggy_prices(prices,PEGS->btcusd,PEGS->btcdbtc,peggy_bases,sizeof(peggy_bases)/sizeof(*peggy_bases),cprices,basevals);
peggy_prices(prices,PEGS->btcusd,PEGS->kmdbtc,peggy_bases,sizeof(peggy_bases)/sizeof(*peggy_bases),cprices,basevals);
for (i=0; i<sizeof(peggy_bases)/sizeof(*peggy_bases); i++)
{
jaddinum(array,prices[i].Pval);
@ -762,16 +762,16 @@ char *peggy_emitprices(int32_t *nonzp,struct peggy_info *PEGS,uint32_t blocktime
double PAX_baseprice(struct peggy_info *PEGS,uint32_t timestamp,int32_t basenum)
{
double btc,btcd,btcdusd,usdval;
double btc,kmd,kmdusd,usdval;
btc = 1000. * _pairaved(PAX_splineval(&PEGS->splines[MAX_CURRENCIES+0],timestamp,0),PAX_splineval(&PEGS->splines[MAX_CURRENCIES+1],timestamp,0));
btcd = .01 * PAX_splineval(&PEGS->splines[MAX_CURRENCIES+2],timestamp,0);
if ( btc != 0. && btcd != 0. )
kmd = .01 * PAX_splineval(&PEGS->splines[MAX_CURRENCIES+2],timestamp,0);
if ( btc != 0. && kmd != 0. )
{
btcdusd = (btc * btcd);
kmdusd = (btc * kmd);
usdval = PAX_splineval(&PEGS->splines[USD],timestamp,0);
if ( basenum == USD )
return(1. / btcdusd);
else return(PAX_splineval(&PEGS->splines[basenum],timestamp,0) / (btcdusd * usdval));
return(1. / kmdusd);
else return(PAX_splineval(&PEGS->splines[basenum],timestamp,0) / (kmdusd * usdval));
}
return(0.);
}
@ -848,7 +848,7 @@ struct peggy_info *PAX_init()
tradebot_monitorall(0,0,0,0,"truefx",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);
PEGS = peggy_init(PEGGY_MAXLOCKDAYS,"KMD",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);

116
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
"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
"BTCD", "BTC", "NXT", "ETC", "ETH", "STEEM", "BTS", "MAID", "XCP", "XMR" // cryptos
"BTCD", "BTC", "NXT", "ETC", "ETH", "KMD", "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
@ -197,10 +197,10 @@ void PAX_btcprices(struct peggy_info *PEGS,int32_t enddatenum,int32_t numdates)
{
int32_t i,n,year,month,day,seconds,datenum; char url[1024],date[64],*dstr,*str;
uint32_t timestamp,utc32[MAX_SPLINES]; struct tai t;
cJSON *coindesk,*quandl,*btcdhist,*bpi,*array,*item;
double btcddaily[MAX_SPLINES],cdaily[MAX_SPLINES],qdaily[MAX_SPLINES],ask,high,low,bid,close,vol,quotevol,open,price = 0.;
cJSON *coindesk,*quandl,*kmdhist,*bpi,*array,*item;
double kmddaily[MAX_SPLINES],cdaily[MAX_SPLINES],qdaily[MAX_SPLINES],ask,high,low,bid,close,vol,quotevol,open,price = 0.;
coindesk = url_json("http://api.coindesk.com/v1/bpi/historical/close.json");
sprintf(url,"https://poloniex.com/public?command=returnChartData&currencyPair=BTC_BTCD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-numdates*3600*24));
sprintf(url,"https://poloniex.com/public?command=returnChartData&currencyPair=BTC_KMD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-numdates*3600*24));
if ( (bpi= jobj(coindesk,"bpi")) != 0 )
{
datenum = enddatenum;
@ -248,11 +248,13 @@ void PAX_btcprices(struct peggy_info *PEGS,int32_t enddatenum,int32_t numdates)
}
PAX_genspline(&PEGS->splines[MAX_CURRENCIES+1],MAX_CURRENCIES+1,"quandl",utc32,qdaily,n<MAX_SPLINES?n:MAX_SPLINES,qdaily);
}
btcdhist = url_json(url);
kmdhist = url_json(url);
//{"date":1406160000,"high":0.01,"low":0.00125,"open":0.01,"close":0.001375,"volume":1.50179994,"quoteVolume":903.58818412,"weightedAverage":0.00166204},
if ( (array= jarray(&n,btcdhist,0)) != 0 )
if ( (array= jarray(&n,kmdhist,0)) != 0 )
{
memset(utc32,0,sizeof(utc32)), memset(btcddaily,0,sizeof(btcddaily));
memset(utc32,0,sizeof(utc32)), memset(kmddaily,0,sizeof(kmddaily));
for (i=0; i<MAX_SPLINES; i++)
kmddaily[i] = 0.0001 * 100.;
//printf("GOT.(%s)\n",cJSON_Print(array));
for (i=0; i<n; i++)
{
@ -262,13 +264,13 @@ void PAX_btcprices(struct peggy_info *PEGS,int32_t enddatenum,int32_t numdates)
//printf("[%u %f %f %f %f %f %f %f]",timestamp,high,low,open,close,vol,quotevol,price);
if ( Debuglevel > 2 )
printf("[%u %d %f]",timestamp,OS_conv_unixtime(&t,&seconds,timestamp),price);
utc32[i] = timestamp - 12*3600, btcddaily[i] = price * 100.;
utc32[i] = timestamp - 12*3600, kmddaily[i] = price * 100.;
}
if ( Debuglevel > 2 )
printf("poloniex.%d\n",n);
PAX_genspline(&PEGS->splines[MAX_CURRENCIES+2],MAX_CURRENCIES+2,"btcdhist",utc32,btcddaily,n<MAX_SPLINES?n:MAX_SPLINES,btcddaily);
PAX_genspline(&PEGS->splines[MAX_CURRENCIES+2],MAX_CURRENCIES+2,"kmdhist",utc32,kmddaily,n<MAX_SPLINES?n:MAX_SPLINES,kmddaily);
}
// https://poloniex.com/public?command=returnChartData&currencyPair=BTC_BTCD&start=1405699200&end=9999999999&period=86400
// https://poloniex.com/public?command=returnChartData&currencyPair=BTC_KMD&start=1405699200&end=9999999999&period=86400
}
int32_t PAX_ecbparse(char *date,double *prices,char *url,int32_t basenum)
@ -397,19 +399,19 @@ int32_t ecb_matrix(double matrix[32][32],char *date)
return(datenum);
}
void PAX_update(struct peggy_info *PEGS,double *btcusdp,double *btcdbtcp)
void PAX_update(struct peggy_info *PEGS,double *btcusdp,double *kmdbtcp)
{
int32_t i,n,seconds,datenum; uint32_t timestamp; char url[1024],*dstr,*str;
double btcddaily=0.,btcusd=0.,ask,high,low,bid,close,vol,quotevol,open,price = 0.;
//cJSON *btcdtrades,*btcdtrades2,*,*bitcoincharts,;
cJSON *quandl,*btcdhist,*array,*item,*bitcoinave,*blockchaininfo,*coindesk=0;
//btcdtrades = url_json("https://poloniex.com/public?command=returnTradeHistory&currencyPair=BTC_BTCD");
//btcdtrades2 = url_json("https://bittrex.com/api/v1.1/public/getmarkethistory?market=BTC-BTCD&count=50");
double kmddaily=0.,btcusd=0.,ask,high,low,bid,close,vol,quotevol,open,price = 0.;
//cJSON *kmdtrades,*kmdtrades2,*,*bitcoincharts,;
cJSON *quandl,*kmdhist,*array,*item,*bitcoinave,*blockchaininfo,*coindesk=0;
//kmdtrades = url_json("https://poloniex.com/public?command=returnTradeHistory&currencyPair=BTC_kmd");
//kmdtrades2 = url_json("https://bittrex.com/api/v1.1/public/getmarkethistory?market=BTC-KMD&count=50");
bitcoinave = url_json("https://api.bitcoinaverage.com/ticker/USD/");
//bitcoincharts = url_json("http://api.bitcoincharts.com/v1/weighted_prices.json");
blockchaininfo = url_json("https://blockchain.info/ticker");
coindesk = url_json("http://api.coindesk.com/v1/bpi/historical/close.json");
sprintf(url,"https://poloniex.com/public?command=returnChartData&currencyPair=BTC_BTCD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-2*3600*24));
sprintf(url,"https://poloniex.com/public?command=returnChartData&currencyPair=BTC_KMD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-2*3600*24));
quandl = url_json("https://www.quandl.com/api/v1/datasets/BAVERAGE/USD.json?rows=1");
if ( quandl != 0 && (str= jstr(quandl,"updated_at")) != 0 && (datenum= conv_date(&seconds,str)) > 0 && (array= jarray(&n,quandl,"data")) != 0 )
{
@ -430,20 +432,20 @@ void PAX_update(struct peggy_info *PEGS,double *btcusdp,double *btcdbtcp)
{
double avebid,aveask,bidvol,askvol; struct exchange_quote sortbuf[512];
struct supernet_info *myinfo = SuperNET_MYINFO(0); cJSON *argjson = cJSON_Parse("{}");
aveask = instantdex_aveprice(myinfo,sortbuf,(int32_t)(sizeof(sortbuf)/sizeof(*sortbuf)),&askvol,"BTCD","BTC",1,argjson);
avebid = instantdex_aveprice(myinfo,sortbuf,(int32_t)(sizeof(sortbuf)/sizeof(*sortbuf)),&bidvol,"BTCD","BTC",-1,argjson);
aveask = instantdex_aveprice(myinfo,sortbuf,(int32_t)(sizeof(sortbuf)/sizeof(*sortbuf)),&askvol,"KMD","BTC",1,argjson);
avebid = instantdex_aveprice(myinfo,sortbuf,(int32_t)(sizeof(sortbuf)/sizeof(*sortbuf)),&bidvol,"KMD","BTC",-1,argjson);
if ( avebid > SMALLVAL && aveask > SMALLVAL )
{
price = (avebid*bidvol + aveask*askvol) / (bidvol + askvol);
*btcdbtcp = price;
printf("set BTCD price %f\n",price);
PEGS->btcdbtc = price;
*kmdbtcp = price;
printf("set KMD price %f\n",price);
PEGS->kmdbtc = price;
}
else
{
btcdhist = url_json(url);
kmdhist = url_json(url);
//{"date":1406160000,"high":0.01,"low":0.00125,"open":0.01,"close":0.001375,"volume":1.50179994,"quoteVolume":903.58818412,"weightedAverage":0.00166204},
if ( btcdhist != 0 && (array= jarray(&n,btcdhist,0)) != 0 )
if ( kmdhist != 0 && (array= jarray(&n,kmdhist,0)) != 0 )
{
//printf("GOT.(%s)\n",cJSON_Print(array));
for (i=0; i<1; i++)
@ -453,14 +455,14 @@ void PAX_update(struct peggy_info *PEGS,double *btcusdp,double *btcdbtcp)
close = jdouble(item,"close"), vol = jdouble(item,"volume"), quotevol = jdouble(item,"quoteVolume"), price = jdouble(item,"weightedAverage");
//printf("[%u %f %f %f %f %f %f %f]",timestamp,high,low,open,close,vol,quotevol,price);
//printf("[%u %d %f]",timestamp,OS_conv_unixtime(&seconds,timestamp),price);
btcddaily = price;
if ( btcddaily != 0 )
PEGS->btcdbtc = *btcdbtcp = btcddaily;
kmddaily = price;
if ( kmddaily != 0 )
PEGS->kmdbtc = *kmdbtcp = kmddaily;
}
//printf("poloniex.%d\n",n);
}
if ( btcdhist != 0 )
free_json(btcdhist);
if ( kmdhist != 0 )
free_json(kmdhist);
}
}
if ( bitcoinave != 0 )
@ -524,19 +526,19 @@ void _crypto_update(struct peggy_info *PEGS,double cryptovols[2][9][2],struct PA
{
char *cryptonatorA = "https://www.cryptonator.com/api/full/%s-%s"; //unity-btc
char *cryptocoinchartsB = "http://api.cryptocoincharts.info/tradingPair/%s_%s"; //bts_btc
char *cryptostrs[9] = { "btc", "nxt", "unity", "eth", "steem", "xmr", "bts", "xcp", "etc" };
int32_t iter,i,j; double btcusd,btcdbtc,cnyusd,prices[9][2],volumes[9][2];
char *cryptostrs[9] = { "btc", "nxt", "unity", "eth", "kmd", "xmr", "bts", "xcp", "etc" };
int32_t iter,i,j; double btcusd,kmdbtc,cnyusd,prices[9][2],volumes[9][2];
char base[16],rel[16],url[512],*str; cJSON *jsonA,*jsonB;
if ( peggyflag != 0 )
{
cnyusd = PEGS->cnyusd;
btcusd = PEGS->btcusd;
btcdbtc = PEGS->btcdbtc;
//printf("update with btcusd %f btcd %f cnyusd %f cnybtc %f\n",btcusd,btcdbtc,cnyusd,cnyusd/btcusd);
if ( btcusd < SMALLVAL || btcdbtc < SMALLVAL )
kmdbtc = PEGS->kmdbtc;
//printf("update with btcusd %f kmd %f cnyusd %f cnybtc %f\n",btcusd,kmdbtc,cnyusd,cnyusd/btcusd);
if ( btcusd < SMALLVAL || kmdbtc < SMALLVAL )
{
PAX_update(PEGS,&btcusd,&btcdbtc);
printf("PAX_update with btcusd %f btcd %f\n",btcusd,btcdbtc);
PAX_update(PEGS,&btcusd,&kmdbtc);
printf("PAX_update with btcusd %f kmd %f\n",btcusd,kmdbtc);
}
memset(prices,0,sizeof(prices));
memset(volumes,0,sizeof(volumes));
@ -553,7 +555,7 @@ void _crypto_update(struct peggy_info *PEGS,double cryptovols[2][9][2],struct PA
for (iter=0; iter<1; iter++)
{
if ( i == 0 && iter == 0 )
strcpy(base,"btcd"), strcpy(rel,"btc");
strcpy(base,"kmd"), strcpy(rel,"btc");
else strcpy(base,str), strcpy(rel,iter==0?"btc":"cny");
//if ( selector == 0 )
{
@ -587,10 +589,10 @@ void _crypto_update(struct peggy_info *PEGS,double cryptovols[2][9][2],struct PA
void PAX_RTupdate(struct peggy_info *PEGS,double cryptovols[2][9][2],double RTmetals[4],double *RTprices,struct PAX_data *dp)
{
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];
char *cryptostrs[9] = { "btc", "nxt", "unity", "eth", "etc", "kmd", "xmr", "bts", "xcp" };
int32_t iter,i,c,baserel,basenum,relnum; double cnyusd,btcusd,kmdbtc,bid,ask,price,vol,prices[8][2],volumes[8][2];
char base[16],rel[16];
PAX_update(PEGS,&btcusd,&btcdbtc);
PAX_update(PEGS,&btcusd,&kmdbtc);
memset(prices,0,sizeof(prices));
memset(volumes,0,sizeof(volumes));
for (i=0; i<sizeof(cryptostrs)/sizeof(*cryptostrs); i++)
@ -600,10 +602,10 @@ void PAX_RTupdate(struct peggy_info *PEGS,double cryptovols[2][9][2],double RTme
volumes[i][iter] = cryptovols[1][i][iter];
}
if ( prices[0][0] > SMALLVAL )
dxblend(&btcdbtc,prices[0][0],.9);
dxblend(&dp->btcdbtc,btcdbtc,.995);
if ( PEGS->btcdbtc < SMALLVAL )
PEGS->btcdbtc = dp->btcdbtc;
dxblend(&kmdbtc,prices[0][0],.9);
dxblend(&dp->kmdbtc,kmdbtc,.995);
if ( PEGS->kmdbtc < SMALLVAL )
PEGS->kmdbtc = dp->kmdbtc;
if ( (cnyusd= PEGS->cnyusd) > SMALLVAL )
{
if ( prices[0][1] > SMALLVAL )
@ -633,15 +635,15 @@ void PAX_RTupdate(struct peggy_info *PEGS,double cryptovols[2][9][2],double RTme
}
}
btcusd = PEGS->btcusd;
btcdbtc = PEGS->btcdbtc;
kmdbtc = PEGS->kmdbtc;
if ( Debuglevel > 2 )
printf(" update with btcusd %f btcd %f\n",btcusd,btcdbtc);
if ( btcusd < SMALLVAL || btcdbtc < SMALLVAL )
printf(" update with btcusd %f kmd %f\n",btcusd,kmdbtc);
if ( btcusd < SMALLVAL || kmdbtc < SMALLVAL )
{
PAX_update(PEGS,&btcusd,&btcdbtc);
PAX_update(PEGS,&btcusd,&kmdbtc);
if ( Debuglevel > 2 )
printf(" price777_update with btcusd %f btcd %f\n",btcusd,btcdbtc);
} else PEGS->btcusd = btcusd, PEGS->btcdbtc = btcdbtc;
printf(" price777_update with btcusd %f kmd %f\n",btcusd,kmdbtc);
} else PEGS->btcusd = btcusd, PEGS->kmdbtc = kmdbtc;
for (c=0; c<sizeof(CONTRACTS)/sizeof(*CONTRACTS); c++)
{
for (iter=0; iter<3; iter++)
@ -708,7 +710,7 @@ struct exchange_info *PAX_bidasks(char *exchangestr,uint32_t *timestamps,double
int32_t PAX_idle(struct peggy_info *PEGS,int32_t peggyflag,int32_t idlegap)
{
static double lastupdate,lastdayupdate; static int32_t didinit; static portable_mutex_t mutex;
struct exchange_info *exchange; struct exchange_quote bidasks[2]; double btcdbtc,btcusd;
struct exchange_info *exchange; struct exchange_quote bidasks[2]; double kmdbtc,btcusd;
int32_t i,datenum,contractnum,seconds; struct tai t; struct PAX_data *dp = &PEGS->tmp;
*dp = PEGS->data;
if ( didinit == 0 )
@ -717,7 +719,7 @@ int32_t PAX_idle(struct peggy_info *PEGS,int32_t peggyflag,int32_t idlegap)
//prices777_init(BUNDLE.jsonstr,peggyflag);
didinit = 1;
datenum = OS_conv_unixtime(&t,&seconds,(uint32_t)time(NULL));
expand_datenum(PEGS->data.edate,datenum);
expand_datenum(dp->edate,datenum);
if ( peggyflag != 0 )
{
//int32_t opreturns_init(uint32_t blocknum,uint32_t blocktimestamp,char *path);
@ -752,15 +754,15 @@ int32_t PAX_idle(struct peggy_info *PEGS,int32_t peggyflag,int32_t idlegap)
dp->itimestamps[contractnum] = bidasks[0].timestamp;
}
}
PAX_update(PEGS,&btcusd,&btcdbtc);
PAX_update(PEGS,&btcusd,&kmdbtc);
if ( btcusd > SMALLVAL )
dxblend(&dp->btcusd,btcusd,0.99);
if ( btcdbtc > SMALLVAL )
dxblend(&dp->btcdbtc,btcdbtc,0.99);
if ( kmdbtc > SMALLVAL )
dxblend(&dp->kmdbtc,kmdbtc,0.99);
if ( dp->btcusd == 0 )
dp->btcusd = dp->btcusd;
if ( dp->btcdbtc == 0 )
dp->btcdbtc = dp->btcdbtc;
if ( dp->kmdbtc == 0 )
dp->kmdbtc = dp->kmdbtc;
if ( dp->ecbmatrix[USD][USD] > SMALLVAL && dp->ecbmatrix[CNY][CNY] > SMALLVAL )
PEGS->cnyusd = (dp->ecbmatrix[CNY][CNY] / dp->ecbmatrix[USD][USD]);
portable_mutex_lock(&mutex);

6
iguana/ramchain_api.c

@ -308,6 +308,12 @@ SS_D_I_S(bitcoinrpc,move,fromaccount,toaccount,amount,minconf,comment)
return(jprint(retjson,1));
}
ZERO_ARGS(pax,start)
{
void PAX_init();
PAX_init();
return(clonestr("{\"result\":\"PAX_init called\"}"));
}
#undef IGUANA_ARGS
#include "../includes/iguana_apiundefs.h"

2
includes/iguana_apideclares.h

@ -21,9 +21,7 @@ ZERO_ARGS(dpow,cancelratify);
TWO_STRINGS(zcash,passthru,function,hex);
TWO_STRINGS(komodo,passthru,function,hex);
#ifdef INCLUDE_PAX
ZERO_ARGS(pax,start);
#endif
HASH_ARRAY_STRING(tradebot,liquidity,hash,vals,targetcoin);
ZERO_ARGS(tradebot,amlp);
ZERO_ARGS(tradebot,notlp);

Loading…
Cancel
Save