It keeps a track of the Stock Value! [ESP32 Project]

Поділитися
Вставка
  • Опубліковано 29 чер 2024
  • In this video, I have explained how you can make a free stock price tracker using ESP32. Watch the full video to know more.
    Important links that you might need:
    Free API key generator:
    finnhub.io/
    To get the list of various stocks, visit:
    stockanalysis.com/
    The code is pinned in the comments. If you love my work, consider subscribing to my channel.
    Chapters:
    00:00 Intro
    00:05 Components
    00:08 What does it do?
    00:28 Build process
    00:50 Code
    01:01 Generating the API key
    01:17 Code Explanation
    01:52 Uploading the code
    02:27 Outro

КОМЕНТАРІ • 13

  • @THEELECTRONICGUY
    @THEELECTRONICGUY  10 місяців тому +2

    Code:
    #include
    #include
    #include
    #include
    #include
    #include
    #define SCREEN_WIDTH 128
    #define SCREEN_HEIGHT 64
    #define OLED_RESET -1
    Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
    const char* ssid = "SSID";
    const char* password = "password";
    String payload = "";
    void connectWiFi() {
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0);
    display.println("Connecting to WiFi...");
    display.display();
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    }
    display.clearDisplay();
    display.setCursor(0, 0);
    display.println("Connected to WiFi");
    display.display();
    delay(2000);
    }
    void resetDisplay() {
    display.clearDisplay();
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0);
    }
    void readPrice(int x, int y, const String& stockName) {
    String httpRequestAddress = "finnhub.io/api/v1/quote?symbol=" + stockName + "&token=c1tjb52ad3ia4h4uee9g";
    HTTPClient http;
    int httpCode;
    http.begin(httpRequestAddress);
    httpCode = http.GET();
    if (httpCode > 0) {
    DynamicJsonDocument doc(1024);
    String payload = http.getString();
    Serial.println(payload);
    deserializeJson(doc, payload);
    float previousClosePrice = doc["pc"];
    float currentPrice = doc["c"];
    float differenceInPrice = ((currentPrice - previousClosePrice) / previousClosePrice) * 100.0;
    resetDisplay();
    display.setTextSize(2);
    display.setCursor(x, y);
    display.println(stockName);
    if (differenceInPrice < 0.0) {
    display.setTextColor(SSD1306_WHITE);
    } else {
    display.setTextColor(SSD1306_WHITE);
    }
    display.setTextSize(2);
    display.setCursor(x, y + 25);
    display.print(currentPrice, 2);
    display.println(" USD");
    display.setTextSize(2);
    display.setCursor(x, y + 50);
    display.print(differenceInPrice, 2);
    display.println("%");
    display.display();
    } else {
    resetDisplay();
    display.setTextSize(1);
    display.setCursor(0, 0);
    display.println("Error in HTTP request");
    display.display();
    }
    http.end();
    }
    void setup() {
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
    display.clearDisplay();
    display.setTextColor(SSD1306_WHITE);
    display.setTextSize(1);
    display.setCursor(0, 0);
    display.println("Stock Prices Tracker");
    display.display();
    connectWiFi();
    }
    void loop() {
    readPrice(0, 0, "AAPL");
    delay(3000);
    display.clearDisplay();
    readPrice(0, 0, "AMZN");
    delay(3000);
    display.clearDisplay();
    readPrice(0, 0, "TSLA");
    delay(3000);
    display.clearDisplay();
    readPrice(0, 0, "MSFT");
    delay(3000);
    readPrice(0, 0, "PFE");
    delay(3000);
    display.clearDisplay();
    readPrice(0, 0, "OXY");
    delay(3000);
    display.clearDisplay();
    readPrice(0, 0, "EBAY");
    delay(3000);
    display.clearDisplay();
    readPrice(0,0, "FDX");
    delay(3000);
    display.clearDisplay();
    }

  • @x01565
    @x01565 3 місяці тому +1

    I built it. Nice Job! The parsing of the string from the API is what I really needed help with. I used the value 'differenceInPrice' to write to a green LED on D18 and a red LED on D19 depending on its absolute value since my OLED screen doesn't support different colors of text. Next I'll use a rotary encoder with a system of menus to manually enter the SSID, PW, and stock tickers. Thanks!

    • @csabalazar8937
      @csabalazar8937 Місяць тому

      Hi, could you pls help me, in order to add 5mm red/green leds? I wanna achieve, IF the price is go down -> there would be a red led on, if it goes up -> there would be a green led on. Also, did you figure out how to screen only BTC/USD price? Seems the API can handle it...

    • @csabalazar8937
      @csabalazar8937 Місяць тому

      eh Crypto profile is not free in the API. :(

  • @user-jz7jr5rr1c
    @user-jz7jr5rr1c 10 місяців тому

    Wow this is awesome bruh 💯💯

  • @user-qf9pc2es5q
    @user-qf9pc2es5q 10 місяців тому

    This is just amazing 💯💯

  • @k9slover
    @k9slover 2 місяці тому

    Very interesting. I had a problem trying to do the same, in the sketch I think I was using a different HttpClient library, as it wanted an argument for the constructor, and other differences. Could you please tell me how to use the libraries you used? Thanks.

  • @NemanjaR8
    @NemanjaR8 7 місяців тому +1

    Great projects , but I get so many problems when I try to upload this sketch to my esp32

  • @decogabry3979
    @decogabry3979 3 місяці тому

    how can I do this for forex?

  • @awaisjatt1499
    @awaisjatt1499 10 місяців тому

    How to copy code from your comment?