polytown 0.1.3 → 0.1.7
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/dist/index.js +93 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -129,7 +129,10 @@ var GammaClient = class {
|
|
|
129
129
|
return fetchJson(buildUrl(this.baseUrl, "/tags", params));
|
|
130
130
|
}
|
|
131
131
|
async getTag(idOrSlug) {
|
|
132
|
-
|
|
132
|
+
if (/^\d+$/.test(idOrSlug)) {
|
|
133
|
+
return fetchJson(buildUrl(this.baseUrl, `/tags/${idOrSlug}`));
|
|
134
|
+
}
|
|
135
|
+
return fetchJson(buildUrl(this.baseUrl, `/tags/slug/${idOrSlug}`));
|
|
133
136
|
}
|
|
134
137
|
async getRelated(idOrSlug) {
|
|
135
138
|
return fetchJson(buildUrl(this.baseUrl, `/tags/${idOrSlug}/related`));
|
|
@@ -194,7 +197,7 @@ var GammaClient = class {
|
|
|
194
197
|
var marketsCommand = new Command2("markets").description(
|
|
195
198
|
"Markets commands"
|
|
196
199
|
);
|
|
197
|
-
marketsCommand.command("list").description("List markets").option("--active", "Only active markets").option("--closed", "Only closed markets").option("--cyom", "Filter by create-your-own-market").option("--limit <n>", "Limit results", parseInt).option("--offset <n>", "Offset results", parseInt).option("--order <field>", "Order by field").option("--ascending", "Sort ascending").option("--id <ids>", "Filter by market IDs (comma-separated)").option("--slug <slugs>", "Filter by slug(s)").option("--clob-token-ids <ids>", "Filter by CLOB token IDs").option("--condition-ids <ids>", "Filter by condition IDs").option("--tag-id <id>", "Filter by tag ID", parseInt).option("--related-tags", "Include related tags").option("--include-tag", "Include tag data").option("--liquidity-min <n>", "Min liquidity", parseFloat).option("--liquidity-max <n>", "Max liquidity", parseFloat).option("--volume-min <n>", "Min volume", parseFloat).option("--volume-max <n>", "Max volume", parseFloat).option("--start-date-min <date>", "Earliest start date").option("--start-date-max <date>", "Latest start date").option("--end-date-min <date>", "Earliest end date").option("--end-date-max <date>", "Latest end date").option("--uma-resolution-status <status>", "UMA resolution status").option("--game-id <id>", "Filter by game ID").option("--sports-market-types <types>", "Filter by sports market types").option("--rewards-min-size <n>", "Min rewards size", parseFloat).option("--question-ids <ids>", "Filter by question IDs").action(async (opts) => {
|
|
200
|
+
marketsCommand.command("list").description("List markets").option("--full", "Output full format (default: simplified)").option("--active", "Only active markets").option("--closed", "Only closed markets").option("--cyom", "Filter by create-your-own-market").option("--limit <n>", "Limit results", parseInt).option("--offset <n>", "Offset results", parseInt).option("--order <field>", "Order by field").option("--ascending", "Sort ascending").option("--id <ids>", "Filter by market IDs (comma-separated)").option("--slug <slugs>", "Filter by slug(s)").option("--clob-token-ids <ids>", "Filter by CLOB token IDs").option("--condition-ids <ids>", "Filter by condition IDs").option("--tag-id <id>", "Filter by tag ID", parseInt).option("--related-tags", "Include related tags").option("--include-tag", "Include tag data").option("--liquidity-min <n>", "Min liquidity", parseFloat).option("--liquidity-max <n>", "Max liquidity", parseFloat).option("--volume-min <n>", "Min volume", parseFloat).option("--volume-max <n>", "Max volume", parseFloat).option("--start-date-min <date>", "Earliest start date").option("--start-date-max <date>", "Latest start date").option("--end-date-min <date>", "Earliest end date").option("--end-date-max <date>", "Latest end date").option("--uma-resolution-status <status>", "UMA resolution status").option("--game-id <id>", "Filter by game ID").option("--sports-market-types <types>", "Filter by sports market types").option("--rewards-min-size <n>", "Min rewards size", parseFloat).option("--question-ids <ids>", "Filter by question IDs").action(async (opts) => {
|
|
198
201
|
const gamma = new GammaClient();
|
|
199
202
|
const params = {
|
|
200
203
|
active: opts.active ?? true,
|
|
@@ -226,7 +229,29 @@ marketsCommand.command("list").description("List markets").option("--active", "O
|
|
|
226
229
|
if (opts.rewardsMinSize) params.rewards_min_size = opts.rewardsMinSize;
|
|
227
230
|
if (opts.questionIds) params.question_ids = opts.questionIds;
|
|
228
231
|
const result = await gamma.getMarkets(params);
|
|
229
|
-
|
|
232
|
+
if (opts.full) {
|
|
233
|
+
console.log(JSON.stringify(result, null, 2));
|
|
234
|
+
} else {
|
|
235
|
+
const simplified = result.map((m) => ({
|
|
236
|
+
id: m.id,
|
|
237
|
+
question: m.question,
|
|
238
|
+
slug: m.slug,
|
|
239
|
+
conditionId: m.conditionId,
|
|
240
|
+
clobTokenIds: m.clobTokenIds,
|
|
241
|
+
description: m.description,
|
|
242
|
+
outcomes: m.outcomes,
|
|
243
|
+
outcomePrices: m.outcomePrices,
|
|
244
|
+
active: m.active,
|
|
245
|
+
closed: m.closed,
|
|
246
|
+
endDate: m.endDate,
|
|
247
|
+
volume: m.volumeNum || m.volume,
|
|
248
|
+
volume24hr: m.volume24hr,
|
|
249
|
+
lastTradePrice: m.lastTradePrice,
|
|
250
|
+
oneWeekPriceChange: m.oneWeekPriceChange,
|
|
251
|
+
...opts.includeTag && m.tags ? { tags: m.tags } : {}
|
|
252
|
+
}));
|
|
253
|
+
console.log(JSON.stringify(simplified, null, 2));
|
|
254
|
+
}
|
|
230
255
|
});
|
|
231
256
|
marketsCommand.command("get <id_or_slug>").description("Get market by ID or slug").action(async (idOrSlug) => {
|
|
232
257
|
const gamma = new GammaClient();
|
|
@@ -244,7 +269,7 @@ import { Command as Command3 } from "commander";
|
|
|
244
269
|
var eventsCommand = new Command3("events").description(
|
|
245
270
|
"Events commands"
|
|
246
271
|
);
|
|
247
|
-
eventsCommand.command("list").description("List events").option("--active", "Only active events").option("--closed", "Only closed events").option("--archived", "Include archived events").option("--featured", "Only featured events").option("--cyom", "Filter by create-your-own-market").option("--limit <n>", "Limit results", parseInt).option("--offset <n>", "Offset results", parseInt).option("--order <field>", "Order by field").option("--ascending", "Sort ascending").option("--id <ids>", "Filter by event IDs (comma-separated)").option("--tag <tag>", "Filter by tag slug").option("--tag-id <id>", "Filter by tag ID", parseInt).option("--exclude-tag-id <ids>", "Exclude tag IDs (comma-separated)").option("--slug <slugs>", "Filter by slug(s)").option("--related-tags", "Include related tags").option("--recurrence <pattern>", "Filter by recurrence pattern").option("--liquidity-min <n>", "Min liquidity", parseFloat).option("--liquidity-max <n>", "Max liquidity", parseFloat).option("--volume-min <n>", "Min volume", parseFloat).option("--volume-max <n>", "Max volume", parseFloat).option("--start-date-min <date>", "Earliest start date").option("--start-date-max <date>", "Latest start date").option("--end-date-min <date>", "Earliest end date").option("--end-date-max <date>", "Latest end date").action(async (opts) => {
|
|
272
|
+
eventsCommand.command("list").description("List events").option("--full", "Output full format (default: simplified)").option("--active", "Only active events").option("--closed", "Only closed events").option("--archived", "Include archived events").option("--featured", "Only featured events").option("--cyom", "Filter by create-your-own-market").option("--limit <n>", "Limit results", parseInt).option("--offset <n>", "Offset results", parseInt).option("--order <field>", "Order by field").option("--ascending", "Sort ascending").option("--id <ids>", "Filter by event IDs (comma-separated)").option("--tag <tag>", "Filter by tag slug").option("--tag-id <id>", "Filter by tag ID", parseInt).option("--exclude-tag-id <ids>", "Exclude tag IDs (comma-separated)").option("--slug <slugs>", "Filter by slug(s)").option("--related-tags", "Include related tags").option("--include-tag", "Include tag data").option("--recurrence <pattern>", "Filter by recurrence pattern").option("--liquidity-min <n>", "Min liquidity", parseFloat).option("--liquidity-max <n>", "Max liquidity", parseFloat).option("--volume-min <n>", "Min volume", parseFloat).option("--volume-max <n>", "Max volume", parseFloat).option("--start-date-min <date>", "Earliest start date").option("--start-date-max <date>", "Latest start date").option("--end-date-min <date>", "Earliest end date").option("--end-date-max <date>", "Latest end date").action(async (opts) => {
|
|
248
273
|
const gamma = new GammaClient();
|
|
249
274
|
const params = {
|
|
250
275
|
active: opts.active ?? true,
|
|
@@ -263,6 +288,7 @@ eventsCommand.command("list").description("List events").option("--active", "Onl
|
|
|
263
288
|
if (opts.excludeTagId) params.exclude_tag_id = opts.excludeTagId.split(",");
|
|
264
289
|
if (opts.slug) params.slug = opts.slug;
|
|
265
290
|
if (opts.relatedTags) params.related_tags = true;
|
|
291
|
+
if (opts.includeTag) params.include_tag = true;
|
|
266
292
|
if (opts.recurrence) params.recurrence = opts.recurrence;
|
|
267
293
|
if (opts.liquidityMin) params.liquidity_min = opts.liquidityMin;
|
|
268
294
|
if (opts.liquidityMax) params.liquidity_max = opts.liquidityMax;
|
|
@@ -273,7 +299,38 @@ eventsCommand.command("list").description("List events").option("--active", "Onl
|
|
|
273
299
|
if (opts.endDateMin) params.end_date_min = opts.endDateMin;
|
|
274
300
|
if (opts.endDateMax) params.end_date_max = opts.endDateMax;
|
|
275
301
|
const result = await gamma.getEvents(params);
|
|
276
|
-
|
|
302
|
+
if (opts.full) {
|
|
303
|
+
console.log(JSON.stringify(result, null, 2));
|
|
304
|
+
} else {
|
|
305
|
+
const simplified = result.map((e) => ({
|
|
306
|
+
id: e.id,
|
|
307
|
+
title: e.title,
|
|
308
|
+
slug: e.slug,
|
|
309
|
+
description: e.description,
|
|
310
|
+
closed: e.closed,
|
|
311
|
+
endDate: e.endDate,
|
|
312
|
+
volume: e.volume,
|
|
313
|
+
...opts.includeTag && e.tags ? { tags: e.tags } : {},
|
|
314
|
+
markets: (e.markets || []).map((m) => ({
|
|
315
|
+
id: m.id,
|
|
316
|
+
question: m.question,
|
|
317
|
+
slug: m.slug,
|
|
318
|
+
conditionId: m.conditionId,
|
|
319
|
+
clobTokenIds: m.clobTokenIds,
|
|
320
|
+
outcomes: m.outcomes,
|
|
321
|
+
outcomePrices: m.outcomePrices,
|
|
322
|
+
active: m.active,
|
|
323
|
+
closed: m.closed,
|
|
324
|
+
endDate: m.endDate,
|
|
325
|
+
volume: m.volumeNum || m.volume,
|
|
326
|
+
volume24hr: m.volume24hr,
|
|
327
|
+
liquidity: m.liquidityNum || m.liquidity,
|
|
328
|
+
lastTradePrice: m.lastTradePrice,
|
|
329
|
+
oneWeekPriceChange: m.oneWeekPriceChange
|
|
330
|
+
}))
|
|
331
|
+
}));
|
|
332
|
+
console.log(JSON.stringify(simplified, null, 2));
|
|
333
|
+
}
|
|
277
334
|
});
|
|
278
335
|
eventsCommand.command("get <id_or_slug>").description("Get event by ID or slug").action(async (idOrSlug) => {
|
|
279
336
|
const gamma = new GammaClient();
|
|
@@ -284,10 +341,24 @@ eventsCommand.command("get <id_or_slug>").description("Get event by ID or slug")
|
|
|
284
341
|
// src/commands/tags.ts
|
|
285
342
|
import { Command as Command4 } from "commander";
|
|
286
343
|
var tagsCommand = new Command4("tags").description("Tags commands");
|
|
287
|
-
tagsCommand.command("list").description("List tags").option("--limit <n>", "Limit results", parseInt).option("--offset <n>", "Offset results", parseInt).option("--ascending", "Sort ascending").action(async (opts) => {
|
|
344
|
+
tagsCommand.command("list").description("List tags").option("--limit <n>", "Limit results", parseInt).option("--offset <n>", "Offset results", parseInt).option("--ascending", "Sort ascending").option("--search <query>", "Search tags by label or slug").action(async (opts) => {
|
|
288
345
|
const gamma = new GammaClient();
|
|
289
|
-
|
|
290
|
-
|
|
346
|
+
if (opts.search) {
|
|
347
|
+
const query = opts.search.toLowerCase();
|
|
348
|
+
const all = [];
|
|
349
|
+
for (let offset = 0; ; offset += 300) {
|
|
350
|
+
const batch = await gamma.getTags({ limit: 300, offset });
|
|
351
|
+
all.push(...batch);
|
|
352
|
+
if (batch.length < 300) break;
|
|
353
|
+
}
|
|
354
|
+
const matched = all.filter(
|
|
355
|
+
(t) => t.label?.toLowerCase().includes(query) || t.slug?.toLowerCase().includes(query)
|
|
356
|
+
);
|
|
357
|
+
console.log(JSON.stringify(matched, null, 2));
|
|
358
|
+
} else {
|
|
359
|
+
const result = await gamma.getTags(opts);
|
|
360
|
+
console.log(JSON.stringify(result, null, 2));
|
|
361
|
+
}
|
|
291
362
|
});
|
|
292
363
|
tagsCommand.command("get <id_or_slug>").description("Get tag by ID or slug").action(async (idOrSlug) => {
|
|
293
364
|
const gamma = new GammaClient();
|
|
@@ -1444,6 +1515,10 @@ var DataClient = class {
|
|
|
1444
1515
|
buildUrl2(this.baseUrl, "/trades", { user: address, ...params })
|
|
1445
1516
|
);
|
|
1446
1517
|
}
|
|
1518
|
+
// Get all trades for a market (no user filter)
|
|
1519
|
+
async getMarketTrades(params) {
|
|
1520
|
+
return fetchJson2(buildUrl2(this.baseUrl, "/trades", params));
|
|
1521
|
+
}
|
|
1447
1522
|
async getActivity(address, params) {
|
|
1448
1523
|
return fetchJson2(
|
|
1449
1524
|
buildUrl2(this.baseUrl, "/activity", { user: address, ...params })
|
|
@@ -1529,6 +1604,16 @@ dataCommand.command("trades [address]").description("Get trade history (defaults
|
|
|
1529
1604
|
});
|
|
1530
1605
|
out5(result);
|
|
1531
1606
|
});
|
|
1607
|
+
dataCommand.command("market-trades").description("Get all trades for a market (no user filter)").option("--market <condition_id>", "Market condition ID").option("--slug <slug>", "Market slug").option("--limit <n>", "Limit results", parseInt).option("--offset <n>", "Offset results", parseInt).action(async (opts) => {
|
|
1608
|
+
const client = new DataClient();
|
|
1609
|
+
const result = await client.getMarketTrades({
|
|
1610
|
+
limit: opts.limit,
|
|
1611
|
+
offset: opts.offset,
|
|
1612
|
+
market: opts.market,
|
|
1613
|
+
slug: opts.slug
|
|
1614
|
+
});
|
|
1615
|
+
out5(result);
|
|
1616
|
+
});
|
|
1532
1617
|
dataCommand.command("activity [address]").description("Get activity history (defaults to your wallet)").option("--private-key <key>", "Private key").option("--limit <n>", "Limit results", parseInt).option("--offset <n>", "Offset results", parseInt).action(async (address, opts) => {
|
|
1533
1618
|
const addr = resolveAddr(address, opts);
|
|
1534
1619
|
const client = new DataClient();
|