NerdMiner_v2 icon indicating copy to clipboard operation
NerdMiner_v2 copied to clipboard

Bitcoin USD price incorrect & blockchain.com API issue

Open maaalex opened this issue 1 year ago • 11 comments

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}

maaalex avatar Apr 12 '24 06:04 maaalex

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.

MyOwn2C avatar Apr 12 '24 16:04 MyOwn2C

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

ChimpRocket avatar Apr 22 '24 17:04 ChimpRocket

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 avatar Apr 23 '24 09:04 ChimpRocket

@ChimpRocket that's great, thanks for the effort! This should be merged into master.

maaalex avatar Apr 23 '24 13:04 maaalex

@19201003080114 @maaalex It's a bit of a hack of esp23_2432s028r.cpp but this is what my updated BTC price screen looks like. image

ChimpRocket avatar Apr 24 '24 23:04 ChimpRocket

+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.

notsureofagoodname avatar May 16 '24 05:05 notsureofagoodname

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);
}

ok, how we flash the firmware with this changes?

yonijuerga avatar Jun 10 '24 21:06 yonijuerga

Do U have some free api?

arcsin3x avatar Jun 25 '24 11:06 arcsin3x

New 1.7.0 version should improve this, can you try?

BitMaker-hub avatar Jun 30 '24 20:06 BitMaker-hub

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.

vagnerac avatar Dec 06 '24 14:12 vagnerac

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.

smharm13 avatar Dec 20 '24 06:12 smharm13