Trustless, Web3 agentic trading copilot with ERC‑8004 identity and x402 payments.
TradeSmart.ai is a modular trading copilot for crypto and markets. It ingests market data, detects opportunities, simulates strategies, and executes trades through a trustless, Web3‑enabled pipeline. The system pairs Python agents in the backend with a modern Next.js frontend and augments them with on‑chain identity/attestations (ERC‑8004) and agent‑to‑agent payments (x402). Core capabilities • Signal generation: Backend agents (indicator, liquidation) compute indicators and liquidation levels, streaming insights over websockets. • Strategy orchestration: The orchestrator composes signals into executable “intents,” validates risk constraints, and schedules execution. • Data ingestion: Fetchers for Binance/NSE and schedulers maintain OHLCV/time‑series in a database; cache layers serve the UI efficiently. • Real‑time UI: Next.js + websockets render live analysis, charts, and chat guidance. Relevant repo areas: • Backend agents: backend/agents/.py • Controllers/API: backend/controllers/.py • Data ingestion: backend/data_ingestion/.py • Services: backend/services/.py • Frontend: frontend/app, frontend/components
We built TradeSmart.ai as an end‑to‑end, agentic trading copilot: a FastAPI backend with Python agents, a real‑time Next.js UI, and a Web3 layer for trustless execution and agent payments. Below is the nuts‑and‑bolts view of what shipped in 15 days, what was stubbed, and what was hacky. Architecture at a glance Backend (Python/FastAPI): backend/main.py, routers in backend/controllers, agents in backend/agents, services in backend/services. Data platform: TimescaleDB/Postgres for OHLC; Redis cache; APScheduler for fetch loops; optional Supabase host. AI/agents: LangChain + Cerebras LLMs (via langchain-cerebras) for chat/analysis; deterministic indicator/liquidation agents. WebSockets: Real‑time streams from backend to UI. Frontend (Next.js + TypeScript): Live charting, strategy builder, chat, and agent telemetry in frontend/app and frontend/components. Orchestration: Docker Compose for TimescaleDB, Redis, backend, MCP server; .env driven config. Web3: EIP‑712 intent signing, ERC‑8004 agent registry/attestations, and x402 agentic payments for pay‑per‑call services. Minimal contracts + adapters, deployed on testnet. Backend internals API server: FastAPI with lifespan hooks for DB, Redis, MCP, schedulers (backend/main.py). Controllers: ohlc_controller.py, strategy_controller.py, websocket_controller.py, chat_controller.py. Agents: indicator_agent.py: RSI/MACD/EMA pipeline over cached OHLC. liquidation_agent.py: Finds probable liquidation clusters; publishes levels for the chart. orchestrator.py: Composes signals → “intents” with risk parameters (slippage, size, deadline). Services: market_data_service.py: Binance/NSE ingestion via data_ingestion/* with APScheduler. cache_service.py: Redis‑first reads with fallback to DB; delta cache for candles. strategy_service.py: Runs sims, bundles intent metadata (agentId, constraints). MCP integration: backend/mcp_server/* for tool calls and model routing to Cerebras. Data + infra details TimescaleDB: Time‑series OHLC with hypertables for fast range scans. Simple upsert on candle ticks. Redis: Hot cache for latest N candles and computed indicators; prevents DB thundering herd from the UI. Schedulers: APScheduler jobs per symbol/timeframe; backfills on cold start; jittered intervals to avoid API rate bursts. Docker Compose: One command brings up TimescaleDB, Redis, backend, and MCP; healthchecks guard service starts. Frontend details Stack: Next.js (App Router), TypeScript, Shadcn UI components, websockets for live updates. Features: Strategy panel, chat panel, TradingView‑style chart wrapper, toasts, skeleton loaders. State: Lightweight local state + server events; no heavyweight global store needed. Web3 and trustless execution EIP‑712 intent signing: Client signs trade intents (market, size, maxSlippageBps, deadline, agentId, metadataHash). Prevents server‑side tampering. Settlement contract (testnet): Verifies signatures, checks Chainlink oracle price bounds, enforces slippage and size caps, and emits on‑chain receipts. ERC‑8004 agent registry (prototype): On‑chain registry mapping agentId → metadataHash, capabilityBitmap, keys. Attestations (EAS‑style) for audits/backtest reports bound to metadataHash. Clients verify agent identity and capabilities before trusting outputs. x402 agentic payments: HTTP 402 challenge with X‑402‑Payment proposal (chain, token, amount, reference). Client/agent pays in USDC (Base testnet), resubmits with X‑402‑Receipt. Backend verifies on‑chain, credits the request, and proceeds. Enables per‑call pricing, agent‑to‑agent micro‑settlements. IPFS receipts (optional): Simulation artifacts/content hashes pinned off‑chain; tx events include CID for auditability.

