All Cloudflare Pages Functions under /api/*. Every response is JSON. The Supabase service key never reaches the browser.
Current wallet balance, PnL since start, open position details, and active bot settings.
Paginated list of all closed trades, newest first. Supports limit and offset query params.
Persist strategy config (EMA periods, leverage, SL %, TP %) to Supabase.
Open or close a leveraged position. Atomically updates both positions and wallet.
In-memory EMA simulation against historical Binance klines. No DB writes.
Three Supabase PostgreSQL tables. All writes go through Cloudflare — the service key never leaves the server.
CREATE TABLE wallet ( id UUID PRIMARY KEY, balance NUMERIC(18,8) DEFAULT 1000, last_updated TIMESTAMPTZ DEFAULT NOW() );
CREATE TABLE positions ( id UUID PRIMARY KEY, side TEXT CHECK ('LONG'|'SHORT'), entry_price NUMERIC(18,8), close_price NUMERIC(18,8), leverage INTEGER CHECK (1..10), size NUMERIC(18,8), margin NUMERIC(18,8), status TEXT CHECK ('OPEN'|'CLOSED'), pnl NUMERIC(18,8), stop_loss NUMERIC(18,8), take_profit NUMERIC(18,8), created_at TIMESTAMPTZ, closed_at TIMESTAMPTZ );
CREATE TABLE bot_settings ( id UUID PRIMARY KEY, config JSONB DEFAULT '{ "strategy": "ema_cross", "leverage": 3, "stop_loss": 0.02, "take_profit": 0.05, "indicators": { "short_ema": 9, "long_ema": 21 } }', updated_at TIMESTAMPTZ DEFAULT NOW() );