metals-mcp_first_idea.md 3.6 KB

Swissquote-Based Market Data MCP Server

Abstract

This paper proposes a lightweight Market Context Protocol (MCP) server that ingests real-time bid/ask quotes from Swissquote’s public forex data feed and exposes normalized price and candle data as reusable tools for downstream applications. The system is designed for macro analysis, market orientation, and local-first architectures where free and consistent data is preferred over institutional-grade feeds.


1. Motivation

Most free financial APIs provide aggregated or delayed data with limited transparency. Swissquote’s public BBO feed offers a rare combination of:

  • Low latency
  • Direct bid/ask quotes
  • Broad instrument coverage (FX + metals)

However, it lacks:

  • Historical data
  • Candle aggregation
  • Stable API abstraction

This project addresses these gaps by introducing an MCP-compatible data layer.


2. System Architecture

Data Flow:

Swissquote Feed → Ingestion Layer → Tick Store → Candle Engine → MCP Server → Client Apps

Components:

  1. Ingestion Layer

    • Polls Swissquote endpoints at fixed intervals
    • Normalizes bid/ask + timestamp
    • Computes mid-price
  2. Tick Store

    • Append-only time series storage
    • Retains raw ticks for replay and recomputation
    • Suggested: SQLite / TimescaleDB / in-memory ring buffer
  3. Candle Engine

    • Aggregates ticks into OHLC candles
    • Uses clock-aligned 5m candles as the base unit
    • Candle windows are fixed, e.g. 00:00–00:05, 00:05–00:10
    • Handles:

      • Missing ticks
      • Market gaps
      • Session boundaries
  4. MCP Server

    • Exposes tools:

      • get_price(symbol)
      • get_candles(symbol, timeframe, limit)
      • get_last_candle(symbol, timeframe)
    • Stateless interface over stateful backend


3. Data Model

Tick:

{
  "symbol": "XAU/USD",
  "bid": 2334.12,
  "ask": 2334.45,
  "mid": 2334.285,
  "timestamp": 1710000000000
}

Candle:

{
  "symbol": "XAU/USD",
  "timeframe": "1m",
  "open": 2330.10,
  "high": 2335.00,
  "low": 2329.80,
  "close": 2334.20,
  "start": 1710000000000
}

4. Design Principles

  • Determinism over accuracy Consistent data is more valuable than theoretically perfect data.

  • Clock-aligned candles A fixed 5-minute window is the primary market unit, even if not every trade is observed.

  • Raw data preservation Store ticks when useful, but the system can remain simple if 5m candles are the base layer.

  • Separation of concerns Ingestion, aggregation, and serving are independent layers.

  • Market orientation first The goal is perception and regime reading, not execution.

  • Stateless interface MCP tools should not depend on internal state assumptions.


Intended shape

  • Primary instruments: gold, silver, and a small relevant subset of metals/forex pairs
  • Primary timeframe: 5m
  • Retention target: 180 days to 1 year, depending on storage needs
  • Use case: understand market structure, world dynamics, and sentiment context

5. Limitations

  • Broker-derived pricing (not exchange-grade)
  • No guaranteed uptime or SLA
  • Possible anomalies during market open/close

6. Extensions

  • Multi-source aggregation (fallback feeds)
  • Volume estimation heuristics
  • Spread analytics
  • Event detection (volatility spikes)

7. Conclusion

A Swissquote-based MCP server provides a robust and flexible foundation for macro-level analysis and experimental trading systems. While not suitable for high-frequency trading, it offers an excellent balance between cost, control, and data quality for independent developers.