How vuongnq10/ai_agent_project works
1. This repo is split into two runtime boundaries: a Python backend in bot-trading/ and a React + TypeScript frontend in fe_chat/. The backend owns market analysis, agent orchestration, and trade execution; the frontend owns charting, chat UI, and user controls.
2. The backend is a FastAPI service started from bot-trading/main.py. It wires routers, loads configuration from config.py, and exposes the API surface used by the browser. The main external dependencies are Binance Futures, Telegram, and LLM provider APIs.
3. The core backend domain service is services/smc_service.py. It fetches OHLCV data from Binance Futures REST and computes Smart Money Concepts plus classic indicators: trend, BOS/CHoCH, order blocks, fair value gaps, liquidity, premium/discount zones, ATR, EMAs, Bollinger Bands, and RSI. This service is the source of truth for all market structure analysis.
4. Agent execution is organized under bot-trading/agents/ with provider-specific wrappers for Gemini, Claude, and ChatGPT. Each provider has an agent.py model wrapper and an agentic_agent.py LangGraph state machine, but they share the same high-level flow: classify intent, analyze market context, decide trade action, optionally invoke tools, then generate a final response.
5. Tooling for the agents lives in tools/cx_connector.py. It exposes two main callable actions: smc_analysis() to retrieve the full SMC payload, and create_order() to place a trade. This is the bridge between the reasoning layer and side effects.
6. Order execution is handled by connectors/binance_v2.py. It wraps the Binance futures connector and creates bracket trades: a LIMIT entry plus TAKE_PROFIT_MARKET and STOP_MARKET orders. It also manages leverage settings, which are exposed through the trading router.
7. Notifications are pushed through connectors/telegram.py. When an order is placed, the system can asynchronously notify a Telegram chat, so trading events are observable outside the web UI.
8. The backend API is split into two routers: routers/trading.py for normal JSON endpoints and routers/stream.py for the streaming chat endpoint. The streaming endpoint returns Server-Sent Events so the agent’s response can be delivered character-by-character to the browser.
9. The frontend is a single-page application built around a chart-and-chat workspace. src/App/index.tsx composes the layout: a candlestick chart area, indicator/SMC overlays, a coin list, leverage controls, and a chat sidebar. The chart stack uses lightweight-charts with custom SMC drawings and indicator panels.
10. Frontend state is split into hooks and services. useCandles, useTicker, and useLeverage manage market data and trading controls; useChat manages SSE chat streaming. Service modules isolate backend calls: chatService.ts for model streaming, tradingService.ts for SMC and leverage APIs, and binanceService.ts for market data access.
11. A key data-flow boundary is smcQueryService.ts. Before a chat message is sent, it requests SMC analysis for multiple timeframes (1h, 2h, 4h), formats the results into structured markdown, and prepends that context to the user prompt. This means the LLM receives precomputed market structure rather than raw candles.
12. The end-to-end interaction path is: user input in the browser → multi-timeframe SMC context assembly → SSE request to the backend agent endpoint → LangGraph analysis/decision/tool execution → optional Binance order placement and Telegram alert → streamed textual result back to the chat UI. That is the primary architecture to draw.
13. There is also a small test boundary under bot-trading/tests/, focused on order creation behavior. The repo’s .claude and .codex folders are agent/operator metadata, not product runtime components, so they do not affect the deployed system architecture.
Main entry points: trading.py Trading router · binance_v2.py Binance executor · main.py FastAPI app · index.tsx App shell
Components 19
Python backend
FastAPI service for market analysis, agent orchestration, and trade execution.
- FastAPI app · Bootstraps the API, loads config, and wires routers.
bot-trading/main.py - Config · Central backend configuration and environment wiring.
bot-trading/config.py - Trading router · JSON endpoints for market data, leverage, and order actions.
bot-trading/routers/trading.py - Stream router · Server-sent event endpoint for streamed agent responses.
bot-trading/routers/stream.py - SMC service · Computes Smart Money Concepts and classic indicators from OHLCV data.
bot-trading/services/smc_service.py - Market data · Fetches candle and ticker data from Binance Futures.
bot-trading/services/binance_market_data_service.py - Agent stack · Provider-specific wrappers and shared LangGraph decision flow.
bot-trading/agents - Tool bridge · Exposes SMC analysis and order creation to agent workflows.
bot-trading/tools/cx_connector.py - Binance executor · Places bracket orders and manages leverage on Binance Futures.
bot-trading/connectors/binance_v2.py - Telegram alerts · Sends trade notifications to Telegram chats.
bot-trading/connectors/telegram.py - Order tests · Focused tests for order creation behavior.
bot-trading/tests/test_create_orders.py
React frontend
Single-page chart and chat workspace for user interaction.
- App shell · Composes the chart, controls, and chat workspace.
fe_chat/src/App/index.tsx - Chart workspace · Candlestick chart, overlays, indicators, and market panels.
fe_chat/src/App/components/Chart/index.tsx - Chat panel · Chat input and streamed message display.
fe_chat/src/App/components/Chat/Input.tsx - Trading controls · Coin list, leverage panel, and header controls.
fe_chat/src/App/components/LeveragePanel/index.tsx - Candle hook · Manages candle loading and chart updates.
fe_chat/src/hooks/useCandles.ts - Chat hook · Handles SSE chat streaming and message state.
fe_chat/src/hooks/useChat.ts - SMC query · Fetches multi-timeframe SMC data and formats prompt context.
fe_chat/src/services/smcQueryService.ts - API services · Frontend clients for market data, chat streaming, and trading actions.
fe_chat/src/services/tradingService.ts
Connections 21
- FastAPI app → Config: loads · Initializes the service from configuration.
- FastAPI app → Trading router: mounts · Registers standard JSON endpoints.
- FastAPI app → Stream router: mounts · Registers the SSE chat endpoint.
- Trading router → SMC service: uses · Serves computed market structure to clients.
- Trading router → Binance executor: orders · Creates and configures futures trades.
- Stream router → Agent stack: invokes · Streams agent reasoning and responses.
- Agent stack → Tool bridge: calls · Uses tools during analysis and decision making.
- Tool bridge → SMC service: analyzes · Retrieves full SMC payload for reasoning.
- Tool bridge → Binance executor: executes · Places trades when the agent decides to act.
- Binance executor → Telegram alerts: notifies · Sends alerts after order placement.
- SMC service → Market data: fetches · Pulls OHLCV data for structure analysis.
- Order tests → Binance executor: verifies · Covers order creation behavior.
- App shell → Chart workspace: composes · Renders the chart and overlays.
- App shell → Chat panel: composes · Renders the conversational panel.
- App shell → Trading controls: composes · Renders market and leverage controls.
- Chart workspace → Candle hook: feeds · Consumes candle state for rendering.
- Chat panel → Chat hook: binds · Streams chat messages and response state.
- Chat hook → SMC query: prepends · Builds prompt context before sending a message.
- SMC query → API services: requests · Calls backend APIs for SMC and chat flow.
- API services → Trading router: api · Uses trading and market endpoints.
- API services → Stream router: api · Uses streaming endpoint for chat responses.