BitMaker-hub / NerdMiner_v2

Improved version of first ESP32 NerdMiner
Other
1.37k stars 249 forks source link

Bitcoin USD price incorrect & blockchain.com API issue #378

Open maaalex opened 2 months ago

maaalex commented 2 months ago

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}

19201003080114 commented 2 months ago

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.

ChimpRocket commented 2 months ago

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 commented 2 months ago

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);
}
maaalex commented 2 months ago

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

ChimpRocket commented 2 months ago

@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

notsureofagoodname commented 1 month ago

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

yonijuerga commented 3 weeks ago

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?

arcsin3x commented 1 week ago

Do U have some free api?

BitMaker-hub commented 1 day ago

New 1.7.0 version should improve this, can you try?