@agg-build/sdk 2.2.0 → 2.3.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.d.mts CHANGED
@@ -871,6 +871,7 @@ type MidpointItem = {
871
871
  timestamp: number | null;
872
872
  outcomes: OutcomeMidpoint[];
873
873
  matched: MatchedMidpoint[];
874
+ arbReturn?: number | null | undefined;
874
875
  };
875
876
  type ComputeSplitsRequest = {
876
877
  side: TradeSide$1;
@@ -1328,13 +1329,21 @@ interface WsTrade {
1328
1329
  type WsCandleInterval = "1m" | "5m" | "1h" | "1d";
1329
1330
  interface WsSubscribed {
1330
1331
  type: "subscribed";
1332
+ /** Confirmed ids. For `orderbook`/`trades` these are venueMarketOutcomeIds.
1333
+ * For `arb` this historically mirrors the marketIds — prefer `marketIds`. */
1331
1334
  outcomeIds: string[];
1332
- channel: "orderbook" | "trades";
1335
+ /** Confirmed marketIds — only set on `arb` confirmations, whose
1336
+ * subscriptions are keyed by marketIds, not outcomeIds. */
1337
+ marketIds?: string[];
1338
+ channel: "orderbook" | "trades" | "arb" | "arb-feed";
1333
1339
  }
1334
1340
  interface WsUnsubscribed {
1335
1341
  type: "unsubscribed";
1342
+ /** See {@link WsSubscribed.outcomeIds}. */
1336
1343
  outcomeIds: string[];
1337
- channel: "orderbook" | "trades";
1344
+ /** Confirmed marketIds — only set on `arb` confirmations. */
1345
+ marketIds?: string[];
1346
+ channel: "orderbook" | "trades" | "arb" | "arb-feed";
1338
1347
  }
1339
1348
  interface WsConnected {
1340
1349
  type: "connected";
@@ -1622,8 +1631,10 @@ declare function applyOrderbookDelta(state: OrderbookState, delta: WsOrderbookDe
1622
1631
  /**
1623
1632
  * Agg platform WebSocket client.
1624
1633
  *
1625
- * Single connection, refcounted subscriptions by ID (venueMarketId or
1626
- * venueMarketOutcomeId). Maintains in-memory orderbook state per subscribed ID.
1634
+ * Single connection, refcounted subscriptions. Orderbook/trades subscriptions
1635
+ * are keyed by venueMarketOutcomeId (the `outcomes[].id` on REST market
1636
+ * responses — NOT a venueMarketId); arb subscriptions are keyed by marketId.
1637
+ * Maintains in-memory orderbook state per subscribed outcome id.
1627
1638
  * All timestamps converted from server ms to seconds before invoking callbacks.
1628
1639
  *
1629
1640
  * Recovery: seq gap or checksum mismatch → resnapshot request.
@@ -1632,8 +1643,10 @@ declare function applyOrderbookDelta(state: OrderbookState, delta: WsOrderbookDe
1632
1643
  */
1633
1644
 
1634
1645
  interface AggWebSocketCallbacks {
1635
- onSnapshot?: (marketId: string, book: OrderbookState) => void;
1636
- onDelta?: (marketId: string, book: OrderbookState) => void;
1646
+ /** Invoked with the venueMarketOutcomeId the snapshot belongs to. */
1647
+ onSnapshot?: (outcomeId: string, book: OrderbookState) => void;
1648
+ /** Invoked with the venueMarketOutcomeId the delta belongs to. */
1649
+ onDelta?: (outcomeId: string, book: OrderbookState) => void;
1637
1650
  onTrade?: (trade: WsTrade) => void;
1638
1651
  onHeartbeat?: (hb: WsHeartbeat) => void;
1639
1652
  onSubscribed?: (msg: WsSubscribed) => void;
@@ -2302,6 +2315,7 @@ interface MidpointRow {
2302
2315
  midpoint: number | null;
2303
2316
  spread: number | null;
2304
2317
  timestamp: number | null;
2318
+ arbReturn?: number | null;
2305
2319
  /** Provenance of `midpoint`. */
2306
2320
  markSource?: MarkSource;
2307
2321
  /**
@@ -2310,6 +2324,10 @@ interface MidpointRow {
2310
2324
  * without re-running the matching logic.
2311
2325
  */
2312
2326
  siblingVenueMarketId?: string;
2327
+ /** Top-of-book buy-side price. Only present when `bestPrice=true`. */
2328
+ bestBid?: number | null;
2329
+ /** Top-of-book sell-side price. Only present when `bestPrice=true`. */
2330
+ bestAsk?: number | null;
2313
2331
  }
2314
2332
  /** Per-outcome midpoint from a live orderbook. */
2315
2333
  interface OutcomeMidpointRow {
@@ -2318,12 +2336,39 @@ interface OutcomeMidpointRow {
2318
2336
  midpoint: number | null;
2319
2337
  /** Provenance of `midpoint`. */
2320
2338
  markSource?: MarkSource;
2339
+ /** Top-of-book buy-side price. Only present when `bestPrice=true`. */
2340
+ bestBid?: number | null;
2341
+ /** Top-of-book sell-side price. Only present when `bestPrice=true`. */
2342
+ bestAsk?: number | null;
2321
2343
  }
2322
2344
  /** Response from GET /midpoints (batch). */
2323
2345
  interface BatchMidpointsResponse {
2324
2346
  data: Array<MidpointRow & {
2325
2347
  outcomes: OutcomeMidpointRow[];
2326
2348
  matched: MidpointRow[];
2349
+ /**
2350
+ * Live, quality-gated cross-venue arbitrage return for this market's
2351
+ * cluster as a decimal fraction (`0.0085` = 0.85%), computed fresh by
2352
+ * the engine on this request. Prefer it over the `arbReturn` embedded
2353
+ * in venue-event listings, which a background sync can leave stale.
2354
+ * Only present when the request set `bestPrice=true`.
2355
+ */
2356
+ arbReturn?: number | null;
2357
+ /**
2358
+ * DB status of the requested market. Present whenever the id resolves
2359
+ * to a known market. Resolved markets never serve a price (see `error`).
2360
+ */
2361
+ marketStatus?: MarketStatus;
2362
+ /**
2363
+ * Structured refusal, mirroring GET /orderbooks per-item errors:
2364
+ * `market_resolved` for settled markets (prices are nulled instead of
2365
+ * serving a stale mark), `market_not_found` for unknown ids.
2366
+ */
2367
+ error?: {
2368
+ code: "market_resolved" | "market_not_found";
2369
+ message: string;
2370
+ retryable: boolean;
2371
+ };
2327
2372
  }>;
2328
2373
  }
2329
2374
  /** Response from GET /orderbook/outcome/:id (single outcome). */
@@ -3291,6 +3336,13 @@ interface SearchParams {
3291
3336
  q: string;
3292
3337
  type: SearchType;
3293
3338
  categoryIds?: string[];
3339
+ /**
3340
+ * Filter results by status (e.g. `["open"]` for tradeable-only). Without
3341
+ * it the server returns all statuses; recurring series ("BTC Up or Down -
3342
+ * 5 Min") can then fill a page with resolved history, which a UI that
3343
+ * hides non-open rows renders as an empty result.
3344
+ */
3345
+ status?: MarketStatus[];
3294
3346
  limit?: number;
3295
3347
  cursor?: string;
3296
3348
  /**
package/dist/index.d.ts CHANGED
@@ -871,6 +871,7 @@ type MidpointItem = {
871
871
  timestamp: number | null;
872
872
  outcomes: OutcomeMidpoint[];
873
873
  matched: MatchedMidpoint[];
874
+ arbReturn?: number | null | undefined;
874
875
  };
875
876
  type ComputeSplitsRequest = {
876
877
  side: TradeSide$1;
@@ -1328,13 +1329,21 @@ interface WsTrade {
1328
1329
  type WsCandleInterval = "1m" | "5m" | "1h" | "1d";
1329
1330
  interface WsSubscribed {
1330
1331
  type: "subscribed";
1332
+ /** Confirmed ids. For `orderbook`/`trades` these are venueMarketOutcomeIds.
1333
+ * For `arb` this historically mirrors the marketIds — prefer `marketIds`. */
1331
1334
  outcomeIds: string[];
1332
- channel: "orderbook" | "trades";
1335
+ /** Confirmed marketIds — only set on `arb` confirmations, whose
1336
+ * subscriptions are keyed by marketIds, not outcomeIds. */
1337
+ marketIds?: string[];
1338
+ channel: "orderbook" | "trades" | "arb" | "arb-feed";
1333
1339
  }
1334
1340
  interface WsUnsubscribed {
1335
1341
  type: "unsubscribed";
1342
+ /** See {@link WsSubscribed.outcomeIds}. */
1336
1343
  outcomeIds: string[];
1337
- channel: "orderbook" | "trades";
1344
+ /** Confirmed marketIds — only set on `arb` confirmations. */
1345
+ marketIds?: string[];
1346
+ channel: "orderbook" | "trades" | "arb" | "arb-feed";
1338
1347
  }
1339
1348
  interface WsConnected {
1340
1349
  type: "connected";
@@ -1622,8 +1631,10 @@ declare function applyOrderbookDelta(state: OrderbookState, delta: WsOrderbookDe
1622
1631
  /**
1623
1632
  * Agg platform WebSocket client.
1624
1633
  *
1625
- * Single connection, refcounted subscriptions by ID (venueMarketId or
1626
- * venueMarketOutcomeId). Maintains in-memory orderbook state per subscribed ID.
1634
+ * Single connection, refcounted subscriptions. Orderbook/trades subscriptions
1635
+ * are keyed by venueMarketOutcomeId (the `outcomes[].id` on REST market
1636
+ * responses — NOT a venueMarketId); arb subscriptions are keyed by marketId.
1637
+ * Maintains in-memory orderbook state per subscribed outcome id.
1627
1638
  * All timestamps converted from server ms to seconds before invoking callbacks.
1628
1639
  *
1629
1640
  * Recovery: seq gap or checksum mismatch → resnapshot request.
@@ -1632,8 +1643,10 @@ declare function applyOrderbookDelta(state: OrderbookState, delta: WsOrderbookDe
1632
1643
  */
1633
1644
 
1634
1645
  interface AggWebSocketCallbacks {
1635
- onSnapshot?: (marketId: string, book: OrderbookState) => void;
1636
- onDelta?: (marketId: string, book: OrderbookState) => void;
1646
+ /** Invoked with the venueMarketOutcomeId the snapshot belongs to. */
1647
+ onSnapshot?: (outcomeId: string, book: OrderbookState) => void;
1648
+ /** Invoked with the venueMarketOutcomeId the delta belongs to. */
1649
+ onDelta?: (outcomeId: string, book: OrderbookState) => void;
1637
1650
  onTrade?: (trade: WsTrade) => void;
1638
1651
  onHeartbeat?: (hb: WsHeartbeat) => void;
1639
1652
  onSubscribed?: (msg: WsSubscribed) => void;
@@ -2302,6 +2315,7 @@ interface MidpointRow {
2302
2315
  midpoint: number | null;
2303
2316
  spread: number | null;
2304
2317
  timestamp: number | null;
2318
+ arbReturn?: number | null;
2305
2319
  /** Provenance of `midpoint`. */
2306
2320
  markSource?: MarkSource;
2307
2321
  /**
@@ -2310,6 +2324,10 @@ interface MidpointRow {
2310
2324
  * without re-running the matching logic.
2311
2325
  */
2312
2326
  siblingVenueMarketId?: string;
2327
+ /** Top-of-book buy-side price. Only present when `bestPrice=true`. */
2328
+ bestBid?: number | null;
2329
+ /** Top-of-book sell-side price. Only present when `bestPrice=true`. */
2330
+ bestAsk?: number | null;
2313
2331
  }
2314
2332
  /** Per-outcome midpoint from a live orderbook. */
2315
2333
  interface OutcomeMidpointRow {
@@ -2318,12 +2336,39 @@ interface OutcomeMidpointRow {
2318
2336
  midpoint: number | null;
2319
2337
  /** Provenance of `midpoint`. */
2320
2338
  markSource?: MarkSource;
2339
+ /** Top-of-book buy-side price. Only present when `bestPrice=true`. */
2340
+ bestBid?: number | null;
2341
+ /** Top-of-book sell-side price. Only present when `bestPrice=true`. */
2342
+ bestAsk?: number | null;
2321
2343
  }
2322
2344
  /** Response from GET /midpoints (batch). */
2323
2345
  interface BatchMidpointsResponse {
2324
2346
  data: Array<MidpointRow & {
2325
2347
  outcomes: OutcomeMidpointRow[];
2326
2348
  matched: MidpointRow[];
2349
+ /**
2350
+ * Live, quality-gated cross-venue arbitrage return for this market's
2351
+ * cluster as a decimal fraction (`0.0085` = 0.85%), computed fresh by
2352
+ * the engine on this request. Prefer it over the `arbReturn` embedded
2353
+ * in venue-event listings, which a background sync can leave stale.
2354
+ * Only present when the request set `bestPrice=true`.
2355
+ */
2356
+ arbReturn?: number | null;
2357
+ /**
2358
+ * DB status of the requested market. Present whenever the id resolves
2359
+ * to a known market. Resolved markets never serve a price (see `error`).
2360
+ */
2361
+ marketStatus?: MarketStatus;
2362
+ /**
2363
+ * Structured refusal, mirroring GET /orderbooks per-item errors:
2364
+ * `market_resolved` for settled markets (prices are nulled instead of
2365
+ * serving a stale mark), `market_not_found` for unknown ids.
2366
+ */
2367
+ error?: {
2368
+ code: "market_resolved" | "market_not_found";
2369
+ message: string;
2370
+ retryable: boolean;
2371
+ };
2327
2372
  }>;
2328
2373
  }
2329
2374
  /** Response from GET /orderbook/outcome/:id (single outcome). */
@@ -3291,6 +3336,13 @@ interface SearchParams {
3291
3336
  q: string;
3292
3337
  type: SearchType;
3293
3338
  categoryIds?: string[];
3339
+ /**
3340
+ * Filter results by status (e.g. `["open"]` for tradeable-only). Without
3341
+ * it the server returns all statuses; recurring series ("BTC Up or Down -
3342
+ * 5 Min") can then fill a page with resolved history, which a UI that
3343
+ * hides non-open rows renders as an empty result.
3344
+ */
3345
+ status?: MarketStatus[];
3294
3346
  limit?: number;
3295
3347
  cursor?: string;
3296
3348
  /**
package/dist/index.js CHANGED
@@ -1593,7 +1593,7 @@ var AggWebSocket = class {
1593
1593
  // src/client.ts
1594
1594
  var COOKIE_REFRESH_DELIVERY = "cookie-refresh";
1595
1595
  var DEFAULT_MIDPOINT_IDS_PER_REQUEST = 75;
1596
- var MAX_MIDPOINT_IDS_PER_REQUEST = 200;
1596
+ var MAX_MIDPOINT_IDS_PER_REQUEST = 75;
1597
1597
  var isUserProfile = (user) => {
1598
1598
  return "accounts" in user && "wallets" in user && "avatarUrl" in user;
1599
1599
  };
@@ -1638,6 +1638,17 @@ var chunkArray = (items, size) => {
1638
1638
  }
1639
1639
  return chunks;
1640
1640
  };
1641
+ var normalizeRequestedVenueMarketIds = (venueMarketIds) => {
1642
+ const normalizedIds = [];
1643
+ const seenIds = /* @__PURE__ */ new Set();
1644
+ for (const venueMarketId of venueMarketIds) {
1645
+ const normalizedVenueMarketId = venueMarketId.trim();
1646
+ if (!normalizedVenueMarketId || seenIds.has(normalizedVenueMarketId)) continue;
1647
+ seenIds.add(normalizedVenueMarketId);
1648
+ normalizedIds.push(normalizedVenueMarketId);
1649
+ }
1650
+ return normalizedIds;
1651
+ };
1641
1652
  var mapChartResolution = (resolution) => {
1642
1653
  switch (resolution) {
1643
1654
  case void 0:
@@ -2714,6 +2725,7 @@ Issued At: ${issuedAt}`;
2714
2725
  type: params.type
2715
2726
  };
2716
2727
  if (params.categoryIds && params.categoryIds.length > 0) query.categoryIds = params.categoryIds;
2728
+ if (params.status && params.status.length > 0) query.status = params.status;
2717
2729
  if (params.limit != null) query.limit = String(params.limit);
2718
2730
  if (params.cursor) query.cursor = params.cursor;
2719
2731
  if (params.deep) query.deepSearch = "true";
@@ -2811,7 +2823,8 @@ Issued At: ${issuedAt}`;
2811
2823
  getMidpoints(paramsOrVenueMarketIds, options) {
2812
2824
  return __async(this, null, function* () {
2813
2825
  var _a;
2814
- const venueMarketIds = Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds : paramsOrVenueMarketIds.venueMarketIds;
2826
+ const requestedVenueMarketIds = Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds : paramsOrVenueMarketIds.venueMarketIds;
2827
+ const venueMarketIds = normalizeRequestedVenueMarketIds(requestedVenueMarketIds);
2815
2828
  const bestPrice = !Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds.bestPrice : options == null ? void 0 : options.bestPrice;
2816
2829
  const maxMidpointIdsPerRequest = resolveMidpointIdsPerRequest(
2817
2830
  (_a = options == null ? void 0 : options.maxMidpointIdsPerRequest) != null ? _a : Array.isArray(paramsOrVenueMarketIds) ? void 0 : paramsOrVenueMarketIds.maxMidpointIdsPerRequest
@@ -2824,6 +2837,9 @@ Issued At: ${issuedAt}`;
2824
2837
  signal: options == null ? void 0 : options.signal
2825
2838
  });
2826
2839
  };
2840
+ if (venueMarketIds.length === 0) {
2841
+ return { data: [] };
2842
+ }
2827
2843
  if (venueMarketIds.length <= maxMidpointIdsPerRequest) {
2828
2844
  return requestBatch(venueMarketIds);
2829
2845
  }
package/dist/index.mjs CHANGED
@@ -1480,7 +1480,7 @@ var AggWebSocket = class {
1480
1480
  // src/client.ts
1481
1481
  var COOKIE_REFRESH_DELIVERY = "cookie-refresh";
1482
1482
  var DEFAULT_MIDPOINT_IDS_PER_REQUEST = 75;
1483
- var MAX_MIDPOINT_IDS_PER_REQUEST = 200;
1483
+ var MAX_MIDPOINT_IDS_PER_REQUEST = 75;
1484
1484
  var isUserProfile = (user) => {
1485
1485
  return "accounts" in user && "wallets" in user && "avatarUrl" in user;
1486
1486
  };
@@ -1525,6 +1525,17 @@ var chunkArray = (items, size) => {
1525
1525
  }
1526
1526
  return chunks;
1527
1527
  };
1528
+ var normalizeRequestedVenueMarketIds = (venueMarketIds) => {
1529
+ const normalizedIds = [];
1530
+ const seenIds = /* @__PURE__ */ new Set();
1531
+ for (const venueMarketId of venueMarketIds) {
1532
+ const normalizedVenueMarketId = venueMarketId.trim();
1533
+ if (!normalizedVenueMarketId || seenIds.has(normalizedVenueMarketId)) continue;
1534
+ seenIds.add(normalizedVenueMarketId);
1535
+ normalizedIds.push(normalizedVenueMarketId);
1536
+ }
1537
+ return normalizedIds;
1538
+ };
1528
1539
  var mapChartResolution = (resolution) => {
1529
1540
  switch (resolution) {
1530
1541
  case void 0:
@@ -2601,6 +2612,7 @@ Issued At: ${issuedAt}`;
2601
2612
  type: params.type
2602
2613
  };
2603
2614
  if (params.categoryIds && params.categoryIds.length > 0) query.categoryIds = params.categoryIds;
2615
+ if (params.status && params.status.length > 0) query.status = params.status;
2604
2616
  if (params.limit != null) query.limit = String(params.limit);
2605
2617
  if (params.cursor) query.cursor = params.cursor;
2606
2618
  if (params.deep) query.deepSearch = "true";
@@ -2698,7 +2710,8 @@ Issued At: ${issuedAt}`;
2698
2710
  getMidpoints(paramsOrVenueMarketIds, options) {
2699
2711
  return __async(this, null, function* () {
2700
2712
  var _a;
2701
- const venueMarketIds = Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds : paramsOrVenueMarketIds.venueMarketIds;
2713
+ const requestedVenueMarketIds = Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds : paramsOrVenueMarketIds.venueMarketIds;
2714
+ const venueMarketIds = normalizeRequestedVenueMarketIds(requestedVenueMarketIds);
2702
2715
  const bestPrice = !Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds.bestPrice : options == null ? void 0 : options.bestPrice;
2703
2716
  const maxMidpointIdsPerRequest = resolveMidpointIdsPerRequest(
2704
2717
  (_a = options == null ? void 0 : options.maxMidpointIdsPerRequest) != null ? _a : Array.isArray(paramsOrVenueMarketIds) ? void 0 : paramsOrVenueMarketIds.maxMidpointIdsPerRequest
@@ -2711,6 +2724,9 @@ Issued At: ${issuedAt}`;
2711
2724
  signal: options == null ? void 0 : options.signal
2712
2725
  });
2713
2726
  };
2727
+ if (venueMarketIds.length === 0) {
2728
+ return { data: [] };
2729
+ }
2714
2730
  if (venueMarketIds.length <= maxMidpointIdsPerRequest) {
2715
2731
  return requestBatch(venueMarketIds);
2716
2732
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agg-build/sdk",
3
- "version": "2.2.0",
3
+ "version": "2.3.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",