> For the complete documentation index, see [llms.txt](https://maiga.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maiga.gitbook.io/docs/maiga-tech/ai-technology/multi-venue-mcp.md).

# Multi venue MCP

### 1. Connector Layer: CEX & AMM Adapters

Each venue (Binance, OKX, Uniswap, Hyperliquid, etc.) is fronted by a **Connector** microservice that implements a unified interface

* **CEX adapters** talk REST/WebSocket APIs, handle rate-limits, and parse order-book, trade, and funding-rate endpoints.
* **AMM adapters** poll on-chain subgraphs or use direct RPC calls to fetch `get_pool_state` (reserves, fees, token balances) and assemble “virtual order books” by inverting the constant-product curve.

All connectors register themselves with the MCP Server’s service registry, advertising capabilities (`supports_order_book`, `supports_swap`, etc.).

### 2. MCP Server: Context Aggregation & Normalization

The MCP Server performs:

1. **Fan-Out Fetch**
   * In parallel, calls each Connector’s `get_order_book`, `get_trades`, and, for AMMs, `get_pool_state`.
2. **Normalization**
   * Maps CEX bids/asks and AMM “swap curve samples” into a unified `OrderBook` object
   * Embeds pool reserves & implied price tiers under `amm_markets`.
3. **Delta Tracking**
   * If `since` is provided, only deltas (new/updated price levels, trades, pool changes) are included to minimize payload.
4. **Merge & Return**
   * Aggregates all venue data into one MCP Context Packet

### 3. Agent Inference: Signal Processing & Analysis

Inside a **TEE-protected enclave**, the MaigaXBT agent:

1. **Ingests** the MCP Context Packet (JSON) and:
   * Converts order books into time-series arrays.
   * Transforms AMM reserves into marginal price curves.
   * Extracts funding-rate trends and volume aggregates.
2. **Feature Engineering**
   * Computes cross-venue liquidity imbalances, price spreads, funding deviations, and on-chain flow ratios.
   * Applies sliding-window volatility measures and social-sentiment embeddings (if multimodal inputs are provided).
3. **Model Inference**
   * Passes engineered features into a neural network (e.g., Llama-based or custom MLP) to output
4. **Risk Check** (in-enclave)
   * Verifies aggregate exposure limits (e.g., max 10 BTC open across venues).
   * Applies position-size caps based on current volatilities.

### 4. Execution: Automated Trade & Swap Calls

The agent then posts its orders to the MCP Server:

1. **Smart Routing**
   * For CEX orders: may further split a large `2.5 BTC` buy across Binance and OKX based on real-time depth.
   * For AMM swaps: calculates optimal path and slippage tolerances.
2. **Atomic Execution**
   * Uses either native OCO/ICEBERG features on CEXs or bundling via Flashbots (for AMM swaps) to ensure either all legs succeed or are rolled back.
3. **Fill Reporting**
   * Streams back a combined `FillReport` with per-venue fills, average fill prices, and gas/fee breakdowns.

### 5. Reporting & Post-Trade Analysis

All context packets, signal decisions, and fill reports are logged to a time-series store. Downstream “Reporting Services” can:

* **Generate PnL Dashboards**
  * Query aggregate fills vs. average execution price across CEX+AMM.
* **Collateral & Fee Reports**
  * Break down gas spent on AMM swaps vs. CEX taker fees.
* **Performance Analytics**
  * Compare model confidence vs. actual profit, refine model hyperparameters.

### 6. End-to-End Automation Loop

1. **Loop Scheduling**
   * A cron-style scheduler inside the agent enclave triggers every minute (or on event hooks) to fetch a new MCP context.
2. **Continuous Learning**
   * Execution and outcome data feed back into an on-chain “Proof-of-Trading” smart contract; later batch-pulled for model retraining.
3. **Failover & Alerts**
   * If a venue connector fails, the MCP Server signals the agent, which can either pause or reroute orders automatically.
4. **Audit & Compliance**
   * All requests/responses are signed inside the enclave; an off-chain auditor can verify the chain of custody before funds are unlocked in PoT.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://maiga.gitbook.io/docs/maiga-tech/ai-technology/multi-venue-mcp.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
