From ec0168dc6c5dad3ea3a02bdb85c57b7c85218863 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 27 Nov 2016 10:25:28 -0300 Subject: [PATCH] test --- iguana/dPoW.h | 4 +-- iguana/dpow/dpow_prices.c | 60 +++++++++++++++++++++++---------------- iguana/dpow/dpow_rpc.c | 2 +- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 8ca6c5a5b..394ce1446 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -19,10 +19,10 @@ #define DPOW_FIRSTRATIFY 1000 #define DPOW_CHECKPOINTFREQ 10 -#define DPOW_MINSIGS ((height < 90000) ? 7 : 13) +#define DPOW_MINSIGS ((height < 90000) ? 7 : 11) //#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1) #define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries) -#define DPOW_VERSION 0x0767 +#define DPOW_VERSION 0x0768 #define DPOW_UTXOSIZE 10000 #define DPOW_MINOUTPUT 6000 #define DPOW_DURATION 300 diff --git a/iguana/dpow/dpow_prices.c b/iguana/dpow/dpow_prices.c index ed91750b7..bcad9c8b9 100755 --- a/iguana/dpow/dpow_prices.c +++ b/iguana/dpow/dpow_prices.c @@ -102,7 +102,7 @@ struct PAX_data char edate[128]; double ecbmatrix[MAX_CURRENCIES][MAX_CURRENCIES],dailyprices[MAX_CURRENCIES * MAX_CURRENCIES],metals[4]; uint32_t lastupdate; int32_t ecbdatenum,ecbyear,ecbmonth,ecbday; double RTmatrix[MAX_CURRENCIES][MAX_CURRENCIES],RTprices[128],RTmetals[4]; - double basevals[MAX_CURRENCIES],cryptovols[2][9][2],BTCUSD,KMDBTC,CNYUSD,btcusd,kmdbtc,cryptos[8]; + double basevals[MAX_CURRENCIES],cryptovols[2][9][2],BTCDBTC,BTCUSD,KMDBTC,CNYUSD,btcusd,kmdbtc,cryptos[8]; struct PAX_spline splines[128]; }; @@ -1182,12 +1182,13 @@ double PAX_yahoo(char *metal) void PAX_btcprices(struct PAX_data *dp,int32_t enddatenum,int32_t numdates) { - int32_t i,n,year,month,day,seconds,datenum; char url[1024],date[64],*dstr,*str; + int32_t i,n,year,month,day,seconds,datenum; char url[1024],url2[1024],date[64],*dstr,*str; uint32_t timestamp,utc32[MAX_SPLINES]; struct tai t; 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¤cyPair=BTC_KMD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-numdates*3600*24)); + sprintf(url2,"https://poloniex.com/public?command=returnChartData¤cyPair=BTC_BTCD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-numdates*3600*24)); if ( (bpi= jobj(coindesk,"bpi")) != 0 ) { datenum = enddatenum; @@ -1415,7 +1416,7 @@ int32_t ecb_matrix(double basevals[MAX_CURRENCIES],double matrix[MAX_CURRENCIES] void PAX_update(struct PAX_data *dp,double *btcusdp,double *kmdbtcp) { - int32_t i,n,seconds,datenum; uint32_t timestamp; char url[1024],*dstr,*str; + int32_t i,n,iter,seconds,datenum; uint32_t timestamp; char url[1024],url2[1024],*dstr,*str; 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,*btctrades,*coindesk=0; @@ -1423,12 +1424,13 @@ void PAX_update(struct PAX_data *dp,double *btcusdp,double *kmdbtcp) btctrades = url_json(url); //kmdtrades = url_json("https://poloniex.com/public?command=returnTradeHistory¤cyPair=USDT_BTC"); //kmdtrades2 = url_json("https://bittrex.com/api/v1.1/public/getmarkethistory?market=BTC-KMD&count=50"); - *kmdbtcp = 0.0001; + *kmdbtcp = 0; bitcoinave = 0;//url_json("https://api.bitcoinaverage.com/ticker/USD/"); //bitcoincharts = url_json("http://api.bitcoincharts.com/v1/weighted_prices.json"); blockchaininfo = 0;//url_json("https://blockchain.info/ticker"); coindesk = 0;//url_json("http://api.coindesk.com/v1/bpi/historical/close.json"); sprintf(url,"https://poloniex.com/public?command=returnChartData¤cyPair=BTC_KMD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-2*3600*24)); + sprintf(url2,"https://poloniex.com/public?command=returnChartData¤cyPair=BTC_BTCD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-2*3600*24)); quandl = 0;//url_json("https://www.quandl.com/api/v1/datasets/BAVERAGE/USD.json?rows=1"); if ( 0 && (str= jstr(quandl,"updated_at")) != 0 && (datenum= conv_date(&seconds,str)) > 0 && (array= jarray(&n,quandl,"data")) != 0 ) { @@ -1461,28 +1463,37 @@ void PAX_update(struct PAX_data *dp,double *btcusdp,double *kmdbtcp) } else { - 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 ( kmdhist != 0 && (array= jarray(&n,kmdhist,0)) != 0 ) + for (iter=0; iter<2; iter++) { - //printf("GOT.(%s)\n",cJSON_Print(array)); - for (i=0; i<1; i++) + kmdhist = url_json(iter == 0 ? url : url2); + //{"date":1406160000,"high":0.01,"low":0.00125,"open":0.01,"close":0.001375,"volume":1.50179994,"quoteVolume":903.58818412,"weightedAverage":0.00166204}, + if ( kmdhist != 0 && (array= jarray(&n,kmdhist,0)) != 0 ) { - item = jitem(array,i); - timestamp = juint(item,"date"), high = jdouble(item,"high"), low = jdouble(item,"low"), open = jdouble(item,"open"); - 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); - kmddaily = price; - if ( kmddaily != 0 ) - dp->KMDBTC = *kmdbtcp = kmddaily; + //printf("GOT.(%s)\n",cJSON_Print(array)); + for (i=0; i<1; i++) + { + item = jitem(array,i); + timestamp = juint(item,"date"), high = jdouble(item,"high"), low = jdouble(item,"low"), open = jdouble(item,"open"); + 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); + if ( price != 0 ) + { + if ( iter == 0 ) + dp->KMDBTC = *kmdbtcp = kmddaily; + else dp->BTCDBTC = price; + } + } + //printf("poloniex.%d\n",n); } - //printf("poloniex.%d\n",n); + if ( kmdhist != 0 ) + free_json(kmdhist); } - if ( kmdhist != 0 ) - free_json(kmdhist); } } + if ( (*kmdbtcp= dp->KMDBTC) == 0. ) + *kmdbtcp = dp->BTCDBTC / 50.22; + printf("KMD/BTC %.8f\n",*kmdbtcp); if ( btctrades != 0 && (array= jarray(&n,btctrades,0)) != 0 ) { //printf("GOT.(%s)\n",cJSON_Print(array)); @@ -1565,8 +1576,9 @@ void _crypto_update(double cryptovols[2][9][2],struct PAX_data *dp,int32_t selec cnyusd = dp->CNYUSD; btcusd = dp->BTCUSD; if ( (kmdbtc= dp->KMDBTC) == 0. ) - kmdbtc = 0.0001; - //printf("update with btcusd %f kmd %f cnyusd %f cnybtc %f\n",btcusd,kmdbtc,cnyusd,cnyusd/btcusd); + ;//kmdbtc = dp->BTCDBTC / 50.22; + printf("DEPRECATED: update with btcusd %f kmd %f cnyusd %f cnybtc %f\n",btcusd,kmdbtc,cnyusd,cnyusd/btcusd); + return; if ( btcusd < SMALLVAL || kmdbtc < SMALLVAL ) { PAX_update(dp,&btcusd,&kmdbtc); @@ -1826,11 +1838,11 @@ int32_t PAX_idle(struct supernet_info *myinfo)//struct PAX_data *argdp,int32_t i } dp = myinfo->PAXDATA; - if ( 0 && time(NULL) > dp->lastupdate+10 ) + /*if ( 0 && time(NULL) > dp->lastupdate+10 ) { _crypto_update(dp->cryptovols,dp,1); dp->lastupdate = (uint32_t)time(NULL); - } + }*/ if ( OS_milliseconds() > lastupdate + (1000*idlegap) ) { lastupdate = OS_milliseconds(); diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 23d8800b9..5b768c75c 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -42,7 +42,7 @@ int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height) decode_hex(pubkeys[i],33,pubkeystr); else printf("error i.%d of %d (%s)\n",i,num,pubkeystr!=0?pubkeystr:""); } - printf("notaries.[%d] <- ht.%d\n",num,height); + //printf("notaries.[%d] <- ht.%d\n",num,height); } free_json(retjson); }