From aee4b6ec2b7dafc2a44de1fd31ae852d9e3c1130 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:25:55 -1100 Subject: [PATCH] alphadvantage api --- src/komodo_gateway.h | 101 +++++++++++++++++++++++++++++++++++++++++-- src/komodo_utils.h | 2 +- 2 files changed, 98 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6a9afd473..5f235ee63 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1631,13 +1631,13 @@ CScript komodo_mineropret(int32_t nHeight) { if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { - memcpy(pricebits,&Mineropret[0],PRICES_SIZEBIT0); + memcpy(pricebits,Mineropret.data(),PRICES_SIZEBIT0); if ( komodo_pricecmp(&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) { // if the new prices are not within tolerance, update Mineropret with clipped prices komodo_priceclamp(pricebits,prevbits,PRICES_MAXCHANGE); fprintf(stderr,"update Mineropret to clamped prices\n"); - memcpy(&Mineropret[0],pricebits,PRICES_SIZEBIT0); + memcpy(Mineropret.data(),pricebits,PRICES_SIZEBIT0); } } return(opret << OP_RETURN << Mineropret); @@ -1677,7 +1677,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) } if ( lag < ASSETCHAINS_BLOCKTIME && Mineropret.size() >= PRICES_SIZEBIT0 ) { - memcpy(localbits,&Mineropret[0],PRICES_SIZEBIT0); + memcpy(localbits,Mineropret.data(),PRICES_SIZEBIT0); if ( maxflag == 0 ) { if ( komodo_pricecmp(&maxflag,localbits,prevbits,PRICES_MAXCHANGE) < 0 ) @@ -1709,6 +1709,19 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) // get_urljson just returns the JSON returned by the URL using issue_curl #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) +char *Cryptos[] = { "KMD", "BTC", "ETH", "LTC", "BCH", "XMR", "IOTA", "DASH", "XTZ", "XEM", "ZEC", "WAVES", "DOGE", "RVN", "LSK", "DCR", "BTS", "ICX", "HOT", "DGB", "STEEM", "ENJ", "STRAT", "VEO" }; + +char *ForexMajor[] = { "USD", "EUR", "JPY", "GBP", "AUD", "CHF", "CNY", "RUB" }; + +char *ForexMinor[] = { "CAD", "NZD", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", "UAH", "AED", "SAR" }; + +char *Metals[] = { "XAU", "XAG", "XPT", "XPD", }; + +char *Markets[] = { "DJIA", "SPX", "NDX", "VIX" }; + +char *Techstocks[] = +{ "AAPL","ADBE","ADSK","AKAM","AMD","AMZN","ATVI","BB","CDW","CRM","CSCO","CYBR","DBX","EA","FB","GDDY","GOOG","GRMN","GSAT","HPQ","IBM","INFY","INTC","INTU","JNPR","MSFT","MSI","MU","MXL","NATI","NCR","NFLX","NTAP","NVDA","ORCL","PANW","PYPL","QCOM","RHT","S","SHOP","SNAP","SPOT","SYMC","SYNA","T","TRIP","TWTR","TXN","VMW","VOD","VRSN","VZ","WDC","XRX","YELP","YNDX","ZEN" +}; cJSON *get_urljson(char *url) { @@ -1722,6 +1735,61 @@ cJSON *get_urljson(char *url) return(json); } +uint32_t get_stockprice(char *symbol) +{ + char url[512]; cJSON *json,*obj; uint32_t high,low,price = 0; + sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + if ( (json= get_urljson(url)) != 0 ) + { + if ( (obj= jobj(jitem(json,"Time Series (15min)"),0)) != 0 ) + { + high = jdouble(jitem(obj,0),"2. high")*10000 + 0.000049; + low = jdouble(jitem(obj,0),"3. low")*10000 + 0.000049; + price = (high + low) / 2; + } + free_json(json); + } + return(price); +} + +uint32_t get_currencyprice(char *symbol) +{ + char url[512]; cJSON *json,*obj; uint32_t price = 0; + sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + if ( (json= get_urljson(url)) != 0 ) + { + if ( (obj= jobj(jitem(json,0),0)) != 0 ) + price = jdouble(obj,"5. Exchange Rate")*10000 + 0.000049; + free_json(json); + } + return(price); +} + +int32_t get_currencies(char *list[],int32_t n) +{ + int32_t i,errs=0; uint32_t price; + for (i=0; i