diff --git a/src/komodo_defs.h b/src/komodo_defs.h index ebfadee69..a78276fb3 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -60,7 +60,7 @@ extern uint32_t ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV1_1, ASSETCHAINS_NO extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; -extern std::vector ASSETCHAINS_PRICES; +extern std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; extern char ASSETCHAINS_SYMBOL[65]; extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dd9f9a6a7..96ce788f9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2014,26 +2014,34 @@ cJSON *get_urljson(char *url) return(json); } -int32_t get_stockprices()//std::vector symbols) +int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector symbols) { - std::vector symbols; - char url[32768],*symbol; cJSON *json,*obj; int32_t i,n=0; uint32_t uprice; - symbols.push_back("AAPL"); - symbols.push_back("MSFT"); - sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=AAPL, MSFT"); + char url[32768],*symbol; cJSON *json,*obj; int32_t i,n=0,retval=-1; uint32_t uprice,timestamp; + sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","")); if ( (json= send_curl(url,(char *)"iex")) != 0 ) //if ( (json= get_urljson(url)) != 0 ) { if ( (n= cJSON_GetArraySize(json)) > 0 ) { + retval = n; for (i=0; i now+60 || timestamp < now-ASSETCHAINS_BLOCKTIME ) + { + fprintf(stderr,"time error.%d\n",timestamp-now); + retval = -1; + } if ( symbols[i] != symbol ) + { + retval = -1; fprintf(stderr,"MISMATCH."); - fprintf(stderr,"(%s %u) ",symbol,uprice); + } + fprintf(stderr,"(%s %u).%d ",symbol,uprice,timestamp-now); } } fprintf(stderr,"numstocks.%d\n",n); @@ -2041,7 +2049,7 @@ int32_t get_stockprices()//std::vector symbols) //https://api.iextrading.com/1.0/tops/last?symbols=AAPL -> [{"symbol":"AAPL","price":198.63,"size":100,"time":1555092606076}] free_json(json); } - return(n); + return(retval); } uint32_t get_dailyfx(uint32_t *prices) @@ -2190,6 +2198,8 @@ int32_t komodo_cbopretsize(uint64_t flags) size += (sizeof(Forex)/sizeof(*Forex)) * sizeof(uint32_t); if ( (ASSETCHAINS_CBOPRET & 4) != 0 ) size += (sizeof(Cryptos)/sizeof(*Cryptos) + ASSETCHAINS_PRICES.size())*sizeof(uint32_t); + if ( (ASSETCHAINS_CBOPRET & 8) != 0 ) + size += (ASSETCHAINS_STOCKS.size())*sizeof(uint32_t); } return(size); } @@ -2198,8 +2208,8 @@ extern uint256 Queued_reconsiderblock; void komodo_cbopretupdate(int32_t forceflag) { - static uint32_t lasttime,lastcrypto,lastbtc,pending; - static uint32_t pricebits[4],cryptoprices[KOMODO_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)]; + static uint32_t lasttime,lastbtc,pending; + static uint32_t pricebits[4],pricebuf[KOMODO_MAXPRICES],forexprices[sizeof(Forex)/sizeof(*Forex)]; int32_t size; uint32_t flags=0,now; CBlockIndex *pindex; if ( Queued_reconsiderblock != zeroid ) { @@ -2213,8 +2223,6 @@ void komodo_cbopretupdate(int32_t forceflag) fprintf(stderr,"pricewait "), sleep(1); return; } - get_stockprices(); - pending = 1; now = (uint32_t)time(NULL); if ( (ASSETCHAINS_CBOPRET & 1) != 0 ) @@ -2248,23 +2256,35 @@ void komodo_cbopretupdate(int32_t forceflag) { if ( forceflag != 0 || flags != 0 ) { - get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos)),ASSETCHAINS_PRICES); + get_cryptoprices(pricebuf,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos)),ASSETCHAINS_PRICES); if ( flags == 0 ) komodo_PriceCache_shift(); - memcpy(&PriceCache[0][size/sizeof(uint32_t)],cryptoprices,(sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t)); + memcpy(&PriceCache[0][size/sizeof(uint32_t)],pricebuf,(sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t)); flags |= 4; // very rarely we can see flags == 6 case } size += (sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t); } + now = (uint32_t)time(NULL); + if ( (ASSETCHAINS_CBOPRET & 8) != 0 ) + { + if ( forceflag != 0 || flags != 0 ) + { + if ( get_stockprices(now,pricebuf,ASSETCHAINS_STOCKS) == ASSETCHAINS_STOCKS.size() ) + { + if ( flags == 0 ) + komodo_PriceCache_shift(); + memcpy(&PriceCache[0][size/sizeof(uint32_t)],pricebuf,ASSETCHAINS_STOCKS.size() * sizeof(uint32_t)); + flags |= 8; // very rarely we can see flags == 10 case + } + } + size += (ASSETCHAINS_STOCKS.size()) * sizeof(uint32_t); + } if ( flags != 0 ) { - now = (uint32_t)time(NULL); if ( (flags & 1) != 0 ) lastbtc = now; if ( (flags & 2) != 0 ) lasttime = now; - if ( (flags & 4) != 0 ) - lastcrypto = now; memcpy(Mineropret.data(),PriceCache[0],size); if ( ExtremePrice.dir != 0 && ExtremePrice.ind > 0 && ExtremePrice.ind < size/sizeof(uint32_t) && now < ExtremePrice.timestamp+3600 ) { @@ -2284,19 +2304,6 @@ void komodo_cbopretupdate(int32_t forceflag) // fprintf(stderr,"%02x",Mineropret[i]); //fprintf(stderr," <- set Mineropret[%d] size.%d %ld\n",(int32_t)Mineropret.size(),size,sizeof(PriceCache[0])); } - /* - if ( (ASSETCHAINS_CBOPRET & 4) != 0 ) - { - get_currencies(Metals,(int32_t)(sizeof(Metals)/sizeof(*Metals))); - } - if ( (ASSETCHAINS_CBOPRET & 32) != 0 ) - { - get_stocks(Markets,(int32_t)(sizeof(Markets)/sizeof(*Markets))); - } - if ( (ASSETCHAINS_CBOPRET & 64) != 0 ) - { - get_stocks(Techstocks,(int32_t)(sizeof(Techstocks)/sizeof(*Techstocks))); - }*/ } pending = 0; } @@ -2320,6 +2327,11 @@ int64_t komodo_pricemult(int32_t ind) for (j=0; j ASSETCHAINS_PRICES; +std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; #define _ASSETCHAINS_EQUIHASH 0 uint32_t ASSETCHAINS_NUMALGOS = 3; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 3ffaf52dd..c5f562b0e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1815,11 +1815,17 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_CBOPRET != 0 ) { SplitStr(GetArg("-ac_prices",""), ASSETCHAINS_PRICES); - for (i=0; i 0 ) ASSETCHAINS_CBOPRET |= 4; + SplitStr(GetArg("-ac_stocks",""), ASSETCHAINS_STOCKS); + if ( ASSETCHAINS_STOCKS.size() > 0 ) + ASSETCHAINS_CBOPRET |= 8; + for (i=0; i