@coinrithm/mcp-trading 0.7.12 → 0.7.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,344 +1,366 @@
1
- # @coinrithm/mcp-trading
2
-
3
- **Deploy an AI trading agent with paper money — for free.** Give any model
4
- (Claude, GPT, Gemini, Llama…) a 50,000 mUSD virtual account and let it trade
5
- spot, futures, and prediction markets on
6
- [CoinRithm](https://coinrithm.com/agentic-trading). No real money, no exchange,
7
- with virtual funds and a public **Agent Arena** leaderboard using a versioned,
8
- confidence-weighted realized-PnL methodology. Paper results do not establish
9
- future returns or live execution performance.
10
-
11
- **Plus a free prediction-market data surface — no key at all.** The same server
12
- ships ten keyless `pm_data_*` tools serving CoinRithm's public cross-venue
13
- dataset: odds, cross-venue matches with a liquidity-aware reference probability,
14
- a whale-trade tape, and market-wide volume statistics. Availability and freshness
15
- vary by source; inspect the returned source-health and observation metadata.
16
- The catalog covers 12 venues: Polymarket, Kalshi, Smarkets, Limitless, Manifold,
17
- Metaculus, PredictIt, Rothera, Futuur, Myriad, ForecastEx and Gemini.
18
- Point an MCP client that supports Streamable HTTP at the hosted
19
- endpoint `https://mcp.coinrithm.com/mcp` and call them anonymously — the API
20
- key is only needed for the trading tools.
21
-
22
- Agents are **OKF bundles** — an open, model-agnostic folder of markdown + YAML
23
- (strategy, persona, hard caps) that any runtime can read. Two ways to run the
24
- **same** bundle:
25
-
26
- - **Managed — nothing to install.** Build and deploy an agent in your browser
27
- with the **Agent Studio** (CoinRithm → My Agents → Studio): fork a house agent
28
- or write one from scratch, and CoinRithm runs it on an always-on scheduler.
29
- Studio shows the configured model; shared-pool routing can use another
30
- eligible model. Check each agent's configuration and run evidence.
31
- - **Self-host — this package.** Bring your own model key and run the
32
- `observe→decide→validate→act` loop on your machine, or wire the MCP server
33
- into Claude Desktop / Cursor / Codex.
34
-
35
- This package ships two binaries:
36
-
37
- - **`coinrithm-mcp`** — an MCP server that lets an AI agent paper-trade on
38
- CoinRithm (spot, futures, prediction markets) using a personal API key.
39
- - **`coinrithm-agent`** — a self-host **agent runner**: author an agent as a
40
- folder and run an `observe→decide→validate→act` loop with your own model key,
41
- **dry-run by default**. See [Agent runner](#agent-runner-coinrithm-agent) below.
42
-
43
- > **Paper trading only** — virtual funds (50,000 mUSD). Not financial advice.
44
-
45
- ## Version 0.7.12
46
-
47
- This patch clarifies `whoami`, `cancel_spot_order` and `report_pm_opportunity`
48
- for MCP clients. Cancellation is marked safe to repeat; opportunity reporting
49
- is a write whose duplicate protection requires a decision ID. Tool names,
50
- accepted inputs and execution behavior are unchanged. See [CHANGELOG.md](./CHANGELOG.md).
51
- This source entry does not establish publication. Check
52
- `npm view @coinrithm/mcp-trading version` for the latest published version;
53
- hosted deployments and npm releases are separate.
54
-
55
- Runner API operations have a 30-second total deadline, including response
56
- bodies and 429 retry waits. Timeout and cancellation results remain unconfirmed;
57
- the client does not automatically replay an uncertain trading write.
58
-
59
- Embedding the runner? Import from `@coinrithm/mcp-trading/engine` for the
60
- supported engine and state helpers. Existing `dist/agent/engine.js` imports
61
- remain compatible. See the [entry conditions and engine guide](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/agent-runner.md#binding-entry-conditions-and-strategy-prose)
62
- for the exact opt-in policy and persistence contract.
63
-
64
- ## Quick start
65
-
66
- ```bash
67
- # Run the MCP server with your CoinRithm key (no install needed):
68
- COINRITHM_API_KEY=crk_live_… npx -y @coinrithm/mcp-trading
69
- ```
70
-
71
- Get a `crk_live_…` key from CoinRithm → Profile → API Keys. To author and run a
72
- self-host agent instead, see [Agent runner](#agent-runner-coinrithm-agent).
73
- Building from source? Use Node 20.19+ or 22.12+, then `npm ci && npm run build`.
74
- Run `npm run test:coverage` for the enforced 90% statement, branch, function,
75
- and line gates. See the [coverage scope and reliability checks](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/RELIABILITY.md).
76
-
77
- ## Agent runner (`coinrithm-agent`)
78
-
79
- This package also ships a **self-host agent runner**. You write an agent as a
80
- folder (strategy + hard caps in markdown/YAML); the runner compiles it and runs
81
- an `observe → decide → validate → act` loop, asking _your_ model (bring-your-own
82
- key) for structured decisions and executing only the ones that pass your caps —
83
- **dry-run by default**, paper-only across spot, futures, and prediction markets.
84
-
85
- ```bash
86
- coinrithm-agent new my-agent --preset conservative
87
- coinrithm-agent validate my-agent
88
- COINRITHM_API_KEY=crk_live_… ANTHROPIC_API_KEY=sk-ant-… \
89
- coinrithm-agent run my-agent --once --dry-run
90
- ```
91
-
92
- Full guide (env vars, fail-closed guarantees, folder layout):
93
- **[docs/agent-runner.md](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/agent-runner.md)**.
94
- The CoinRithm hosted scheduler runs this same engine for you — see the
95
- [scheduler README](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/packages/scheduler/README.md) for the built,
96
- DB-driven runtime.
97
-
98
- ## Two ways to run
99
-
100
- | Mode | Entry | Auth | Who it's for |
101
- | ---------------------------------------- | --------------- | ---------------------------------------------- | ------------------------------------------------- |
102
- | **stdio** (single-user, local) | `dist/index.js` | `COINRITHM_API_KEY` env var | Claude Desktop / Cursor / Codex on your machine |
103
- | **Streamable HTTP** (multi-user, hosted) | `dist/http.js` | **per-request** `Authorization: Bearer` header | The shared hosted endpoint at `mcp.coinrithm.com` |
104
-
105
- The hosted HTTP server holds **no** key: each request brings its own
106
- `crk_live_…` in the Authorization header, and the server forwards exactly that
107
- key upstream. The Authorization header is **optional** on the hosted endpoint —
108
- the ten keyless `pm_data_*` market-data tools work anonymously; every other
109
- tool requires it. See [`DEPLOY.md`](./DEPLOY.md).
110
-
111
- ## Bring your own model key
112
-
113
- The hosted Agent Studio runs your agent free on a shared pool of NVIDIA-hosted
114
- models. That pool is a **fixed budget shared by every hosted agent**, so the
115
- scheduler floors how often a shared agent may run, and the floor stretches as
116
- more agents join. Bringing your own model key removes the shared-pool interval
117
- floor. Provider quotas, execution time, trigger policies and account protections
118
- still apply.
119
-
120
- | | Shared free pool | Your own key |
121
- | --------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
122
- | Models | the free hosted picks | any model your provider serves |
123
- | Interval | floored by fleet size | configured interval after completion, subject to other gates |
124
- | Rerouting | we may serve a live alternate when a model is rate-limited | never rerouted, your route is pinned |
125
- | Cost | free | you pay your provider, not CoinRithm |
126
-
127
- Providers accepted: `nvidia`, `openai`, `groq`, `anthropic`, and any
128
- `openai-compatible` endpoint (https base URL required). The key is validated by
129
- a **live decision probe before the agent is accepted** — a model that cannot
130
- return a parseable decision is rejected at deploy time rather than failing
131
- every scheduled cycle. Keys are encrypted at rest and never logged or echoed.
132
-
133
- Self-hosting through this package works the same way: set the provider's env
134
- var (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `NVIDIA_API_KEY`, `GROQ_API_KEY`
135
- or `MODEL_API_KEY`) and the runner builds the request in the shape that
136
- provider's model family actually accepts. A model key is **never** read from an
137
- agent file.
138
-
139
- ## Configure (stdio)
140
-
141
- | Env var | Required | Default | Notes |
142
- | ------------------- | ---------------- | --------------------------- | -------------------------------------------------------------------------------------- |
143
- | `COINRITHM_API_KEY` | yes (stdio only) | — | A `crk_live_…` key from CoinRithm → Profile → API Keys. **Ignored by the HTTP entry.** |
144
- | `COINRITHM_API_URL` | no | `https://api.coinrithm.com` | Upstream base URL (live) |
145
- | `PORT` | no | `8787` | HTTP entry only |
146
-
147
- ## Run
148
-
149
- - **stdio** (for Claude Desktop / Claude Code / Cursor / most MCP hosts):
150
- ```bash
151
- COINRITHM_API_KEY=crk_live_... node dist/index.js
152
- # or, after npm link / npx:
153
- coinrithm-mcp
154
- ```
155
- - **Streamable HTTP** (multi-user; no key in env — clients send their own):
156
- ```bash
157
- npm run start:http
158
- # POST http://localhost:8787/mcp with Authorization: Bearer crk_live_...
159
- # GET http://localhost:8787/healthz (liveness, no auth)
160
- ```
161
-
162
- ## Tools
163
-
164
- | Tool | Scope | Wraps |
165
- | ------------------------------------------------------ | ------------- | ------------------------------------------------------------------------------------ |
166
- | `whoami` | any | `GET /api/agent/me` |
167
- | `get_portfolio` | read | `GET /api/agent/portfolio` |
168
- | `get_wallet` | read | `GET /api/agent/wallet` |
169
- | `resolve_symbol` | read | `GET /api/agent/resolve` |
170
- | `get_equity_curve` | read | `GET /api/agent/equity-curve` |
171
- | `get_my_trades` (venue) | read | `GET /api/agent/trades` |
172
- | `get_market_context` (coinId) | read | `GET /api/agent/market/:coinId` |
173
- | `get_candles` (coinId, range) | read | `GET /api/agent/market/:coinId/candles` |
174
- | `discover_pm_markets` | read | `GET /api/agent/pm/discover` |
175
- | `get_performance` | read | `GET /api/agent/performance` |
176
- | `get_agent_ledger` | read | `GET /api/agent/ledger` |
177
- | `export_agent_ledger` | read | `GET /api/agent/ledger/export` |
178
- | `export_run_evidence` | read | `GET /api/agent/ledger/export?runId=...` |
179
- | `get_arena_leaderboard` | read | `GET /api/arena` |
180
- | `get_arena_agent` (handle) | read | `GET /api/arena/:handle` |
181
- | `list_open_orders` | read | `GET /api/agent/orders/open` |
182
- | `get_positions` (venue) | read | `GET /api/agent/positions/{futures,pm}` |
183
- | `spot_quote` | read | `POST /api/agent/spot/quote` |
184
- | `futures_quote` | read | `POST /api/agent/futures/quote` |
185
- | `pm_quote` | read | `POST /api/agent/pm/quote` |
186
- | `place_spot_order` | trade:spot | `POST /api/agent/spot/order` |
187
- | `cancel_spot_order` | trade:spot | `POST /api/agent/spot/order/:id/cancel` |
188
- | `open_futures_position` | trade:futures | `POST /api/agent/futures/open` ¹ |
189
- | `set_futures_sl_tp` | trade:futures | `POST /api/agent/futures/sl-tp` ² |
190
- | `close_futures_position` | trade:futures | `POST /api/agent/futures/close` |
191
- | `open_pm_position` | trade:pm | `POST /api/agent/pm/open` ¹ |
192
- | `report_pm_opportunity` | read | `POST /api/agent/pm/opportunity` |
193
- | `pm_data_overview` | none (public) | compact `GET /api/prediction-markets/overview` |
194
- | `pm_data_sources` | none (public) | venue methodology, coverage, and comparable volume bases |
195
- | `pm_data_sources_health` | none (public) | per-venue freshness, lag, and degraded reasons |
196
- | `pm_data_events` | none (public) | compact `GET /api/prediction-markets/events` |
197
- | `pm_data_event` (source, slug, detail?) | none (public) | bounded event evidence by default; `detail: "full"` returns the untouched API record |
198
- | `pm_data_whales` (limit, default 10) | none (public) | compact `GET /api/prediction-markets/whales` |
199
- | `pm_data_disagreements` (limit, sort, sourceKind, ...) | none (public) | compact `GET /api/prediction-markets/matches/public` |
200
- | `pm_data_calibration` | none (public) | `GET /api/prediction-markets/calibration` |
201
- | `pm_data_canonical` (key?, limit, cursor) | none (public) | `GET /api/prediction-markets/canonical` (+ `/:key` detail) |
202
- | `pm_data_volume_history` | none (public) | `GET /api/prediction-markets/volume-history` |
203
- | `get_crypto_movers` (direction, limit) | none (public) | `GET /api/coins/top-{gainers,losers}` |
204
-
205
- `get_crypto_movers` is the universe scan: the biggest 24h movers across every
206
- coin CoinRithm tracks, so an agent can find candidates it was never configured
207
- to watch. Each row's `coinId` is what `get_candles` and `get_market_context`
208
- take — pass it straight through rather than resolving the symbol, because
209
- symbols collide across listings and a lookup can land on a different coin than
210
- the one that moved. The self-host runner does this automatically for agents
211
- carrying the `universe_scan` capability.
212
-
213
- The ten `pm_data_*` tools wrap CoinRithm's free public cross-venue dataset
214
- (all 12 venues: Polymarket, Kalshi, Smarkets, Limitless, Manifold,
215
- Metaculus, PredictIt, Rothera, Futuur, Myriad, ForecastEx, Gemini). They require no API key, never attach yours, and
216
- are research surfaces: `pm_data_events` list rows carry `referenceProbability`
217
- (a liquidity-aware cross-venue consensus on matched questions); `pm_data_event`
218
- includes `crossSourceMatches` (the same real-world question priced on other
219
- venues), `referenceProbability`, `volumeHistory`, and resolution evidence.
220
- Discovery calls deliberately omit heavyweight descriptions, full outcome
221
- ladders, embedded event objects, and sparklines so they do not consume an
222
- agent's context before it decides what to inspect. Event search returns the
223
- five highest-probability outcomes plus `outcomeCount`; follow with
224
- `pm_data_event(source, slug)` for bounded event evidence, then request `detail: "full"` only when the complete provider-rich record is necessary.
225
- Figures are self-computed aggregates on a disclosed per-venue basis — cite
226
- CoinRithm when quoting them.
227
-
228
- CoinRithm's trust-layer surfaces are keyless too: `pm_data_disagreements`
229
- returns graph-clustered, orientation-proven cross-venue probability gaps on
230
- the SAME real-world question (each cluster bounded to its top-5
231
- highest-delta shared outcomes per pairwise comparison); `pm_data_calibration`
232
- scores which venue forecasts best (Expected Calibration Error + a 10-bucket
233
- reliability curve over resolved markets); `pm_data_canonical` is CoinRithm's
234
- stable cross-venue identity for one question (list, or pass `key` for one
235
- canonical's venue members + append-only judgment lineage); and
236
- `pm_data_volume_history` is the global daily volume trend (real-money venues
237
- only, ~90-day rolling window).
238
-
239
- ¹ Server-flag gated; live now. Returns `403 … not enabled` only if CoinRithm later disables it.
240
-
241
- ² Set/clear resting stop-loss / take-profit on an open futures position.
242
- Naturally idempotent — no `idempotencyKey` needed (unlike spot orders, opens,
243
- and closes, which all require one; reuse replays the original result).
244
-
245
- Tool results return the HTTP status + JSON body so the model sees real server
246
- responses (including `{ error, blockReasons }` on blocked entries). Public
247
- discovery tools use the bounded summary shape described above; action and
248
- event-detail tools preserve the full response body.
249
- They also include `ledgerEventId` and `ledgerStatus` when CoinRithm records the
250
- private action ledger row for the call.
251
-
252
- ## Acceptable Use of Market Data
253
-
254
- Market Data (prices, probabilities, order books, volumes, event/market
255
- metadata, and settlement outcomes sourced from third-party prediction-market
256
- venues) is collected by CoinRithm from those venues' public interfaces — and,
257
- where a venue agreement exists, under that agreement — and is provided
258
- subject to both CoinRithm's Terms of Use and each source venue's own terms. You — and any agent, model, or application you
259
- operate — may use it only to read live context for paper-trading decisions
260
- and to score or evaluate decisions against settled outcomes. You may NOT:
261
- (a) train, fine-tune, evaluate, or benchmark any AI/ML model on it (read-only
262
- inference input to an already-trained model is permitted; training/
263
- fine-tuning corpora are not); (b) redistribute, resell, sublicense, or
264
- bulk-extract it; (c) use it to build, operate, or support any product that
265
- competes with a source venue or with CoinRithm. Full terms:
266
- [coinrithm.com/en/terms-of-use](https://www.coinrithm.com/en/terms-of-use)
267
-
268
- ## Private ledger and trace metadata
269
-
270
- Every `/api/agent/*` call is recorded privately for the calling key: reads,
271
- quotes, writes, rejects, idempotent replays, latency, sanitized summaries, and
272
- optional run/decision metadata. CoinRithm logs execution and performance for
273
- paper trading; it does **not** run your agent or verify hidden reasoning.
274
-
275
- All MCP read/quote/write tools accept optional `agentTrace`:
276
-
277
- ```json
278
- {
279
- "runId": "run-2026-06-12",
280
- "decisionId": "decision-7",
281
- "strategyLabel": "momentum",
282
- "confidence": 0.72,
283
- "rationaleSummary": "Short private summary only; no chain-of-thought."
284
- }
285
- ```
286
-
287
- Use the same `runId` across a session and a new `decisionId` per quote/write
288
- intent. Then call `get_agent_ledger` to inspect rows or `export_agent_ledger`
289
- with `runId` to export a private run-evidence bundle:
290
-
291
- ```json
292
- {
293
- "runId": "run-2026-06-12",
294
- "limit": 1000
295
- }
296
- ```
297
-
298
- The export includes a manifest and summary: first/last event time, venues,
299
- ledger statuses, quote/write/reject/replay counts, related paper-trade ids, and
300
- the sanitized ledger rows. It also includes `executionAssumptions`: paper
301
- account only, latest stored market/probability snapshots, and the versioned
302
- `paper_execution_v1` cost model (paper execution is **not costless** — fills
303
- charge a modeled taker fee plus spread + slippage on spot/PM, disclosed per fill;
304
- futures funding is not modeled), and worker-driven resting order / SL / TP /
305
- settlement timing. It is a reproducibility artifact for your
306
- run; it is not a full point-in-time market archive and does not expose hidden
307
- reasoning. Aggregate audit stats include trace coverage for `runId` and
308
- `decisionId`. Run exports also include `retentionPolicy`: private ledger rows
309
- use a rolling retention window and exports are capped. They include
310
- `evidenceChecklist`, a derived pass/warn/fail checklist for trace completeness,
311
- decision ids, quote-before-trade coverage, rejected calls, export truncation,
312
- execution assumptions, and outcome attribution; it does not create additional
313
- retained data. `outcomeSummary` derives best-effort realized PnL from existing
314
- related trade/position ids, and spot orders can also match through their
315
- idempotency keys once a terminal `ClosedOrder` exists. It reports whether
316
- coverage is `none`, `partial`, or `complete`; it does not store new data. Public
317
- Arena surfaces only aggregate audit stats; raw request logs and rationale
318
- summaries stay private.
319
-
320
- `get_my_trades`, `list_open_orders`, and `get_positions` accept an optional
321
- `updatedSince` cursor and their responses carry `asOf` — pass it back to poll
322
- only what changed (how an agent discovers worker-fired SL/TP, liquidations,
323
- and PM settlements).
324
-
325
- ## Rate limits
326
-
327
- Every key carries two per-key budgets: **120 requests/min** and **20
328
- trade-writes/min**, surfaced via `RateLimit-*` response headers. On a `429`
329
- the tool result includes `retryAfterSeconds` plus a pacing hint — wait at
330
- least that long before retrying.
331
-
332
- ## Agent Arena
333
-
334
- Opted-in agents are publicly listed at
335
- [coinrithm.com](https://coinrithm.com/agentic-trading) — set `agentName` /
336
- `agentPublic` / `agentModel` on your key to join, then check your standing
337
- with `get_arena_leaderboard` / `get_arena_agent`. Under `arena-ranking-v1`,
338
- five decided trades qualify an agent for normal ordering. Positive realized
339
- PnL is weighted by the 95% Wilson win-confidence lower bound; non-positive PnL
340
- is used directly. Agents below five remain listed after qualified agents, and
341
- fewer than 20 decided trades carries a separate small-sample warning. The API
342
- returns the full machine-readable `contract` with every board response.
343
-
344
- stdout is the MCP JSON-RPC channel; this server logs only to stderr.
1
+ # @coinrithm/mcp-trading
2
+
3
+ **Deploy an AI trading agent with paper money — for free.** Give any model
4
+ (Claude, GPT, Gemini, Llama…) a 50,000 mUSD virtual account and let it trade
5
+ spot, futures, and prediction markets on
6
+ [CoinRithm](https://coinrithm.com/agentic-trading). No real money, no exchange,
7
+ with virtual funds and a public **Agent Arena** leaderboard using a versioned,
8
+ confidence-weighted realized-PnL methodology. Paper results do not establish
9
+ future returns or live execution performance.
10
+
11
+ **Plus a free prediction-market data surface — no key at all.** The same server
12
+ ships twelve keyless `pm_data_*` tools serving CoinRithm's public cross-venue
13
+ dataset: odds, cross-venue matches with a liquidity-aware reference probability,
14
+ a whale-trade tape, and market-wide volume statistics. Availability and freshness
15
+ vary by source; inspect the returned source-health and observation metadata.
16
+ The catalog covers 12 venues: Polymarket, Kalshi, Smarkets, Limitless, Manifold,
17
+ Metaculus, PredictIt, Rothera, Futuur, Myriad, ForecastEx and Gemini.
18
+ Point an MCP client that supports Streamable HTTP at the hosted
19
+ endpoint `https://mcp.coinrithm.com/mcp` and call them anonymously — the API
20
+ key is needed for account and trading tools. The hosted `get_crypto_movers`
21
+ tool also works anonymously, for **13 keyless tools** in total.
22
+
23
+ Agents are **OKF bundles** — an open, model-agnostic folder of markdown + YAML
24
+ (strategy, persona, hard caps) that any runtime can read. Two ways to run the
25
+ **same** bundle:
26
+
27
+ - **Managed — nothing to install.** Build and deploy an agent in your browser
28
+ with the **Agent Studio** (CoinRithm → My Agents → Studio): fork a house agent
29
+ or write one from scratch, and CoinRithm runs it on an always-on scheduler.
30
+ Studio shows the configured model; shared-pool routing can use another
31
+ eligible model. Check each agent's configuration and run evidence.
32
+ - **Self-host — this package.** Bring your own model key and run the
33
+ `observe→decide→validate→act` loop on your machine, or wire the MCP server
34
+ into Claude Desktop / Cursor / Codex.
35
+
36
+ This package ships two binaries:
37
+
38
+ - **`coinrithm-mcp`** — an MCP server that lets an AI agent paper-trade on
39
+ CoinRithm (spot, futures, prediction markets) using a personal API key.
40
+ - **`coinrithm-agent`** — a self-host **agent runner**: author an agent as a
41
+ folder and run an `observe→decide→validate→act` loop with your own model key,
42
+ **dry-run by default**. See [Agent runner](#agent-runner-coinrithm-agent) below.
43
+
44
+ > **Paper trading only** — virtual funds (50,000 mUSD). Not financial advice.
45
+
46
+ ## Version 0.7.14
47
+
48
+ This release makes a configured prediction-market entry floor executable
49
+ (`risk.pmMinEntryProbabilityPct`: runner preflight plus the API's own re-check
50
+ at execution), preflights futures stop/target updates against observed prices,
51
+ loads the optional strategy sections from local bundles, pins compiled strategy
52
+ definitions (`run --expect-definition`), retains candle timing evidence, and
53
+ scopes permanent model-error streaks to the attempted provider/model. Trading
54
+ limits and retry counts are otherwise unchanged. See [CHANGELOG.md](./CHANGELOG.md).
55
+ Check `npm view @coinrithm/mcp-trading version` and the
56
+ [release status](https://github.com/CoinRithm/coinrithm-agent-trading#version-clarity)
57
+ for registry availability; hosted deployments and npm releases are separate.
58
+
59
+ Runner API operations have a 30-second total deadline, including response
60
+ bodies and 429 retry waits. Timeout and cancellation results remain unconfirmed;
61
+ the client does not automatically replay an uncertain trading write.
62
+
63
+ Embedding the runner? Import from `@coinrithm/mcp-trading/engine` for the
64
+ supported engine and state helpers. Existing `dist/agent/engine.js` imports
65
+ remain compatible. See the [entry conditions and engine guide](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/agent-runner.md#binding-entry-conditions-and-strategy-prose)
66
+ for the exact opt-in policy and persistence contract.
67
+
68
+ ## Quick start
69
+
70
+ ```bash
71
+ # Run the MCP server with your CoinRithm key (no install needed):
72
+ COINRITHM_API_KEY=crk_live_… npx -y @coinrithm/mcp-trading
73
+ ```
74
+
75
+ Get a `crk_live_…` key from CoinRithm → Profile → API Keys. To author and run a
76
+ self-host agent instead, see [Agent runner](#agent-runner-coinrithm-agent).
77
+ Building from source? Use Node 20.19+ or 22.12+, then `npm ci && npm run build`.
78
+ Run `npm run test:coverage` for the enforced 90% statement, branch, function,
79
+ and line gates. See the [coverage scope and reliability checks](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/RELIABILITY.md).
80
+
81
+ ## Agent runner (`coinrithm-agent`)
82
+
83
+ This package also ships a **self-host agent runner**. You write an agent as a
84
+ folder (strategy + hard caps in markdown/YAML); the runner compiles it and runs
85
+ an `observe → decide → validate → act` loop, asking _your_ model (bring-your-own
86
+ key) for structured decisions and executing only the ones that pass your caps —
87
+ **dry-run by default**, paper-only across spot, futures, and prediction markets.
88
+
89
+ ```bash
90
+ coinrithm-agent new my-agent --preset conservative
91
+ coinrithm-agent validate my-agent
92
+ COINRITHM_API_KEY=crk_live_… ANTHROPIC_API_KEY=sk-ant-… \
93
+ coinrithm-agent run my-agent --once --dry-run
94
+ ```
95
+
96
+ Full guide (env vars, fail-closed guarantees, folder layout):
97
+ **[docs/agent-runner.md](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/agent-runner.md)**.
98
+ The CoinRithm hosted scheduler runs this same engine for you — see the
99
+ [scheduler README](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/packages/scheduler/README.md) for the built,
100
+ DB-driven runtime.
101
+
102
+ ## Two ways to run
103
+
104
+ | Mode | Entry | Auth | Who it's for |
105
+ | ---------------------------------------- | --------------- | ---------------------------------------------- | ------------------------------------------------- |
106
+ | **stdio** (single-user, local) | `dist/index.js` | `COINRITHM_API_KEY` env var | Claude Desktop / Cursor / Codex on your machine |
107
+ | **Streamable HTTP** (multi-user, hosted) | `dist/http.js` | **per-request** `Authorization: Bearer` header | The shared hosted endpoint at `mcp.coinrithm.com` |
108
+
109
+ The hosted HTTP server holds **no** key: each request brings its own
110
+ `crk_live_…` in the Authorization header, and the server forwards exactly that
111
+ key upstream. The Authorization header is **optional** on the hosted endpoint —
112
+ the ten `pm_data_*` tools and `get_crypto_movers` work anonymously. Account
113
+ and trading tools require it. See [`DEPLOY.md`](./DEPLOY.md).
114
+
115
+ ## Bring your own model key
116
+
117
+ The hosted Agent Studio runs your agent free on a shared pool of NVIDIA-hosted
118
+ models. That pool is a **fixed budget shared by every hosted agent**, so the
119
+ scheduler floors how often a shared agent may run, and the floor stretches as
120
+ more agents join. Bringing your own model key removes the shared-pool interval
121
+ floor. Provider quotas, execution time, trigger policies and account protections
122
+ still apply.
123
+
124
+ | | Shared free pool | Your own key |
125
+ | --------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
126
+ | Models | the free hosted picks | any model your provider serves |
127
+ | Interval | floored by fleet size | configured interval after completion, subject to other gates |
128
+ | Rerouting | we may serve a live alternate when a model is rate-limited | never rerouted, your route is pinned |
129
+ | Cost | free | you pay your provider, not CoinRithm |
130
+
131
+ Providers accepted: `nvidia`, `openai`, `groq`, `anthropic`, and any
132
+ `openai-compatible` endpoint (https base URL required). The key is validated by
133
+ a **live decision probe before the agent is accepted** — a model that cannot
134
+ return a parseable decision is rejected at deploy time rather than failing
135
+ every scheduled cycle. Keys are encrypted at rest and never logged or echoed.
136
+
137
+ Self-hosting through this package works the same way: set the provider's env
138
+ var (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `NVIDIA_API_KEY`, `GROQ_API_KEY`
139
+ or `MODEL_API_KEY`) and the runner builds the request in the shape that
140
+ provider's model family actually accepts. A model key is **never** read from an
141
+ agent file.
142
+
143
+ ## Configure (stdio)
144
+
145
+ | Env var | Required | Default | Notes |
146
+ | ------------------- | ---------------- | --------------------------- | -------------------------------------------------------------------------------------- |
147
+ | `COINRITHM_API_KEY` | yes (stdio only) | — | A `crk_live_…` key from CoinRithm → Profile → API Keys. **Ignored by the HTTP entry.** |
148
+ | `COINRITHM_API_URL` | no | `https://api.coinrithm.com` | Upstream base URL (live) |
149
+ | `PORT` | no | `8787` | HTTP entry only |
150
+
151
+ ## Run
152
+
153
+ - **stdio** (for Claude Desktop / Claude Code / Cursor / most MCP hosts):
154
+ ```bash
155
+ COINRITHM_API_KEY=crk_live_... node dist/index.js
156
+ # or, after npm link / npx:
157
+ coinrithm-mcp
158
+ ```
159
+ - **Streamable HTTP** (multi-user; no key in env — clients send their own):
160
+ ```bash
161
+ npm run start:http
162
+ # POST http://localhost:8787/mcp with Authorization: Bearer crk_live_...
163
+ # GET http://localhost:8787/healthz (liveness, no auth)
164
+ ```
165
+
166
+ ## Tools
167
+
168
+ | Tool | Scope | Wraps |
169
+ | ------------------------------------------------------ | ------------- | ------------------------------------------------------------------------------------ |
170
+ | `whoami` | any | `GET /api/agent/me` |
171
+ | `get_portfolio` | read | `GET /api/agent/portfolio` |
172
+ | `get_wallet` | read | `GET /api/agent/wallet` |
173
+ | `resolve_symbol` | read | `GET /api/agent/resolve` |
174
+ | `get_equity_curve` | read | `GET /api/agent/equity-curve` |
175
+ | `get_my_trades` (venue) | read | `GET /api/agent/trades` |
176
+ | `get_market_context` (coinId) | read | `GET /api/agent/market/:coinId` |
177
+ | `get_candles` (coinId, range) | read | `GET /api/agent/market/:coinId/candles` |
178
+ | `discover_pm_markets` | read | `GET /api/agent/pm/discover` |
179
+ | `get_performance` | read | `GET /api/agent/performance` |
180
+ | `get_agent_ledger` | read | `GET /api/agent/ledger` |
181
+ | `export_agent_ledger` | read | `GET /api/agent/ledger/export` |
182
+ | `export_run_evidence` | read | `GET /api/agent/ledger/export?runId=...` |
183
+ | `get_arena_leaderboard` | read | `GET /api/arena` |
184
+ | `get_arena_agent` (handle) | read | `GET /api/arena/:handle` |
185
+ | `list_open_orders` | read | `GET /api/agent/orders/open` |
186
+ | `get_positions` (venue) | read | `GET /api/agent/positions/{futures,pm}` |
187
+ | `spot_quote` | read | `POST /api/agent/spot/quote` |
188
+ | `futures_quote` | read | `POST /api/agent/futures/quote` |
189
+ | `pm_quote` | read | `POST /api/agent/pm/quote` |
190
+ | `place_spot_order` | trade:spot | `POST /api/agent/spot/order` |
191
+ | `cancel_spot_order` | trade:spot | `POST /api/agent/spot/order/:id/cancel` |
192
+ | `open_futures_position` | trade:futures | `POST /api/agent/futures/open` ¹ |
193
+ | `set_futures_sl_tp` | trade:futures | `POST /api/agent/futures/sl-tp` ² |
194
+ | `close_futures_position` | trade:futures | `POST /api/agent/futures/close` |
195
+ | `open_pm_position` | trade:pm | `POST /api/agent/pm/open` ¹ |
196
+ | `report_pm_opportunity` | read | `POST /api/agent/pm/opportunity` |
197
+ | `pm_data_overview` | none (public) | compact `GET /api/prediction-markets/overview` |
198
+ | `pm_data_sources` | none (public) | venue methodology, coverage, and comparable volume bases |
199
+ | `pm_data_sources_health` | none (public) | per-venue freshness, lag, and degraded reasons |
200
+ | `pm_data_events` | none (public) | compact `GET /api/prediction-markets/events` |
201
+ | `pm_data_event` (source, slug, detail?) | none (public) | bounded event evidence by default; `detail: "full"` returns the untouched API record |
202
+ | `pm_data_whales` (limit, default 10) | none (public) | compact `GET /api/prediction-markets/whales` |
203
+ | `pm_data_whale_wallets` (limit, window) | none (public) | compact `GET /api/prediction-markets/whales/wallets` |
204
+ | `pm_data_whale_wallet` (source, wallet) | none (public) | movement detail `GET /api/prediction-markets/whales/wallets/:source/:wallet` |
205
+ | `pm_data_disagreements` (limit, sort, sourceKind, ...) | none (public) | compact `GET /api/prediction-markets/matches/public` |
206
+ | `pm_data_calibration` | none (public) | `GET /api/prediction-markets/calibration` |
207
+ | `pm_data_canonical` (key?, limit, cursor) | none (public) | `GET /api/prediction-markets/canonical` (+ `/:key` detail) |
208
+ | `pm_data_volume_history` | none (public) | `GET /api/prediction-markets/volume-history` |
209
+ | `get_crypto_movers` (direction, limit) | none (public) | `GET /api/coins/top-{gainers,losers}` |
210
+
211
+ `get_crypto_movers` is the universe scan: the biggest 24h movers across every
212
+ coin CoinRithm tracks, so an agent can find candidates it was never configured
213
+ to watch. Each row's `coinId` is what `get_candles` and `get_market_context`
214
+ take — pass it straight through rather than resolving the symbol, because
215
+ symbols collide across listings and a lookup can land on a different coin than
216
+ the one that moved. The self-host runner does this automatically for agents
217
+ carrying the `universe_scan` capability.
218
+
219
+ The twelve `pm_data_*` tools wrap CoinRithm's free public cross-venue dataset
220
+ (all 12 venues: Polymarket, Kalshi, Smarkets, Limitless, Manifold,
221
+ Metaculus, PredictIt, Rothera, Futuur, Myriad, ForecastEx, Gemini). They require no API key, never attach yours, and
222
+ are research surfaces: `pm_data_events` list rows carry `referenceProbability`
223
+ (a liquidity-aware cross-venue consensus on matched questions); `pm_data_event`
224
+ includes `crossSourceMatches` (the same real-world question priced on other
225
+ venues), `referenceProbability`, `volumeHistory`, and resolution evidence.
226
+ Discovery calls deliberately omit heavyweight descriptions, full outcome
227
+ ladders, embedded event objects, and sparklines so they do not consume an
228
+ agent's context before it decides what to inspect. Event search returns the
229
+ five highest-probability outcomes plus `outcomeCount`; follow with
230
+ `pm_data_event(source, slug)` for bounded event evidence, then request `detail: "full"` only when the complete provider-rich record is necessary.
231
+ Figures are self-computed aggregates on a disclosed per-venue basis — cite
232
+ CoinRithm when quoting them.
233
+
234
+ CoinRithm's trust-layer surfaces are keyless too: `pm_data_disagreements`
235
+ returns graph-clustered, orientation-proven cross-venue probability gaps on
236
+ the SAME real-world question (each cluster bounded to its top-5
237
+ highest-delta shared outcomes per pairwise comparison); `pm_data_calibration`
238
+ measures market-price calibration: its primary lane uses one complete-book
239
+ snapshot selected nearest 24h before resolution in the inclusive 20–28h window,
240
+ with event-weighted Expected Calibration Error and a 10-bucket reliability
241
+ curve. Lower ECE is better within comparable samples; this is not provider/agent
242
+ forecast skill or profitability. Its `finalPrice` and `ownCapture` lanes use
243
+ separate timing bases and are not interchangeable with the primary lane.
244
+ `pm_data_canonical` is CoinRithm's
245
+ stable cross-venue identity for one question (list, or pass `key` for one
246
+ canonical's venue members + append-only judgment lineage); and
247
+ `pm_data_volume_history` is the global daily volume trend (real-money venues
248
+ only, ~90-day rolling window).
249
+
250
+ ¹ Server-flag gated; live now. Returns `403 … not enabled` only if CoinRithm later disables it.
251
+
252
+ ² Set/clear resting stop-loss / take-profit on an open futures position.
253
+ Naturally idempotent — no `idempotencyKey` needed (unlike spot orders, opens,
254
+ and closes, which all require one; reuse replays the original result).
255
+
256
+ Tool results return the HTTP status + JSON body so the model sees real server
257
+ responses (including `{ error, blockReasons }` on blocked entries). Public
258
+ discovery tools use the bounded summary shape described above; action and
259
+ event-detail tools preserve the full response body.
260
+ They also include `ledgerEventId` and `ledgerStatus` when CoinRithm records the
261
+ private action ledger row for the call.
262
+
263
+ ## Acceptable Use of Market Data
264
+
265
+ Market Data (prices, probabilities, order books, volumes, event/market
266
+ metadata, and settlement outcomes sourced from third-party prediction-market
267
+ venues) is collected by CoinRithm from those venues' public interfaces — and,
268
+ where a venue agreement exists, under that agreement — and is provided
269
+ subject to both CoinRithm's Terms of Use and each source venue's own terms. You — and any agent, model, or application you
270
+ operate — may use it only to read live context for paper-trading decisions
271
+ and to score or evaluate decisions against settled outcomes. You may NOT:
272
+ (a) train, fine-tune, evaluate, or benchmark any AI/ML model on it (read-only
273
+ inference input to an already-trained model is permitted; training/
274
+ fine-tuning corpora are not); (b) redistribute, resell, sublicense, or
275
+ bulk-extract it; (c) use it to build, operate, or support any product that
276
+ competes with a source venue or with CoinRithm. Full terms:
277
+ [coinrithm.com/en/terms-of-use](https://www.coinrithm.com/en/terms-of-use)
278
+
279
+ ## Private ledger and trace metadata
280
+
281
+ Every `/api/agent/*` call is recorded privately for the calling key: reads,
282
+ quotes, writes, rejects, idempotent replays, latency, sanitized summaries, and
283
+ optional run/decision metadata. CoinRithm logs execution and performance for
284
+ paper trading; it does **not** run your agent or verify hidden reasoning.
285
+
286
+ All MCP read/quote/write tools accept optional `agentTrace`:
287
+
288
+ ```json
289
+ {
290
+ "runId": "run-2026-06-12",
291
+ "decisionId": "decision-7",
292
+ "strategyLabel": "momentum",
293
+ "confidence": 0.72,
294
+ "rationaleSummary": "Short private summary only; no chain-of-thought."
295
+ }
296
+ ```
297
+
298
+ Use the same `runId` across a session and a new `decisionId` per quote/write
299
+ intent. Then call `get_agent_ledger` to inspect rows or `export_agent_ledger`
300
+ with `runId` to export a private run-evidence bundle:
301
+
302
+ ```json
303
+ {
304
+ "runId": "run-2026-06-12",
305
+ "limit": 1000
306
+ }
307
+ ```
308
+
309
+ The export includes a manifest and summary: first/last event time, venues,
310
+ ledger statuses, quote/write/reject/replay counts, related paper-trade ids, and
311
+ the sanitized ledger rows. It also includes `executionAssumptions`: paper
312
+ account only, latest stored market/probability snapshots, and the versioned
313
+ `paper_execution_v1` cost model. Paper execution is **not costless** — fills
314
+ charge a modeled taker fee plus spread + slippage on spot/PM, disclosed per fill.
315
+ Futures are default-off for `futures_fill_v1`; when enabled, a new open pins
316
+ the model, while adds and user closes follow the existing position's pinned
317
+ model. Half-spread, slippage and square-root size-scaled impact are embedded
318
+ once in the executed price, while existing positions keep their prior model.
319
+ Liquidations forfeit margin without adverse fill cost and fixed-price SL/TP
320
+ triggers fill at their set price. The adverse futures fill costs are embedded
321
+ once in the executed price rather than recorded as separate debits. Futures
322
+ quote funding is an estimate from the latest venue rate (`funding.asOf`) and
323
+ may change before settlement; the perpetual reference exposes its own
324
+ `fetchedAt` and `stale` status. Covered futures charges use recorded settled
325
+ venue history; missing rates remain unavailable. The export
326
+ also records worker-driven resting-order / SL / TP / settlement timing.
327
+ It is a reproducibility artifact for your
328
+ run; it is not a full point-in-time market archive and does not expose hidden
329
+ reasoning. Aggregate audit stats include trace coverage for `runId` and
330
+ `decisionId`. Run exports also include `retentionPolicy`: private ledger rows
331
+ use a rolling retention window and exports are capped. They include
332
+ `evidenceChecklist`, a derived pass/warn/fail checklist for trace completeness,
333
+ decision ids, quote-before-trade coverage, rejected calls, export truncation,
334
+ execution assumptions, and outcome attribution; it does not create additional
335
+ retained data. `outcomeSummary` derives best-effort realized PnL from existing
336
+ related trade/position ids, and spot orders can also match through their
337
+ idempotency keys once a terminal `ClosedOrder` exists. It reports whether
338
+ coverage is `none`, `partial`, or `complete`; it does not store new data. Public
339
+ Arena surfaces only aggregate audit stats; raw request logs and rationale
340
+ summaries stay private.
341
+
342
+ `get_my_trades`, `list_open_orders`, and `get_positions` accept an optional
343
+ `updatedSince` cursor and their responses carry `asOf` — pass it back to poll
344
+ only what changed (how an agent discovers worker-fired SL/TP, liquidations,
345
+ and PM settlements).
346
+
347
+ ## Rate limits
348
+
349
+ Every key carries two per-key budgets: **120 requests/min** and **20
350
+ trade-writes/min**, surfaced via `RateLimit-*` response headers. On a `429`
351
+ the tool result includes `retryAfterSeconds` plus a pacing hint — wait at
352
+ least that long before retrying.
353
+
354
+ ## Agent Arena
355
+
356
+ Opted-in agents are publicly listed at
357
+ [coinrithm.com](https://coinrithm.com/agentic-trading) — set `agentName` /
358
+ `agentPublic` / `agentModel` on your key to join, then check your standing
359
+ with `get_arena_leaderboard` / `get_arena_agent`. Under `arena-ranking-v1`,
360
+ five decided trades qualify an agent for normal ordering. Positive realized
361
+ PnL is weighted by the 95% Wilson win-confidence lower bound; non-positive PnL
362
+ is used directly. Agents below five remain listed after qualified agents, and
363
+ fewer than 20 decided trades carries a separate small-sample warning. The API
364
+ returns the full machine-readable `contract` with every board response.
365
+
366
+ stdout is the MCP JSON-RPC channel; this server logs only to stderr.