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!
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...
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.
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();
}
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!
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...
eh Crypto profile is not free in the API. :(
Wow this is awesome bruh 💯💯
Thank you:)
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.
Great projects , but I get so many problems when I try to upload this sketch to my esp32
which error
Yoo... what is that Wi-Fi password 😅
😂
how can I do this for forex?
How to copy code from your comment?
This is just amazing 💯💯
Thanks :)