@coinrithm/mcp-trading 0.7.16 → 0.7.17

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +885 -811
  2. package/README.md +486 -415
  3. package/dist/agent/capitalSizing.d.ts +10 -1
  4. package/dist/agent/capitalSizing.js +28 -4
  5. package/dist/agent/client.d.ts +13 -0
  6. package/dist/agent/client.js +17 -6
  7. package/dist/agent/decision.d.ts +21 -16
  8. package/dist/agent/decision.js +7 -0
  9. package/dist/agent/decisionValidator.d.ts +1 -0
  10. package/dist/agent/decisionValidator.js +1 -1
  11. package/dist/agent/engine.d.ts +3 -1
  12. package/dist/agent/engine.js +3 -1
  13. package/dist/agent/futuresCloseOutcome.d.ts +19 -0
  14. package/dist/agent/futuresCloseOutcome.js +54 -0
  15. package/dist/agent/futuresEligibility.d.ts +13 -0
  16. package/dist/agent/futuresEligibility.js +43 -5
  17. package/dist/agent/observe.d.ts +2 -1
  18. package/dist/agent/observe.js +1 -1
  19. package/dist/agent/pmPaperCandidates.d.ts +17 -0
  20. package/dist/agent/pmPaperCandidates.js +125 -0
  21. package/dist/agent/pmPaperCycle.d.ts +16 -0
  22. package/dist/agent/pmPaperCycle.js +372 -0
  23. package/dist/agent/pmPaperDecision.d.ts +187 -0
  24. package/dist/agent/pmPaperDecision.js +101 -0
  25. package/dist/agent/pmPaperPolicy.d.ts +71 -0
  26. package/dist/agent/pmPaperPolicy.js +46 -0
  27. package/dist/agent/prompt.d.ts +12 -1
  28. package/dist/agent/prompt.js +90 -3
  29. package/dist/agent/providerCapabilities.d.ts +1 -0
  30. package/dist/agent/providerCapabilities.js +4 -1
  31. package/dist/agent/providers.d.ts +1 -0
  32. package/dist/agent/providers.js +9 -4
  33. package/dist/agent/runner.d.ts +9 -1
  34. package/dist/agent/runner.js +152 -24
  35. package/dist/agent/skill.js +9 -0
  36. package/dist/agent/skillValidator.js +23 -0
  37. package/dist/agent/strictLint.js +1 -0
  38. package/dist/agent/templates.js +30 -30
  39. package/dist/agent/types.d.ts +31 -0
  40. package/dist/agent/version.d.ts +1 -1
  41. package/dist/agent/version.js +1 -1
  42. package/dist/client.d.ts +14 -0
  43. package/dist/client.js +31 -1
  44. package/dist/http.js +1 -1
  45. package/dist/pmPaperV2.d.ts +81 -0
  46. package/dist/pmPaperV2.js +53 -0
  47. package/dist/tools.js +84 -6
  48. package/package.json +100 -98
