@agg-build/sdk 2.2.0 → 2.2.1
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 +51 -6
- package/dist/index.d.ts +51 -6
- package/dist/index.js +17 -2
- package/dist/index.mjs +17 -2
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
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
|
|
1626
|
-
*
|
|
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
|
-
|
|
1636
|
-
|
|
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). */
|
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
|
-
|
|
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
|
-
|
|
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
|
|
1626
|
-
*
|
|
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
|
-
|
|
1636
|
-
|
|
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). */
|
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 =
|
|
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:
|
|
@@ -2811,7 +2822,8 @@ Issued At: ${issuedAt}`;
|
|
|
2811
2822
|
getMidpoints(paramsOrVenueMarketIds, options) {
|
|
2812
2823
|
return __async(this, null, function* () {
|
|
2813
2824
|
var _a;
|
|
2814
|
-
const
|
|
2825
|
+
const requestedVenueMarketIds = Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds : paramsOrVenueMarketIds.venueMarketIds;
|
|
2826
|
+
const venueMarketIds = normalizeRequestedVenueMarketIds(requestedVenueMarketIds);
|
|
2815
2827
|
const bestPrice = !Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds.bestPrice : options == null ? void 0 : options.bestPrice;
|
|
2816
2828
|
const maxMidpointIdsPerRequest = resolveMidpointIdsPerRequest(
|
|
2817
2829
|
(_a = options == null ? void 0 : options.maxMidpointIdsPerRequest) != null ? _a : Array.isArray(paramsOrVenueMarketIds) ? void 0 : paramsOrVenueMarketIds.maxMidpointIdsPerRequest
|
|
@@ -2824,6 +2836,9 @@ Issued At: ${issuedAt}`;
|
|
|
2824
2836
|
signal: options == null ? void 0 : options.signal
|
|
2825
2837
|
});
|
|
2826
2838
|
};
|
|
2839
|
+
if (venueMarketIds.length === 0) {
|
|
2840
|
+
return { data: [] };
|
|
2841
|
+
}
|
|
2827
2842
|
if (venueMarketIds.length <= maxMidpointIdsPerRequest) {
|
|
2828
2843
|
return requestBatch(venueMarketIds);
|
|
2829
2844
|
}
|
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 =
|
|
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:
|
|
@@ -2698,7 +2709,8 @@ Issued At: ${issuedAt}`;
|
|
|
2698
2709
|
getMidpoints(paramsOrVenueMarketIds, options) {
|
|
2699
2710
|
return __async(this, null, function* () {
|
|
2700
2711
|
var _a;
|
|
2701
|
-
const
|
|
2712
|
+
const requestedVenueMarketIds = Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds : paramsOrVenueMarketIds.venueMarketIds;
|
|
2713
|
+
const venueMarketIds = normalizeRequestedVenueMarketIds(requestedVenueMarketIds);
|
|
2702
2714
|
const bestPrice = !Array.isArray(paramsOrVenueMarketIds) ? paramsOrVenueMarketIds.bestPrice : options == null ? void 0 : options.bestPrice;
|
|
2703
2715
|
const maxMidpointIdsPerRequest = resolveMidpointIdsPerRequest(
|
|
2704
2716
|
(_a = options == null ? void 0 : options.maxMidpointIdsPerRequest) != null ? _a : Array.isArray(paramsOrVenueMarketIds) ? void 0 : paramsOrVenueMarketIds.maxMidpointIdsPerRequest
|
|
@@ -2711,6 +2723,9 @@ Issued At: ${issuedAt}`;
|
|
|
2711
2723
|
signal: options == null ? void 0 : options.signal
|
|
2712
2724
|
});
|
|
2713
2725
|
};
|
|
2726
|
+
if (venueMarketIds.length === 0) {
|
|
2727
|
+
return { data: [] };
|
|
2728
|
+
}
|
|
2714
2729
|
if (venueMarketIds.length <= maxMidpointIdsPerRequest) {
|
|
2715
2730
|
return requestBatch(venueMarketIds);
|
|
2716
2731
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agg-build/sdk",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
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",
|