@agg-build/sdk 1.3.0 → 2.1.0

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.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  __async,
3
+ __objRest,
3
4
  __spreadProps,
4
5
  __spreadValues
5
- } from "./chunk-AXBFBHS2.mjs";
6
+ } from "./chunk-WNQUEZJF.mjs";
6
7
 
7
8
  // ../common/src/enums/venue.ts
8
9
  var Venue = /* @__PURE__ */ ((Venue3) => {
@@ -94,8 +95,14 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
94
95
  OrderStatus2["pending_bridge"] = "pending_bridge";
95
96
  OrderStatus2["submitting"] = "submitting";
96
97
  OrderStatus2["submitted"] = "submitted";
98
+ OrderStatus2["open"] = "open";
99
+ OrderStatus2["partially_filled_open"] = "partially_filled_open";
100
+ OrderStatus2["cancel_pending"] = "cancel_pending";
97
101
  OrderStatus2["filled"] = "filled";
98
102
  OrderStatus2["partial_fill"] = "partial_fill";
103
+ OrderStatus2["failed"] = "failed";
104
+ OrderStatus2["expired"] = "expired";
105
+ OrderStatus2["cancelled"] = "cancelled";
99
106
  return OrderStatus2;
100
107
  })(OrderStatus || {});
101
108
  var TradeSide = /* @__PURE__ */ ((TradeSide2) => {
@@ -103,6 +110,20 @@ var TradeSide = /* @__PURE__ */ ((TradeSide2) => {
103
110
  TradeSide2["Sell"] = "sell";
104
111
  return TradeSide2;
105
112
  })(TradeSide || {});
113
+ var OrderType = /* @__PURE__ */ ((OrderType2) => {
114
+ OrderType2["Market"] = "market";
115
+ OrderType2["Limit"] = "limit";
116
+ return OrderType2;
117
+ })(OrderType || {});
118
+ var TimeInForce = /* @__PURE__ */ ((TimeInForce2) => {
119
+ TimeInForce2["GTC"] = "GTC";
120
+ TimeInForce2["GTD"] = "GTD";
121
+ TimeInForce2["FOK"] = "FOK";
122
+ TimeInForce2["FAK"] = "FAK";
123
+ TimeInForce2["IOC"] = "IOC";
124
+ TimeInForce2["ALO"] = "ALO";
125
+ return TimeInForce2;
126
+ })(TimeInForce || {});
106
127
 
107
128
  // ../common/src/utils/format-market-display.ts
108
129
  function formatOutcomeLabel(venue, outcome, _market) {
@@ -1458,6 +1479,8 @@ var AggWebSocket = class {
1458
1479
 
1459
1480
  // src/client.ts
1460
1481
  var COOKIE_REFRESH_DELIVERY = "cookie-refresh";
1482
+ var DEFAULT_MIDPOINT_IDS_PER_REQUEST = 75;
1483
+ var MAX_MIDPOINT_IDS_PER_REQUEST = 200;
1461
1484
  var isUserProfile = (user) => {
1462
1485
  return "accounts" in user && "wallets" in user && "avatarUrl" in user;
1463
1486
  };
@@ -1491,6 +1514,17 @@ var normalizeSessionUser = (user, currentUser) => {
1491
1514
  walletAddress: null
1492
1515
  });
1493
1516
  };
1517
+ var resolveMidpointIdsPerRequest = (value) => {
1518
+ if (value == null || !Number.isFinite(value)) return DEFAULT_MIDPOINT_IDS_PER_REQUEST;
1519
+ return Math.min(MAX_MIDPOINT_IDS_PER_REQUEST, Math.max(1, Math.floor(value)));
1520
+ };
1521
+ var chunkArray = (items, size) => {
1522
+ const chunks = [];
1523
+ for (let index = 0; index < items.length; index += size) {
1524
+ chunks.push(items.slice(index, index + size));
1525
+ }
1526
+ return chunks;
1527
+ };
1494
1528
  var mapChartResolution = (resolution) => {
1495
1529
  switch (resolution) {
1496
1530
  case void 0:
@@ -1535,6 +1569,27 @@ var AggClient = class {
1535
1569
  this.restoreSession();
1536
1570
  this.initAuthChannel();
1537
1571
  }
1572
+ resolvePaperTradingAppId(appId) {
1573
+ const resolvedAppId = appId != null ? appId : this.appId;
1574
+ if (!resolvedAppId) {
1575
+ throw new Error(
1576
+ "Paper trading account methods require appId in client options or method options"
1577
+ );
1578
+ }
1579
+ return encodeURIComponent(resolvedAppId);
1580
+ }
1581
+ paperTradingAccountsPath(appId) {
1582
+ return `/apps/${this.resolvePaperTradingAppId(appId)}/paper-trading/accounts`;
1583
+ }
1584
+ paperTradingAccountPath(accountId, appId) {
1585
+ return `${this.paperTradingAccountsPath(appId)}/${encodeURIComponent(accountId)}`;
1586
+ }
1587
+ paperTradingListQuery(params = {}) {
1588
+ const query = {};
1589
+ if (params.limit != null) query.limit = String(params.limit);
1590
+ if (params.cursor) query.cursor = params.cursor;
1591
+ return Object.keys(query).length ? query : void 0;
1592
+ }
1538
1593
  withAuthPayload(payload) {
1539
1594
  var _a, _b, _c;
1540
1595
  if (typeof payload.earlyAccessCode === "string" && payload.earlyAccessCode.trim().length > 0) {
@@ -2164,6 +2219,100 @@ Issued At: ${issuedAt}`;
2164
2219
  });
2165
2220
  });
2166
2221
  }
2222
+ /** Create a server-managed paper trading account for an app. Requires adminKey or apiKey. */
2223
+ createPaperTradingAccount(params, options) {
2224
+ return __async(this, null, function* () {
2225
+ return this.request(this.paperTradingAccountsPath(options == null ? void 0 : options.appId), {
2226
+ method: "POST",
2227
+ body: JSON.stringify(params)
2228
+ });
2229
+ });
2230
+ }
2231
+ /** List server-managed paper trading accounts for an app. Requires adminKey or apiKey. */
2232
+ listPaperTradingAccounts() {
2233
+ return __async(this, arguments, function* (params = {}) {
2234
+ const _a = params, { appId } = _a, listParams = __objRest(_a, ["appId"]);
2235
+ return this.request(this.paperTradingAccountsPath(appId), {
2236
+ query: this.paperTradingListQuery(listParams)
2237
+ });
2238
+ });
2239
+ }
2240
+ /** Fetch a server-managed paper trading account. Requires adminKey or apiKey. */
2241
+ getPaperTradingAccount(accountId, options) {
2242
+ return __async(this, null, function* () {
2243
+ return this.request(
2244
+ this.paperTradingAccountPath(accountId, options == null ? void 0 : options.appId)
2245
+ );
2246
+ });
2247
+ }
2248
+ /** Set a paper trading account cash balance. Requires adminKey or apiKey. */
2249
+ setPaperTradingBalance(accountId, params, options) {
2250
+ return __async(this, null, function* () {
2251
+ return this.request(
2252
+ `${this.paperTradingAccountPath(accountId, options == null ? void 0 : options.appId)}/balance`,
2253
+ {
2254
+ method: "PATCH",
2255
+ body: JSON.stringify(params)
2256
+ }
2257
+ );
2258
+ });
2259
+ }
2260
+ /** Clear positions and reset cash for a paper trading account. Requires adminKey or apiKey. */
2261
+ resetPaperTradingAccount(_0) {
2262
+ return __async(this, arguments, function* (accountId, params = {}, options) {
2263
+ return this.request(
2264
+ `${this.paperTradingAccountPath(accountId, options == null ? void 0 : options.appId)}/reset`,
2265
+ {
2266
+ method: "POST",
2267
+ body: JSON.stringify(params)
2268
+ }
2269
+ );
2270
+ });
2271
+ }
2272
+ /** Place a direct simulated order in a paper trading account. Requires adminKey or apiKey. */
2273
+ placePaperTradingOrder(accountId, params, options) {
2274
+ return __async(this, null, function* () {
2275
+ return this.request(
2276
+ `${this.paperTradingAccountPath(accountId, options == null ? void 0 : options.appId)}/orders`,
2277
+ {
2278
+ method: "POST",
2279
+ body: JSON.stringify(params)
2280
+ }
2281
+ );
2282
+ });
2283
+ }
2284
+ /** List positions for a server-managed paper trading account. Requires adminKey or apiKey. */
2285
+ listPaperTradingPositions(_0) {
2286
+ return __async(this, arguments, function* (accountId, params = {}) {
2287
+ const _a = params, { appId } = _a, listParams = __objRest(_a, ["appId"]);
2288
+ return this.request(
2289
+ `${this.paperTradingAccountPath(accountId, appId)}/positions`,
2290
+ {
2291
+ query: this.paperTradingListQuery(listParams)
2292
+ }
2293
+ );
2294
+ });
2295
+ }
2296
+ /** List orders for a server-managed paper trading account. Requires adminKey or apiKey. */
2297
+ listPaperTradingOrders(_0) {
2298
+ return __async(this, arguments, function* (accountId, params = {}) {
2299
+ const _a = params, { appId } = _a, listParams = __objRest(_a, ["appId"]);
2300
+ return this.request(
2301
+ `${this.paperTradingAccountPath(accountId, appId)}/orders`,
2302
+ {
2303
+ query: this.paperTradingListQuery(listParams)
2304
+ }
2305
+ );
2306
+ });
2307
+ }
2308
+ /** Fetch account-level paper trading equity, P&L, and marked positions. Requires adminKey or apiKey. */
2309
+ getPaperTradingPortfolio(accountId, options) {
2310
+ return __async(this, null, function* () {
2311
+ return this.request(
2312
+ `${this.paperTradingAccountPath(accountId, options == null ? void 0 : options.appId)}/portfolio`
2313
+ );
2314
+ });
2315
+ }
2167
2316
  /** Cancel a pending managed execution by order id. */
2168
2317
  cancelManagedOrder(orderId, options) {
2169
2318
  return __async(this, null, function* () {
@@ -2211,6 +2360,92 @@ Issued At: ${issuedAt}`;
2211
2360
  });
2212
2361
  });
2213
2362
  }
2363
+ /** List deterministic recurring crypto window markets across venues. Requires appId or admin auth. */
2364
+ listRecurringCryptoMarkets(options) {
2365
+ return __async(this, null, function* () {
2366
+ const query = {};
2367
+ if ((options == null ? void 0 : options.assets) && options.assets.length > 0) query.assets = options.assets;
2368
+ if ((options == null ? void 0 : options.durations) && options.durations.length > 0) query.durations = options.durations;
2369
+ if (options == null ? void 0 : options.interval) query.interval = options.interval;
2370
+ if (options == null ? void 0 : options.window) query.window = options.window;
2371
+ if ((options == null ? void 0 : options.venues) && options.venues.length > 0) query.venues = options.venues;
2372
+ if ((options == null ? void 0 : options.status) && options.status.length > 0) query.status = options.status;
2373
+ if (options == null ? void 0 : options.windowStartFrom) query.windowStartFrom = options.windowStartFrom;
2374
+ if (options == null ? void 0 : options.windowStartTo) query.windowStartTo = options.windowStartTo;
2375
+ if (options == null ? void 0 : options.cursor) query.cursor = options.cursor;
2376
+ if ((options == null ? void 0 : options.limit) != null) query.limit = String(options.limit);
2377
+ if ((options == null ? void 0 : options.includeOrderbookPrices) != null) {
2378
+ query.includeOrderbookPrices = String(options.includeOrderbookPrices);
2379
+ }
2380
+ if ((options == null ? void 0 : options.includeReferencePrices) != null) {
2381
+ query.includeReferencePrices = String(options.includeReferencePrices);
2382
+ }
2383
+ if ((options == null ? void 0 : options.includeDirectVenueMarkets) != null) {
2384
+ query.includeDirectVenueMarkets = String(options.includeDirectVenueMarkets);
2385
+ }
2386
+ return this.request("/crypto/recurring-markets", {
2387
+ query: Object.keys(query).length > 0 ? query : void 0,
2388
+ signal: options == null ? void 0 : options.signal
2389
+ });
2390
+ });
2391
+ }
2392
+ /** Poll fresh reference prices for recurring crypto markets. Requires appId or admin auth. */
2393
+ getCryptoReferencePrices(options) {
2394
+ return __async(this, null, function* () {
2395
+ var _a, _b, _c, _d, _e, _f;
2396
+ const targets = [
2397
+ ...(_a = options.targets) != null ? _a : [],
2398
+ ...((_b = options.venueMarketIds) != null ? _b : []).map((venueMarketId) => ({
2399
+ type: "venueMarket",
2400
+ venueMarketId
2401
+ })),
2402
+ ...((_c = options.venueEventIds) != null ? _c : []).map((venueEventId) => ({
2403
+ type: "venueEvent",
2404
+ venueEventId
2405
+ })),
2406
+ ...((_d = options.externalMarkets) != null ? _d : []).map((market) => ({
2407
+ type: "externalVenueMarket",
2408
+ venue: market.venue,
2409
+ externalMarketId: market.externalMarketId
2410
+ })),
2411
+ ...((_e = options.markets) != null ? _e : []).map((market) => {
2412
+ var _a2;
2413
+ return {
2414
+ type: "market",
2415
+ venue: market.venue,
2416
+ venueEventId: market.venueEventId,
2417
+ venueMarketId: market.venueMarketId,
2418
+ externalEventId: market.externalEventId,
2419
+ externalMarketId: market.externalMarketId,
2420
+ asset: market.asset,
2421
+ quoteAsset: (_a2 = market.quoteAsset) != null ? _a2 : "USD",
2422
+ resolution: market.resolution
2423
+ };
2424
+ }),
2425
+ ...((_f = options.windowMarkets) != null ? _f : []).flatMap(
2426
+ (windowMarket) => windowMarket.markets.map((market) => ({
2427
+ type: "market",
2428
+ venue: market.venue,
2429
+ venueEventId: market.venueEventId,
2430
+ venueMarketId: market.venueMarketId,
2431
+ externalEventId: market.externalEventId,
2432
+ externalMarketId: market.externalMarketId,
2433
+ asset: windowMarket.asset,
2434
+ quoteAsset: windowMarket.quoteAsset,
2435
+ resolution: market.resolution
2436
+ }))
2437
+ )
2438
+ ];
2439
+ if (targets.length === 0) {
2440
+ throw new Error("getCryptoReferencePrices requires at least one target");
2441
+ }
2442
+ return this.request("/crypto/reference-prices", {
2443
+ method: "POST",
2444
+ body: JSON.stringify({ targets }),
2445
+ signal: options.signal
2446
+ });
2447
+ });
2448
+ }
2214
2449
  /** List venue markets with optional filters. Requires appId or admin auth. Supports cursor-based pagination. */
2215
2450
  getVenueMarkets(options) {
2216
2451
  return __async(this, null, function* () {
@@ -2250,6 +2485,61 @@ Issued At: ${issuedAt}`;
2250
2485
  return this.request("/app/config", init);
2251
2486
  });
2252
2487
  }
2488
+ buildNewsFeedQuery(options) {
2489
+ const query = {};
2490
+ if (options == null ? void 0 : options.cursor) query.cursor = options.cursor;
2491
+ if (options == null ? void 0 : options.since) query.since = options.since;
2492
+ if (options == null ? void 0 : options.before) query.before = options.before;
2493
+ if ((options == null ? void 0 : options.limit) != null) query.limit = String(options.limit);
2494
+ return Object.keys(query).length > 0 ? query : void 0;
2495
+ }
2496
+ /** List available market news feeds and item counts. */
2497
+ getNewsFeeds(options) {
2498
+ return __async(this, null, function* () {
2499
+ return this.request("/news-feed", {
2500
+ signal: options == null ? void 0 : options.signal
2501
+ });
2502
+ });
2503
+ }
2504
+ /** Get the article-centric market news feed for a category. */
2505
+ getNewsFeed(category, options) {
2506
+ return __async(this, null, function* () {
2507
+ return this.request(`/news-feed/${encodeURIComponent(category)}`, {
2508
+ query: this.buildNewsFeedQuery(options),
2509
+ signal: options == null ? void 0 : options.signal
2510
+ });
2511
+ });
2512
+ }
2513
+ /** Get the market-centric market news feed for a category. */
2514
+ getNewsFeedMarkets(category, options) {
2515
+ return __async(this, null, function* () {
2516
+ return this.request(
2517
+ `/news-feed/${encodeURIComponent(category)}/markets`,
2518
+ {
2519
+ query: this.buildNewsFeedQuery(options),
2520
+ signal: options == null ? void 0 : options.signal
2521
+ }
2522
+ );
2523
+ });
2524
+ }
2525
+ /** Get news feed coverage and per-category counts. */
2526
+ getNewsFeedStatus(options) {
2527
+ return __async(this, null, function* () {
2528
+ return this.request("/news-feed/status", {
2529
+ signal: options == null ? void 0 : options.signal
2530
+ });
2531
+ });
2532
+ }
2533
+ /** Search recent news for specific markets and return market impact summaries. */
2534
+ getMarketNews(params, options) {
2535
+ return __async(this, null, function* () {
2536
+ return this.request("/news-feed/market-news", {
2537
+ method: "POST",
2538
+ body: JSON.stringify(params),
2539
+ signal: options == null ? void 0 : options.signal
2540
+ });
2541
+ });
2542
+ }
2253
2543
  /**
2254
2544
  * Search events or markets by query string. Supports cursor-based pagination.
2255
2545
  *
@@ -2361,14 +2651,27 @@ Issued At: ${issuedAt}`;
2361
2651
  }
2362
2652
  getMidpoints(paramsOrVenueMarketIds, options) {
2363
2653
  return __async(this, null, function* () {
2654
+ var _a;
2364
2655
  const venueMarketIds = Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds : paramsOrVenueMarketIds.venueMarketIds;
2365
2656
  const bestPrice = !Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds.bestPrice : options == null ? void 0 : options.bestPrice;
2366
- const query = { venueMarketIds };
2367
- if (bestPrice) query.bestPrice = "true";
2368
- return this.request("/midpoints", {
2369
- query,
2370
- signal: options == null ? void 0 : options.signal
2371
- });
2657
+ const maxMidpointIdsPerRequest = resolveMidpointIdsPerRequest(
2658
+ (_a = options == null ? void 0 : options.maxMidpointIdsPerRequest) != null ? _a : Array.isArray(paramsOrVenueMarketIds) ? void 0 : paramsOrVenueMarketIds.maxMidpointIdsPerRequest
2659
+ );
2660
+ const requestBatch = (batchVenueMarketIds) => {
2661
+ const query = { venueMarketIds: batchVenueMarketIds };
2662
+ if (bestPrice) query.bestPrice = "true";
2663
+ return this.request("/midpoints", {
2664
+ query,
2665
+ signal: options == null ? void 0 : options.signal
2666
+ });
2667
+ };
2668
+ if (venueMarketIds.length <= maxMidpointIdsPerRequest) {
2669
+ return requestBatch(venueMarketIds);
2670
+ }
2671
+ const responses = yield Promise.all(
2672
+ chunkArray(venueMarketIds, maxMidpointIdsPerRequest).map((batch) => requestBatch(batch))
2673
+ );
2674
+ return { data: responses.flatMap((response) => response.data) };
2372
2675
  });
2373
2676
  }
2374
2677
  /** Get a single outcome-level orderbook from the engine. */
@@ -2472,6 +2775,19 @@ Issued At: ${issuedAt}`;
2472
2775
  });
2473
2776
  });
2474
2777
  }
2778
+ /**
2779
+ * Preview a withdrawal — real fee + receive estimate without creating one.
2780
+ * Optional: `withdrawManaged` does NOT require a prior preview, so partners
2781
+ * integrating against the SDK can ignore this entirely.
2782
+ */
2783
+ withdrawPreview(params) {
2784
+ return __async(this, null, function* () {
2785
+ return this.request("/execution/withdraw/preview", {
2786
+ method: "POST",
2787
+ body: JSON.stringify(params)
2788
+ });
2789
+ });
2790
+ }
2475
2791
  /**
2476
2792
  * Read the current persisted state of a withdrawal. Used as a backfill for
2477
2793
  * the WS lifecycle channel: the client polls this on hook mount and on WS
@@ -2504,6 +2820,19 @@ Issued At: ${issuedAt}`;
2504
2820
  return this.request("/execution/deposit-addresses");
2505
2821
  });
2506
2822
  }
