@coinrithm/mcp-trading 0.7.11 → 0.7.13

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