SQLite-first crypto decision agent with live market capture, AI analysis, and a modern dashboard
Binance Agent collects live Binance market data, builds technical indicators and multi-timeframe snapshots, sends structured payloads to an OpenAI-compatible model, and stores runtime data in SQLite.
The system now uses:
- SQLite as the source of truth for settings, snapshots, AI usage, AI decisions, events, notifications, and live snapshots
- backup mirror tables inside the same SQLite database for recovery and inspection
- a live AI Decision stream in the web UI with a scrollable recent-history panel
- a FastAPI backend plus a React dashboard for day-to-day operation
This project is a decision assistant, not an execution bot. It does not place trades.
- Collects closed
1mBinance candles through the websocket collector - Builds rolling and confirmed
5m,10m, and20mstructures - Computes indicators such as RSI, ATR, trend, support/resistance, breakout state, and volatility regime
- Sends a structured JSON payload to an OpenAI-compatible API
- Streams the AI response into the dashboard live
- Persists settings, snapshots, events, decisions, usage, notifications, and live snapshots in SQLite
- Mirrors runtime records into backup tables with the
*_bkpsuffix - Supports Telegram notifications when a decision is marked
should_notify=true - Exposes FastAPI endpoints for dashboard, config, analysis, and maintenance
Binance REST API
|
v
WebSocket Collector -> MarketService -> LiveSnapshot
| |
| +-> SQLite live_snapshots / live_snapshots_bkp
v
Snapshot Builder -> AI Payload Builder -> OpenAI-compatible model
| |
| +-> ai_decision / ai_decision_bkp
| +-> ai_usage / ai_usage_bkp
v
FastAPI backend -> React dashboard -> live AI Decision stream
|
+-> events / events_bkp
+-> snapshots / snapshots_bkp
+-> notifications / notifications_bkp
+-> settings
Primary tables:
settingssnapshotsai_decisionai_usageeventsnotificationslive_snapshots
Backup mirror tables:
snapshots_bkpai_decision_bkpai_usage_bkpevents_bkpnotifications_bkplive_snapshots_bkp
The backup tables live in the same SQLite file and mirror the primary inserts.
- Python 3.10+
- Node.js 18+ for the UI
- An OpenAI-compatible API key or base URL
pip install -r requirements.txt
cd ui
npm install
cd ..Create .env from .env.example and set at least:
OPENAI_API_KEY=your_key
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=your_model_name
BINANCE_SYMBOL=BTCUSDT
BINANCE_INTERVAL=5m
BINANCE_MODE=manual
BINANCE_USE_SQLITE=true
BINANCE_SQLITE_PATH=data/binance_agent.sqlite3python binance_event_bot.pyTo run the API only:
python binance_event_bot.py --apiTo run the web UI:
cd ui
npm run dev| Mode | Behavior |
|---|---|
manual |
Runs on demand and through the dashboard |
live |
Streams market data continuously and updates the dashboard |
continuous |
Repeats snapshot collection and analysis on a delay |
static |
Runs a one-shot snapshot and analysis cycle |
The dashboard now shows the AI response as a live stream.
The AI panel:
- streams the response chunk by chunk
- keeps the last 5 responses visible in a scrollable history area
- switches to the analysis tab automatically when a run starts
This is wired through the backend streaming endpoint and the dashboard event flow.
The model is expected to return structured JSON like this:
{
"decision_id": "uuid-or-stable-id",
"action": "BUY",
"bias": "uptrend",
"confidence": 0.81,
"position_action": "enter",
"next_state": "in_long",
"symbol": "BTCUSDT",
"primary_timeframe": "10m",
"entry_trigger": "Confirmed breakout and retest with volume support.",
"invalidation": "Exit if confirmed 5m closes back inside the broken range.",
"wait_reason": "",
"one_line_summary": "Confirmed breakout with aligned trend.",
"rationale": "Multi-timeframe structure supports an entry.",
"risk_level": "medium",
"cooldown_seconds": 600,
"should_notify": true,
"report": {
"reason": "Directional edge is present.",
"best_timeframe": "10m",
"support": 74890.0,
"resistance": 75240.0,
"current_price": 75190.0,
"trade_direction": "higher",
"risk_note": "Avoid if follow-through fails.",
"regime": "trend_follow",
"breakout_status": "confirmed_breakout",
"pullback_status": "clean_retest",
"volume_confirmation": "confirmed",
"no_trade_filters": []
}
}| Endpoint | Method | Purpose |
|---|---|---|
/health |
GET | Health check |
/config |
GET | Runtime config |
/settings |
GET / PUT | Persisted settings |
/snapshot |
GET | Latest market snapshot |
/state |
GET | Current position state |
/dashboard |
GET | Combined dashboard payload |
/decisions/recent |
GET | Recent decision history |
/events/recent |
GET | Recent events |
/errors/recent |
GET | Recent errors |
/snapshots/recent |
GET | Recent snapshots |
/notifications/recent |
GET | Recent notifications |
/ai/usage |
GET | AI usage logs |
/ai/decisions |
GET | AI decision records |
/agent/run |
POST | Trigger analysis |
/agent/stream |
POST | Stream live AI output |
/refresh |
POST | Refresh current symbol data |
/maintenance/clear |
POST | Clear runtime data |
- SQLite is now the default persistence layer.
- The app also writes backup rows to
*_bkptables inside the same database. - The old JSONL helpers are legacy and are no longer the runtime source of truth.
binance_event_bot.py
binance_agent/
ui/
data/
samples-img/
README.md
README-SETUP.md
MIT License.




