NerdMiner_v2
NerdMiner_v2 copied to clipboard
Bitcoin USD price incorrect & blockchain.com API issue
for the last week the price updates seem to not work and price is not updated - at least for an hour or so… worked fine before, running 1.6.3.
Update: Seems blockchain API is providing wrong price
pice on blockain.com $70,965.87 while same time endpoint returns: {"symbol":"BTC-USD","price_24h":71000.0,"volume_24h":1.0004972,"last_trade_price":71900.0}
Check here. It shows the "last_trade_price", not "price_24h" https://github.com/BitMaker-hub/NerdMiner_v2/blob/master/src/monitor.cpp Also I think Nerdminer only checks every hour, but update interval from api.blockchain.com is unknown.
Hi guys,
Are there any plans to use a btc price api that updates in realtime? The main reason I got a nerd miner (today) was to get a mini display for the price but the blockchain.com "last_trade_price" hasn't changed all afternoon.
Here's a list of API's with open auth List of Crypto Market Data APIs.
The coinbase one seems to update in realtime https://api.coinbase.com/v2/prices/BTC-USD/spot
{"data":{"amount":"66413.775","base":"BTC","currency":"USD"}}
Cheers, JS
Further to my comment above. I complied my own firmware with these changes as a test and to see if I could do it.
The price updates every 1 minute and the dollar sign is moved as a prefix to the price.
monitor.h
//API BTC price
#define getBTCAPI "https://api.coinbase.com/v2/prices/BTC-USD/spot"
#define UPDATE_BTC_min 1
monitor.cpp
String getBTCprice(void){
if((mBTCUpdate == 0) || (millis() - mBTCUpdate > UPDATE_BTC_min * 60 * 1000)){
if (WiFi.status() != WL_CONNECTED) return "$" + String(bitcoin_price);
HTTPClient http;
try {
http.begin(getBTCAPI);
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
if (doc.containsKey("data") && doc["data"].containsKey("amount")) bitcoin_price = doc["data"]["amount"];
doc.clear();
mBTCUpdate = millis();
}
http.end();
} catch(...) {
http.end();
}
}
return "$" + String(bitcoin_price);
}
@ChimpRocket that's great, thanks for the effort! This should be merged into master.
@19201003080114 @maaalex
It's a bit of a hack of esp23_2432s028r.cpp but this is what my updated BTC price screen looks like.
+1, I bought a nerd miner as a price proxy clock. Seeing it painfully out of date isn't great. Would appreciate all prices are updated per minute/few etc.
Further to my comment above. I complied my own firmware with these changes as a test and to see if I could do it.
The price updates every 1 minute and the dollar sign is moved as a prefix to the price.
monitor.h
//API BTC price #define getBTCAPI "https://api.coinbase.com/v2/prices/BTC-USD/spot" #define UPDATE_BTC_min 1monitor.cpp
String getBTCprice(void){ if((mBTCUpdate == 0) || (millis() - mBTCUpdate > UPDATE_BTC_min * 60 * 1000)){ if (WiFi.status() != WL_CONNECTED) return "$" + String(bitcoin_price); HTTPClient http; try { http.begin(getBTCAPI); int httpCode = http.GET(); if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); DynamicJsonDocument doc(1024); deserializeJson(doc, payload); if (doc.containsKey("data") && doc["data"].containsKey("amount")) bitcoin_price = doc["data"]["amount"]; doc.clear(); mBTCUpdate = millis(); } http.end(); } catch(...) { http.end(); } } return "$" + String(bitcoin_price); }
ok, how we flash the firmware with this changes?
Do U have some free api?
New 1.7.0 version should improve this, can you try?
BTC price does not update in the 1.7.0 version. I have downloaded the code and applied changes mentioned by @ChimpRocket and it worked for me. I am not a C developer and don't know how exactly it should be done to ensure all code could be validated after changes. So anyone with this knowledge could apply the changes and add a pull request to this small fix.
Just wanted to comment that I also made the recommended changes identified here and its working for me now as well. Updating off the Coinbase price as well as the $ moving to be located in the correct place. Had never used visual studio before so this was a really helpful guide for learning to edit files and compile from source.
The only additional change I had to make was in the platformio.ini file to reduce the upload setting down to 115200 because it kept failing on the upload the default was to fast for the little ESP32 board.