context-markets-cli 0.1.0 → 0.1.2

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
@@ -80,8 +80,8 @@ context portfolio get
80
80
  | Package | Description |
81
81
  |---------|-------------|
82
82
  | **[context-markets](https://github.com/contextwtf/context-sdk)** | TypeScript SDK for trading |
83
- | **[@contextwtf/react](https://github.com/contextwtf/context-react)** | React hooks for market data and trading |
84
- | **[@contextwtf/mcp](https://github.com/contextwtf/context-mcp)** | MCP server for AI agents |
83
+ | **[context-markets-react](https://github.com/contextwtf/context-react)** | React hooks for market data and trading |
84
+ | **[context-markets-mcp](https://github.com/contextwtf/context-mcp)** | MCP server for AI agents |
85
85
  | **[context-markets-cli](https://github.com/contextwtf/context-cli)** | CLI for trading from the terminal |
86
86
  | **[context-skills](https://github.com/contextwtf/context-skills)** | AI agent skill files |
87
87
  | **[context-plugin](https://github.com/contextwtf/context-plugin)** | Claude Code plugin |
@@ -0,0 +1,207 @@
1
+ import {
2
+ formatAddress,
3
+ formatMoney,
4
+ truncate
5
+ } from "./chunk-IRVQREUN.js";
6
+ import {
7
+ tradingClient
8
+ } from "./chunk-Q7JYRQZG.js";
9
+ import {
10
+ fail,
11
+ out,
12
+ requirePositional
13
+ } from "./chunk-QC6BGRUQ.js";
14
+
15
+ // src/commands/account.ts
16
+ var HELP = `Usage: context account <subcommand> [options]
17
+
18
+ Subcommands:
19
+ status Check wallet status (balances, approvals)
20
+ setup Approve contracts for gasless trading
21
+ mint-test-usdc Mint test USDC on testnet
22
+ --amount <n> Amount to mint (default: 1000)
23
+
24
+ deposit <amount> Deposit USDC into the exchange
25
+ withdraw <amount> Withdraw USDC from the exchange
26
+
27
+ mint-complete-sets <market-id> <amount>
28
+ Mint complete sets of outcome tokens
29
+ burn-complete-sets <market-id> <amount>
30
+ Burn complete sets of outcome tokens
31
+ --credit-internal <true|false> Credit internal balance (default: true)
32
+
33
+ help Show this help text
34
+
35
+ All account commands require a signer (--private-key or CONTEXT_PRIVATE_KEY).
36
+
37
+ Global options:
38
+ --api-key <key> Context API key (or CONTEXT_API_KEY env)
39
+ --private-key <key> Private key for signing (or CONTEXT_PRIVATE_KEY env)`;
40
+ async function handleAccount(parsed) {
41
+ const { subcommand, positional, flags } = parsed;
42
+ switch (subcommand) {
43
+ case "status":
44
+ return status(flags);
45
+ case "setup":
46
+ return setup(flags);
47
+ case "mint-test-usdc":
48
+ return mintTestUsdc(flags);
49
+ case "deposit":
50
+ return deposit(positional, flags);
51
+ case "withdraw":
52
+ return withdraw(positional, flags);
53
+ case "mint-complete-sets":
54
+ return mintCompleteSets(positional, flags);
55
+ case "burn-complete-sets":
56
+ return burnCompleteSets(positional, flags);
57
+ case "relay-operator-approval":
58
+ return fail(
59
+ "Use `context gasless-approve` for gasless operator approval."
60
+ );
61
+ case "relay-deposit":
62
+ return fail(
63
+ "Use `context gasless-deposit <amount>` for gasless deposit."
64
+ );
65
+ case "help":
66
+ case void 0:
67
+ console.log(HELP);
68
+ return;
69
+ default:
70
+ fail(
71
+ `Unknown account subcommand: "${subcommand}". Run "context account help" for usage.`
72
+ );
73
+ }
74
+ }
75
+ async function status(flags) {
76
+ const ctx = tradingClient(flags);
77
+ const result = await ctx.account.status();
78
+ const s = result;
79
+ out(result, {
80
+ detail: [
81
+ ["Address", formatAddress(s.address)],
82
+ ["ETH Balance", s.ethBalance || "\u2014"],
83
+ ["USDC Allowance", s.usdcAllowance ? "\u2713 Approved" : "\u2717 None"],
84
+ ["Operator", s.isOperatorApproved ? "\u2713 Approved" : "\u2717 Not approved"],
85
+ ["Needs Setup", s.needsApprovals ? "Yes \u2014 run `context setup`" : "No"]
86
+ ]
87
+ });
88
+ }
89
+ async function setup(flags) {
90
+ const ctx = tradingClient(flags);
91
+ const result = await ctx.account.setup();
92
+ out(result, {
93
+ detail: [
94
+ ["Status", "\u2713 Contracts approved"]
95
+ ]
96
+ });
97
+ }
98
+ async function mintTestUsdc(flags) {
99
+ const amountRaw = flags["amount"];
100
+ let amount;
101
+ if (amountRaw) {
102
+ amount = parseFloat(amountRaw);
103
+ if (isNaN(amount) || amount <= 0) {
104
+ fail("--amount must be a positive number", { received: amountRaw });
105
+ }
106
+ }
107
+ const ctx = tradingClient(flags);
108
+ const result = await ctx.account.mintTestUsdc(amount);
109
+ const r = result;
110
+ out(result, {
111
+ detail: [
112
+ ["Status", "\u2713 Minted"],
113
+ ["Amount", formatMoney(r.amount ?? amount)],
114
+ ["Tx Hash", formatAddress(r.txHash || r.tx_hash)]
115
+ ]
116
+ });
117
+ }
118
+ async function deposit(positional, flags) {
119
+ const raw = requirePositional(
120
+ positional,
121
+ 0,
122
+ "amount",
123
+ "context account deposit <amount>"
124
+ );
125
+ const amount = parseFloat(raw);
126
+ if (isNaN(amount) || amount <= 0) {
127
+ fail("Deposit amount must be a positive number", { received: raw });
128
+ }
129
+ const ctx = tradingClient(flags);
130
+ const txHash = await ctx.account.deposit(amount);
131
+ out({ status: "deposited", amount_usdc: amount, tx_hash: txHash }, {
132
+ detail: [
133
+ ["Status", "\u2713 Deposited"],
134
+ ["Amount", formatMoney(amount)],
135
+ ["Tx Hash", formatAddress(txHash)]
136
+ ]
137
+ });
138
+ }
139
+ async function withdraw(positional, flags) {
140
+ const raw = requirePositional(
141
+ positional,
142
+ 0,
143
+ "amount",
144
+ "context account withdraw <amount>"
145
+ );
146
+ const amount = parseFloat(raw);
147
+ if (isNaN(amount) || amount <= 0) {
148
+ fail("Withdraw amount must be a positive number", { received: raw });
149
+ }
150
+ const ctx = tradingClient(flags);
151
+ const txHash = await ctx.account.withdraw(amount);
152
+ out({ status: "withdrawn", amount_usdc: amount, tx_hash: txHash }, {
153
+ detail: [
154
+ ["Status", "\u2713 Withdrawn"],
155
+ ["Amount", formatMoney(amount)],
156
+ ["Tx Hash", formatAddress(txHash)]
157
+ ]
158
+ });
159
+ }
160
+ async function mintCompleteSets(positional, flags) {
161
+ const usage = "context account mint-complete-sets <market-id> <amount>";
162
+ const marketId = requirePositional(positional, 0, "market-id", usage);
163
+ const amountRaw = requirePositional(positional, 1, "amount", usage);
164
+ const amount = parseFloat(amountRaw);
165
+ if (isNaN(amount) || amount <= 0) {
166
+ fail("Amount must be a positive number", { received: amountRaw });
167
+ }
168
+ const ctx = tradingClient(flags);
169
+ const txHash = await ctx.account.mintCompleteSets(marketId, amount);
170
+ out({ status: "minted", market_id: marketId, amount, tx_hash: txHash }, {
171
+ detail: [
172
+ ["Status", "\u2713 Minted complete sets"],
173
+ ["Market", truncate(marketId, 20)],
174
+ ["Amount", String(amount)],
175
+ ["Tx Hash", formatAddress(txHash)]
176
+ ]
177
+ });
178
+ }
179
+ async function burnCompleteSets(positional, flags) {
180
+ const usage = "context account burn-complete-sets <market-id> <amount>";
181
+ const marketId = requirePositional(positional, 0, "market-id", usage);
182
+ const amountRaw = requirePositional(positional, 1, "amount", usage);
183
+ const amount = parseFloat(amountRaw);
184
+ if (isNaN(amount) || amount <= 0) {
185
+ fail("Amount must be a positive number", { received: amountRaw });
186
+ }
187
+ const creditInternalRaw = flags["credit-internal"];
188
+ const creditInternal = creditInternalRaw !== "false";
189
+ const ctx = tradingClient(flags);
190
+ const txHash = await ctx.account.burnCompleteSets(
191
+ marketId,
192
+ amount,
193
+ creditInternal
194
+ );
195
+ out({ status: "burned", market_id: marketId, amount, credit_internal: creditInternal, tx_hash: txHash }, {
196
+ detail: [
197
+ ["Status", "\u2713 Burned complete sets"],
198
+ ["Market", truncate(marketId, 20)],
199
+ ["Amount", String(amount)],
200
+ ["Credit Internal", String(creditInternal)],
201
+ ["Tx Hash", formatAddress(txHash)]
202
+ ]
203
+ });
204
+ }
205
+ export {
206
+ handleAccount as default
207
+ };
@@ -0,0 +1,45 @@
1
+ import {
2
+ fail
3
+ } from "./chunk-QC6BGRUQ.js";
4
+
5
+ // src/client.ts
6
+ import { ContextClient } from "context-markets";
7
+ function resolveChain(flags) {
8
+ const raw = flags.chain ?? process.env.CONTEXT_CHAIN;
9
+ if (!raw) return void 0;
10
+ return raw;
11
+ }
12
+ function readClient(flags = {}) {
13
+ const apiKey = flags["api-key"] ?? process.env.CONTEXT_API_KEY;
14
+ if (!apiKey) fail("Missing CONTEXT_API_KEY env var or --api-key flag");
15
+ const rpcUrl = flags["rpc-url"] ?? process.env.CONTEXT_RPC_URL;
16
+ const baseUrl = flags["base-url"] ?? process.env.CONTEXT_BASE_URL;
17
+ const chain = resolveChain(flags);
18
+ return new ContextClient({ apiKey, rpcUrl, baseUrl, chain });
19
+ }
20
+ function tradingClient(flags = {}) {
21
+ const apiKey = flags["api-key"] ?? process.env.CONTEXT_API_KEY;
22
+ if (!apiKey) fail("Missing CONTEXT_API_KEY env var or --api-key flag");
23
+ const privateKey = flags["private-key"] ?? process.env.CONTEXT_PRIVATE_KEY;
24
+ if (!privateKey) {
25
+ fail(
26
+ "A private key is required for trading operations.",
27
+ { hint: "Set CONTEXT_PRIVATE_KEY env var or pass --private-key <key>" }
28
+ );
29
+ }
30
+ const rpcUrl = flags["rpc-url"] ?? process.env.CONTEXT_RPC_URL;
31
+ const baseUrl = flags["base-url"] ?? process.env.CONTEXT_BASE_URL;
32
+ const chain = resolveChain(flags);
33
+ return new ContextClient({
34
+ apiKey,
35
+ rpcUrl,
36
+ baseUrl,
37
+ chain,
38
+ signer: { privateKey }
39
+ });
40
+ }
41
+
42
+ export {
43
+ readClient,
44
+ tradingClient
45
+ };
package/dist/cli.js CHANGED
@@ -31,6 +31,7 @@ Options:
31
31
  --api-key <key> Context API key (or CONTEXT_API_KEY env)
32
32
  --private-key <key> Private key (or CONTEXT_PRIVATE_KEY env)
33
33
  --rpc-url <url> Base Sepolia RPC URL (or CONTEXT_RPC_URL env)
34
+ --chain <chain> Target chain (or CONTEXT_CHAIN env, default: mainnet)
34
35
  --yes Skip confirmations (for automation)
35
36
 
36
37
  Run "context help" for this message, or "context <command> help" for details.`;
@@ -88,34 +89,34 @@ async function main() {
88
89
  const parsed = parseArgs(process.argv);
89
90
  setOutputMode(parsed.flags);
90
91
  if (parsed.command === "help" && process.stdout.isTTY && process.stdin.isTTY) {
91
- const { runShell } = await import("./shell-XBM2FEIR.js");
92
+ const { runShell } = await import("./shell-HLJLCIUW.js");
92
93
  await runShell();
93
94
  return;
94
95
  }
95
96
  try {
96
97
  switch (parsed.command) {
97
98
  case "markets": {
98
- const mod = await import("./markets-WZCKLKJR.js");
99
+ const mod = await import("./markets-WZG67OAH.js");
99
100
  await mod.default(parsed);
100
101
  break;
101
102
  }
102
103
  case "questions": {
103
- const mod = await import("./questions-P6AUM6D4.js");
104
+ const mod = await import("./questions-NJZXH3AZ.js");
104
105
  await mod.default(parsed);
105
106
  break;
106
107
  }
107
108
  case "orders": {
108
- const mod = await import("./orders-IA2XKE5J.js");
109
+ const mod = await import("./orders-KGS5MLNX.js");
109
110
  await mod.default(parsed);
110
111
  break;
111
112
  }
112
113
  case "portfolio": {
113
- const mod = await import("./portfolio-73RM2RAQ.js");
114
+ const mod = await import("./portfolio-2R52VSBA.js");
114
115
  await mod.default(parsed);
115
116
  break;
116
117
  }
117
118
  case "account": {
118
- const mod = await import("./account-DL4WGQCC.js");
119
+ const mod = await import("./account-X5TGY5RX.js");
119
120
  await mod.default(parsed);
120
121
  break;
121
122
  }
@@ -124,7 +125,7 @@ async function main() {
124
125
  case "deposit":
125
126
  case "gasless-approve":
126
127
  case "gasless-deposit": {
127
- const mod = await import("./setup-KDTGKF6O.js");
128
+ const mod = await import("./setup-STVAAHHF.js");
128
129
  const positional = parsed.subcommand ? [parsed.subcommand, ...parsed.positional] : parsed.positional;
129
130
  await mod.default({ ...parsed, subcommand: parsed.command, positional });
130
131
  break;
@@ -135,7 +136,7 @@ async function main() {
135
136
  break;
136
137
  }
137
138
  case "shell": {
138
- const { runShell } = await import("./shell-XBM2FEIR.js");
139
+ const { runShell } = await import("./shell-HLJLCIUW.js");
139
140
  await runShell();
140
141
  break;
141
142
  }
@@ -0,0 +1,313 @@
1
+ import {
2
+ formatAddress,
3
+ formatDate,
4
+ formatPrice,
5
+ formatVolume,
6
+ truncate
7
+ } from "./chunk-IRVQREUN.js";
8
+ import {
9
+ readClient,
10
+ tradingClient
11
+ } from "./chunk-Q7JYRQZG.js";
12
+ import {
13
+ fail,
14
+ out,
15
+ requireFlag,
16
+ requirePositional
17
+ } from "./chunk-QC6BGRUQ.js";
18
+
19
+ // src/commands/markets.ts
20
+ var HELP = `Usage: context markets <subcommand> [options]
21
+
22
+ Subcommands:
23
+ list Browse markets
24
+ --status <status> Filter by status
25
+ --limit <n> Max results
26
+ --sort-by <field> Sort field
27
+ --sort <asc|desc> Sort direction
28
+ --visibility <value> Visibility filter
29
+ --resolution-status <value> Resolution status filter
30
+ --creator <address> Filter by creator
31
+ --category <slug> Filter by category
32
+ --cursor <token> Pagination cursor
33
+
34
+ search <query> Search markets by text
35
+ --limit <n> Max results (default: 10)
36
+ --offset <n> Offset for pagination
37
+
38
+ get <id> Get a single market by ID
39
+ quotes <id> Current quotes for a market
40
+ orderbook <id> Full orderbook (YES and NO sides)
41
+ --depth <n> Number of price levels
42
+
43
+ simulate <id> Simulate a trade
44
+ --side <yes|no> (required) Trade side
45
+ --amount <n> (required) Trade amount
46
+ --amount-type <usd|contracts> Amount type (default: usd)
47
+ --trader <address> Trader address
48
+
49
+ price-history <id> Price history for a market
50
+ --timeframe <1h|6h|1d|1w|1M|all> Timeframe
51
+
52
+ oracle <id> Oracle info for a market
53
+ oracle-quotes <id> Oracle quotes for a market
54
+ request-oracle-quote <id> Request a new oracle quote
55
+
56
+ activity <id> Activity feed for a market
57
+ --limit <n> Max results
58
+ --cursor <token> Pagination cursor
59
+
60
+ global-activity Global activity feed
61
+ --limit <n> Max results
62
+ --cursor <token> Pagination cursor
63
+
64
+ create <questionId> Create a market from a generated question ID
65
+
66
+ help Show this help text
67
+
68
+ Global options:
69
+ --api-key <key> Context API key (or CONTEXT_API_KEY env)`;
70
+ async function handleMarkets(parsed) {
71
+ const { subcommand, positional, flags } = parsed;
72
+ switch (subcommand) {
73
+ case "list":
74
+ return list(flags);
75
+ case "search":
76
+ return search(positional, flags);
77
+ case "get":
78
+ return get(positional, flags);
79
+ case "quotes":
80
+ return quotes(positional, flags);
81
+ case "orderbook":
82
+ return orderbook(positional, flags);
83
+ case "simulate":
84
+ return simulate(positional, flags);
85
+ case "price-history":
86
+ return priceHistory(positional, flags);
87
+ case "oracle":
88
+ return oracle(positional, flags);
89
+ case "oracle-quotes":
90
+ return oracleQuotes(positional, flags);
91
+ case "request-oracle-quote":
92
+ return requestOracleQuote(positional, flags);
93
+ case "activity":
94
+ return activity(positional, flags);
95
+ case "global-activity":
96
+ return globalActivity(flags);
97
+ case "create":
98
+ return create(positional, flags);
99
+ case "help":
100
+ case void 0:
101
+ console.log(HELP);
102
+ return;
103
+ default:
104
+ fail(`Unknown markets subcommand: "${subcommand}". Run "context markets help" for usage.`);
105
+ }
106
+ }
107
+ async function list(flags) {
108
+ const ctx = readClient(flags);
109
+ const result = await ctx.markets.list({
110
+ status: flags["status"] || void 0,
111
+ sortBy: flags["sort-by"] || void 0,
112
+ sort: flags["sort"] || void 0,
113
+ limit: flags["limit"] ? parseInt(flags["limit"], 10) : void 0,
114
+ cursor: flags["cursor"] || void 0,
115
+ visibility: flags["visibility"] || void 0,
116
+ resolutionStatus: flags["resolution-status"] || void 0,
117
+ creator: flags["creator"] || void 0,
118
+ category: flags["category"] || void 0
119
+ });
120
+ out(result, {
121
+ rows: result.markets || [],
122
+ columns: [
123
+ { key: "shortQuestion", label: "Question", format: (v) => truncate(v, 34) },
124
+ { key: "outcomePrices[1].buyPrice", label: "Yes", format: formatPrice },
125
+ { key: "outcomePrices[0].buyPrice", label: "No", format: formatPrice },
126
+ { key: "volume", label: "Volume", format: formatVolume },
127
+ { key: "status", label: "Status", format: (v) => String(v ?? "\u2014") }
128
+ ],
129
+ numbered: true,
130
+ emptyMessage: "No markets found.",
131
+ cursor: result.cursor || null
132
+ });
133
+ }
134
+ async function search(positional, flags) {
135
+ const q = requirePositional(positional, 0, "query", "context markets search <query>");
136
+ const ctx = readClient(flags);
137
+ const result = await ctx.markets.search({
138
+ q,
139
+ limit: flags["limit"] ? parseInt(flags["limit"], 10) : void 0,
140
+ offset: flags["offset"] ? parseInt(flags["offset"], 10) : void 0
141
+ });
142
+ out(result, {
143
+ rows: result.markets || [],
144
+ columns: [
145
+ { key: "shortQuestion", label: "Question", format: (v) => truncate(v, 34) },
146
+ { key: "outcomePrices[1].currentPrice", label: "Yes", format: formatPrice },
147
+ { key: "outcomePrices[0].currentPrice", label: "No", format: formatPrice },
148
+ { key: "volume", label: "Volume", format: formatVolume },
149
+ { key: "status", label: "Status", format: (v) => String(v ?? "\u2014") }
150
+ ],
151
+ numbered: true,
152
+ emptyMessage: "No markets found."
153
+ });
154
+ }
155
+ async function get(positional, flags) {
156
+ const id = requirePositional(positional, 0, "id", "context markets get <id>");
157
+ const ctx = readClient(flags);
158
+ const market = await ctx.markets.get(id);
159
+ const m = market;
160
+ out(market, {
161
+ detail: [
162
+ ["ID", String(m.id || "\u2014")],
163
+ ["Question", String(m.question || m.shortQuestion || "\u2014")],
164
+ ["Status", String(m.status || "\u2014")],
165
+ ["Yes", m.outcomePrices?.[1] ? `${formatPrice(m.outcomePrices[1].bestBid)} bid / ${formatPrice(m.outcomePrices[1].bestAsk)} ask` : "\u2014"],
166
+ ["No", m.outcomePrices?.[0] ? `${formatPrice(m.outcomePrices[0].bestBid)} bid / ${formatPrice(m.outcomePrices[0].bestAsk)} ask` : "\u2014"],
167
+ ["Volume", formatVolume(m.volume)],
168
+ ["24h Volume", formatVolume(m.volume24h)],
169
+ ["Participants", String(m.participantCount ?? "\u2014")],
170
+ ["Deadline", formatDate(m.deadline)],
171
+ ["Creator", formatAddress(m.creator || m.metadata?.creator)]
172
+ ]
173
+ });
174
+ }
175
+ async function quotes(positional, flags) {
176
+ const id = requirePositional(positional, 0, "id", "context markets quotes <id>");
177
+ const ctx = readClient(flags);
178
+ const result = await ctx.markets.quotes(id);
179
+ const q = result;
180
+ out(result, {
181
+ detail: [
182
+ ["Market", String(q.marketId || "\u2014")],
183
+ ["Yes", `${formatPrice(q.yes?.bid)} bid / ${formatPrice(q.yes?.ask)} ask / ${formatPrice(q.yes?.last)} last`],
184
+ ["No", `${formatPrice(q.no?.bid)} bid / ${formatPrice(q.no?.ask)} ask / ${formatPrice(q.no?.last)} last`],
185
+ ["Spread", q.spread != null ? `${formatPrice(q.spread)}` : "\u2014"]
186
+ ]
187
+ });
188
+ }
189
+ async function orderbook(positional, flags) {
190
+ const id = requirePositional(positional, 0, "id", "context markets orderbook <id>");
191
+ const ctx = readClient(flags);
192
+ const result = await ctx.markets.fullOrderbook(id, {
193
+ depth: flags["depth"] ? parseInt(flags["depth"], 10) : void 0
194
+ });
195
+ const ob = result;
196
+ out(result, {
197
+ detail: [
198
+ ["Market", String(ob.marketId || "\u2014")],
199
+ ["Yes Bids", (ob.yes?.bids || []).map((l) => `${formatPrice(l.price)} \xD7 ${l.size}`).join(", ") || "\u2014"],
200
+ ["Yes Asks", (ob.yes?.asks || []).map((l) => `${formatPrice(l.price)} \xD7 ${l.size}`).join(", ") || "\u2014"],
201
+ ["No Bids", (ob.no?.bids || []).map((l) => `${formatPrice(l.price)} \xD7 ${l.size}`).join(", ") || "\u2014"],
202
+ ["No Asks", (ob.no?.asks || []).map((l) => `${formatPrice(l.price)} \xD7 ${l.size}`).join(", ") || "\u2014"]
203
+ ]
204
+ });
205
+ }
206
+ async function simulate(positional, flags) {
207
+ const id = requirePositional(positional, 0, "id", "context markets simulate <id> --side <yes|no> --amount <n>");
208
+ const side = requireFlag(flags, "side", "context markets simulate <id> --side <yes|no> --amount <n>");
209
+ const amountRaw = requireFlag(flags, "amount", "context markets simulate <id> --side <yes|no> --amount <n>");
210
+ if (side !== "yes" && side !== "no") {
211
+ fail("--side must be 'yes' or 'no'", { received: side });
212
+ }
213
+ const amount = parseFloat(amountRaw);
214
+ if (isNaN(amount) || amount <= 0) {
215
+ fail("--amount must be a positive number", { received: amountRaw });
216
+ }
217
+ const ctx = readClient(flags);
218
+ const result = await ctx.markets.simulate(id, {
219
+ side,
220
+ amount,
221
+ amountType: flags["amount-type"] === "contracts" ? "contracts" : "usd",
222
+ trader: flags["trader"] || void 0
223
+ });
224
+ const sim = result;
225
+ out(result, {
226
+ detail: [
227
+ ["Market", String(sim.marketId || "\u2014")],
228
+ ["Side", String(sim.side || "\u2014")],
229
+ ["Amount", String(sim.amount ?? "\u2014")],
230
+ ["Est. Contracts", String(sim.estimatedContracts ?? "\u2014")],
231
+ ["Avg Price", formatPrice(sim.estimatedAvgPrice)],
232
+ ["Slippage", sim.estimatedSlippage != null ? `${(sim.estimatedSlippage * 100).toFixed(1)}%` : "\u2014"]
233
+ ]
234
+ });
235
+ }
236
+ async function priceHistory(positional, flags) {
237
+ const id = requirePositional(positional, 0, "id", "context markets price-history <id>");
238
+ const ctx = readClient(flags);
239
+ const result = await ctx.markets.priceHistory(id, {
240
+ timeframe: flags["timeframe"] || void 0
241
+ });
242
+ out(result);
243
+ }
244
+ async function oracle(positional, flags) {
245
+ const id = requirePositional(positional, 0, "id", "context markets oracle <id>");
246
+ const ctx = readClient(flags);
247
+ const result = await ctx.markets.oracle(id);
248
+ out(result);
249
+ }
250
+ async function oracleQuotes(positional, flags) {
251
+ const id = requirePositional(positional, 0, "id", "context markets oracle-quotes <id>");
252
+ const ctx = readClient(flags);
253
+ const result = await ctx.markets.oracleQuotes(id);
254
+ out(result);
255
+ }
256
+ async function requestOracleQuote(positional, flags) {
257
+ const id = requirePositional(positional, 0, "id", "context markets request-oracle-quote <id>");
258
+ const ctx = readClient(flags);
259
+ const result = await ctx.markets.requestOracleQuote(id);
260
+ out(result);
261
+ }
262
+ async function activity(positional, flags) {
263
+ const id = requirePositional(positional, 0, "id", "context markets activity <id>");
264
+ const ctx = readClient(flags);
265
+ const result = await ctx.markets.activity(id, {
266
+ limit: flags["limit"] ? parseInt(flags["limit"], 10) : void 0,
267
+ cursor: flags["cursor"] || void 0
268
+ });
269
+ const act = result;
270
+ out(result, {
271
+ rows: act.activity || [],
272
+ columns: [
273
+ { key: "type", label: "Type" },
274
+ { key: "timestamp", label: "Time", format: formatDate }
275
+ ],
276
+ numbered: true,
277
+ emptyMessage: "No activity found.",
278
+ cursor: act.pagination?.cursor || null
279
+ });
280
+ }
281
+ async function globalActivity(flags) {
282
+ const ctx = readClient(flags);
283
+ const result = await ctx.markets.globalActivity({
284
+ limit: flags["limit"] ? parseInt(flags["limit"], 10) : void 0,
285
+ cursor: flags["cursor"] || void 0
286
+ });
287
+ const act = result;
288
+ out(result, {
289
+ rows: act.activity || [],
290
+ columns: [
291
+ { key: "type", label: "Type" },
292
+ { key: "timestamp", label: "Time", format: formatDate }
293
+ ],
294
+ numbered: true,
295
+ emptyMessage: "No activity found.",
296
+ cursor: act.pagination?.cursor || null
297
+ });
298
+ }
299
+ async function create(positional, flags) {
300
+ const questionId = requirePositional(positional, 0, "questionId", "context markets create <questionId>");
301
+ const ctx = tradingClient(flags);
302
+ const result = await ctx.markets.create(questionId);
303
+ const r = result;
304
+ out(result, {
305
+ detail: [
306
+ ["Market ID", String(r.marketId || "\u2014")],
307
+ ["Tx Hash", String(r.txHash || "\u2014")]
308
+ ]
309
+ });
310
+ }
311
+ export {
312
+ handleMarkets as default
313
+ };