bitreka

Software Engineering Leader | AI-Assisted Development | .NET & C# | FinTech & Payments | E-Commerce | Architecture • Backend • Microservices • DevOps • Test Automation • AI Agents

All work

Market Copilot

A multi-agent paper-trading copilot where AI agents research and debate, and deterministic rules decide.

Status
simulator onlyRuns against a simulator, never against real money or devices.
Role
Sole engineer: architecture, agent flow, strategy and risk rules, RAG, API, dashboard and the eval gate.
Started
Categories
Fintech, AI and LLM
Parts
Web

Purpose

Show how LLM agents can support trading decisions safely: they research and explain each signal, while fixed rules, risk limits and a human have the final say — all against a simulated broker.

The problem

Letting a language model place orders is risky: it can be confidently wrong, be steered by poisoned news, or simply be unavailable. An agent system for markets has to fail toward lower risk and stay explainable, not just sound convincing.

What I built

  • A LangGraph flow — ingest, signal, research, debate, risk gate, human approval, execute, report — with a PostgreSQL checkpointer, so a pending approval survives a restart and each run executes at most once.
  • Deterministic "buy the dip, sell the rally" rules with stop-loss, position limits and order sizing; the LLM only approves or vetoes and never creates or sizes an order.
  • A bounded three-agent AutoGen debate (analyst, critic, risk manager) over cited RAG research: pgvector hybrid search, prompt-injection quarantine and no LLM call when there is no evidence.
  • An LLM fallback chain from Bedrock to Vertex AI to a local Ollama model behind circuit breakers, plus MCP servers for market data, news and filings, and the paper broker.
  • A FastAPI service and a Next.js dashboard for the watchlist, portfolio, approvals and run history, with a shared kill switch and fault-injection controls for resilience demos.
  • An LLM-free regression gate for retrieval, backtest and agent-flow behaviour, run in CI next to type checks, coverage and security scans; optional Langfuse tracing.

Features

  • Buy-the-dip and rally signals from deterministic rules, with a backtest script.
  • Watches the BIST, US stocks, and gold, silver and oil.
  • Cited research on news and filings with hybrid search.
  • A three-agent debate for every run, shown in the interface.
  • Approval cards for orders above a threshold.
  • A kill-switch bar that stops trading at once.
  • A chaos fault-injection panel, switched off in production.
  • A paper portfolio with metric cards.
  • Turkish and English interface.
  • Replay mode and a scan that runs every 30 minutes.

Stack

  • Python
  • FastAPI
  • LangGraph
  • PostgreSQL
  • pgvector
  • Ollama
  • Next.js
  • TypeScript
  • Tailwind CSS
  • Playwright

AI in this project

In the product

  • A three-agent debate (analyst, critic, risk manager) argues over a signal that fixed rules produced. The risk manager returns a structured verdict with the ids of the documents it cites. The model can only approve or veto: it never sizes or creates an order, an approval without valid citations is turned into a rejection, and a provider outage or timeout fails closed.
  • Cited research answers in at most four sentences from retrieved documents only, or says the evidence is insufficient. With no evidence no model is called, and an answer that cites nothing retrieved is discarded.
  • The model chain falls back from Bedrock to Vertex to a local Ollama model, with a circuit breaker after three failures. An optional offline heuristic exists for demos and labels every verdict as not a language model.
  • Retrieved documents are treated as untrusted data and instruction-like passages are quarantined before ranking: a mitigation, not a guarantee.
  • Orders above a configurable threshold pause until a human approves them, and the broker is paper only.

In how it was built

  • 45 of 50 commits carry a Claude co-author trailer.
  • Permanent project rules live in rule files, backed by a shared gate: lint, strict type checking, tests at 80% line coverage, an evaluation gate against regressions, a dependency audit and a secret scan.

Key flows

Steps

From a price dip to a simulated order

  1. Step 1 of 5: Ingest

    A scan reads live or replayed prices for the watchlist; prices that are too old stop the run before any analysis.

  2. Step 2 of 5: Signal

    Deterministic rules flag a dip, a rally or a stop-loss; anything else ends as a hold with a short report.

  3. Step 3 of 5: Research and debate

    Cited research is retrieved from news and filings, and three agents debate it; without sufficient evidence and an approving verdict there is no buy.

  4. Step 4 of 5: Risk gate and approval

    The broker's guards check the kill switch, cash and position limits; orders above the threshold wait for a human in the dashboard.

  5. Step 5 of 5: Execute and report

    The simulated broker fills the order, and the run is logged with its outcome, per-step latency and paper PnL.

Limitations

  • Paper trading only: the broker is a simulator, no real orders are ever placed and no real money is involved. Nothing here is investment advice.
  • Demo prices and the news corpus are synthetic, and the self-hosted deployment is prepared but not live yet.

Want something like this?

Tell me about your project — I reply within two working days.

Start a project