Best free ai video generator : Synthesia
Best free ai audio generator.(realistic speech in your language) : Elevenlabs
LiquidCrystal_I2C) | Display price, P/L |cpp
/*
ESP32 Algo Trading Demo with LCD (16x2 I2C)
-------------------------------------------
Features:
- Fetches LTP from dummy API
- Sends mock buy/sell orders
- Displays current LTP and P/L on LCD
Replace BROKER_ORDER_URL with your actual broker endpoint
*/
#include <WiFi.h>
#include <HTTPClient.h>
#include <LiquidCrystal_I2C.h>
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
// Dummy endpoints (replace with real ones)
const char* PRICE_API_URL = "https://api.example.com/ltp?symbol=RELIANCE";
const char* BROKER_ORDER_URL = "https://api.example.com/order";
const char* BROKER_API_KEY = "DUMMY_API_KEY";
// LCD settings
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Trade parameters
String symbol = "RELIANCE";
float entryPrice = 0;
float ltp = 0;
float profitLoss = 0;
String position = "NONE";
int quantity = 10;
// Helper function to fetch latest price
float fetchLTP() {
if (WiFi.status() != WL_CONNECTED) return 0.0;
HTTPClient http;
http.begin(PRICE_API_URL);
int code = http.GET();
if (code != 200) {
Serial.printf("Price fetch failed: %d\n", code);
http.end();
return 0.0;
}
String payload = http.getString();
http.end();
// If payload = plain number like "2543.65"
float price = payload.toFloat();
if (price <= 0) {
// try extracting from JSON: {"ltp":2543.65}
int p = payload.indexOf(":");
int e = payload.indexOf("}");
price = payload.substring(p + 1, e).toFloat();
}
return price;
}
// Mock trade execution
void placeOrder(String side) {
if (WiFi.status() != WL_CONNECTED) return;
HTTPClient http;
http.begin(BROKER_ORDER_URL);
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", String("Bearer ") + BROKER_API_KEY);
String body = "{\"symbol\":\"" + symbol + "\",\"side\":\"" + side + "\",\"qty\":" + String(quantity) + "}";
int code = http.POST(body);
String resp = http.getString();
http.end();
Serial.printf("%s order response %d: %s\n", side.c_str(), code, resp.c_str());
if (side == "BUY") {
position = "LONG";
entryPrice = ltp;
} else if (side == "SELL") {
if (position == "LONG") {
float diff = ltp - entryPrice;
profitLoss += diff * quantity;
position = "NONE";
} else {
position = "SHORT";
entryPrice = ltp;
}
}
}
// Display data > 0) {
Serial.printf("LTP: %.2f\n", ltp);
}
// Simple strategy: Buy below 2500, Sell above 2600 (demo logic)
if (position == "NONE" && ltp < 2500) {
placeOrder("BUY");
} else if (position == "LONG" && ltp > 2600) {
placeOrder("SELL");
}
updateLCD();
delay(10000); // fetch every 10 sec
}
RELIANCE:2560.7LONG P/L:60.0
WiFi Connected!
LTP: 2560.70
BUY order response 200: {"status":"ok"}
SELL order response 200: {"status":"ok"}
PRICE_API_URL with the broker’s quote endpointBROKER_ORDER_URL with their order endpoint