package/README.md CHANGED
@@ -1,415 +1,486 @@
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. `get_crypto_movers`,
21
- `get_arena_leaderboard` and `get_arena_agent` also work anonymously,
22
- for **15 keyless tools** in total.
23
-
24
- Agents are **OKF bundles** — an open, model-agnostic folder of markdown + YAML
25
- (strategy, persona, hard caps) that any runtime can read. Two ways to run the
26
- **same** bundle:
27
-
28
- - **Managed — nothing to install.** Build and deploy an agent in your browser
29
- with the **Agent Studio** (CoinRithm → My Agents → Studio): fork a house agent
30
- or write one from scratch, and CoinRithm runs it on an always-on scheduler.
31
- Studio shows the configured model; shared-pool routing can use another
32
- eligible model. Check each agent's configuration and run evidence.
33
- - **Self-host — this package.** Bring your own model key and run the
34
- `observe→decide→validate→act` loop on your machine, or wire the MCP server
35
- into Claude Desktop / Cursor / Codex.
36
-
37
- This package ships two binaries:
38
-
39
- - **`coinrithm-mcp`** — an MCP server that lets an AI agent paper-trade on
40
- CoinRithm (spot, futures, prediction markets) using a personal API key.
41
- - **`coinrithm-agent`** — a self-host **agent runner**: author an agent as a
42
- folder and run an `observe→decide→validate→act` loop with your own model key,
43
- **dry-run by default**. See [Agent runner](#agent-runner-coinrithm-agent) below.
44
-
45
- > **Paper trading only** — virtual funds (50,000 mUSD). Not financial advice.
46
-
47
- ## Version 0.7.16 (unpublished)
48
-
49
- The runner rejects explicitly incomplete provider responses before execution,
50
- including valid-looking prefixes, and preserves their token usage. Bounded
51
- shape diagnostics still reject string-valued actions. These guards do not raise
52
- completion limits, repair model proposals or change customer strategies.
53
-
54
- This release also includes configurable universe and signal boundaries, PM
55
- policies, objective guidance, separately timed market context and the
56
- `record`/`bench`/`label` evaluation tools. Funding-by-venue context does not
57
- change settlement; optional data retains source, coverage and timing limits.
58
- Benchmarks preserve missing outcomes and bounded route diagnostics. They do not
59
- establish a profitable strategy or a superior model. See the changelog and
60
- [runner documentation](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/agent-runner.md).
61
-
62
- The preceding published version, 0.7.15, includes the following capabilities.
63
-
64
- It preserves observed-price evidence in public market summaries
65
- (`hasObservedPrice` and bounded `sourceObservation`, including both sides of
66
- venue comparisons), keeps full public `walletAddress` values in whale summaries
67
- for `pm_data_whale_wallet` follow-up, adds the opt-in `whale_context` runner
68
- capability, and records explicit zero model/action evidence for cycles skipped
69
- before inference. `pm_data_canonical` documents the new canonical `consensus`
70
- and labelled `consensusHistory`. The hosted HTTP server recovers the
71
- pasted-markdown descriptor link (GET/HEAD redirect to the descriptor; POST runs
72
- MCP). Trading limits, risk gates and retry counts are unchanged. See
73
- [CHANGELOG.md](./CHANGELOG.md).
74
- Check `npm view @coinrithm/mcp-trading version` and the
75
- [release status](https://github.com/CoinRithm/coinrithm-agent-trading#version-clarity)
76
- for registry availability; hosted deployments and npm releases are separate.
77
-
78
- Runner API operations have a 30-second total deadline, including response
79
- bodies and 429 retry waits. Timeout and cancellation results remain unconfirmed;
80
- the client does not automatically replay an uncertain trading write.
81
-
82
- Embedding the runner? Import from `@coinrithm/mcp-trading/engine` for the
83
- supported engine and state helpers. Existing `dist/agent/engine.js` imports
84
- 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)
85
- for the exact opt-in policy and persistence contract.
86
-
87
- ## Quick start
88
-
89
- ```bash
90
- # Run the MCP server with your CoinRithm key (no install needed):
91
- COINRITHM_API_KEY=crk_live_… npx -y @coinrithm/mcp-trading
92
- ```
93
-
94
- Get a `crk_live_…` key from CoinRithm → Profile → API Keys. To author and run a
95
- self-host agent instead, see [Agent runner](#agent-runner-coinrithm-agent).
96
- Building from source? Use Node 20.19+ or 22.12+, then `npm ci && npm run build`.
97
- Run `npm run test:coverage` for the enforced 90% statement, branch, function,
98
- and line gates. See the [coverage scope and reliability checks](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/RELIABILITY.md).
99
-
100
- ## Agent runner (`coinrithm-agent`)
101
-
102
- This package also ships a **self-host agent runner**. You write an agent as a
103
- folder (strategy + hard caps in markdown/YAML); the runner compiles it and runs
104
- an `observe → decide → validate → act` loop, asking _your_ model (bring-your-own
105
- key) for structured decisions and executing only the ones that pass your caps —
106
- **dry-run by default**, paper-only across spot, futures, and prediction markets.
107
-
108
- ```bash
109
- coinrithm-agent new my-agent --preset conservative
110
- coinrithm-agent validate my-agent
111
- COINRITHM_API_KEY=crk_live_… ANTHROPIC_API_KEY=sk-ant-… \
112
- coinrithm-agent run my-agent --once --dry-run
113
- ```
114
-
115
- Full guide (env vars, fail-closed guarantees, folder layout):
116
- **[docs/agent-runner.md](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/agent-runner.md)**.
117
- The hosted scheduler supports an opt-in `whale_context`
118
- capability when `pm` is in scope. After the event-driven gate fires, the runner
119
- adds a bounded public tape sample and up to two validated wallet movement
120
- summaries to the model observation for non-mechanical providers. The read is best effort with explicit
121
- availability status; it never expands PM candidates or bypasses risk and write
122
- gates. Owners can enable it in Agent Studio under Risk & caps; existing agents
123
- remain opted out unless their owners choose it. It ships in package version
124
- 0.7.15; earlier MCP `0.7.14` does not include it.
125
- The CoinRithm hosted scheduler runs this same engine for you — see the
126
- [scheduler README](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/packages/scheduler/README.md) for the built,
127
- DB-driven runtime.
128
-
129
- ## Two ways to run
130
-
131
- | Mode | Entry | Auth | Who it's for |
132
- | ---------------------------------------- | --------------- | ---------------------------------------------- | ------------------------------------------------- |
133
- | **stdio** (single-user, local) | `dist/index.js` | `COINRITHM_API_KEY` env var | Claude Desktop / Cursor / Codex on your machine |
134
- | **Streamable HTTP** (multi-user, hosted) | `dist/http.js` | **per-request** `Authorization: Bearer` header | The shared hosted endpoint at `mcp.coinrithm.com` |
135
-
136
- The hosted HTTP server holds **no** key: each request brings its own
137
- `crk_live_…` in the Authorization header, and the server forwards exactly that
138
- key upstream. The Authorization header is **optional** on the hosted endpoint —
139
- the twelve `pm_data_*` tools, `get_crypto_movers`, `get_arena_leaderboard` and
140
- `get_arena_agent` work anonymously. Account and trading tools require it.
141
- See [`DEPLOY.md`](./DEPLOY.md).
142
-
143
- ## Bring your own model key
144
-
145
- The hosted Agent Studio runs your agent free on a shared pool of NVIDIA-hosted
146
- models. That pool is a **fixed budget shared by every hosted agent**, so the
147
- scheduler floors how often a shared agent may run, and the floor stretches as
148
- more agents join. Bringing your own model key removes the shared-pool interval
149
- floor. Provider quotas, execution time, trigger policies and account protections
150
- still apply.
151
-
152
- | | Shared free pool | Your own key |
153
- | --------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
154
- | Models | the free hosted picks | any model your provider serves |
155
- | Interval | floored by fleet size | configured interval after completion, subject to other gates |
156
- | Rerouting | we may serve a live alternate when a model is rate-limited | never rerouted, your route is pinned |
157
- | Cost | free | you pay your provider, not CoinRithm |
158
-
159
- Providers accepted: `nvidia`, `openai`, `groq`, `anthropic`, and any
160
- `openai-compatible` endpoint (https base URL required). The key is validated by
161
- a **live decision probe before the agent is accepted** — a model that cannot
162
- return a parseable decision is rejected at deploy time rather than failing
163
- every scheduled cycle. Keys are encrypted at rest and never logged or echoed.
164
-
165
- Self-hosting through this package works the same way: set the provider's env
166
- var (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `NVIDIA_API_KEY`, `GROQ_API_KEY`
167
- or `MODEL_API_KEY`) and the runner builds the request in the shape that
168
- provider's model family actually accepts. A model key is **never** read from an
169
- agent file.
170
-
171
- ## Configure (stdio)
172
-
173
- | Env var | Required | Default | Notes |
174
- | ------------------- | ---------------- | --------------------------- | -------------------------------------------------------------------------------------- |
175
- | `COINRITHM_API_KEY` | yes (stdio only) | — | A `crk_live_…` key from CoinRithm → Profile → API Keys. **Ignored by the HTTP entry.** |
176
- | `COINRITHM_API_URL` | no | `https://api.coinrithm.com` | Upstream base URL (live) |
177
- | `PORT` | no | `8787` | HTTP entry only |
178
-
179
- ## Run
180
-
181
- - **stdio** (for Claude Desktop / Claude Code / Cursor / most MCP hosts):
182
- ```bash
183
- COINRITHM_API_KEY=crk_live_... node dist/index.js
184
- # or, after npm link / npx:
185
- coinrithm-mcp
186
- ```
187
- - **Streamable HTTP** (multi-user; no key in env — clients send their own):
188
- ```bash
189
- npm run start:http
190
- # POST http://localhost:8787/mcp with Authorization: Bearer crk_live_...
191
- # GET http://localhost:8787/healthz (liveness, no auth)
192
- ```
193
-
194
- ## Tools
195
-
196
- | Tool | Scope | Wraps |
197
- | ------------------------------------------------------ | ------------- | ------------------------------------------------------------------------------------ |
198
- | `whoami` | any | `GET /api/agent/me` |
199
- | `get_portfolio` | read | `GET /api/agent/portfolio` |
200
- | `get_wallet` | read | `GET /api/agent/wallet` |
201
- | `resolve_symbol` | read | `GET /api/agent/resolve` |
202
- | `get_equity_curve` | read | `GET /api/agent/equity-curve` |
203
- | `get_my_trades` (venue) | read | `GET /api/agent/trades` |
204
- | `get_market_context` (coinId) | read | `GET /api/agent/market/:coinId` |
205
- | `get_news` (coins, limit?, hours?, minImportance?) | read | `GET /api/agent/news` |
206
- | `get_candles` (coinId, range) | read | `GET /api/agent/market/:coinId/candles` |
207
- | `discover_pm_markets` | read | `GET /api/agent/pm/discover` |
208
- | `get_performance` | read | `GET /api/agent/performance` |
209
- | `get_agent_ledger` | read | `GET /api/agent/ledger` |
210
- | `export_agent_ledger` | read | `GET /api/agent/ledger/export` |
211
- | `export_run_evidence` | read | `GET /api/agent/ledger/export?runId=...` |
212
- | `get_arena_leaderboard` | none (public) | `GET /api/arena` |
213
- | `get_arena_agent` (handle) | none (public) | `GET /api/arena/:handle` |
214
- | `list_open_orders` | read | `GET /api/agent/orders/open` |
215
- | `get_positions` (venue) | read | `GET /api/agent/positions/{futures,pm}` |
216
- | `spot_quote` | read | `POST /api/agent/spot/quote` |
217
- | `futures_quote` | read | `POST /api/agent/futures/quote` |
218
- | `pm_quote` | read | `POST /api/agent/pm/quote` |
219
- | `place_spot_order` | trade:spot | `POST /api/agent/spot/order` |
220
- | `cancel_spot_order` | trade:spot | `POST /api/agent/spot/order/:id/cancel` |
221
- | `open_futures_position` | trade:futures | `POST /api/agent/futures/open` ¹ |
222
- | `set_futures_sl_tp` | trade:futures | `POST /api/agent/futures/sl-tp` ² |
223
- | `close_futures_position` | trade:futures | `POST /api/agent/futures/close` |
224
- | `open_pm_position` | trade:pm | `POST /api/agent/pm/open` ¹ |
225
- | `report_pm_opportunity` | read | `POST /api/agent/pm/opportunity` |
226
- | `pm_data_overview` | none (public) | compact `GET /api/prediction-markets/overview` |
227
- | `pm_data_sources` | none (public) | venue methodology, coverage, and comparable volume bases |
228
- | `pm_data_sources_health` | none (public) | per-venue freshness, lag, and degraded reasons |
229
- | `pm_data_events` | none (public) | compact `GET /api/prediction-markets/events` |
230
- | `pm_data_event` (source, slug, detail?) | none (public) | bounded event evidence by default; `detail: "full"` returns the untouched API record |
231
- | `pm_data_whales` (limit, default 10) | none (public) | compact `GET /api/prediction-markets/whales` |
232
- | `pm_data_whale_wallets` (limit, window) | none (public) | compact `GET /api/prediction-markets/whales/wallets` |
233
- | `pm_data_whale_wallet` (source, wallet) | none (public) | movement detail `GET /api/prediction-markets/whales/wallets/:source/:wallet` |
234
- | `pm_data_disagreements` (limit, sort, sourceKind, ...) | none (public) | compact `GET /api/prediction-markets/matches/public` |
235
- | `pm_data_calibration` | none (public) | `GET /api/prediction-markets/calibration` |
236
- | `pm_data_canonical` (key?, limit, cursor) | none (public) | `GET /api/prediction-markets/canonical` (+ `/:key` detail) |
237
- | `pm_data_volume_history` | none (public) | `GET /api/prediction-markets/volume-history` |
238
- | `get_crypto_movers` (direction, limit) | none (public) | `GET /api/coins/top-{gainers,losers}` |
239
-
240
- From package version 0.7.15 (not in npm `0.7.14`), `pm_data_whales` and default
241
- `pm_data_event` summaries preserve the API's full public `walletAddress`. Pass
242
- that value with its `source` to `pm_data_whale_wallet` for Polymarket, Limitless
243
- or Myriad. The shorter `wallet` field is display text; a null or absent
244
- `walletAddress` supplies no usable wallet identity, including anonymous Kalshi
245
- trades. Wallet leaderboard rows use `address` for the same tool input.
246
-
247
- `get_crypto_movers` is the universe scan: the biggest 24h movers across every
248
- coin CoinRithm tracks, so an agent can find candidates it was never configured
249
- to watch. Each row's `coinId` is what `get_candles` and `get_market_context`
250
- take — pass it straight through rather than resolving the symbol, because
251
- symbols collide across listings and a lookup can land on a different coin than
252
- the one that moved. The self-host runner does this automatically for agents
253
- carrying the `universe_scan` capability.
254
-
255
- The twelve `pm_data_*` tools wrap CoinRithm's free public cross-venue dataset
256
- (all 12 venues: Polymarket, Kalshi, Smarkets, Limitless, Manifold,
257
- Metaculus, PredictIt, Rothera, Futuur, Myriad, ForecastEx, Gemini). They require no API key, never attach yours, and
258
- are research surfaces: `pm_data_events` list rows carry `referenceProbability`
259
- (a liquidity-aware cross-venue consensus on matched questions); `pm_data_event`
260
- includes `crossSourceMatches` (the same real-world question priced on other
261
- venues), `referenceProbability`, `volumeHistory`, and resolution evidence.
262
- Discovery calls deliberately omit heavyweight descriptions, full outcome
263
- ladders, embedded event objects, and sparklines so they do not consume an
264
- agent's context before it decides what to inspect. Event search returns up to
265
- five outcomes plus `outcomeCount`. For open events, outcomes without a result
266
- or a `closed`, `resolved` or `voided` lifecycle state come first; for other
267
- event statuses, provider-confirmed winners come first. Within each group,
268
- outcomes with valid probabilities sort highest first, with ties retaining
269
- their original order. Follow with
270
- `pm_data_event(source, slug)` for bounded event evidence, then request `detail: "full"` only when the complete provider-rich record is necessary.
271
- Bounded outcome summaries may include `hasObservedPrice` and
272
- `sourceObservation`: `hasObservedPrice:false` means the provider supplied no
273
- usable observed price input, while an omitted `hasObservedPrice` field is
274
- unknown. `sourceObservation:null` means unavailable provenance, not proof that
275
- the outcome has no price. Neither field claims live pricing, liquidity or
276
- tradability. `priceBasis` (Polymarket and Kalshi open outcomes) says what the
277
- probability is: `book_mid`, `last_trade`, or `unquoted`, which means never
278
- traded with no usable book, so the number is not a price.
279
- Figures are self-computed aggregates on a disclosed per-venue basis — cite
280
- CoinRithm when quoting them.
281
-
282
- CoinRithm's trust-layer surfaces are keyless too: `pm_data_disagreements`
283
- returns graph-clustered, orientation-proven cross-venue probability gaps on
284
- the SAME real-world question (each cluster bounded to its top-5
285
- highest-delta shared outcomes per pairwise comparison); `pm_data_calibration`
286
- measures market-price calibration: its primary lane uses one complete-book
287
- snapshot selected nearest 24h before resolution in the inclusive 20–28h window,
288
- with event-weighted Expected Calibration Error and a 10-bucket reliability
289
- curve. Lower ECE is better within comparable samples; this is not provider/agent
290
- forecast skill or profitability. Its `finalPrice` and `ownCapture` lanes use
291
- separate timing bases and are not interchangeable with the primary lane.
292
- `pm_data_canonical` is CoinRithm's
293
- stable cross-venue identity for one question (list, or pass `key` for one
294
- canonical's venue members + append-only judgment lineage); and
295
- `pm_data_volume_history` is the global daily volume trend (real-money venues
296
- only, ~90-day rolling window).
297
-
298
- ¹ Server-flag gated; live now. Returns `403 … not enabled` only if CoinRithm later disables it.
299
-
300
- ² Set/clear resting stop-loss / take-profit on an open futures position.
301
- Naturally idempotent — no `idempotencyKey` needed (unlike spot orders, opens,
302
- and closes, which all require one; reuse replays the original result).
303
-
304
- Tool results return the HTTP status + JSON body so the model sees real server
305
- responses (including `{ error, blockReasons }` on blocked entries). Public
306
- discovery tools use the bounded summary shape described above. `pm_data_event`
307
- also returns a bounded summary by default; pass `detail: "full"` to preserve
308
- the full event response body. Action tools preserve the full response body.
309
- They also include `ledgerEventId` and `ledgerStatus` when CoinRithm records the
310
- private action ledger row for the call.
311
-
312
- ## Acceptable Use of Market Data
313
-
314
- Market Data (prices, probabilities, order books, volumes, event/market
315
- metadata, and settlement outcomes sourced from third-party prediction-market
316
- venues) is collected by CoinRithm from those venues' public interfaces — and,
317
- where a venue agreement exists, under that agreement — and is provided
318
- subject to both CoinRithm's Terms of Use and each source venue's own terms. You — and any agent, model, or application you
319
- operate — may use it only to read live context for paper-trading decisions
320
- and to score or evaluate decisions against settled outcomes. You may NOT:
321
- (a) train, fine-tune, evaluate, or benchmark any AI/ML model on it (read-only
322
- inference input to an already-trained model is permitted; training/
323
- fine-tuning corpora are not); (b) redistribute, resell, sublicense, or
324
- bulk-extract it; (c) use it to build, operate, or support any product that
325
- competes with a source venue or with CoinRithm. Full terms:
326
- [coinrithm.com/en/terms-of-use](https://www.coinrithm.com/en/terms-of-use)
327
-
328
- ## Private ledger and trace metadata
329
-
330
- Every `/api/agent/*` call is recorded privately for the calling key: reads,
331
- quotes, writes, rejects, idempotent replays, latency, sanitized summaries, and
332
- optional run/decision metadata. CoinRithm logs execution and performance for
333
- paper trading; it does **not** run your agent or verify hidden reasoning.
334
-
335
- All MCP read/quote/write tools accept optional `agentTrace`:
336
-
337
- ```json
338
- {
339
- "runId": "run-2026-06-12",
340
- "decisionId": "decision-7",
341
- "strategyLabel": "momentum",
342
- "confidence": 0.72,
343
- "rationaleSummary": "Short private summary only; no chain-of-thought."
344
- }
345
- ```
346
-
347
- Use the same `runId` across a session and a new `decisionId` per quote/write
348
- intent. Then call `get_agent_ledger` to inspect rows or `export_agent_ledger`
349
- with `runId` to export a private run-evidence bundle:
350
-
351
- ```json
352
- {
353
- "runId": "run-2026-06-12",
354
- "limit": 1000
355
- }
356
- ```
357
-
358
- The export includes a manifest and summary: first/last event time, venues,
359
- ledger statuses, quote/write/reject/replay counts, related paper-trade ids, and
360
- the sanitized ledger rows. It also includes `executionAssumptions`: paper
361
- account only, latest stored market/probability snapshots, and the versioned
362
- `paper_execution_v1` cost model. Paper execution is **not costless** — fills
363
- charge a modeled taker fee plus spread + slippage on spot/PM, disclosed per fill.
364
- Futures are default-off for `futures_fill_v1`; when enabled, a new open pins
365
- the model, while adds and user closes follow the existing position's pinned
366
- model. Half-spread, slippage and square-root size-scaled impact are embedded
367
- once in the executed price, while existing positions keep their prior model.
368
- Liquidations forfeit margin without adverse fill cost and fixed-price SL/TP
369
- triggers fill at their set price. The adverse futures fill costs are embedded
370
- once in the executed price rather than recorded as separate debits. Futures
371
- quote funding is an estimate from the latest venue rate (`funding.asOf`) and
372
- may change before settlement; the perpetual reference exposes its own
373
- `fetchedAt` and `stale` status. Covered futures charges use recorded settled
374
- venue history; missing rates remain unavailable. The export
375
- also records worker-driven resting-order / SL / TP / settlement timing.
376
- It is a reproducibility artifact for your
377
- run; it is not a full point-in-time market archive and does not expose hidden
378
- reasoning. Aggregate audit stats include trace coverage for `runId` and
379
- `decisionId`. Run exports also include `retentionPolicy`: private ledger rows
380
- use a rolling retention window and exports are capped. They include
381
- `evidenceChecklist`, a derived pass/warn/fail checklist for trace completeness,
382
- decision ids, quote-before-trade coverage, rejected calls, export truncation,
383
- execution assumptions, and outcome attribution; it does not create additional
384
- retained data. `outcomeSummary` derives best-effort realized PnL from existing
385
- related trade/position ids, and spot orders can also match through their
386
- idempotency keys once a terminal `ClosedOrder` exists. It reports whether
387
- coverage is `none`, `partial`, or `complete`; it does not store new data. Public
388
- Arena surfaces only aggregate audit stats; raw request logs and rationale
389
- summaries stay private.
390
-
391
- `get_my_trades`, `list_open_orders`, and `get_positions` accept an optional
392
- `updatedSince` cursor and their responses carry `asOf` — pass it back to poll
393
- only what changed (how an agent discovers worker-fired SL/TP, liquidations,
394
- and PM settlements).
395
-
396
- ## Rate limits
397
-
398
- Every key carries two per-key budgets: **120 requests/min** and **20
399
- trade-writes/min**, surfaced via `RateLimit-*` response headers. On a `429`
400
- the tool result includes `retryAfterSeconds` plus a pacing hint — wait at
401
- least that long before retrying.
402
-
403
- ## Agent Arena
404
-
405
- Opted-in agents are publicly listed at
406
- [coinrithm.com](https://coinrithm.com/agentic-trading) — set `agentName` /
407
- `agentPublic` / `agentModel` on your key to join, then check your standing
408
- with `get_arena_leaderboard` / `get_arena_agent`. Under `arena-ranking-v1`,
409
- five decided trades qualify an agent for normal ordering. Positive realized
410
- PnL is weighted by the 95% Wilson win-confidence lower bound; non-positive PnL
411
- is used directly. Agents below five remain listed after qualified agents, and
412
- fewer than 20 decided trades carries a separate small-sample warning. The API
413
- returns the full machine-readable `contract` with every board response.
414
-
415
- 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. `get_crypto_movers`,
21
+ `get_arena_leaderboard` and `get_arena_agent` also work anonymously,
22
+ for **15 keyless tools** in total.
23
+
24
+ Agents are **OKF bundles** — an open, model-agnostic folder of markdown + YAML
25
+ (strategy, persona, hard caps) that any runtime can read. Two ways to run the
26
+ **same** bundle:
27
+
28
+ - **Managed — nothing to install.** Build and deploy an agent in your browser
29
+ with the **Agent Studio** (CoinRithm → My Agents → Studio): fork a house agent
30
+ or write one from scratch, and CoinRithm runs it on an always-on scheduler.
31
+ Studio shows the configured model; shared-pool routing can use another
32
+ eligible model. Check each agent's configuration and run evidence.
33
+ - **Self-host — this package.** Bring your own model key and run the
34
+ `observe→decide→validate→act` loop on your machine, or wire the MCP server
35
+ into Claude Desktop / Cursor / Codex.
36
+
37
+ This package ships two binaries:
38
+
39
+ - **`coinrithm-mcp`** — an MCP server that lets an AI agent paper-trade on
40
+ CoinRithm (spot, futures, prediction markets) using a personal API key.
41
+ - **`coinrithm-agent`** — a self-host **agent runner**: author an agent as a
42
+ folder and run an `observe→decide→validate→act` loop with your own model key,
43
+ **dry-run by default**. See [Agent runner](#agent-runner-coinrithm-agent) below.
44
+
45
+ > **Paper trading only** — virtual funds (50,000 mUSD). Not financial advice.
46
+
47
+ ## Version 0.7.17
48
+
49
+ The default tool surface is unchanged at 41 tools. Two server-wide opt-in
50
+ flags add tools that stay off unless enabled: the
51
+ [PM paper v2 tools](#opt-in-pm-paper-v2-tools) for configured house keys and
52
+ the [spot reference tool](#opt-in-spot-reference-tool).
53
+
54
+ The runner adds an opt-in `capitalSizing.highConviction` tier, widens a
55
+ correct-side take-profit that falls inside the agent's own reward:risk floor
56
+ (capital-sizing agents only) and records the requested and applied targets.
57
+ The next prompt lists the previous decision's refused actions, each open
58
+ position's stop-loss side of the mark, and which watched coins can take a new
59
+ futures entry. Pending futures exits are recorded as pending, not as executed
60
+ or failed. See [CHANGELOG.md](./CHANGELOG.md).
61
+
62
+ Version 0.7.16 (published 2026-10-07) rejects explicitly incomplete provider
63
+ responses before execution, including valid-looking prefixes, and preserves
64
+ their token usage. It also added configurable universe and signal boundaries,
65
+ PM policies, objective guidance, separately timed market context and the
66
+ `record`/`bench`/`label` evaluation tools. Funding-by-venue context does not
67
+ change settlement; optional data retains source, coverage and timing limits.
68
+ Benchmarks preserve missing outcomes and bounded route diagnostics. They do not
69
+ establish a profitable strategy or a superior model. See the
70
+ [runner documentation](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/agent-runner.md).
71
+
72
+ Version 0.7.15 preserves observed-price evidence in public market summaries
73
+ (`hasObservedPrice` and bounded `sourceObservation`, including both sides of
74
+ venue comparisons), keeps full public `walletAddress` values in whale summaries
75
+ for `pm_data_whale_wallet` follow-up, adds the opt-in `whale_context` runner
76
+ capability, and records explicit zero model/action evidence for cycles skipped
77
+ before inference. `pm_data_canonical` documents the new canonical `consensus`
78
+ and labelled `consensusHistory`. The hosted HTTP server recovers the
79
+ pasted-markdown descriptor link (GET/HEAD redirect to the descriptor; POST runs
80
+ MCP). Trading limits, risk gates and retry counts are unchanged. See
81
+ [CHANGELOG.md](./CHANGELOG.md).
82
+ Check `npm view @coinrithm/mcp-trading version` and the
83
+ [release status](https://github.com/CoinRithm/coinrithm-agent-trading#version-clarity)
84
+ for registry availability; hosted deployments and npm releases are separate.
85
+
86
+ Runner API operations have a 30-second total deadline, including response
87
+ bodies and 429 retry waits. Timeout and cancellation results remain unconfirmed;
88
+ the client does not automatically replay an uncertain trading write.
89
+
90
+ Embedding the runner? Import from `@coinrithm/mcp-trading/engine` for the
91
+ supported engine and state helpers. Existing `dist/agent/engine.js` imports
92
+ 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)
93
+ for the exact opt-in policy and persistence contract.
94
+
95
+ ## Quick start
96
+
97
+ ```bash
98
+ # Run the MCP server with your CoinRithm key (no install needed):
99
+ COINRITHM_API_KEY=crk_live_… npx -y @coinrithm/mcp-trading
100
+ ```
101
+
102
+ Get a `crk_live_…` key from CoinRithm → Settings → API Keys. To author and run a
103
+ self-host agent instead, see [Agent runner](#agent-runner-coinrithm-agent).
104
+ Building from source? Use Node 20.19+ or 22.12+, then `npm ci && npm run build`.
105
+ Run `npm run test:coverage` for the enforced 90% statement, branch, function,
106
+ and line gates. See the [coverage scope and reliability checks](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/RELIABILITY.md).
107
+
108
+ ## Agent runner (`coinrithm-agent`)
109
+
110
+ This package also ships a **self-host agent runner**. You write an agent as a
111
+ folder (strategy + hard caps in markdown/YAML); the runner compiles it and runs
112
+ an `observe → decide → validate → act` loop, asking _your_ model (bring-your-own
113
+ key) for structured decisions and executing only the ones that pass your caps —
114
+ **dry-run by default**, paper-only across spot, futures, and prediction markets.
115
+
116
+ ```bash
117
+ coinrithm-agent new my-agent --preset conservative
118
+ coinrithm-agent validate my-agent
119
+ COINRITHM_API_KEY=crk_live_… ANTHROPIC_API_KEY=sk-ant-… \
120
+ coinrithm-agent run my-agent --once --dry-run
121
+ ```
122
+
123
+ Full guide (env vars, fail-closed guarantees, folder layout):
124
+ **[docs/agent-runner.md](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/docs/agent-runner.md)**.
125
+ The hosted scheduler supports an opt-in `whale_context`
126
+ capability when `pm` is in scope. After the event-driven gate fires, the runner
127
+ adds a bounded public tape sample and up to two validated wallet movement
128
+ summaries to the model observation for non-mechanical providers. The read is best effort with explicit
129
+ availability status; it never expands PM candidates or bypasses risk and write
130
+ gates. Owners can enable it in Agent Studio under Risk & caps; existing agents
131
+ remain opted out unless their owners choose it. It ships in package version
132
+ 0.7.15; earlier MCP `0.7.14` does not include it.
133
+ The CoinRithm hosted scheduler runs this same engine for you — see the
134
+ [scheduler README](https://github.com/CoinRithm/coinrithm-agent-trading/blob/main/packages/scheduler/README.md) for the built,
135
+ DB-driven runtime.
136
+
137
+ ## Two ways to run
138
+
139
+ | Mode | Entry | Auth | Who it's for |
140
+ | ---------------------------------------- | --------------- | ---------------------------------------------- | ------------------------------------------------- |
141
+ | **stdio** (single-user, local) | `dist/index.js` | `COINRITHM_API_KEY` env var | Claude Desktop / Cursor / Codex on your machine |
142
+ | **Streamable HTTP** (multi-user, hosted) | `dist/http.js` | **per-request** `Authorization: Bearer` header | The shared hosted endpoint at `mcp.coinrithm.com` |
143
+
144
+ The hosted HTTP server holds **no** key: each request brings its own
145
+ `crk_live_…` in the Authorization header, and the server forwards exactly that
146
+ key upstream. The Authorization header is **optional** on the hosted endpoint —
147
+ the twelve `pm_data_*` tools, `get_crypto_movers`, `get_arena_leaderboard` and
148
+ `get_arena_agent` work anonymously. Account and trading tools require it.
149
+ See [`DEPLOY.md`](./DEPLOY.md).
150
+
151
+ ## Bring your own model key
152
+
153
+ The hosted Agent Studio runs your agent free on a shared pool of NVIDIA-hosted
154
+ models. That pool is a **fixed budget shared by every hosted agent**, so the
155
+ scheduler floors how often a shared agent may run, and the floor stretches as
156
+ more agents join. Bringing your own model key removes the shared-pool interval
157
+ floor. Provider quotas, execution time, trigger policies and account protections
158
+ still apply.
159
+
160
+ | | Shared free pool | Your own key |
161
+ | --------- | ---------------------------------------------------------- | ------------------------------------------------------------ |
162
+ | Models | the free hosted picks | any model your provider serves |
163
+ | Interval | floored by fleet size | configured interval after completion, subject to other gates |
164
+ | Rerouting | we may serve a live alternate when a model is rate-limited | never rerouted, your route is pinned |
165
+ | Cost | free | you pay your provider, not CoinRithm |
166
+
167
+ Providers accepted: `nvidia`, `openai`, `groq`, `anthropic`, and any
168
+ `openai-compatible` endpoint (https base URL required). The key is validated by
169
+ a **live decision probe before the agent is accepted** — a model that cannot
170
+ return a parseable decision is rejected at deploy time rather than failing
171
+ every scheduled cycle. Keys are encrypted at rest and never logged or echoed.
172
+
173
+ Self-hosting through this package works the same way: set the provider's env
174
+ var (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `NVIDIA_API_KEY`, `GROQ_API_KEY`,
175
+ `GEMINI_API_KEY` or `MODEL_API_KEY`) and the runner builds the request in the shape that
176
+ provider's model family actually accepts. A model key is **never** read from an
177
+ agent file.
178
+
179
+ ## Configure (stdio)
180
+
181
+ | Env var | Required | Default | Notes |
182
+ | ---------------------------------------- | ---------------- | --------------------------- | ----------------------------------------------------------------------------------------- |
183
+ | `COINRITHM_API_KEY` | yes (stdio only) | — | A `crk_live_…` key from CoinRithm → Settings → API Keys. **Ignored by the HTTP entry.** |
184
+ | `COINRITHM_API_URL` | no | `https://api.coinrithm.com` | Upstream base URL (live) |
185
+ | `PORT` | no | `8787` | HTTP entry only |
186
+ | `COINRITHM_PM_PAPER_V2_TOOLS_ENABLED` | no | off | `true` adds the [PM paper v2 tools](#opt-in-pm-paper-v2-tools) for configured house keys. |
187
+ | `COINRITHM_SPOT_REFERENCE_TOOLS_ENABLED` | no | off | `true` adds [`get_spot_reference`](#opt-in-spot-reference-tool). |
188
+
189
+ ## Run
190
+
191
+ - **stdio** (for Claude Desktop / Claude Code / Cursor / most MCP hosts):
192
+ ```bash
193
+ COINRITHM_API_KEY=crk_live_... node dist/index.js
194
+ # or, after npm link / npx:
195
+ coinrithm-mcp
196
+ ```
197
+ - **Streamable HTTP** (multi-user; no key in env — clients send their own):
198
+ ```bash
199
+ npm run start:http
200
+ # POST http://localhost:8787/mcp with Authorization: Bearer crk_live_...
201
+ # GET http://localhost:8787/healthz (liveness, no auth)
202
+ ```
203
+
204
+ ## Tools
205
+
206
+ | Tool | Scope | Wraps |
207
+ | ------------------------------------------------------ | ------------- | ------------------------------------------------------------------------------------ |
208
+ | `whoami` | any | `GET /api/agent/me` |
209
+ | `get_portfolio` | read | `GET /api/agent/portfolio` |
210
+ | `get_wallet` | read | `GET /api/agent/wallet` |
211
+ | `resolve_symbol` | read | `GET /api/agent/resolve` |
212
+ | `get_equity_curve` | read | `GET /api/agent/equity-curve` |
213
+ | `get_my_trades` (venue) | read | `GET /api/agent/trades` |
214
+ | `get_market_context` (coinId) | read | `GET /api/agent/market/:coinId` |
215
+ | `get_news` (coins, limit?, hours?, minImportance?) | read | `GET /api/agent/news` |
216
+ | `get_candles` (coinId, range) | read | `GET /api/agent/market/:coinId/candles` |
217
+ | `discover_pm_markets` | read | `GET /api/agent/pm/discover` |
218
+ | `get_performance` | read | `GET /api/agent/performance` |
219
+ | `get_agent_ledger` | read | `GET /api/agent/ledger` |
220
+ | `export_agent_ledger` | read | `GET /api/agent/ledger/export` |
221
+ | `export_run_evidence` | read | `GET /api/agent/ledger/export?runId=...` |
222
+ | `get_arena_leaderboard` | none (public) | `GET /api/arena` |
223
+ | `get_arena_agent` (handle) | none (public) | `GET /api/arena/:handle` |
224
+ | `list_open_orders` | read | `GET /api/agent/orders/open` |
225
+ | `get_positions` (venue) | read | `GET /api/agent/positions/{futures,pm}` |
226
+ | `spot_quote` | read | `POST /api/agent/spot/quote` |
227
+ | `futures_quote` | read | `POST /api/agent/futures/quote` |
228
+ | `pm_quote` | read | `POST /api/agent/pm/quote` |
229
+ | `place_spot_order` | trade:spot | `POST /api/agent/spot/order` |
230
+ | `cancel_spot_order` | trade:spot | `POST /api/agent/spot/order/:id/cancel` |
231
+ | `open_futures_position` | trade:futures | `POST /api/agent/futures/open` ¹ |
232
+ | `set_futures_sl_tp` | trade:futures | `POST /api/agent/futures/sl-tp` ² |
233
+ | `close_futures_position` | trade:futures | `POST /api/agent/futures/close` |
234
+ | `open_pm_position` | trade:pm | `POST /api/agent/pm/open` ¹ |
235
+ | `report_pm_opportunity` | read | `POST /api/agent/pm/opportunity` |
236
+ | `pm_data_overview` | none (public) | compact `GET /api/prediction-markets/overview` |
237
+ | `pm_data_sources` | none (public) | venue methodology, coverage, and comparable volume bases |
238
+ | `pm_data_sources_health` | none (public) | per-venue freshness, lag, and degraded reasons |
239
+ | `pm_data_events` | none (public) | compact `GET /api/prediction-markets/events` |
240
+ | `pm_data_event` (source, slug, detail?) | none (public) | bounded event evidence by default; `detail: "full"` returns the untouched API record |
241
+ | `pm_data_whales` (limit, default 10) | none (public) | compact `GET /api/prediction-markets/whales` |
242
+ | `pm_data_whale_wallets` (limit, window) | none (public) | compact `GET /api/prediction-markets/whales/wallets` |
243
+ | `pm_data_whale_wallet` (source, wallet) | none (public) | movement detail `GET /api/prediction-markets/whales/wallets/:source/:wallet` |
244
+ | `pm_data_disagreements` (limit, sort, sourceKind, ...) | none (public) | compact `GET /api/prediction-markets/matches/public` |
245
+ | `pm_data_calibration` | none (public) | `GET /api/prediction-markets/calibration` |
246
+ | `pm_data_canonical` (key?, limit, cursor) | none (public) | `GET /api/prediction-markets/canonical` (+ `/:key` detail) |
247
+ | `pm_data_volume_history` | none (public) | `GET /api/prediction-markets/volume-history` |
248
+ | `get_crypto_movers` (direction, limit) | none (public) | `GET /api/coins/top-{gainers,losers}` |
249
+
250
+ From package version 0.7.15 (not in npm `0.7.14`), `pm_data_whales` and default
251
+ `pm_data_event` summaries preserve the API's full public `walletAddress`. Pass
252
+ that value with its `source` to `pm_data_whale_wallet` for Polymarket, Limitless
253
+ or Myriad. The shorter `wallet` field is display text; a null or absent
254
+ `walletAddress` supplies no usable wallet identity, including anonymous Kalshi
255
+ trades. Wallet leaderboard rows use `address` for the same tool input.
256
+
257
+ `get_crypto_movers` is the universe scan: the biggest 24h movers across every
258
+ coin CoinRithm tracks, so an agent can find candidates it was never configured
259
+ to watch. Each row's `coinId` is what `get_candles` and `get_market_context`
260
+ take — pass it straight through rather than resolving the symbol, because
261
+ symbols collide across listings and a lookup can land on a different coin than
262
+ the one that moved. The self-host runner does this automatically for agents
263
+ carrying the `universe_scan` capability.
264
+
265
+ The twelve `pm_data_*` tools wrap CoinRithm's free public cross-venue dataset
266
+ (all 12 venues: Polymarket, Kalshi, Smarkets, Limitless, Manifold,
267
+ Metaculus, PredictIt, Rothera, Futuur, Myriad, ForecastEx, Gemini). They require no API key, never attach yours, and
268
+ are research surfaces: `pm_data_events` list rows carry `referenceProbability`
269
+ (a liquidity-aware cross-venue consensus on matched questions); `pm_data_event`
270
+ includes `crossSourceMatches` (the same real-world question priced on other
271
+ venues), `referenceProbability`, `volumeHistory`, and resolution evidence.
272
+ Discovery calls deliberately omit heavyweight descriptions, full outcome
273
+ ladders, embedded event objects, and sparklines so they do not consume an
274
+ agent's context before it decides what to inspect. Event search returns up to
275
+ five outcomes plus `outcomeCount`. For open events, outcomes without a result
276
+ or a `closed`, `resolved` or `voided` lifecycle state come first; for other
277
+ event statuses, provider-confirmed winners come first. Within each group,
278
+ outcomes with valid probabilities sort highest first, with ties retaining
279
+ their original order. Follow with
280
+ `pm_data_event(source, slug)` for bounded event evidence, then request `detail: "full"` only when the complete provider-rich record is necessary.
281
+ Bounded outcome summaries may include `hasObservedPrice` and
282
+ `sourceObservation`: `hasObservedPrice:false` means the provider supplied no
283
+ usable observed price input, while an omitted `hasObservedPrice` field is
284
+ unknown. `sourceObservation:null` means unavailable provenance, not proof that
285
+ the outcome has no price. Neither field claims live pricing, liquidity or
286
+ tradability. `priceBasis` (Polymarket and Kalshi open outcomes) says what the
287
+ probability is: `book_mid`, `last_trade`, or `unquoted`, which means never
288
+ traded with no usable book, so the number is not a price.
289
+ Figures are self-computed aggregates on a disclosed per-venue basis — cite
290
+ CoinRithm when quoting them.
291
+
292
+ CoinRithm's trust-layer surfaces are keyless too: `pm_data_disagreements`
293
+ returns graph-clustered, orientation-proven cross-venue probability gaps on
294
+ the SAME real-world question (each cluster bounded to its top-5
295
+ highest-delta shared outcomes per pairwise comparison); `pm_data_calibration`
296
+ measures market-price calibration: its primary lane uses one complete-book
297
+ snapshot selected nearest 24h before resolution in the inclusive 20–28h window,
298
+ with event-weighted Expected Calibration Error and a 10-bucket reliability
299
+ curve. Lower ECE is better within comparable samples; this is not provider/agent
300
+ forecast skill or profitability. Its `finalPrice` and `ownCapture` lanes use
301
+ separate timing bases and are not interchangeable with the primary lane.
302
+ `pm_data_canonical` is CoinRithm's
303
+ stable cross-venue identity for one question (list, or pass `key` for one
304
+ canonical's venue members + append-only judgment lineage); and
305
+ `pm_data_volume_history` is the global daily volume trend (real-money venues
306
+ only, ~90-day rolling window).
307
+
308
+ ¹ Server-flag gated; live now. Returns `403 … not enabled` only if CoinRithm later disables it.
309
+
310
+ ² Set/clear resting stop-loss / take-profit on an open futures position.
311
+ Naturally idempotent — no `idempotencyKey` needed (unlike spot orders, opens,
312
+ and closes, which all require one; reuse replays the original result).
313
+
314
+ Tool results return the HTTP status + JSON body so the model sees real server
315
+ responses (including `{ error, blockReasons }` on blocked entries). Public
316
+ discovery tools use the bounded summary shape described above. `pm_data_event`
317
+ also returns a bounded summary by default; pass `detail: "full"` to preserve
318
+ the full event response body. Action tools preserve the full response body.
319
+ They also include `ledgerEventId` and `ledgerStatus` when CoinRithm records the
320
+ private action ledger row for the call.
321
+
322
+ ## Acceptable Use of Market Data
323
+
324
+ Market Data (prices, probabilities, order books, volumes, event/market
325
+ metadata, and settlement outcomes sourced from third-party prediction-market
326
+ venues) is collected by CoinRithm from those venues' public interfaces — and,
327
+ where a venue agreement exists, under that agreement — and is provided
328
+ subject to both CoinRithm's Terms of Use and each source venue's own terms. You — and any agent, model, or application you
329
+ operate — may use it only to read live context for paper-trading decisions
330
+ and to score or evaluate decisions against settled outcomes. You may NOT:
331
+ (a) train, fine-tune, evaluate, or benchmark any AI/ML model on it (read-only
332
+ inference input to an already-trained model is permitted; training/
333
+ fine-tuning corpora are not); (b) redistribute, resell, sublicense, or
334
+ bulk-extract it; (c) use it to build, operate, or support any product that
335
+ competes with a source venue or with CoinRithm. Full terms:
336
+ [coinrithm.com/en/terms-of-use](https://www.coinrithm.com/en/terms-of-use)
337
+
338
+ ## Private ledger and trace metadata
339
+
340
+ Every `/api/agent/*` call is recorded privately for the calling key: reads,
341
+ quotes, writes, rejects, idempotent replays, latency, sanitized summaries, and
342
+ optional run/decision metadata. CoinRithm logs execution and performance for
343
+ paper trading; it does **not** run your agent or verify hidden reasoning.
344
+
345
+ All MCP read/quote/write tools accept optional `agentTrace`:
346
+
347
+ ```json
348
+ {
349
+ "runId": "run-2026-06-12",
350
+ "decisionId": "decision-7",
351
+ "strategyLabel": "momentum",
352
+ "confidence": 0.72,
353
+ "rationaleSummary": "Short private summary only; no chain-of-thought."
354
+ }
355
+ ```
356
+
357
+ Use the same `runId` across a session and a new `decisionId` per quote/write
358
+ intent. Then call `get_agent_ledger` to inspect rows or `export_agent_ledger`
359
+ with `runId` to export a private run-evidence bundle:
360
+
361
+ ```json
362
+ {
363
+ "runId": "run-2026-06-12",
364
+ "limit": 1000
365
+ }
366
+ ```
367
+
368
+ The export includes a manifest and summary: first/last event time, venues,
369
+ ledger statuses, quote/write/reject/replay counts, related paper-trade ids, and
370
+ the sanitized ledger rows. It also includes `executionAssumptions`: paper
371
+ account only, latest stored market/probability snapshots, and the versioned
372
+ `paper_execution_v1` cost model. Paper execution is **not costless** — fills
373
+ charge a modeled taker fee plus spread + slippage on spot/PM, disclosed per fill.
374
+ Futures are default-off for `futures_fill_v1`; when enabled, a new open pins
375
+ the model, while adds and user closes follow the existing position's pinned
376
+ model. Half-spread, slippage and square-root size-scaled impact are embedded
377
+ once in the executed price, while existing positions keep their prior model.
378
+ Liquidations forfeit margin without adverse fill cost and fixed-price SL/TP
379
+ triggers fill at their set price. The adverse futures fill costs are embedded
380
+ once in the executed price rather than recorded as separate debits. Futures
381
+ quote funding is an estimate from the latest venue rate (`funding.asOf`) and
382
+ may change before settlement; the perpetual reference exposes its own
383
+ `fetchedAt` and `stale` status. Covered futures charges use recorded settled
384
+ venue history; missing rates remain unavailable. The export
385
+ also records worker-driven resting-order / SL / TP / settlement timing.
386
+ It is a reproducibility artifact for your
387
+ run; it is not a full point-in-time market archive and does not expose hidden
388
+ reasoning. Aggregate audit stats include trace coverage for `runId` and
389
+ `decisionId`. Run exports also include `retentionPolicy`: private ledger rows
390
+ use a rolling retention window and exports are capped. They include
391
+ `evidenceChecklist`, a derived pass/warn/fail checklist for trace completeness,
392
+ decision ids, quote-before-trade coverage, rejected calls, export truncation,
393
+ execution assumptions, and outcome attribution; it does not create additional
394
+ retained data. `outcomeSummary` derives best-effort realized PnL from existing
395
+ related trade/position ids, and spot orders can also match through their
396
+ idempotency keys once a terminal `ClosedOrder` exists. It reports whether
397
+ coverage is `none`, `partial`, or `complete`; it does not store new data. Public
398
+ Arena surfaces only aggregate audit stats; raw request logs and rationale
399
+ summaries stay private.
400
+
401
+ `get_my_trades`, `list_open_orders`, and `get_positions` accept an optional
402
+ `updatedSince` cursor and their responses carry `asOf` — pass it back to poll
403
+ only what changed (how an agent discovers worker-fired SL/TP, liquidations,
404
+ and PM settlements).
405
+
406
+ ## Rate limits
407
+
408
+ Every key carries two per-key budgets: **120 requests/min** and **20
409
+ trade-writes/min**, surfaced via `RateLimit-*` response headers. On a `429`
410
+ the tool result includes `retryAfterSeconds` plus a pacing hint — wait at
411
+ least that long before retrying.
412
+
413
+ ## Agent Arena
414
+
415
+ Opted-in agents are publicly listed at
416
+ [coinrithm.com](https://coinrithm.com/agentic-trading) — set `agentName` /
417
+ `agentPublic` / `agentModel` on your key to join, then check your standing
418
+ with `get_arena_leaderboard` / `get_arena_agent`. Under `arena-ranking-v1`,
419
+ five decided trades qualify an agent for normal ordering. Positive realized
420
+ PnL is weighted by the 95% Wilson win-confidence lower bound; non-positive PnL
421
+ is used directly. Agents below five remain listed after qualified agents, and
422
+ fewer than 20 decided trades carries a separate small-sample warning. The API
423
+ returns the full machine-readable `contract` with every board response.
424
+
425
+ stdout is the MCP JSON-RPC channel; this server logs only to stderr.
426
+
427
+ ### Opt-in PM paper v2 tools
428
+
429
+ The default tool list is unchanged. Set `COINRITHM_PM_PAPER_V2_TOOLS_ENABLED=true`
430
+ only for a server intended to expose the separately authorized house pilot:
431
+ `discover_pm_paper_v2_markets`, `open_pm_paper_v2`, `close_pm_paper_v2`, and
432
+ `get_pm_paper_v2_positions`. With both opt-in flags on, the server registers
433
+ 46 tools.
434
+
435
+ | Tool | Scope | Wraps |
436
+ | ------------------------------ | ---------- | -------------------------------------------- |
437
+ | `discover_pm_paper_v2_markets` | `read` | `GET /api/agent/pm/v2/discover` (q?, limit?) |
438
+ | `open_pm_paper_v2` | `trade:pm` | `POST /api/agent/pm/v2/open` |
439
+ | `close_pm_paper_v2` | `trade:pm` | `POST /api/agent/pm/v2/close` |
440
+ | `get_pm_paper_v2_positions` | `read` | `GET /api/agent/pm/v2/positions` |
441
+
442
+ These tools are meant for keys that match a configured house; discovery
443
+ returns `403 house_opt_in_required` for any other key. Discovery returns
444
+ Kalshi and Polymarket outcomes with their stored native identity
445
+ (`nativeMarket.key`) and scheduled native end, filtered to the house's
446
+ configured horizon, and reports exclusions in `meta.boundedSelection`. It is
447
+ candidate evidence only: the open reacquires identity, maturity, book and fees
448
+ and can still refuse.
449
+
450
+ The API validates each request's key against its configured house tuple; the
451
+ client cannot choose an accounting model or wallet. Opens cover Kalshi and
452
+ Polymarket only. An exact decimal `maxCashBudget` (10 to 1,000,000 mUSD)
453
+ includes entry fees and never substitutes for legacy stake. API-key opens must
454
+ send `forecastProbability`: the chance that the side you buy pays out, as a
455
+ percent above 1 and below 100 (`"62.5"`), or as a fraction above 0 and below 1
456
+ (`"0.625"`). Exactly `1` is refused as ambiguous, as are `0` and `100`; the
457
+ tool schema rejects these locally. The API refuses an open without it (`forecast_required`) or when it does not exceed the
458
+ fee-inclusive cost per share (`entry_forecast_not_above_cost`).
459
+ Idempotency keys use the `pm-entry:` and `pm-exit:` prefixes. A close may
460
+ return HTTP 202 (accepted, still pending); only `executed: true` confirms
461
+ completion. Reuse the same scoped idempotency key and body after uncertain
462
+ delivery. Disabling entry admission still permits prior-receipt reconciliation
463
+ and management of already-open paper exposure.
464
+
465
+ ### Opt-in spot reference tool
466
+
467
+ `COINRITHM_SPOT_REFERENCE_TOOLS_ENABLED=true` adds `get_spot_reference` on an
468
+ explicitly opted-in MCP server. It is off by default and independent of the PM
469
+ tool flag. The 41 default tools, hosted runner observations and existing agent
470
+ prompts stay unchanged. Enabling this server-wide flag advertises the tool to
471
+ every client of that server; keep it off on shared servers serving existing
472
+ agents unless those clients are intentionally opted in.
473
+
474
+ The tool accepts a `coinId` from `resolve_symbol` and optional `agentTrace`,
475
+ requires the caller's `read` scope and calls `GET /api/agent/spot/reference/:coinId`
476
+ without query parameters. It returns the server's complete reference response,
477
+ including unavailable reasons, stale fallback status and original timestamps.
478
+ The API's separate `BINANCE_SPOT_REFERENCE_ENABLED` flag controls stream reads;
479
+ disabled or missing stream data can still return a stored fallback.
480
+
481
+ Stream last-ticker price and rolling 24h quote volume are denominated in USDT;
482
+ the stored REST consensus fallback is USD. No conversion or consensus replacement
483
+ is implied. Check each branch's status and `expiresAt`; `preferredSource` is not
484
+ a freshness or execution guarantee. Emission, statistics-window close, receipt
485
+ and local price-change times are distinct; `lastTradeAt` is unknown. The result
486
+ does not supply executable depth, change paper fills or replace market context.