Skip to main content

Research Intelligence Layer - peer-reviewed AI signal validation for trading bots

Project description

Trading-RIL — Research Intelligence Layer

Open source peer-reviewed signal validation for AI trading bots.

MIT License Python 3.11+ MCP Compatible Claude Skill

Before your trading bot places any order, Trading-RIL runs a peer review of the signal using three independent research engines. Like an academic paper reviewed before publication — except it runs in 45 seconds and costs ~$0.03.

What It Does

Every trading signal gets reviewed by three layers before execution:

Layer Engine What It Adds
Layer 0 Bull/Bear Debate (TradingAgents inspired) Structured debate between optimist and pessimist agents
Layer 1 OASIS Crowd Simulation 50 trader agents argue for 5 rounds → dissent_rate
Layer 2 MiroFish Swarm Intelligence Swarm sentiment direction + confidence score

Output: gate0_pass (True/False) + confidence_modifier (-0.05 to +0.05) + research_brief (human-readable)

The Key Signal Nobody Else Has: dissent_rate

dissent_rate = 0.18  → Strong consensus → lower threshold (more trades)
dissent_rate = 0.43  → Market confused → raise threshold (sit tight)

High dissent means the market is genuinely split. Traditional sentiment scoring misses this entirely.

Quick Start

pip install trading-ril
from trading_ril import RILGate0

# Layer 0 only (Bull/Bear debate). No external state required.
gate = RILGate0(anthropic_api_key="sk-ant-...")

result = gate.evaluate(
    instrument="MGC",           # Micro Gold Futures
    strategy="MACRO_GOLD",
    signal_confidence=0.93,
    news_context="Fed holds rates. Gold edges higher on dollar weakness.",
)

print(result["gate0_pass"])           # True
print(result["confidence_modifier"])  # -0.010 (research agrees - ease threshold)
print(result["research_brief"])       # "MGC MACRO_GOLD | Research:Overweight | Crowd:n/a | Swarm:n/a | ..."

Enabling all 3 layers (optional)

By default Trading-RIL runs Layer 0 only (Bull/Bear debate). Layers 1 (OASIS crowd) and 2 (MiroFish swarm) require pre-computed daily signals stored in your own Firestore project — populated by trading-ril-morning once per day before market open.

To enable Layers 1 + 2, pass firestore_project:

gate = RILGate0(
    anthropic_api_key="sk-ant-...",
    firestore_project="your-gcp-project-id",  # reads tah2_oasis_signals + tah2_mirofish_signals
)

And populate your Firestore once per day (typically 8am market local time):

trading-ril-morning --instruments MGC MCL MES MNQ MHG MNG \
                    --firestore-project your-gcp-project-id

Cost note: the morning batch costs ~$0.08 (50 agents × 5 rounds for 6 instruments). Per-signal Layer 0 review is ~$0.03. Total: $0.38/day for 10 trades. Without the morning batch, you only pay the per-signal cost ($0.03/trade).

As a Claude Skill / MCP Server

Add to Claude Code (stdio, runs locally):

claude mcp add trading-ril -- uvx trading-ril-server

Or connect to the hosted MCP server (HTTP):

claude mcp add --transport http trading-ril https://trading-ril-1073730545783.us-central1.run.app/mcp

The hosted server runs Layer 0 only (no Firestore — keeps it stateless and free for everyone). To get all 3 layers from the hosted server, pass your own firestore_project to the tool:

Review this trade with my Firestore: MGC, MACRO_GOLD, confidence 0.93,
firestore_project=my-gcp-project-id, news: "Fed holds rates"

(Your GCP project's Firestore needs tah2_oasis_signals and tah2_mirofish_signals collections — populated by trading-ril-morning. The hosted server's service account does not have read access to your Firestore — it uses your project's own credentials via the MCP tool argument.)

Then in Claude Code, ask:

Review this gold trade: MGC, MACRO_GOLD strategy, confidence 0.93,
news: "Fed holds rates steady"

Supported Instruments

Symbol Name Typical Drivers
MGC Micro Gold Fed, DXY, inflation, ETF flows
MCL Micro Crude Oil OPEC, EIA, demand
MES Micro S&P 500 Earnings, Fed, VIX
MNQ Micro Nasdaq Tech earnings, rates
MHG Micro Copper China PMI, EV demand
MNG Micro Natural Gas Weather, storage
Custom Any instrument You define the context

Morning Batch Mode

Run once before market open. Populates all six instruments:

trading-ril-morning --instruments MGC MCL MES MNQ MHG MNG

Outputs dissent_rate + direction + confidence per instrument. Gate 0 reads these instantly — no simulation overhead per trade.

Research Foundation

Trading-RIL synthesizes five academic frameworks:

Paper Institution Contribution
TradingAgents Tauric Research Bull/Bear debate framework
FinMem Stanford/IEEE 3-layer memory architecture
FinAgent Multimodal AI Dual-level reflection
OASIS Oxford/KAUST/Imperial Social simulation engine
ContestTrade FinStep-AI Competitive agent ranking

Cost

Component Daily Cost
Morning batch (6 instruments) ~$0.08
Per-signal review (10/day) ~$0.30
Total ~$0.38/day ≈ $11.50/month

Built entirely on open source. MIT licensed. No per-seat fees. No cloud lock-in.

Who Built This

Trading-RIL is the open source release of the research layer built for TAH-2 — a personal commodity futures trading system on IBKR PRO.

TAH-2 paper trades on GLOBEX micro futures (MGC, MCL, MES, MNQ, MHG, MNG). Every signal goes through this peer review before execution.

Contributing

PRs welcome. Areas that need help:

  • Additional instrument contexts (crypto, equity, FX)
  • More agent personas for OASIS simulation
  • Integration examples (Alpaca, Interactive Brokers, Binance)
  • Backtesting framework

License

MIT. Do whatever you want with it. If it makes you money, consider contributing back.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trading_ril-1.0.3.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trading_ril-1.0.3-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file trading_ril-1.0.3.tar.gz.

File metadata

  • Download URL: trading_ril-1.0.3.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for trading_ril-1.0.3.tar.gz
Algorithm Hash digest
SHA256 83cd48a31d4eecf7ab39a72310f07f7779783651694cfd51380032bdda5a5b4c
MD5 763821fd09015fbd5fe896c0b7b33141
BLAKE2b-256 6aca410e3b325e6f527ed0a00006c62d584da755335a7109ad17ce7ea5e72d3a

See more details on using hashes here.

File details

Details for the file trading_ril-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: trading_ril-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for trading_ril-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 05a3cb90450af68748affd4451711eb73f9467c99faf1608d793f51f1c23431c
MD5 dd41f8df0b06a68c8a8f3d6f546ba286
BLAKE2b-256 f278dbe7e2f5886b2b77492062184f5bbaf6279034852b412cb62a045354c0c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page