2823
+ /**
2824
+ * Internal: record that a deposit tx was initiated via the in-app
2825
+ * connected-wallet flow, so the activity feed can label it correctly.
2826
+ * Best-effort — callers should not block the UX on this.
2827
+ */
2828
+ recordDepositIntent(body) {
2829
+ return __async(this, null, function* () {
2830
+ yield this.request(
2831
+ "/execution/deposit-intent",
2832
+ this.buildAuthRequestInit({ method: "POST", body: JSON.stringify(body) })
2833
+ );
2834
+ });
2835
+ }
2507
2836
  /** Get open positions grouped by matched market with per-venue breakdown. */
2508
2837
  getPositions(params) {
2509
2838
  return __async(this, null, function* () {
@@ -2550,6 +2879,18 @@ Issued At: ${issuedAt}`;
2550
2879
  // src/best-split.ts
2551
2880
  var computeBestSplitsByAmount2 = computeBestSplitsByAmount;
2552
2881
 
2882
+ // src/types.ts
2883
+ var RECURRENCE_CADENCES = [
2884
+ "PT5M",
2885
+ "PT10M",
2886
+ "PT15M",
2887
+ "PT1H",
2888
+ "P1D",
2889
+ "P1W",
2890
+ "P1M",
2891
+ "P1Y"
2892
+ ];
2893
+
2553
2894
  // src/errors.ts
2554
2895
  var TurnstileChallengeError = class extends Error {
2555
2896
  constructor(siteKey) {
@@ -2761,6 +3102,9 @@ export {
2761
3102
  MatchStatus,
2762
3103
  MatchType,
2763
3104
  OrderStatus,
3105
+ OrderType,
3106
+ RECURRENCE_CADENCES,
3107
+ TimeInForce,
2764
3108
  TradeSide,
2765
3109
  TurnstileChallengeError,
2766
3110
  VENUES,
package/dist/server.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  __async,
3
3
  __spreadProps,
4
4
  __spreadValues
5
- } from "./chunk-AXBFBHS2.mjs";
5
+ } from "./chunk-WNQUEZJF.mjs";
6
6
 
7
7
  // src/server.ts
8
8
  import { createHmac, timingSafeEqual } from "crypto";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agg-build/sdk",
3
- "version": "1.3.0",
3
+ "version": "2.1.0",
4
4
  "description": "Vanilla TypeScript client for the AGG prediction market aggregator (auth, markets, orderbooks, charts, trading, managed execution, WebSockets). Works in browsers, Node.js, and React Native.",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",