How an AI trading agent gets a compact market-state brief in one API call
Short answer: don't put raw OHLCV candles in the model's context. Call one endpoint that returns the digested market state — compact candles, patterns, support/resistance, regime, and interpreted indicators — small enough to drop straight into a prompt or read from an MCP tool.
The problem with raw candles
The instinct when wiring market data into an LLM agent is to fetch the last few hundred OHLCV candles and paste them in. Two things go wrong:
- Token cost. A few hundred candles is a big, repetitive block of numbers, re-sent on every turn. It dominates the context window and the bill.
- Hallucination on numbers. LLMs are weak at deriving structure — trendlines, support/resistance, indicator values — from raw number arrays. They confidently get it wrong.
What a market-state brief contains
patternfetch does the structural work deterministically, server-side, and returns a compact brief per (ticker, timeframe):
- Compact candles + SAX shape signature — the price path, compressed.
- Chart & candlestick patterns — double top/bottom, head & shoulders, engulfing, hammer, doji.
- Support / resistance clusters — the levels that actually matter right now.
- Trend / regime — a label for the current state.
- Interpreted indicators — RSI / EMA / ATR as state, not just raw values.
- Historical analogs — similar past windows and how they resolved (informational, not a prediction).
- A one-line summary the agent can reason over directly.
The one call
# 1) get a free key
curl -X POST https://patternfetch.com/v1/keys -d '{"email":"you@example.com"}'
# 2) get a brief
curl -X POST https://patternfetch.com/v1/brief \
-H "authorization: Bearer pf_..." \
-d '{"ticker":"BTC/USDT","timeframe":"4h"}'
Feed the returned brief — not the raw candles — into the model. Other endpoints: /v1/delta (what changed since last brief), /v1/candles (compact codec only), /v1/analogs (historical analogs). Full schema in the OpenAPI spec and llms.txt.
From an MCP agent
If your agent speaks MCP, point it at the patternfetch MCP server and call patternfetch_brief directly — no glue code. Tools: patternfetch_brief, patternfetch_delta, patternfetch_analogs, patternfetch_capabilities. Billed per call via x402 (USDC on Base, no account) or Stripe.