@agg-build/sdk 1.0.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/README.md +355 -0
- package/dist/chunk-AXBFBHS2.mjs +45 -0
- package/dist/index.d.mts +2546 -0
- package/dist/index.d.ts +2546 -0
- package/dist/index.js +2581 -0
- package/dist/index.mjs +2483 -0
- package/dist/server.d.mts +155 -0
- package/dist/server.d.ts +155 -0
- package/dist/server.js +254 -0
- package/dist/server.mjs +194 -0
- package/package.json +82 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2546 @@
|
|
|
1
|
+
/** Use these constants instead of hardcoding "kalshi" or "polymarket". */
|
|
2
|
+
declare enum Venue {
|
|
3
|
+
kalshi = "kalshi",
|
|
4
|
+
polymarket = "polymarket",
|
|
5
|
+
limitless = "limitless",
|
|
6
|
+
opinion = "opinion",
|
|
7
|
+
predict = "predict",
|
|
8
|
+
probable = "probable",
|
|
9
|
+
myriad = "myriad",
|
|
10
|
+
hyperliquid = "hyperliquid"
|
|
11
|
+
}
|
|
12
|
+
/** Single source of truth for venue identifiers. */
|
|
13
|
+
declare const VENUES: readonly [Venue.kalshi, Venue.polymarket, Venue.limitless, Venue.opinion, Venue.predict, Venue.probable, Venue.myriad, Venue.hyperliquid];
|
|
14
|
+
|
|
15
|
+
declare enum ImageSize {
|
|
16
|
+
sm = 44,
|
|
17
|
+
md = 48,
|
|
18
|
+
lg = 60,
|
|
19
|
+
original = 0
|
|
20
|
+
}
|
|
21
|
+
declare const IMAGE_SIZES: readonly [ImageSize.sm, ImageSize.md, ImageSize.lg];
|
|
22
|
+
|
|
23
|
+
declare enum AccountType {
|
|
24
|
+
oauth = "oauth",
|
|
25
|
+
siwe = "siwe",
|
|
26
|
+
siws = "siws",
|
|
27
|
+
email = "email"
|
|
28
|
+
}
|
|
29
|
+
declare enum AccountProvider {
|
|
30
|
+
wallet = "wallet",
|
|
31
|
+
solana_wallet = "solana_wallet",
|
|
32
|
+
google = "google",
|
|
33
|
+
twitter = "twitter",
|
|
34
|
+
apple = "apple",
|
|
35
|
+
email = "email"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare enum Chain {
|
|
39
|
+
evm = "evm",
|
|
40
|
+
svm = "svm"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare enum MatchStatus {
|
|
44
|
+
pending = "pending",
|
|
45
|
+
unmatched = "unmatched",
|
|
46
|
+
review = "review",
|
|
47
|
+
matched = "matched",
|
|
48
|
+
verified = "verified",
|
|
49
|
+
rejected = "rejected"
|
|
50
|
+
}
|
|
51
|
+
declare enum MatchType {
|
|
52
|
+
manual = "manual",
|
|
53
|
+
llm = "llm"
|
|
54
|
+
}
|
|
55
|
+
/** Match statuses considered "confirmed" for user-facing data (orderbooks, listings, aggregation). */
|
|
56
|
+
declare const CONFIRMED_MATCH_STATUSES: MatchStatus[];
|
|
57
|
+
declare enum MarketStatus {
|
|
58
|
+
open = "open",
|
|
59
|
+
closed = "closed",
|
|
60
|
+
resolved = "resolved",
|
|
61
|
+
unopened = "unopened",
|
|
62
|
+
paused = "paused"
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare enum OrderStatus {
|
|
66
|
+
pending = "pending",
|
|
67
|
+
signing = "signing",
|
|
68
|
+
pending_bridge = "pending_bridge",
|
|
69
|
+
submitting = "submitting",
|
|
70
|
+
submitted = "submitted",
|
|
71
|
+
filled = "filled",
|
|
72
|
+
partial_fill = "partial_fill"
|
|
73
|
+
}
|
|
74
|
+
declare enum TradeSide$1 {
|
|
75
|
+
Buy = "buy",
|
|
76
|
+
Sell = "sell"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Standalone type definitions — no Zod dependency.
|
|
81
|
+
* These mirror the types in types/index.ts but are defined as plain interfaces.
|
|
82
|
+
* Used by the types-only barrel to avoid leaking Zod into SDK/hooks declarations.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
type HelloResponse = {
|
|
86
|
+
message: string;
|
|
87
|
+
};
|
|
88
|
+
type App = {
|
|
89
|
+
id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
allowedOrigins: string[];
|
|
92
|
+
active: boolean;
|
|
93
|
+
blockedCountries: string[];
|
|
94
|
+
blockedRegions: string[];
|
|
95
|
+
orderFee: string;
|
|
96
|
+
signupBonus: string;
|
|
97
|
+
createdAt: string;
|
|
98
|
+
updatedAt: string;
|
|
99
|
+
};
|
|
100
|
+
type CreateApp = {
|
|
101
|
+
name: string;
|
|
102
|
+
allowedOrigins: string[];
|
|
103
|
+
blockedCountries: string[];
|
|
104
|
+
blockedRegions: string[];
|
|
105
|
+
};
|
|
106
|
+
type NonceResponse = {
|
|
107
|
+
nonce: string;
|
|
108
|
+
};
|
|
109
|
+
type AuthUser = {
|
|
110
|
+
id: string;
|
|
111
|
+
};
|
|
112
|
+
type UserProfile = {
|
|
113
|
+
id: string;
|
|
114
|
+
username: string | null;
|
|
115
|
+
avatarUrl: string | null;
|
|
116
|
+
externalId: string | null;
|
|
117
|
+
isLocationBlocked: boolean;
|
|
118
|
+
accounts: {
|
|
119
|
+
type: AccountType;
|
|
120
|
+
provider: AccountProvider;
|
|
121
|
+
providerAccountId: string;
|
|
122
|
+
}[];
|
|
123
|
+
wallets: {
|
|
124
|
+
chain: Chain;
|
|
125
|
+
address: string;
|
|
126
|
+
}[];
|
|
127
|
+
venueAccounts: {
|
|
128
|
+
status: string;
|
|
129
|
+
id: string;
|
|
130
|
+
venue: Venue;
|
|
131
|
+
kycStatus: string;
|
|
132
|
+
}[] | null;
|
|
133
|
+
};
|
|
134
|
+
type Account = {
|
|
135
|
+
type: AccountType;
|
|
136
|
+
provider: AccountProvider;
|
|
137
|
+
providerAccountId: string;
|
|
138
|
+
};
|
|
139
|
+
type ServerWallet = {
|
|
140
|
+
chain: Chain;
|
|
141
|
+
address: string;
|
|
142
|
+
};
|
|
143
|
+
type UpdateUserBody = {
|
|
144
|
+
username?: string | undefined;
|
|
145
|
+
confirmAvatar?: true | undefined;
|
|
146
|
+
removeAvatar?: true | undefined;
|
|
147
|
+
};
|
|
148
|
+
type VerifyBody = {
|
|
149
|
+
message: string;
|
|
150
|
+
signature: string;
|
|
151
|
+
};
|
|
152
|
+
type VerifyResponse = {
|
|
153
|
+
accessToken: string;
|
|
154
|
+
user: {
|
|
155
|
+
id: string;
|
|
156
|
+
};
|
|
157
|
+
refreshToken?: string | undefined;
|
|
158
|
+
};
|
|
159
|
+
type AuthTokenResponse = {
|
|
160
|
+
accessToken: string;
|
|
161
|
+
user: {
|
|
162
|
+
id: string;
|
|
163
|
+
};
|
|
164
|
+
refreshToken?: string | undefined;
|
|
165
|
+
};
|
|
166
|
+
type AuthCodeResponse = {
|
|
167
|
+
code: string;
|
|
168
|
+
};
|
|
169
|
+
type UpsertVenueKey = {
|
|
170
|
+
venue: Venue.kalshi;
|
|
171
|
+
credentials: {
|
|
172
|
+
keyId: string;
|
|
173
|
+
privateKey: string;
|
|
174
|
+
};
|
|
175
|
+
} | {
|
|
176
|
+
venue: Venue.polymarket;
|
|
177
|
+
credentials: {
|
|
178
|
+
apiKey: string;
|
|
179
|
+
secret: string;
|
|
180
|
+
passphrase: string;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
type VenueKeySummary = {
|
|
184
|
+
updatedAt: string;
|
|
185
|
+
venue: Venue;
|
|
186
|
+
};
|
|
187
|
+
type TradeSplit = {
|
|
188
|
+
venue: Venue;
|
|
189
|
+
venueMarketOutcomeId: string;
|
|
190
|
+
side: TradeSide$1;
|
|
191
|
+
price: number;
|
|
192
|
+
size: number;
|
|
193
|
+
signedOrder?: any;
|
|
194
|
+
negRisk?: boolean | undefined;
|
|
195
|
+
outcomeExternalIdentifier?: string | undefined;
|
|
196
|
+
};
|
|
197
|
+
type ComputeSplitsSelection = {
|
|
198
|
+
venue: Venue;
|
|
199
|
+
venueMarketOutcomeId: string;
|
|
200
|
+
};
|
|
201
|
+
type SetupVenueKeyStep = {
|
|
202
|
+
type: "setup_venue_key";
|
|
203
|
+
venue: Venue;
|
|
204
|
+
stepPayload: {
|
|
205
|
+
instructions: string;
|
|
206
|
+
setupUrl?: string | undefined;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
type DepositStep = {
|
|
210
|
+
type: "deposit";
|
|
211
|
+
venue: Venue;
|
|
212
|
+
currency: string;
|
|
213
|
+
stepPayload?: {
|
|
214
|
+
instructions: string;
|
|
215
|
+
setupUrl?: string | undefined;
|
|
216
|
+
depositUrl?: string | undefined;
|
|
217
|
+
} | undefined;
|
|
218
|
+
requiredAmountCents?: number | undefined;
|
|
219
|
+
requiredAmountUsd?: string | undefined;
|
|
220
|
+
transactionData?: {
|
|
221
|
+
value: string;
|
|
222
|
+
chainId: number;
|
|
223
|
+
to: string;
|
|
224
|
+
data: string;
|
|
225
|
+
} | undefined;
|
|
226
|
+
};
|
|
227
|
+
type SetupDepositAddressStep = {
|
|
228
|
+
type: "setup_deposit_address";
|
|
229
|
+
venue: Venue.polymarket;
|
|
230
|
+
stepPayload: {
|
|
231
|
+
setupUrl: string;
|
|
232
|
+
instructions: string;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
type ValidateBalanceOnClientStep = {
|
|
236
|
+
type: "validate_balance_on_client";
|
|
237
|
+
venue: Venue.polymarket;
|
|
238
|
+
stepPayload: {
|
|
239
|
+
requiredAmountUsd: string;
|
|
240
|
+
instructions?: string | undefined;
|
|
241
|
+
currency?: string | undefined;
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
type TradeStep = {
|
|
245
|
+
type: "setup_venue_key";
|
|
246
|
+
venue: Venue;
|
|
247
|
+
stepPayload: {
|
|
248
|
+
instructions: string;
|
|
249
|
+
setupUrl?: string | undefined;
|
|
250
|
+
};
|
|
251
|
+
} | {
|
|
252
|
+
type: "deposit";
|
|
253
|
+
venue: Venue;
|
|
254
|
+
currency: string;
|
|
255
|
+
stepPayload?: {
|
|
256
|
+
instructions: string;
|
|
257
|
+
setupUrl?: string | undefined;
|
|
258
|
+
depositUrl?: string | undefined;
|
|
259
|
+
} | undefined;
|
|
260
|
+
requiredAmountCents?: number | undefined;
|
|
261
|
+
requiredAmountUsd?: string | undefined;
|
|
262
|
+
transactionData?: {
|
|
263
|
+
value: string;
|
|
264
|
+
chainId: number;
|
|
265
|
+
to: string;
|
|
266
|
+
data: string;
|
|
267
|
+
} | undefined;
|
|
268
|
+
} | {
|
|
269
|
+
type: "setup_deposit_address";
|
|
270
|
+
venue: Venue.polymarket;
|
|
271
|
+
stepPayload: {
|
|
272
|
+
setupUrl: string;
|
|
273
|
+
instructions: string;
|
|
274
|
+
};
|
|
275
|
+
} | {
|
|
276
|
+
type: "validate_balance_on_client";
|
|
277
|
+
venue: Venue.polymarket;
|
|
278
|
+
stepPayload: {
|
|
279
|
+
requiredAmountUsd: string;
|
|
280
|
+
instructions?: string | undefined;
|
|
281
|
+
currency?: string | undefined;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
type ValidateTradeRequest = {
|
|
285
|
+
splits: {
|
|
286
|
+
venue: Venue;
|
|
287
|
+
venueMarketOutcomeId: string;
|
|
288
|
+
side: TradeSide$1;
|
|
289
|
+
price: number;
|
|
290
|
+
size: number;
|
|
291
|
+
signedOrder?: any;
|
|
292
|
+
negRisk?: boolean | undefined;
|
|
293
|
+
outcomeExternalIdentifier?: string | undefined;
|
|
294
|
+
}[];
|
|
295
|
+
};
|
|
296
|
+
type ValidateTradeResponse = {
|
|
297
|
+
steps: ({
|
|
298
|
+
type: "setup_venue_key";
|
|
299
|
+
venue: Venue;
|
|
300
|
+
stepPayload: {
|
|
301
|
+
instructions: string;
|
|
302
|
+
setupUrl?: string | undefined;
|
|
303
|
+
};
|
|
304
|
+
} | {
|
|
305
|
+
type: "deposit";
|
|
306
|
+
venue: Venue;
|
|
307
|
+
currency: string;
|
|
308
|
+
stepPayload?: {
|
|
309
|
+
instructions: string;
|
|
310
|
+
setupUrl?: string | undefined;
|
|
311
|
+
depositUrl?: string | undefined;
|
|
312
|
+
} | undefined;
|
|
313
|
+
requiredAmountCents?: number | undefined;
|
|
314
|
+
requiredAmountUsd?: string | undefined;
|
|
315
|
+
transactionData?: {
|
|
316
|
+
value: string;
|
|
317
|
+
chainId: number;
|
|
318
|
+
to: string;
|
|
319
|
+
data: string;
|
|
320
|
+
} | undefined;
|
|
321
|
+
} | {
|
|
322
|
+
type: "setup_deposit_address";
|
|
323
|
+
venue: Venue.polymarket;
|
|
324
|
+
stepPayload: {
|
|
325
|
+
setupUrl: string;
|
|
326
|
+
instructions: string;
|
|
327
|
+
};
|
|
328
|
+
} | {
|
|
329
|
+
type: "validate_balance_on_client";
|
|
330
|
+
venue: Venue.polymarket;
|
|
331
|
+
stepPayload: {
|
|
332
|
+
requiredAmountUsd: string;
|
|
333
|
+
instructions?: string | undefined;
|
|
334
|
+
currency?: string | undefined;
|
|
335
|
+
};
|
|
336
|
+
})[];
|
|
337
|
+
canExecute: boolean;
|
|
338
|
+
};
|
|
339
|
+
type ExecuteTradeRequest = {
|
|
340
|
+
splits: {
|
|
341
|
+
venue: Venue;
|
|
342
|
+
venueMarketOutcomeId: string;
|
|
343
|
+
side: TradeSide$1;
|
|
344
|
+
price: number;
|
|
345
|
+
size: number;
|
|
346
|
+
signedOrder?: any;
|
|
347
|
+
negRisk?: boolean | undefined;
|
|
348
|
+
outcomeExternalIdentifier?: string | undefined;
|
|
349
|
+
}[];
|
|
350
|
+
};
|
|
351
|
+
type ExecuteTradeResponse = {
|
|
352
|
+
orders: {
|
|
353
|
+
venue: Venue;
|
|
354
|
+
orders: {
|
|
355
|
+
orderId: string;
|
|
356
|
+
}[];
|
|
357
|
+
}[];
|
|
358
|
+
errors?: {
|
|
359
|
+
message: string;
|
|
360
|
+
venue: Venue;
|
|
361
|
+
}[] | undefined;
|
|
362
|
+
};
|
|
363
|
+
type GetBalanceQuery = {
|
|
364
|
+
venue: Venue;
|
|
365
|
+
};
|
|
366
|
+
type GetBalanceResponse = {
|
|
367
|
+
venue: Venue;
|
|
368
|
+
currency: string;
|
|
369
|
+
balances: {
|
|
370
|
+
tradingBalanceCents?: number | undefined;
|
|
371
|
+
walletBalanceCents?: number | undefined;
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
type WalletChainBalance = {
|
|
375
|
+
chainId: number;
|
|
376
|
+
tokenAddress: string;
|
|
377
|
+
balanceRaw: string;
|
|
378
|
+
lastSyncedAt: string;
|
|
379
|
+
};
|
|
380
|
+
type WalletTokenBalance = {
|
|
381
|
+
tokenSymbol: string;
|
|
382
|
+
totalRaw: string;
|
|
383
|
+
decimals: number;
|
|
384
|
+
chains: {
|
|
385
|
+
chainId: number;
|
|
386
|
+
tokenAddress: string;
|
|
387
|
+
balanceRaw: string;
|
|
388
|
+
decimals: number;
|
|
389
|
+
lastSyncedAt: string;
|
|
390
|
+
}[];
|
|
391
|
+
};
|
|
392
|
+
type VenuePositionBalance = {
|
|
393
|
+
venue: Venue;
|
|
394
|
+
balance: number;
|
|
395
|
+
costBasis: number;
|
|
396
|
+
unrealizedPnl: number;
|
|
397
|
+
realizedPnl: number;
|
|
398
|
+
};
|
|
399
|
+
type UnifiedBalanceResponse = {
|
|
400
|
+
cash: {
|
|
401
|
+
tokenSymbol: string;
|
|
402
|
+
totalRaw: string;
|
|
403
|
+
decimals: number;
|
|
404
|
+
chains: {
|
|
405
|
+
chainId: number;
|
|
406
|
+
tokenAddress: string;
|
|
407
|
+
balanceRaw: string;
|
|
408
|
+
decimals: number;
|
|
409
|
+
lastSyncedAt: string;
|
|
410
|
+
}[];
|
|
411
|
+
}[];
|
|
412
|
+
positions: {
|
|
413
|
+
venue: Venue;
|
|
414
|
+
balance: number;
|
|
415
|
+
costBasis: number;
|
|
416
|
+
unrealizedPnl: number;
|
|
417
|
+
realizedPnl: number;
|
|
418
|
+
}[];
|
|
419
|
+
};
|
|
420
|
+
type UserHolding = {
|
|
421
|
+
venue: Venue;
|
|
422
|
+
side: "long" | "short";
|
|
423
|
+
size: number;
|
|
424
|
+
marketId: string;
|
|
425
|
+
outcomeId: string;
|
|
426
|
+
outcomeLabel?: string | undefined;
|
|
427
|
+
conditionId?: string | undefined;
|
|
428
|
+
avgPrice?: number | undefined;
|
|
429
|
+
pnl?: number | undefined;
|
|
430
|
+
};
|
|
431
|
+
type GetHoldingsResponse = {
|
|
432
|
+
data: {
|
|
433
|
+
venue: Venue;
|
|
434
|
+
side: "long" | "short";
|
|
435
|
+
size: number;
|
|
436
|
+
marketId: string;
|
|
437
|
+
outcomeId: string;
|
|
438
|
+
outcomeLabel?: string | undefined;
|
|
439
|
+
conditionId?: string | undefined;
|
|
440
|
+
avgPrice?: number | undefined;
|
|
441
|
+
pnl?: number | undefined;
|
|
442
|
+
}[];
|
|
443
|
+
nextCursor: string | null;
|
|
444
|
+
hasMore: boolean;
|
|
445
|
+
};
|
|
446
|
+
type GetHoldingsQuery = {
|
|
447
|
+
venue: Venue;
|
|
448
|
+
venueMarketId?: string | undefined;
|
|
449
|
+
venueEventId?: string | undefined;
|
|
450
|
+
cursor?: string | undefined;
|
|
451
|
+
};
|
|
452
|
+
type GetOrdersQuery = {
|
|
453
|
+
status?: OrderStatus | undefined;
|
|
454
|
+
orderId?: string | undefined;
|
|
455
|
+
cursor?: string | undefined;
|
|
456
|
+
limit?: number | undefined;
|
|
457
|
+
};
|
|
458
|
+
type GetPositionsQuery = {
|
|
459
|
+
cursor?: string | undefined;
|
|
460
|
+
limit?: number | undefined;
|
|
461
|
+
status?: "active" | "closed" | undefined;
|
|
462
|
+
};
|
|
463
|
+
type OrderListItem = {
|
|
464
|
+
status: string;
|
|
465
|
+
id: string;
|
|
466
|
+
createdAt: Date;
|
|
467
|
+
updatedAt: Date;
|
|
468
|
+
venue: Venue;
|
|
469
|
+
side: string;
|
|
470
|
+
amountRaw: string;
|
|
471
|
+
slippageBps: number | null;
|
|
472
|
+
quotedPriceRaw: string | null;
|
|
473
|
+
quotedCostRaw: string | null;
|
|
474
|
+
filledAmountRaw: string | null;
|
|
475
|
+
executionPrice: string | null;
|
|
476
|
+
txHash: string | null;
|
|
477
|
+
errorMessage: string | null;
|
|
478
|
+
dagRunId: string | null;
|
|
479
|
+
venueMarket: {
|
|
480
|
+
id: string;
|
|
481
|
+
venueEventId?: string | undefined;
|
|
482
|
+
question: string;
|
|
483
|
+
image: string | null;
|
|
484
|
+
} | null;
|
|
485
|
+
venueMarketOutcome: {
|
|
486
|
+
label: string;
|
|
487
|
+
title: string | null;
|
|
488
|
+
} | null;
|
|
489
|
+
};
|
|
490
|
+
type PositionGroup = {
|
|
491
|
+
venueMarket: {
|
|
492
|
+
venueEventId: string;
|
|
493
|
+
question: string;
|
|
494
|
+
image: string | null;
|
|
495
|
+
status: MarketStatus;
|
|
496
|
+
venueMarketOutcomes: {
|
|
497
|
+
unrealizedPnl: number;
|
|
498
|
+
label: string;
|
|
499
|
+
title: string | null;
|
|
500
|
+
winner: boolean | null;
|
|
501
|
+
venueBreakdown: {
|
|
502
|
+
venue: Venue;
|
|
503
|
+
size: number;
|
|
504
|
+
venueMarketId: string;
|
|
505
|
+
venueMarketOutcomeId?: string | null;
|
|
506
|
+
}[];
|
|
507
|
+
totalSize: number;
|
|
508
|
+
avgEntryPrice: number;
|
|
509
|
+
currentPrice: number;
|
|
510
|
+
totalValue: number;
|
|
511
|
+
unrealizedPnlPercent: number;
|
|
512
|
+
}[];
|
|
513
|
+
};
|
|
514
|
+
targetMarketId: string;
|
|
515
|
+
eventId?: string | undefined;
|
|
516
|
+
redeemStatus: "eligible" | "pending" | "redeemed" | "ineligible";
|
|
517
|
+
status: "active" | "closed";
|
|
518
|
+
resolutionDate: string | null;
|
|
519
|
+
};
|
|
520
|
+
type VenueMarket = {
|
|
521
|
+
id: string;
|
|
522
|
+
venue: Venue;
|
|
523
|
+
question: string;
|
|
524
|
+
venueMarketOutcomes: {
|
|
525
|
+
id: string;
|
|
526
|
+
price: number;
|
|
527
|
+
venueMarketId: string;
|
|
528
|
+
label: string;
|
|
529
|
+
title?: string | null | undefined;
|
|
530
|
+
externalIdentifier?: string | null | undefined;
|
|
531
|
+
winner?: boolean | null | undefined;
|
|
532
|
+
}[];
|
|
533
|
+
externalIdentifier: string;
|
|
534
|
+
status?: MarketStatus | undefined;
|
|
535
|
+
createdAt?: string | null | undefined;
|
|
536
|
+
negRisk?: boolean | undefined;
|
|
537
|
+
marketId?: string | null | undefined;
|
|
538
|
+
conditionId?: string | null | undefined;
|
|
539
|
+
venueEventId?: string | null | undefined;
|
|
540
|
+
image?: string | null | undefined;
|
|
541
|
+
description?: string | null | undefined;
|
|
542
|
+
rulesPrimary?: string | null | undefined;
|
|
543
|
+
rulesSecondary?: string | null | undefined;
|
|
544
|
+
volume?: number | null | undefined;
|
|
545
|
+
startDate?: string | null | undefined;
|
|
546
|
+
endDate?: string | null | undefined;
|
|
547
|
+
creationDate?: string | null | undefined;
|
|
548
|
+
resolutionDate?: string | null | undefined;
|
|
549
|
+
matchedVenueMarkets?: {
|
|
550
|
+
id: string;
|
|
551
|
+
venue: Venue;
|
|
552
|
+
question: string;
|
|
553
|
+
externalIdentifier: string;
|
|
554
|
+
status?: MarketStatus | undefined;
|
|
555
|
+
conditionId?: string | null | undefined;
|
|
556
|
+
venueMarketOutcomes?: {
|
|
557
|
+
id: string;
|
|
558
|
+
price: number;
|
|
559
|
+
venueMarketId: string;
|
|
560
|
+
label: string;
|
|
561
|
+
winner?: boolean | null | undefined;
|
|
562
|
+
}[] | undefined;
|
|
563
|
+
volume?: number | null | undefined;
|
|
564
|
+
venueEvent?: {
|
|
565
|
+
id: string;
|
|
566
|
+
externalIdentifier: string;
|
|
567
|
+
slug?: string | null | undefined;
|
|
568
|
+
series?: {
|
|
569
|
+
id: string;
|
|
570
|
+
venue: string;
|
|
571
|
+
externalIdentifier: string;
|
|
572
|
+
name?: string | null | undefined;
|
|
573
|
+
} | null | undefined;
|
|
574
|
+
} | null | undefined;
|
|
575
|
+
}[] | undefined;
|
|
576
|
+
};
|
|
577
|
+
type VenueEvent = {
|
|
578
|
+
id: string;
|
|
579
|
+
venue: Venue;
|
|
580
|
+
image: string | null;
|
|
581
|
+
title: string;
|
|
582
|
+
externalIdentifier: string;
|
|
583
|
+
categories: {
|
|
584
|
+
id: string;
|
|
585
|
+
category: {
|
|
586
|
+
id: string;
|
|
587
|
+
name: string;
|
|
588
|
+
parentId: string | null;
|
|
589
|
+
eventCount: number;
|
|
590
|
+
};
|
|
591
|
+
}[];
|
|
592
|
+
status?: MarketStatus | undefined;
|
|
593
|
+
updatedAt?: string | null | undefined;
|
|
594
|
+
description?: string | null | undefined;
|
|
595
|
+
volume?: number | null | undefined;
|
|
596
|
+
startDate?: string | null | undefined;
|
|
597
|
+
endDate?: string | null | undefined;
|
|
598
|
+
creationDate?: string | null | undefined;
|
|
599
|
+
slug?: string | null | undefined;
|
|
600
|
+
subtitle?: string | null | undefined;
|
|
601
|
+
venues?: Venue[];
|
|
602
|
+
venueCount?: number | undefined;
|
|
603
|
+
marketCount?: number | undefined;
|
|
604
|
+
};
|
|
605
|
+
type Orderbook = {
|
|
606
|
+
bids: {
|
|
607
|
+
price: number;
|
|
608
|
+
size: number;
|
|
609
|
+
}[];
|
|
610
|
+
asks: {
|
|
611
|
+
price: number;
|
|
612
|
+
size: number;
|
|
613
|
+
}[];
|
|
614
|
+
negRisk?: boolean | undefined;
|
|
615
|
+
};
|
|
616
|
+
type AttributedOrderbookLevel = {
|
|
617
|
+
price: number;
|
|
618
|
+
size: number;
|
|
619
|
+
venues: Record<string, number>;
|
|
620
|
+
};
|
|
621
|
+
type AttributedOrderbook = {
|
|
622
|
+
bids: {
|
|
623
|
+
price: number;
|
|
624
|
+
size: number;
|
|
625
|
+
venues: Record<string, number>;
|
|
626
|
+
}[];
|
|
627
|
+
asks: {
|
|
628
|
+
price: number;
|
|
629
|
+
size: number;
|
|
630
|
+
venues: Record<string, number>;
|
|
631
|
+
}[];
|
|
632
|
+
};
|
|
633
|
+
type PricePoint = {
|
|
634
|
+
price: number;
|
|
635
|
+
timestamp: number;
|
|
636
|
+
open?: number | undefined;
|
|
637
|
+
high?: number | undefined;
|
|
638
|
+
low?: number | undefined;
|
|
639
|
+
close?: number | undefined;
|
|
640
|
+
};
|
|
641
|
+
type MarketPriceHistory = {
|
|
642
|
+
venue: Venue;
|
|
643
|
+
marketId: string;
|
|
644
|
+
marketTicker: string;
|
|
645
|
+
points: {
|
|
646
|
+
price: number;
|
|
647
|
+
timestamp: number;
|
|
648
|
+
open?: number | undefined;
|
|
649
|
+
high?: number | undefined;
|
|
650
|
+
low?: number | undefined;
|
|
651
|
+
close?: number | undefined;
|
|
652
|
+
}[];
|
|
653
|
+
};
|
|
654
|
+
type PricesHistoryResponse = {
|
|
655
|
+
data: {
|
|
656
|
+
venue: Venue;
|
|
657
|
+
marketId: string;
|
|
658
|
+
marketTicker: string;
|
|
659
|
+
points: {
|
|
660
|
+
price: number;
|
|
661
|
+
timestamp: number;
|
|
662
|
+
open?: number | undefined;
|
|
663
|
+
high?: number | undefined;
|
|
664
|
+
low?: number | undefined;
|
|
665
|
+
close?: number | undefined;
|
|
666
|
+
}[];
|
|
667
|
+
}[];
|
|
668
|
+
};
|
|
669
|
+
type OrderbookHistoryPoint = {
|
|
670
|
+
volume: number | null;
|
|
671
|
+
timestamp: number;
|
|
672
|
+
midpoint: number;
|
|
673
|
+
bestBid: number | null;
|
|
674
|
+
bestAsk: number | null;
|
|
675
|
+
spread: number | null;
|
|
676
|
+
open?: number | undefined;
|
|
677
|
+
high?: number | undefined;
|
|
678
|
+
low?: number | undefined;
|
|
679
|
+
close?: number | undefined;
|
|
680
|
+
};
|
|
681
|
+
type OrderbookHistoryResponse = {
|
|
682
|
+
venueMarketOutcomeId: string;
|
|
683
|
+
points: {
|
|
684
|
+
volume: number | null;
|
|
685
|
+
timestamp: number;
|
|
686
|
+
midpoint: number;
|
|
687
|
+
bestBid: number | null;
|
|
688
|
+
bestAsk: number | null;
|
|
689
|
+
spread: number | null;
|
|
690
|
+
open?: number | undefined;
|
|
691
|
+
high?: number | undefined;
|
|
692
|
+
low?: number | undefined;
|
|
693
|
+
close?: number | undefined;
|
|
694
|
+
}[];
|
|
695
|
+
};
|
|
696
|
+
type VenueMarketOutcome = {
|
|
697
|
+
id: string;
|
|
698
|
+
price: number;
|
|
699
|
+
venueMarketId: string;
|
|
700
|
+
label: string;
|
|
701
|
+
title?: string | null | undefined;
|
|
702
|
+
externalIdentifier?: string | null | undefined;
|
|
703
|
+
winner?: boolean | null | undefined;
|
|
704
|
+
};
|
|
705
|
+
type VenueEventWithMarkets = VenueEvent & {
|
|
706
|
+
venueMarkets: VenueMarket[];
|
|
707
|
+
};
|
|
708
|
+
type VenueMarketListItem = Omit<VenueMarket, "matchedVenueMarkets">;
|
|
709
|
+
type VenueEventListItem = VenueEvent & {
|
|
710
|
+
venueMarkets: VenueMarketListItem[];
|
|
711
|
+
marketCount: number;
|
|
712
|
+
};
|
|
713
|
+
type MatchedMidpoint = {
|
|
714
|
+
venueMarketId: string;
|
|
715
|
+
venue: string;
|
|
716
|
+
midpoint: number | null;
|
|
717
|
+
};
|
|
718
|
+
type OutcomeMidpoint = {
|
|
719
|
+
venueMarketOutcomeId: string;
|
|
720
|
+
label: string;
|
|
721
|
+
midpoint: number | null;
|
|
722
|
+
};
|
|
723
|
+
type MidpointItem = {
|
|
724
|
+
venueMarketId: string;
|
|
725
|
+
venue: string;
|
|
726
|
+
midpoint: number | null;
|
|
727
|
+
spread: number | null;
|
|
728
|
+
timestamp: number | null;
|
|
729
|
+
outcomes: OutcomeMidpoint[];
|
|
730
|
+
matched: MatchedMidpoint[];
|
|
731
|
+
};
|
|
732
|
+
type ComputeSplitsRequest = {
|
|
733
|
+
side: TradeSide$1;
|
|
734
|
+
selections: {
|
|
735
|
+
venue: Venue;
|
|
736
|
+
venueMarketOutcomeId: string;
|
|
737
|
+
}[];
|
|
738
|
+
maxDollarAmount: number;
|
|
739
|
+
};
|
|
740
|
+
type ComputeSplitsResponse = {
|
|
741
|
+
splits: {
|
|
742
|
+
venue: Venue;
|
|
743
|
+
venueMarketOutcomeId: string;
|
|
744
|
+
side: TradeSide$1;
|
|
745
|
+
price: number;
|
|
746
|
+
size: number;
|
|
747
|
+
signedOrder?: any;
|
|
748
|
+
negRisk?: boolean | undefined;
|
|
749
|
+
outcomeExternalIdentifier?: string | undefined;
|
|
750
|
+
}[];
|
|
751
|
+
totalSize: number;
|
|
752
|
+
totalCost: number;
|
|
753
|
+
};
|
|
754
|
+
type Category = {
|
|
755
|
+
id: string;
|
|
756
|
+
name: string;
|
|
757
|
+
parentId: string | null;
|
|
758
|
+
eventCount: number;
|
|
759
|
+
};
|
|
760
|
+
type SettlementSource = {
|
|
761
|
+
name: string;
|
|
762
|
+
url?: string | null | undefined;
|
|
763
|
+
};
|
|
764
|
+
type QuoteManagedRequest = {
|
|
765
|
+
venueMarketOutcomeIds: string[];
|
|
766
|
+
side: "buy" | "sell";
|
|
767
|
+
amount: number;
|
|
768
|
+
slippageBps?: number | undefined;
|
|
769
|
+
};
|
|
770
|
+
type QuoteStep = {
|
|
771
|
+
type: string;
|
|
772
|
+
description: string;
|
|
773
|
+
estimatedDurationMs: number;
|
|
774
|
+
};
|
|
775
|
+
type QuoteSplit = {
|
|
776
|
+
venue: Venue;
|
|
777
|
+
venueMarketId: string;
|
|
778
|
+
venueMarketOutcomeId: string;
|
|
779
|
+
tokenId: string;
|
|
780
|
+
price: string;
|
|
781
|
+
size: string;
|
|
782
|
+
costRaw: string;
|
|
783
|
+
};
|
|
784
|
+
type ExecuteManagedRequest = {
|
|
785
|
+
quoteId: string;
|
|
786
|
+
};
|
|
787
|
+
type ValidateManagedRequest = {
|
|
788
|
+
venueMarketOutcomeIds: string[];
|
|
789
|
+
side: "buy" | "sell";
|
|
790
|
+
amount: number;
|
|
791
|
+
};
|
|
792
|
+
type WithdrawManagedRequest = {
|
|
793
|
+
amountRaw: string;
|
|
794
|
+
tokenSymbol: string;
|
|
795
|
+
destinationAddress: string;
|
|
796
|
+
destinationChainId?: number | undefined;
|
|
797
|
+
};
|
|
798
|
+
type WithdrawalSource = {
|
|
799
|
+
amountRaw: string;
|
|
800
|
+
chainId: number;
|
|
801
|
+
txHash?: string | undefined;
|
|
802
|
+
bridgeOperationId?: string | undefined;
|
|
803
|
+
};
|
|
804
|
+
type SyncBalancesResponse = {
|
|
805
|
+
synced: true;
|
|
806
|
+
};
|
|
807
|
+
type MatchingReport = {
|
|
808
|
+
summary: {
|
|
809
|
+
events: {
|
|
810
|
+
pending: number;
|
|
811
|
+
total: number;
|
|
812
|
+
unmatched: number;
|
|
813
|
+
review: number;
|
|
814
|
+
matched: number;
|
|
815
|
+
verified: number;
|
|
816
|
+
rejected: number;
|
|
817
|
+
};
|
|
818
|
+
markets: {
|
|
819
|
+
pending: number;
|
|
820
|
+
total: number;
|
|
821
|
+
unmatched: number;
|
|
822
|
+
review: number;
|
|
823
|
+
matched: number;
|
|
824
|
+
verified: number;
|
|
825
|
+
rejected: number;
|
|
826
|
+
};
|
|
827
|
+
crossVenue: {
|
|
828
|
+
events: number;
|
|
829
|
+
markets: number;
|
|
830
|
+
};
|
|
831
|
+
matchTypes: {
|
|
832
|
+
manual: number;
|
|
833
|
+
llm: number;
|
|
834
|
+
dome: number;
|
|
835
|
+
};
|
|
836
|
+
llm: {
|
|
837
|
+
pending: number;
|
|
838
|
+
total: number;
|
|
839
|
+
matched: number;
|
|
840
|
+
rejected: number;
|
|
841
|
+
resolved: number;
|
|
842
|
+
failed: number;
|
|
843
|
+
avgConfidenceMatched: number | null;
|
|
844
|
+
avgConfidenceRelated: number | null;
|
|
845
|
+
avgConfidenceNoMatch: number | null;
|
|
846
|
+
avgLatencyMs: number | null;
|
|
847
|
+
};
|
|
848
|
+
};
|
|
849
|
+
matchDistribution: {
|
|
850
|
+
events: {
|
|
851
|
+
min: number;
|
|
852
|
+
max: number;
|
|
853
|
+
avg: number;
|
|
854
|
+
};
|
|
855
|
+
markets: {
|
|
856
|
+
min: number;
|
|
857
|
+
max: number;
|
|
858
|
+
avg: number;
|
|
859
|
+
};
|
|
860
|
+
};
|
|
861
|
+
byCategory: {
|
|
862
|
+
total: number;
|
|
863
|
+
unmatched: number;
|
|
864
|
+
matched: number;
|
|
865
|
+
categoryId: string;
|
|
866
|
+
categoryName: string;
|
|
867
|
+
byVenue: Record<string, number>;
|
|
868
|
+
}[];
|
|
869
|
+
byVenue: {
|
|
870
|
+
venue: string;
|
|
871
|
+
events: {
|
|
872
|
+
total: number;
|
|
873
|
+
matched: number;
|
|
874
|
+
verified: number;
|
|
875
|
+
rejected: number;
|
|
876
|
+
};
|
|
877
|
+
markets: {
|
|
878
|
+
total: number;
|
|
879
|
+
matched: number;
|
|
880
|
+
verified: number;
|
|
881
|
+
rejected: number;
|
|
882
|
+
};
|
|
883
|
+
}[];
|
|
884
|
+
timeSeries: {
|
|
885
|
+
date: string;
|
|
886
|
+
matchedEvents: number;
|
|
887
|
+
matchedMarkets: number;
|
|
888
|
+
llmTotal: number;
|
|
889
|
+
llmMatched: number;
|
|
890
|
+
llmRejected: number;
|
|
891
|
+
}[];
|
|
892
|
+
};
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* API response-boundary formatters for market display fields.
|
|
896
|
+
*
|
|
897
|
+
* Called by the response mappers (mapVenueMarketRow, toVenueEventDto) to
|
|
898
|
+
* produce display-ready text before it reaches the client. Internal code
|
|
899
|
+
* (matching, sorting, DB) uses the raw DB values.
|
|
900
|
+
*/
|
|
901
|
+
/**
|
|
902
|
+
* Resolve the display label for a VenueMarketOutcome.
|
|
903
|
+
*
|
|
904
|
+
* - **Kalshi:** Always return `label`. Kalshi's label IS the canonical
|
|
905
|
+
* display text ("Yes"/"No"); `title` is a subtitle shown elsewhere.
|
|
906
|
+
* - **All other venues:** Return `title` if present and non-empty,
|
|
907
|
+
* otherwise `label`. Polymarket normalizes binary outcomes to
|
|
908
|
+
* "Yes"/"No" labels and stores the original descriptive text in `title`
|
|
909
|
+
* (e.g. label="Yes", title="Trump Wins").
|
|
910
|
+
*
|
|
911
|
+
* When `market` context is provided and the outcome's `title` duplicates
|
|
912
|
+
* the market's `question` (a known Limitless group-sub-market quirk where
|
|
913
|
+
* the driver name lands on every outcome's title), fall back to `label`
|
|
914
|
+
* so "Yes"/"No" remain distinguishable instead of both collapsing to the
|
|
915
|
+
* market subject.
|
|
916
|
+
*/
|
|
917
|
+
declare function formatOutcomeLabel(venue: Venue, outcome: {
|
|
918
|
+
label: string;
|
|
919
|
+
title?: string | null;
|
|
920
|
+
}, _market?: {
|
|
921
|
+
question?: string | null;
|
|
922
|
+
}): string;
|
|
923
|
+
/**
|
|
924
|
+
* Resolve the display question for a VenueMarket.
|
|
925
|
+
*
|
|
926
|
+
* - **Kalshi:** Return the first outcome's `title` if available. Kalshi
|
|
927
|
+
* market tickers (e.g. "INXD-26APR08-T7563.43") are stored in
|
|
928
|
+
* `question` but the human-readable text is in the outcome's `title`
|
|
929
|
+
* (e.g. "S&P 500 closes above 7,563.43"). Falls back to `question` if
|
|
930
|
+
* no outcome title exists.
|
|
931
|
+
* - **All other venues:** Return `question` as-is (already human-readable).
|
|
932
|
+
*/
|
|
933
|
+
declare function formatMarketQuestion(venue: Venue, market: {
|
|
934
|
+
question: string;
|
|
935
|
+
shortTitle?: string | null;
|
|
936
|
+
venueMarketOutcomes?: Array<{
|
|
937
|
+
label: string;
|
|
938
|
+
title?: string | null;
|
|
939
|
+
}>;
|
|
940
|
+
}): string;
|
|
941
|
+
|
|
942
|
+
declare function getWalletAddressFromUserProfile(user: UserProfile | undefined): string | undefined;
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Lightweight runtime validation utilities — zero dependencies.
|
|
946
|
+
* Replaces Zod's safeParse/parse for simple type-guard-based validation.
|
|
947
|
+
*/
|
|
948
|
+
type SafeParseSuccess<T> = {
|
|
949
|
+
success: true;
|
|
950
|
+
data: T;
|
|
951
|
+
};
|
|
952
|
+
type SafeParseFailure = {
|
|
953
|
+
success: false;
|
|
954
|
+
error?: {
|
|
955
|
+
issues: Array<{
|
|
956
|
+
message: string;
|
|
957
|
+
}>;
|
|
958
|
+
};
|
|
959
|
+
};
|
|
960
|
+
type SafeParseResult<T> = SafeParseSuccess<T> | SafeParseFailure;
|
|
961
|
+
/** Generic safeParse — drop-in replacement for zod's schema.safeParse(). */
|
|
962
|
+
declare function safeParse<T>(value: unknown, guard: (v: unknown) => v is T): SafeParseResult<T>;
|
|
963
|
+
/** Throwing parse — drop-in replacement for zod's schema.parse(). */
|
|
964
|
+
declare function parse<T>(value: unknown, guard: (v: unknown) => v is T, message?: string): T;
|
|
965
|
+
/** Creates a type guard for a set of string values (enums, string unions). */
|
|
966
|
+
declare function isEnum<T extends string>(values: ReadonlySet<string>): (v: unknown) => v is T;
|
|
967
|
+
/** Creates a type guard for a set of string values from an enum or array. */
|
|
968
|
+
declare function enumGuard<T extends string>(source: Record<string, T> | readonly T[]): (v: unknown) => v is T;
|
|
969
|
+
/** Finite, non-negative number. */
|
|
970
|
+
declare function isFiniteNonNeg(v: unknown): v is number;
|
|
971
|
+
/** Non-empty string. */
|
|
972
|
+
declare function isNonEmptyString(v: unknown): v is string;
|
|
973
|
+
/** Object with specific keys present and of the right primitive type. */
|
|
974
|
+
declare function hasShape<T>(v: unknown, checks: Record<string, (val: unknown) => boolean>): v is T;
|
|
975
|
+
/**
|
|
976
|
+
* Linear-scan email check matching /^[^\s@]+@[^\s@]+\.[^\s@]+$/ semantics
|
|
977
|
+
* without polynomial-regex backtracking. Exported so the API's TypeBox
|
|
978
|
+
* FormatRegistry can share the same implementation.
|
|
979
|
+
*/
|
|
980
|
+
declare function isEmail(v: string): boolean;
|
|
981
|
+
/** Validates + trims email. Returns safeParse-compatible result with error.issues shape. */
|
|
982
|
+
declare function parseEmail(raw: string): SafeParseResult<{
|
|
983
|
+
email: string;
|
|
984
|
+
}>;
|
|
985
|
+
/** Strict email parse — throws with .issues for catch-block compat. */
|
|
986
|
+
declare function parseEmailStrict(raw: string): {
|
|
987
|
+
email: string;
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
interface SplitsByAmountResult {
|
|
991
|
+
splits: TradeSplit[];
|
|
992
|
+
totalSize: number;
|
|
993
|
+
totalCost: number;
|
|
994
|
+
}
|
|
995
|
+
declare function computeBestSplitsByAmount$1(selections: Array<{
|
|
996
|
+
market: VenueMarket;
|
|
997
|
+
outcome: VenueMarketOutcome;
|
|
998
|
+
orderbook: Orderbook;
|
|
999
|
+
}>, side: TradeSide$1, maxDollarAmount: number): SplitsByAmountResult;
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* Rewrite a CDN image URL to use the pre-processed variant closest to `maxPx`.
|
|
1003
|
+
*
|
|
1004
|
+
* - CDN URLs ending in `/original.webp` or `/{size}.webp` are rewritten.
|
|
1005
|
+
* - External URLs (venue logos, non-CDN) pass through unchanged.
|
|
1006
|
+
* - Falsy inputs return `undefined`.
|
|
1007
|
+
*
|
|
1008
|
+
* @param url Full image URL from the API (e.g. `https://assets.agg.market/users/.../original.webp`)
|
|
1009
|
+
* @param maxPx Largest dimension the image will be rendered at, in CSS pixels.
|
|
1010
|
+
* Pass the **largest** responsive breakpoint size (e.g. 60 for `size-10 md:size-[60px]`).
|
|
1011
|
+
*/
|
|
1012
|
+
declare function optimizedImageUrl(url: string | null | undefined, maxPx: number): string | undefined;
|
|
1013
|
+
|
|
1014
|
+
type VenueMarketClusterNode<TMarket = unknown> = {
|
|
1015
|
+
id: string;
|
|
1016
|
+
venue: string;
|
|
1017
|
+
matchedVenueMarkets?: readonly TMarket[] | null;
|
|
1018
|
+
matchEntry?: {
|
|
1019
|
+
targetVenueMarketId?: string | null;
|
|
1020
|
+
targetVenueMarket?: TMarket | null;
|
|
1021
|
+
} | null | undefined;
|
|
1022
|
+
venues?: readonly string[] | null;
|
|
1023
|
+
venueCount?: number | null;
|
|
1024
|
+
};
|
|
1025
|
+
declare const normalizeVenueMarketCluster: <TMarket extends VenueMarketClusterNode<TMarket>>(markets: readonly TMarket[], selectedMarketId?: string | null) => TMarket[];
|
|
1026
|
+
|
|
1027
|
+
declare const sortVenues: <T extends string>(venues: readonly T[]) => T[];
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* WebSocket protocol types for the Agg platform.
|
|
1031
|
+
* All callback timestamps are in **seconds** (converted from server ms at SDK dispatch).
|
|
1032
|
+
* These are plain TS interfaces — no Zod dependency for partner-side usage.
|
|
1033
|
+
*/
|
|
1034
|
+
/** Aggregated level wire format: [price, totalSize, {venue: sizeAtPrice}] */
|
|
1035
|
+
type WsAttributedLevel = [number, number, Record<string, number>];
|
|
1036
|
+
/** Per-venue level wire format: [price, size] */
|
|
1037
|
+
type WsVenueLevel = [number, number];
|
|
1038
|
+
interface WsVenueInfo {
|
|
1039
|
+
bestBid: number | null;
|
|
1040
|
+
bestAsk: number | null;
|
|
1041
|
+
}
|
|
1042
|
+
interface WsVenueBook {
|
|
1043
|
+
bids: WsVenueLevel[];
|
|
1044
|
+
asks: WsVenueLevel[];
|
|
1045
|
+
}
|
|
1046
|
+
interface WsOrderbookSnapshot {
|
|
1047
|
+
type: "orderbook_snapshot";
|
|
1048
|
+
outcomeId: string;
|
|
1049
|
+
channel?: "orderbook" | "trades";
|
|
1050
|
+
seq: number;
|
|
1051
|
+
checksum: number;
|
|
1052
|
+
bids: WsAttributedLevel[];
|
|
1053
|
+
asks: WsAttributedLevel[];
|
|
1054
|
+
venueOrderbooks: Record<string, WsVenueBook>;
|
|
1055
|
+
venues: Record<string, WsVenueInfo>;
|
|
1056
|
+
midpoint: number | null;
|
|
1057
|
+
spread: number | null;
|
|
1058
|
+
/** @unit seconds (converted from server ms) */
|
|
1059
|
+
timestamp: number;
|
|
1060
|
+
/**
|
|
1061
|
+
* Sticky tick of this outcome's book, inferred at runtime by the engine.
|
|
1062
|
+
* `null` until inferred. Optional — older snapshot producers (REST fallback)
|
|
1063
|
+
* may omit this field entirely.
|
|
1064
|
+
*/
|
|
1065
|
+
tick?: number | null;
|
|
1066
|
+
/** Provenance of the published `midpoint`. See {@link MarkSource}. */
|
|
1067
|
+
markSource?: MarkSource$1;
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Provenance tag for a published midpoint. Mirrors the Rust engine
|
|
1071
|
+
* `MarkSource::as_str()` output.
|
|
1072
|
+
*/
|
|
1073
|
+
type WsMarkSource = "local" | "local_merged" | "local_one_sided" | "sibling" | "local_boundary" | "none";
|
|
1074
|
+
type MarkSource$1 = WsMarkSource;
|
|
1075
|
+
interface WsOrderbookDelta {
|
|
1076
|
+
type: "orderbook_delta";
|
|
1077
|
+
outcomeId: string;
|
|
1078
|
+
channel?: "orderbook" | "trades";
|
|
1079
|
+
seq: number;
|
|
1080
|
+
checksum: number;
|
|
1081
|
+
bidChanges: WsAttributedLevel[];
|
|
1082
|
+
askChanges: WsAttributedLevel[];
|
|
1083
|
+
venueDeltaBooks: Record<string, {
|
|
1084
|
+
bidChanges: WsVenueLevel[];
|
|
1085
|
+
askChanges: WsVenueLevel[];
|
|
1086
|
+
}>;
|
|
1087
|
+
venues: Record<string, WsVenueInfo>;
|
|
1088
|
+
midpoint: number | null;
|
|
1089
|
+
spread: number | null;
|
|
1090
|
+
/** @unit seconds (converted from server ms) */
|
|
1091
|
+
timestamp: number;
|
|
1092
|
+
}
|
|
1093
|
+
interface WsTrade {
|
|
1094
|
+
type: "trade";
|
|
1095
|
+
outcomeId: string;
|
|
1096
|
+
channel?: "orderbook" | "trades";
|
|
1097
|
+
venue: string;
|
|
1098
|
+
side: "buy" | "sell";
|
|
1099
|
+
price: number;
|
|
1100
|
+
size: number;
|
|
1101
|
+
/** @unit seconds (converted from server ms) */
|
|
1102
|
+
timestamp: number;
|
|
1103
|
+
}
|
|
1104
|
+
type WsCandleInterval = "1m" | "5m" | "1h" | "1d";
|
|
1105
|
+
interface WsSubscribed {
|
|
1106
|
+
type: "subscribed";
|
|
1107
|
+
outcomeIds: string[];
|
|
1108
|
+
channel: "orderbook" | "trades";
|
|
1109
|
+
}
|
|
1110
|
+
interface WsUnsubscribed {
|
|
1111
|
+
type: "unsubscribed";
|
|
1112
|
+
outcomeIds: string[];
|
|
1113
|
+
channel: "orderbook" | "trades";
|
|
1114
|
+
}
|
|
1115
|
+
interface WsConnected {
|
|
1116
|
+
type: "connected";
|
|
1117
|
+
appId: string;
|
|
1118
|
+
userId?: string;
|
|
1119
|
+
}
|
|
1120
|
+
interface WsAuthenticated {
|
|
1121
|
+
type: "authenticated";
|
|
1122
|
+
userId: string;
|
|
1123
|
+
}
|
|
1124
|
+
interface WsHeartbeat {
|
|
1125
|
+
type: "heartbeat";
|
|
1126
|
+
/** @unit seconds (converted from server ms) */
|
|
1127
|
+
ts: number;
|
|
1128
|
+
}
|
|
1129
|
+
interface WsResolvedOutcome {
|
|
1130
|
+
label: string;
|
|
1131
|
+
winner?: boolean;
|
|
1132
|
+
externalIdentifier?: string;
|
|
1133
|
+
}
|
|
1134
|
+
interface WsMarketResolved {
|
|
1135
|
+
type: "market_resolved";
|
|
1136
|
+
outcomeId: string;
|
|
1137
|
+
status: "resolved" | "closed";
|
|
1138
|
+
/** Winning outcome label, or null if unknown. */
|
|
1139
|
+
result: string | null;
|
|
1140
|
+
/** Per-outcome resolution data. */
|
|
1141
|
+
outcomes: WsResolvedOutcome[];
|
|
1142
|
+
/** @unit seconds (converted from server ms) */
|
|
1143
|
+
timestamp: number;
|
|
1144
|
+
}
|
|
1145
|
+
interface WsError {
|
|
1146
|
+
type: "error";
|
|
1147
|
+
message: string;
|
|
1148
|
+
}
|
|
1149
|
+
interface WsOrderSubmitted {
|
|
1150
|
+
type: "order_submitted";
|
|
1151
|
+
venue: string;
|
|
1152
|
+
orderId: string;
|
|
1153
|
+
side: string;
|
|
1154
|
+
price: number;
|
|
1155
|
+
size: number;
|
|
1156
|
+
outcomeId?: string;
|
|
1157
|
+
/** @unit seconds (converted from server ms) */
|
|
1158
|
+
timestamp: number;
|
|
1159
|
+
}
|
|
1160
|
+
interface WsBalanceUpdate {
|
|
1161
|
+
type: "balance_update";
|
|
1162
|
+
venue: string;
|
|
1163
|
+
tradingBalanceCents: number;
|
|
1164
|
+
walletBalanceCents?: number;
|
|
1165
|
+
/** @unit seconds (converted from server ms) */
|
|
1166
|
+
timestamp: number;
|
|
1167
|
+
}
|
|
1168
|
+
type WsOrderEventType = "created" | "signed" | "pending_bridge" | "bridge_complete" | "submitting" | "submitted" | "expired" | "dag_started" | "dag_completed" | "dag_failed" | "dag_cancelled" | "step_started" | "step_completed" | "step_waiting" | "step_failed" | "step_retrying" | "filled" | "partial_fill" | "failed" | "bridge_ws_subscribed" | "bridge_ws_subscribe_failed" | "bridge_polling_fallback";
|
|
1169
|
+
interface WsOrderEvent {
|
|
1170
|
+
type: "order_event";
|
|
1171
|
+
event: WsOrderEventType;
|
|
1172
|
+
userId: string;
|
|
1173
|
+
orderId: string;
|
|
1174
|
+
venue: string;
|
|
1175
|
+
dagRunId?: string;
|
|
1176
|
+
stepId?: string;
|
|
1177
|
+
stepType?: string;
|
|
1178
|
+
/** 1-based step index. Pair with `totalSteps` to render "Step 3 of 7". */
|
|
1179
|
+
sequence?: number;
|
|
1180
|
+
totalSteps?: number;
|
|
1181
|
+
templateName?: string;
|
|
1182
|
+
/** Maps sequence → stepType for all steps — sent on dag_started so labels are available upfront. */
|
|
1183
|
+
stepTypes?: Record<number, string>;
|
|
1184
|
+
filledAmountRaw?: string;
|
|
1185
|
+
remainingAmountRaw?: string;
|
|
1186
|
+
errorReason?: string;
|
|
1187
|
+
attempt?: number;
|
|
1188
|
+
correlationId?: string;
|
|
1189
|
+
/** @unit milliseconds (raw from server — NOT converted like other WS types) */
|
|
1190
|
+
timestamp: number;
|
|
1191
|
+
}
|
|
1192
|
+
interface WsRedeemEvent {
|
|
1193
|
+
type: "redeem_event";
|
|
1194
|
+
redeemId: string;
|
|
1195
|
+
venueMarketOutcomeId: string;
|
|
1196
|
+
status: "submitted" | "confirmed" | "failed";
|
|
1197
|
+
callsId: string | null;
|
|
1198
|
+
pendingUserOpId: string | null;
|
|
1199
|
+
txHash: string | null;
|
|
1200
|
+
errorMessage: string | null;
|
|
1201
|
+
/** @unit seconds (converted from server ms) */
|
|
1202
|
+
timestamp: number;
|
|
1203
|
+
}
|
|
1204
|
+
type WsServerMessage = WsOrderbookSnapshot | WsOrderbookDelta | WsTrade | WsSubscribed | WsUnsubscribed | WsConnected | WsAuthenticated | WsHeartbeat | WsMarketResolved | WsError | WsOrderSubmitted | WsBalanceUpdate | WsOrderEvent | WsRedeemEvent;
|
|
1205
|
+
type WsClientMessage = {
|
|
1206
|
+
action: "subscribe";
|
|
1207
|
+
channel: "orderbook" | "trades";
|
|
1208
|
+
outcomeIds: string[];
|
|
1209
|
+
} | {
|
|
1210
|
+
action: "unsubscribe";
|
|
1211
|
+
channel: "orderbook" | "trades";
|
|
1212
|
+
outcomeIds: string[];
|
|
1213
|
+
} | {
|
|
1214
|
+
action: "resnapshot";
|
|
1215
|
+
channel: "orderbook";
|
|
1216
|
+
outcomeIds: string[];
|
|
1217
|
+
} | {
|
|
1218
|
+
action: "authenticate";
|
|
1219
|
+
token: string;
|
|
1220
|
+
};
|
|
1221
|
+
type DiagnosticEvent = {
|
|
1222
|
+
type: "seq_gap";
|
|
1223
|
+
marketId: string;
|
|
1224
|
+
outcomeId: string;
|
|
1225
|
+
expected: number;
|
|
1226
|
+
received: number;
|
|
1227
|
+
} | {
|
|
1228
|
+
type: "checksum_mismatch";
|
|
1229
|
+
marketId: string;
|
|
1230
|
+
outcomeId: string;
|
|
1231
|
+
expected: number;
|
|
1232
|
+
computed: number;
|
|
1233
|
+
} | {
|
|
1234
|
+
type: "reconnect";
|
|
1235
|
+
attempt: number;
|
|
1236
|
+
delayMs: number;
|
|
1237
|
+
} | {
|
|
1238
|
+
type: "stale_connection";
|
|
1239
|
+
lastMessageAge: number;
|
|
1240
|
+
};
|
|
1241
|
+
type DiagnosticCallback = (event: DiagnosticEvent) => void;
|
|
1242
|
+
|
|
1243
|
+
/**
|
|
1244
|
+
* Immutable orderbook utility functions for the SDK.
|
|
1245
|
+
* Applies WS deltas to local book state, computes checksums for integrity verification.
|
|
1246
|
+
* Every function returns a **new object** — never mutates inputs.
|
|
1247
|
+
*/
|
|
1248
|
+
|
|
1249
|
+
interface OrderbookLevel {
|
|
1250
|
+
price: number;
|
|
1251
|
+
size: number;
|
|
1252
|
+
venues: Record<string, number>;
|
|
1253
|
+
}
|
|
1254
|
+
interface VenueOrderbookLevel {
|
|
1255
|
+
price: number;
|
|
1256
|
+
size: number;
|
|
1257
|
+
}
|
|
1258
|
+
interface OrderbookState {
|
|
1259
|
+
marketId: string;
|
|
1260
|
+
/** The outcome whose price the midpoint represents (e.g. the "Yes" outcome in binary markets). */
|
|
1261
|
+
outcomeId?: string | null;
|
|
1262
|
+
bids: OrderbookLevel[];
|
|
1263
|
+
asks: OrderbookLevel[];
|
|
1264
|
+
venueOrderbooks: Record<string, {
|
|
1265
|
+
bids: VenueOrderbookLevel[];
|
|
1266
|
+
asks: VenueOrderbookLevel[];
|
|
1267
|
+
}>;
|
|
1268
|
+
venues: Record<string, WsVenueInfo>;
|
|
1269
|
+
midpoint: number | null;
|
|
1270
|
+
spread: number | null;
|
|
1271
|
+
seq: number;
|
|
1272
|
+
checksum: number;
|
|
1273
|
+
/** @unit seconds */
|
|
1274
|
+
timestamp: number;
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Compute the XOR-based checksum of an orderbook.
|
|
1278
|
+
* Matches the Rust engine's checksum: XOR of crc32("B{price}:{size}") for each
|
|
1279
|
+
* bid and crc32("A{price}:{size}") for each ask, independently hashed then XOR'd.
|
|
1280
|
+
*/
|
|
1281
|
+
declare function computeChecksum(book: {
|
|
1282
|
+
bids: OrderbookLevel[];
|
|
1283
|
+
asks: OrderbookLevel[];
|
|
1284
|
+
}): number;
|
|
1285
|
+
/**
|
|
1286
|
+
* Convert a WS snapshot message into local OrderbookState.
|
|
1287
|
+
* Timestamp is expected to already be in seconds (converted by AggWebSocket).
|
|
1288
|
+
*/
|
|
1289
|
+
declare function snapshotToOrderbook(snapshot: WsOrderbookSnapshot): OrderbookState;
|
|
1290
|
+
/**
|
|
1291
|
+
* Apply a WS delta to an existing OrderbookState, returning a new state.
|
|
1292
|
+
* Bids sorted descending, asks ascending (maintained invariant).
|
|
1293
|
+
*/
|
|
1294
|
+
declare function applyOrderbookDelta(state: OrderbookState, delta: WsOrderbookDelta): OrderbookState;
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Agg platform WebSocket client.
|
|
1298
|
+
*
|
|
1299
|
+
* Single connection, refcounted subscriptions by ID (venueMarketId or
|
|
1300
|
+
* venueMarketOutcomeId). Maintains in-memory orderbook state per subscribed ID.
|
|
1301
|
+
* All timestamps converted from server ms to seconds before invoking callbacks.
|
|
1302
|
+
*
|
|
1303
|
+
* Recovery: seq gap or checksum mismatch → resnapshot request.
|
|
1304
|
+
* Stale delta guard: deltas with seq <= current book seq are silently dropped.
|
|
1305
|
+
* Liveness: no message for 45s → reconnect (server sends heartbeat every 30s).
|
|
1306
|
+
*/
|
|
1307
|
+
|
|
1308
|
+
interface AggWebSocketCallbacks {
|
|
1309
|
+
onSnapshot?: (marketId: string, book: OrderbookState) => void;
|
|
1310
|
+
onDelta?: (marketId: string, book: OrderbookState) => void;
|
|
1311
|
+
onTrade?: (trade: WsTrade) => void;
|
|
1312
|
+
onHeartbeat?: (hb: WsHeartbeat) => void;
|
|
1313
|
+
onSubscribed?: (msg: WsSubscribed) => void;
|
|
1314
|
+
onUnsubscribed?: (msg: WsUnsubscribed) => void;
|
|
1315
|
+
onConnected?: (msg: WsConnected) => void;
|
|
1316
|
+
onAuthenticated?: (msg: WsAuthenticated) => void;
|
|
1317
|
+
onMarketResolved?: (msg: WsMarketResolved) => void;
|
|
1318
|
+
onError?: (msg: WsError) => void;
|
|
1319
|
+
onOrderSubmitted?: (msg: WsOrderSubmitted) => void;
|
|
1320
|
+
onBalanceUpdate?: (msg: WsBalanceUpdate) => void;
|
|
1321
|
+
onOrderEvent?: (msg: WsOrderEvent) => void;
|
|
1322
|
+
onRedeemEvent?: (msg: WsRedeemEvent) => void;
|
|
1323
|
+
onDiagnostics?: DiagnosticCallback;
|
|
1324
|
+
onConnectionStateChange?: (connected: boolean) => void;
|
|
1325
|
+
}
|
|
1326
|
+
interface AggWebSocketOptions {
|
|
1327
|
+
/** Full WebSocket URL including query params (appId). Token should NOT be in the URL. */
|
|
1328
|
+
url: string;
|
|
1329
|
+
callbacks?: AggWebSocketCallbacks;
|
|
1330
|
+
/** JWT to send via the authenticate message after connecting (avoids token in URL/logs). */
|
|
1331
|
+
initialToken?: string;
|
|
1332
|
+
/** Enable websocket debug logs. Default: false. */
|
|
1333
|
+
enableLogs?: boolean;
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Agg WebSocket client. Single WS connection with refcounted market subscriptions.
|
|
1337
|
+
*/
|
|
1338
|
+
declare class AggWebSocket {
|
|
1339
|
+
private ws;
|
|
1340
|
+
private readonly url;
|
|
1341
|
+
private callbacks;
|
|
1342
|
+
private readonly subs;
|
|
1343
|
+
private readonly pendingSubs;
|
|
1344
|
+
private readonly pendingTradeSubs;
|
|
1345
|
+
private readonly pendingResnapshots;
|
|
1346
|
+
private readonly pendingFlushSubs;
|
|
1347
|
+
private readonly pendingFlushUnsubs;
|
|
1348
|
+
private readonly pendingFlushTradeSubs;
|
|
1349
|
+
private readonly pendingFlushTradeUnsubs;
|
|
1350
|
+
private flushScheduled;
|
|
1351
|
+
private readonly books;
|
|
1352
|
+
/** Markets currently resyncing (awaiting snapshot after seq gap / checksum mismatch). */
|
|
1353
|
+
private readonly resyncing;
|
|
1354
|
+
private connecting;
|
|
1355
|
+
private _connected;
|
|
1356
|
+
private reconnectAttempts;
|
|
1357
|
+
private reconnectTimer;
|
|
1358
|
+
private staleTimer;
|
|
1359
|
+
private lastMessageTime;
|
|
1360
|
+
private destroyed;
|
|
1361
|
+
private initialToken?;
|
|
1362
|
+
private readonly enableLogs;
|
|
1363
|
+
constructor(options: AggWebSocketOptions);
|
|
1364
|
+
get connected(): boolean;
|
|
1365
|
+
/** Get the current orderbook state for an outcome (or null if no snapshot received yet). */
|
|
1366
|
+
getBook(outcomeId: string): OrderbookState | null;
|
|
1367
|
+
/** Whether an outcome is currently resyncing (waiting for fresh snapshot). */
|
|
1368
|
+
isResyncing(outcomeId: string): boolean;
|
|
1369
|
+
/**
|
|
1370
|
+
* Subscribe to a feed by outcome ID.
|
|
1371
|
+
* @param outcomeId The venueMarketOutcomeId to subscribe to.
|
|
1372
|
+
* @param channel "orderbook" (default) or "trades".
|
|
1373
|
+
* Returns an unsubscribe function (ref-counted).
|
|
1374
|
+
*/
|
|
1375
|
+
subscribe(outcomeId: string, channel?: "orderbook" | "trades"): () => void;
|
|
1376
|
+
/**
|
|
1377
|
+
* Subscribe to an outcome's trade feed.
|
|
1378
|
+
* @deprecated Use `subscribe(outcomeId, "trades")` instead.
|
|
1379
|
+
* Returns an unsubscribe function.
|
|
1380
|
+
*/
|
|
1381
|
+
subscribeTrades(outcomeId: string): () => void;
|
|
1382
|
+
private _subscribeTrades;
|
|
1383
|
+
/** Send a JWT to authenticate (or re-authenticate) the connection. */
|
|
1384
|
+
authenticate(token: string): void;
|
|
1385
|
+
/** Request a fresh snapshot for one or more subscribed outcomes. */
|
|
1386
|
+
resnapshot(outcomeIdOrIds: string | string[]): void;
|
|
1387
|
+
/** Connect (idempotent). Called automatically on first subscribe. */
|
|
1388
|
+
connect(): void;
|
|
1389
|
+
/** Disconnect and clean up. Reusable — call connect() to reconnect. */
|
|
1390
|
+
disconnect(): void;
|
|
1391
|
+
/** Permanently destroy. Cannot reconnect after this. */
|
|
1392
|
+
destroy(): void;
|
|
1393
|
+
/** Update callbacks (e.g., after React re-render). */
|
|
1394
|
+
setCallbacks(callbacks: AggWebSocketCallbacks): void;
|
|
1395
|
+
private ensureConnected;
|
|
1396
|
+
private doConnect;
|
|
1397
|
+
private scheduleReconnect;
|
|
1398
|
+
private cancelReconnect;
|
|
1399
|
+
private resetStaleTimer;
|
|
1400
|
+
private cancelStaleTimer;
|
|
1401
|
+
private handleMessage;
|
|
1402
|
+
/**
|
|
1403
|
+
* Server confirmed the connection — gateway has validated our appId and is
|
|
1404
|
+
* ready to accept subscriptions. Now flush all pending subs.
|
|
1405
|
+
*/
|
|
1406
|
+
private handleConnected;
|
|
1407
|
+
private handleSnapshot;
|
|
1408
|
+
private handleDelta;
|
|
1409
|
+
private handleTrade;
|
|
1410
|
+
private handleHeartbeat;
|
|
1411
|
+
private handleMarketResolved;
|
|
1412
|
+
private handleOrderSubmitted;
|
|
1413
|
+
private handleBalanceUpdate;
|
|
1414
|
+
private handleRedeemEvent;
|
|
1415
|
+
private requestResnapshot;
|
|
1416
|
+
/**
|
|
1417
|
+
* Schedule a microtask that flushes queued subscribe/unsubscribe frames.
|
|
1418
|
+
* Coalesces multiple same-tick sub/unsub calls into at most one frame per
|
|
1419
|
+
* channel+action pair.
|
|
1420
|
+
*/
|
|
1421
|
+
private scheduleFlush;
|
|
1422
|
+
private flushPending;
|
|
1423
|
+
private sendSubscribe;
|
|
1424
|
+
private send;
|
|
1425
|
+
private activeOrderbookMarkets;
|
|
1426
|
+
private activeTradeMarkets;
|
|
1427
|
+
private emitDiagnostic;
|
|
1428
|
+
private summarizeTopLevels;
|
|
1429
|
+
private debugOrderbook;
|
|
1430
|
+
private isOrderbookDebugEnabled;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
interface AppClientConfigResponse {
|
|
1434
|
+
disabledVenues: Venue[];
|
|
1435
|
+
disabledCategoryPresets: string[];
|
|
1436
|
+
earlyAccessEnabled: boolean;
|
|
1437
|
+
}
|
|
1438
|
+
type AggAuthProviderType = "siwe" | "siws" | "google" | "twitter" | "apple" | "email";
|
|
1439
|
+
type AggAuthDeliveryMode = "body" | "cookie-refresh";
|
|
1440
|
+
interface AggClientAuthOptions {
|
|
1441
|
+
getEarlyAccessCode?: () => string | null;
|
|
1442
|
+
}
|
|
1443
|
+
type AggAuthStartBody = {
|
|
1444
|
+
provider: Exclude<AggAuthProviderType, "email">;
|
|
1445
|
+
redirectUrl?: string;
|
|
1446
|
+
/** Cloudflare Turnstile token — required when a prior authStart returned `challenge_required`. */
|
|
1447
|
+
turnstileToken?: string;
|
|
1448
|
+
earlyAccessCode?: string;
|
|
1449
|
+
} | {
|
|
1450
|
+
provider: "email";
|
|
1451
|
+
email: string;
|
|
1452
|
+
redirectUrl?: string;
|
|
1453
|
+
/** Cloudflare Turnstile token — required when a prior authStart returned `challenge_required`. */
|
|
1454
|
+
turnstileToken?: string;
|
|
1455
|
+
earlyAccessCode?: string;
|
|
1456
|
+
};
|
|
1457
|
+
interface AggAuthVerifyBody {
|
|
1458
|
+
message: string;
|
|
1459
|
+
signature: string;
|
|
1460
|
+
earlyAccessCode?: string;
|
|
1461
|
+
}
|
|
1462
|
+
type AggAuthStartResult = {
|
|
1463
|
+
type: "nonce";
|
|
1464
|
+
nonce: string;
|
|
1465
|
+
} | {
|
|
1466
|
+
type: "redirect";
|
|
1467
|
+
url: string;
|
|
1468
|
+
} | {
|
|
1469
|
+
type: "magic_link";
|
|
1470
|
+
success: true;
|
|
1471
|
+
} | {
|
|
1472
|
+
type: "challenge_required";
|
|
1473
|
+
siteKey: string;
|
|
1474
|
+
};
|
|
1475
|
+
/**
|
|
1476
|
+
* Body for `POST /users/me/link-account/start` — authenticated account linking.
|
|
1477
|
+
*
|
|
1478
|
+
* `redirectUrl` is required for every provider: the callback / magic-link verify
|
|
1479
|
+
* hands the partner a `link_confirm_token` by redirecting to `redirectUrl`, and
|
|
1480
|
+
* the partner app completes the flow by calling `/confirm` from that page.
|
|
1481
|
+
*/
|
|
1482
|
+
type AggLinkAccountBody = {
|
|
1483
|
+
provider: "google" | "twitter" | "apple";
|
|
1484
|
+
redirectUrl: string;
|
|
1485
|
+
} | {
|
|
1486
|
+
provider: "email";
|
|
1487
|
+
email: string;
|
|
1488
|
+
redirectUrl: string;
|
|
1489
|
+
};
|
|
1490
|
+
type AggLinkAccountResult = {
|
|
1491
|
+
type: "redirect";
|
|
1492
|
+
url: string;
|
|
1493
|
+
} | {
|
|
1494
|
+
type: "magic_link";
|
|
1495
|
+
success: true;
|
|
1496
|
+
};
|
|
1497
|
+
/**
|
|
1498
|
+
* Success result of /users/me/link-account/confirm.
|
|
1499
|
+
* - `linked` — new Account row written.
|
|
1500
|
+
* - `already_linked_same` — identity was already attached to the caller's Principal
|
|
1501
|
+
* (idempotent; safe to retry).
|
|
1502
|
+
*
|
|
1503
|
+
* Collisions with a different Principal surface as HTTP 409 and are thrown by the
|
|
1504
|
+
* SDK's request layer — catch them at the call site, don't expect them here.
|
|
1505
|
+
*/
|
|
1506
|
+
type AggLinkAccountConfirmResult = {
|
|
1507
|
+
status: "linked" | "already_linked_same";
|
|
1508
|
+
provider: string;
|
|
1509
|
+
};
|
|
1510
|
+
type AggSessionUser = AuthUser | UserProfile;
|
|
1511
|
+
interface AggClientSessionInput {
|
|
1512
|
+
accessToken: string;
|
|
1513
|
+
refreshToken?: string;
|
|
1514
|
+
user?: AggSessionUser;
|
|
1515
|
+
}
|
|
1516
|
+
/** Non-sensitive auth snapshot persisted to localStorage for UI bootstrapping.
|
|
1517
|
+
* Tokens are NEVER included — they exist only in process memory. */
|
|
1518
|
+
interface PersistedAuthSnapshot {
|
|
1519
|
+
user: {
|
|
1520
|
+
id: string;
|
|
1521
|
+
username: string | null;
|
|
1522
|
+
avatarUrl: string | null;
|
|
1523
|
+
walletAddress?: string | null;
|
|
1524
|
+
} | null;
|
|
1525
|
+
authHint: {
|
|
1526
|
+
wasAuthenticated: boolean;
|
|
1527
|
+
};
|
|
1528
|
+
}
|
|
1529
|
+
/** Auth lifecycle status for UI state machines. */
|
|
1530
|
+
type AuthStatus = "unknown" | "authenticated" | "unauthenticated";
|
|
1531
|
+
interface AggClientOptions {
|
|
1532
|
+
baseUrl: string;
|
|
1533
|
+
/** Public App ID — sent as x-app-id header. For client-side partner usage. */
|
|
1534
|
+
appId?: string;
|
|
1535
|
+
/** Secret admin key — sent as x-admin-key header. Server-side only. */
|
|
1536
|
+
adminKey?: string;
|
|
1537
|
+
/**
|
|
1538
|
+
* Partner API key for server-side use. Sent as `x-app-api-key`. NEVER embed
|
|
1539
|
+
* in browser bundles, source maps, or logs. Keys start with `agg_<appId>_`.
|
|
1540
|
+
*/
|
|
1541
|
+
apiKey?: string;
|
|
1542
|
+
/** WebSocket URL for real-time feeds. Must be set explicitly to use createWebSocket(). */
|
|
1543
|
+
wsUrl?: string;
|
|
1544
|
+
/** Use Kalshi demo environment (https://demo-api.kalshi.co) when true. */
|
|
1545
|
+
kalshiDemo?: boolean;
|
|
1546
|
+
/** Optional auth request hooks used to enrich auth payloads. */
|
|
1547
|
+
auth?: AggClientAuthOptions;
|
|
1548
|
+
/** Move refresh delivery to an HttpOnly cookie on auth endpoints. Defaults to "body". */
|
|
1549
|
+
authDelivery?: AggAuthDeliveryMode;
|
|
1550
|
+
/** Persist a non-sensitive auth hint to localStorage for UI bootstrapping.
|
|
1551
|
+
* Tokens are NEVER persisted — they exist only in process memory.
|
|
1552
|
+
* When authDelivery is "body", refresh tokens are lost on page reload.
|
|
1553
|
+
* When authDelivery is "cookie-refresh", refresh tokens survive via HttpOnly cookies
|
|
1554
|
+
* and the SDK attempts a silent refresh on cold start. Defaults to true. */
|
|
1555
|
+
persistSession?: boolean;
|
|
1556
|
+
}
|
|
1557
|
+
interface SiweMessageParams {
|
|
1558
|
+
domain: string;
|
|
1559
|
+
address: string;
|
|
1560
|
+
uri: string;
|
|
1561
|
+
nonce: string;
|
|
1562
|
+
chainId?: number;
|
|
1563
|
+
statement?: string;
|
|
1564
|
+
issuedAt?: string;
|
|
1565
|
+
}
|
|
1566
|
+
interface SiwsMessageParams {
|
|
1567
|
+
domain: string;
|
|
1568
|
+
/** Base58-encoded Solana public key. */
|
|
1569
|
+
address: string;
|
|
1570
|
+
uri: string;
|
|
1571
|
+
nonce: string;
|
|
1572
|
+
/** Solana chain ID: "mainnet", "devnet", "testnet", or "localnet". Defaults to "mainnet". */
|
|
1573
|
+
chainId?: string;
|
|
1574
|
+
statement?: string;
|
|
1575
|
+
issuedAt?: string;
|
|
1576
|
+
}
|
|
1577
|
+
/** OHLCV bar point for chart rendering. */
|
|
1578
|
+
interface ChartCandle {
|
|
1579
|
+
/** Open time in Unix milliseconds. */
|
|
1580
|
+
t: number;
|
|
1581
|
+
/** Open price (0-1). */
|
|
1582
|
+
o: number;
|
|
1583
|
+
/** High price (0-1). */
|
|
1584
|
+
h: number;
|
|
1585
|
+
/** Low price (0-1). */
|
|
1586
|
+
l: number;
|
|
1587
|
+
/** Close price (0-1). */
|
|
1588
|
+
c: number;
|
|
1589
|
+
/** Volume (null if unavailable). */
|
|
1590
|
+
v: number | null;
|
|
1591
|
+
}
|
|
1592
|
+
/** @deprecated Historical chart bars are canonical per outcome. Use ChartBarsResponse instead. */
|
|
1593
|
+
interface ChartVenueCandles {
|
|
1594
|
+
venue: string;
|
|
1595
|
+
candles: ChartCandle[];
|
|
1596
|
+
}
|
|
1597
|
+
type ChartResolution = "1m" | "5m" | "1h" | "1d";
|
|
1598
|
+
/**
|
|
1599
|
+
* Freshness signal embedded in every chart response. Compare
|
|
1600
|
+
* `staleSeconds` against the resolution to decide whether to show a
|
|
1601
|
+
* "delayed" badge on the chart.
|
|
1602
|
+
*/
|
|
1603
|
+
interface ChartBarsMeta {
|
|
1604
|
+
/** Server-side wall clock when the response was assembled, in milliseconds. */
|
|
1605
|
+
serverTime: number;
|
|
1606
|
+
/** `open_time` of the most-recent bar in `data`, in milliseconds. Null if `data` is empty. */
|
|
1607
|
+
lastBarOpenTime: number | null;
|
|
1608
|
+
/** `serverTime - lastBarOpenTime` in seconds. Null if `data` is empty. */
|
|
1609
|
+
staleSeconds: number | null;
|
|
1610
|
+
}
|
|
1611
|
+
/** Response from GET /charts/bars. */
|
|
1612
|
+
interface ChartBarsResponse {
|
|
1613
|
+
/** VenueMarketOutcome.id requested by the caller. */
|
|
1614
|
+
venueMarketOutcomeId: string;
|
|
1615
|
+
/** Venue of the canonical historical series. */
|
|
1616
|
+
venue: string;
|
|
1617
|
+
/** Resolution returned by the backend. */
|
|
1618
|
+
resolution: ChartResolution;
|
|
1619
|
+
/** Bars sorted in ascending open time. */
|
|
1620
|
+
data: ChartCandle[];
|
|
1621
|
+
/** Freshness signal — see {@link ChartBarsMeta}. */
|
|
1622
|
+
meta: ChartBarsMeta;
|
|
1623
|
+
}
|
|
1624
|
+
/** Matched market reference returned by batch/aggregate endpoints. */
|
|
1625
|
+
interface VenueMarketRef {
|
|
1626
|
+
venue: string;
|
|
1627
|
+
venueMarketId: string;
|
|
1628
|
+
}
|
|
1629
|
+
type OrderbookBatchItemStatus = "ok" | "market_not_found" | "market_resolved" | "market_closed" | "market_paused" | "market_unopened" | "book_not_loaded";
|
|
1630
|
+
type OrderbookBatchItemErrorCode = "market_not_found" | "market_resolved" | "market_closed" | "market_paused" | "market_unopened" | "book_not_loaded";
|
|
1631
|
+
interface OrderbookBatchItemError {
|
|
1632
|
+
code: OrderbookBatchItemErrorCode;
|
|
1633
|
+
message: string;
|
|
1634
|
+
retryable: boolean;
|
|
1635
|
+
}
|
|
1636
|
+
interface OrderbooksOnlyError {
|
|
1637
|
+
code: "use_orderbooks_endpoint";
|
|
1638
|
+
message: string;
|
|
1639
|
+
retryable: boolean;
|
|
1640
|
+
}
|
|
1641
|
+
interface OrderbookServiceUnavailableError {
|
|
1642
|
+
code: "orderbook_service_unavailable";
|
|
1643
|
+
message: string;
|
|
1644
|
+
retryable: boolean;
|
|
1645
|
+
}
|
|
1646
|
+
interface RequestedOrderbookMarket {
|
|
1647
|
+
venueMarketId: string;
|
|
1648
|
+
venue: string;
|
|
1649
|
+
marketStatus: "open" | "closed" | "resolved" | "unopened" | "paused";
|
|
1650
|
+
tickSize: number | null;
|
|
1651
|
+
endDate: string | null;
|
|
1652
|
+
resolutionDate: string | null;
|
|
1653
|
+
}
|
|
1654
|
+
interface MatchedOrderbookMarket extends VenueMarketRef {
|
|
1655
|
+
marketStatus: "open" | "closed" | "resolved" | "unopened" | "paused";
|
|
1656
|
+
tickSize: number | null;
|
|
1657
|
+
hasOrderbook: boolean;
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Provenance of a published `midpoint`. Mirrors the engine's `MarkSource`.
|
|
1661
|
+
*
|
|
1662
|
+
* - `local` — true two-sided midpoint from the venue's own book
|
|
1663
|
+
* - `local_merged` — midpoint from the cross-venue merged book
|
|
1664
|
+
* - `local_one_sided` — only one side present; mark is the live side, NOT a midpoint
|
|
1665
|
+
* - `sibling` — derived from the complementary outcome (e.g. NO from YES)
|
|
1666
|
+
* - `local_boundary` — clamped to the [tick, 1-tick] boundary
|
|
1667
|
+
* - `none` — no mark available
|
|
1668
|
+
*/
|
|
1669
|
+
type MarkSource = "local" | "local_merged" | "local_one_sided" | "sibling" | "local_boundary" | "none";
|
|
1670
|
+
/** Per-venue orderbook entry with native tick spacing. */
|
|
1671
|
+
interface VenueOrderbookEntry {
|
|
1672
|
+
venueMarketId: string;
|
|
1673
|
+
tickSize: number | null;
|
|
1674
|
+
orderbook: Orderbook;
|
|
1675
|
+
/**
|
|
1676
|
+
* Sticky tick of this venue's book inferred at runtime by the engine. May
|
|
1677
|
+
* differ from the seed `tickSize` when the live grid is finer than the DB
|
|
1678
|
+
* metadata. Optional — only populated when the engine has emitted runtime
|
|
1679
|
+
* metadata for this entry.
|
|
1680
|
+
*/
|
|
1681
|
+
tick?: number | null;
|
|
1682
|
+
/** Provenance of this venue book's published midpoint. See {@link MarkSource}. */
|
|
1683
|
+
markSource?: MarkSource;
|
|
1684
|
+
}
|
|
1685
|
+
/** Response from GET /orderbooks (batch). */
|
|
1686
|
+
interface BatchOrderbooksResponse {
|
|
1687
|
+
data: Array<{
|
|
1688
|
+
venueMarketId: string;
|
|
1689
|
+
status: OrderbookBatchItemStatus;
|
|
1690
|
+
error: OrderbookBatchItemError | null;
|
|
1691
|
+
requestedMarket: RequestedOrderbookMarket | null;
|
|
1692
|
+
venueOrderbooks: Record<string, VenueOrderbookEntry>;
|
|
1693
|
+
matchedMarkets: MatchedOrderbookMarket[];
|
|
1694
|
+
}>;
|
|
1695
|
+
meta: {
|
|
1696
|
+
requestedCount: number;
|
|
1697
|
+
okCount: number;
|
|
1698
|
+
errorCount: number;
|
|
1699
|
+
};
|
|
1700
|
+
}
|
|
1701
|
+
/** A single market midpoint row returned by GET /midpoints. */
|
|
1702
|
+
interface MidpointRow {
|
|
1703
|
+
venueMarketId: string;
|
|
1704
|
+
venue: string;
|
|
1705
|
+
midpoint: number | null;
|
|
1706
|
+
spread: number | null;
|
|
1707
|
+
timestamp: number | null;
|
|
1708
|
+
/** Provenance of `midpoint`. */
|
|
1709
|
+
markSource?: MarkSource;
|
|
1710
|
+
/**
|
|
1711
|
+
* When `markSource === "sibling"`, the matched venueMarketId whose book
|
|
1712
|
+
* supplied the headline mark. Allows the FE to label "sourced from venue X"
|
|
1713
|
+
* without re-running the matching logic.
|
|
1714
|
+
*/
|
|
1715
|
+
siblingVenueMarketId?: string;
|
|
1716
|
+
}
|
|
1717
|
+
/** Per-outcome midpoint from a live orderbook. */
|
|
1718
|
+
interface OutcomeMidpointRow {
|
|
1719
|
+
venueMarketOutcomeId: string;
|
|
1720
|
+
label: string;
|
|
1721
|
+
midpoint: number | null;
|
|
1722
|
+
/** Provenance of `midpoint`. */
|
|
1723
|
+
markSource?: MarkSource;
|
|
1724
|
+
}
|
|
1725
|
+
/** Response from GET /midpoints (batch). */
|
|
1726
|
+
interface BatchMidpointsResponse {
|
|
1727
|
+
data: Array<MidpointRow & {
|
|
1728
|
+
outcomes: OutcomeMidpointRow[];
|
|
1729
|
+
matched: MidpointRow[];
|
|
1730
|
+
}>;
|
|
1731
|
+
}
|
|
1732
|
+
/** Response from GET /orderbook/outcome/:id (single outcome). */
|
|
1733
|
+
interface OutcomeOrderbookResponse {
|
|
1734
|
+
venueMarketOutcomeId: string;
|
|
1735
|
+
venueMarketId: string;
|
|
1736
|
+
venue: string;
|
|
1737
|
+
orderbook: {
|
|
1738
|
+
bids: Array<{
|
|
1739
|
+
price: number;
|
|
1740
|
+
size: number;
|
|
1741
|
+
}>;
|
|
1742
|
+
asks: Array<{
|
|
1743
|
+
price: number;
|
|
1744
|
+
size: number;
|
|
1745
|
+
}>;
|
|
1746
|
+
};
|
|
1747
|
+
midpoint: number | null;
|
|
1748
|
+
spread: number | null;
|
|
1749
|
+
seq: number;
|
|
1750
|
+
checksum: number;
|
|
1751
|
+
timestamp: number;
|
|
1752
|
+
/** Sticky tick of this outcome's book, inferred at runtime. `null` until inferred. */
|
|
1753
|
+
tick: number | null;
|
|
1754
|
+
/** Provenance of `midpoint`. See {@link MarkSource}. */
|
|
1755
|
+
markSource: MarkSource;
|
|
1756
|
+
}
|
|
1757
|
+
/** Standard paginated list response from the API. */
|
|
1758
|
+
interface PaginatedResponse<T> {
|
|
1759
|
+
data: T[];
|
|
1760
|
+
nextCursor: string | null;
|
|
1761
|
+
hasMore: boolean;
|
|
1762
|
+
}
|
|
1763
|
+
interface OrderListQuery {
|
|
1764
|
+
userId?: string;
|
|
1765
|
+
status?: string;
|
|
1766
|
+
limit?: number;
|
|
1767
|
+
offset?: number;
|
|
1768
|
+
}
|
|
1769
|
+
interface TradeExecutorOrder {
|
|
1770
|
+
id: string;
|
|
1771
|
+
userId: string;
|
|
1772
|
+
venue: string;
|
|
1773
|
+
status: string;
|
|
1774
|
+
marketId: string;
|
|
1775
|
+
tokenId: string;
|
|
1776
|
+
side: string;
|
|
1777
|
+
amountRaw: string;
|
|
1778
|
+
quoteId: string | null;
|
|
1779
|
+
dagRunId: string | null;
|
|
1780
|
+
filledAmountRaw: string | null;
|
|
1781
|
+
executionPrice: string | null;
|
|
1782
|
+
txHash: string | null;
|
|
1783
|
+
errorMessage: string | null;
|
|
1784
|
+
createdAt: string;
|
|
1785
|
+
updatedAt: string;
|
|
1786
|
+
}
|
|
1787
|
+
interface TradeExecutorOrderListResponse {
|
|
1788
|
+
orders: TradeExecutorOrder[];
|
|
1789
|
+
total: number;
|
|
1790
|
+
}
|
|
1791
|
+
/** A single level in the aggregated orderbook with per-venue attribution. */
|
|
1792
|
+
interface AggregatedOrderbookLevel {
|
|
1793
|
+
price: number;
|
|
1794
|
+
size: number;
|
|
1795
|
+
venues: Record<string, number>;
|
|
1796
|
+
}
|
|
1797
|
+
/** A simple orderbook level without venue attribution. */
|
|
1798
|
+
interface SimpleOrderbookLevel {
|
|
1799
|
+
price: number;
|
|
1800
|
+
size: number;
|
|
1801
|
+
}
|
|
1802
|
+
/** Per-venue best-bid/ask info. */
|
|
1803
|
+
interface VenuePriceInfo {
|
|
1804
|
+
bestBid: number | null;
|
|
1805
|
+
bestAsk: number | null;
|
|
1806
|
+
}
|
|
1807
|
+
/** Response from GET /orderbook/:venueMarketId — canonical aggregated orderbook. */
|
|
1808
|
+
interface AggregatedOrderbookResponse {
|
|
1809
|
+
venueMarketId: string;
|
|
1810
|
+
orderbook: {
|
|
1811
|
+
bids: AggregatedOrderbookLevel[];
|
|
1812
|
+
asks: AggregatedOrderbookLevel[];
|
|
1813
|
+
};
|
|
1814
|
+
venueOrderbooks: Record<string, {
|
|
1815
|
+
bids: SimpleOrderbookLevel[];
|
|
1816
|
+
asks: SimpleOrderbookLevel[];
|
|
1817
|
+
}>;
|
|
1818
|
+
venues: Record<string, VenuePriceInfo>;
|
|
1819
|
+
midpoint: number | null;
|
|
1820
|
+
spread: number | null;
|
|
1821
|
+
timestamp: number;
|
|
1822
|
+
/** Sequence number (present in live responses). */
|
|
1823
|
+
seq?: number;
|
|
1824
|
+
/** CRC32 checksum (present in live responses). */
|
|
1825
|
+
checksum?: number | null;
|
|
1826
|
+
/** Markets matched across venues for this canonical market. */
|
|
1827
|
+
matchedMarkets?: Array<{
|
|
1828
|
+
venue: string;
|
|
1829
|
+
venueMarketId: string;
|
|
1830
|
+
}>;
|
|
1831
|
+
}
|
|
1832
|
+
interface QuoteManagedParams {
|
|
1833
|
+
venueMarketOutcomeIds: string[];
|
|
1834
|
+
side: "buy" | "sell";
|
|
1835
|
+
amount: number;
|
|
1836
|
+
slippageBps?: number;
|
|
1837
|
+
}
|
|
1838
|
+
interface QuoteManagedStep {
|
|
1839
|
+
type: string;
|
|
1840
|
+
description: string;
|
|
1841
|
+
estimatedDurationMs: number;
|
|
1842
|
+
}
|
|
1843
|
+
interface QuoteManagedSplit {
|
|
1844
|
+
venue: string;
|
|
1845
|
+
venueMarketId: string;
|
|
1846
|
+
venueMarketOutcomeId: string;
|
|
1847
|
+
tokenId: string;
|
|
1848
|
+
price: string;
|
|
1849
|
+
size: string;
|
|
1850
|
+
costRaw: string;
|
|
1851
|
+
}
|
|
1852
|
+
interface QuoteManagedResponse {
|
|
1853
|
+
quoteId: string;
|
|
1854
|
+
canExecute: boolean;
|
|
1855
|
+
estimatedCostRaw: string;
|
|
1856
|
+
steps: QuoteManagedStep[];
|
|
1857
|
+
splits: QuoteManagedSplit[];
|
|
1858
|
+
expiresAt: string;
|
|
1859
|
+
}
|
|
1860
|
+
interface ExecuteManagedParams {
|
|
1861
|
+
quoteId: string;
|
|
1862
|
+
}
|
|
1863
|
+
interface ExecuteManagedResponse {
|
|
1864
|
+
quoteId: string;
|
|
1865
|
+
orderIds: string[];
|
|
1866
|
+
status: "pending";
|
|
1867
|
+
}
|
|
1868
|
+
interface ValidateManagedParams {
|
|
1869
|
+
venueMarketOutcomeIds: string[];
|
|
1870
|
+
side: "buy" | "sell";
|
|
1871
|
+
amount: number;
|
|
1872
|
+
}
|
|
1873
|
+
interface ValidateManagedResponse {
|
|
1874
|
+
canExecute: boolean;
|
|
1875
|
+
availableBalanceRaw: string;
|
|
1876
|
+
requiredBalanceRaw: string;
|
|
1877
|
+
bridgeSourceChainId?: number;
|
|
1878
|
+
bridgeAmountRaw?: string;
|
|
1879
|
+
}
|
|
1880
|
+
interface WithdrawManagedParams {
|
|
1881
|
+
amountRaw: string;
|
|
1882
|
+
tokenSymbol: string;
|
|
1883
|
+
destinationAddress: string;
|
|
1884
|
+
destinationChainId?: number;
|
|
1885
|
+
}
|
|
1886
|
+
interface WithdrawManagedSourceItem {
|
|
1887
|
+
chainId: number;
|
|
1888
|
+
amountRaw: string;
|
|
1889
|
+
txHash?: string;
|
|
1890
|
+
bridgeOperationId?: string;
|
|
1891
|
+
}
|
|
1892
|
+
interface WithdrawManagedResponse {
|
|
1893
|
+
sources: WithdrawManagedSourceItem[];
|
|
1894
|
+
}
|
|
1895
|
+
interface DepositAddressesToken {
|
|
1896
|
+
symbol: string;
|
|
1897
|
+
address: string;
|
|
1898
|
+
decimals: number;
|
|
1899
|
+
}
|
|
1900
|
+
interface DepositAddressesSupportedChain {
|
|
1901
|
+
chainId: number;
|
|
1902
|
+
name: string;
|
|
1903
|
+
tokens: DepositAddressesToken[];
|
|
1904
|
+
}
|
|
1905
|
+
interface DepositAddressesReadyResponse {
|
|
1906
|
+
ready: true;
|
|
1907
|
+
evmAddress: string;
|
|
1908
|
+
svmAddress: string;
|
|
1909
|
+
supportedChains: DepositAddressesSupportedChain[];
|
|
1910
|
+
}
|
|
1911
|
+
interface DepositAddressesPendingResponse {
|
|
1912
|
+
ready: false;
|
|
1913
|
+
}
|
|
1914
|
+
type DepositAddressesResponse = DepositAddressesReadyResponse | DepositAddressesPendingResponse;
|
|
1915
|
+
interface GetPositionsParams {
|
|
1916
|
+
cursor?: string;
|
|
1917
|
+
limit?: number;
|
|
1918
|
+
status?: "active" | "closed";
|
|
1919
|
+
}
|
|
1920
|
+
interface GetOrdersParams {
|
|
1921
|
+
status?: string;
|
|
1922
|
+
cursor?: string;
|
|
1923
|
+
limit?: number;
|
|
1924
|
+
}
|
|
1925
|
+
interface OrderbookQuoteParams {
|
|
1926
|
+
marketId: string;
|
|
1927
|
+
side: "buy" | "sell";
|
|
1928
|
+
size: number;
|
|
1929
|
+
}
|
|
1930
|
+
interface OrderbookQuoteFill {
|
|
1931
|
+
venue: string;
|
|
1932
|
+
size: number;
|
|
1933
|
+
avgPrice: number;
|
|
1934
|
+
cost: number;
|
|
1935
|
+
}
|
|
1936
|
+
interface OrderbookQuoteResponse {
|
|
1937
|
+
marketId: string;
|
|
1938
|
+
side: "buy" | "sell";
|
|
1939
|
+
requestedSize: number;
|
|
1940
|
+
filledSize: number;
|
|
1941
|
+
avgPrice: number | null;
|
|
1942
|
+
totalCost: number;
|
|
1943
|
+
slippage: number | null;
|
|
1944
|
+
fills: OrderbookQuoteFill[];
|
|
1945
|
+
}
|
|
1946
|
+
type ExecutionOrdersQuery = GetOrdersQuery;
|
|
1947
|
+
type ExecutionOrderItem = OrderListItem;
|
|
1948
|
+
type ExecutionPositionsQuery = GetPositionsQuery;
|
|
1949
|
+
type ExecutionPositionGroup = PositionGroup;
|
|
1950
|
+
type UserActivityType = "trade" | "withdrawal" | "bridge" | "deposit" | "user_op";
|
|
1951
|
+
interface UserActivityBase {
|
|
1952
|
+
id: string;
|
|
1953
|
+
createdAt: string;
|
|
1954
|
+
updatedAt: string;
|
|
1955
|
+
status: string;
|
|
1956
|
+
}
|
|
1957
|
+
interface UserActivityVenueMarket {
|
|
1958
|
+
id: string;
|
|
1959
|
+
venueEventId: string;
|
|
1960
|
+
question: string | null;
|
|
1961
|
+
image: string | null;
|
|
1962
|
+
}
|
|
1963
|
+
interface UserActivityVenueMarketOutcome {
|
|
1964
|
+
id: string;
|
|
1965
|
+
label: string;
|
|
1966
|
+
title: string | null;
|
|
1967
|
+
price: number;
|
|
1968
|
+
}
|
|
1969
|
+
interface UserActivityTrade extends UserActivityBase {
|
|
1970
|
+
type: "trade";
|
|
1971
|
+
venue: string;
|
|
1972
|
+
side: string;
|
|
1973
|
+
amountRaw: string;
|
|
1974
|
+
filledAmountRaw: string | null;
|
|
1975
|
+
executionPrice: string | null;
|
|
1976
|
+
venueMarket: UserActivityVenueMarket | null;
|
|
1977
|
+
venueMarketOutcome: UserActivityVenueMarketOutcome | null;
|
|
1978
|
+
txHash: string | null;
|
|
1979
|
+
errorMessage: string | null;
|
|
1980
|
+
/** @deprecated Use venueMarket.question. */
|
|
1981
|
+
marketQuestion?: string | null;
|
|
1982
|
+
/** @deprecated Use venueMarketOutcome.label/title. */
|
|
1983
|
+
outcomeLabel?: string | null;
|
|
1984
|
+
}
|
|
1985
|
+
interface UserActivityWithdrawal extends UserActivityBase {
|
|
1986
|
+
type: "withdrawal";
|
|
1987
|
+
tokenSymbol: string;
|
|
1988
|
+
amountRaw: string;
|
|
1989
|
+
destinationAddress: string;
|
|
1990
|
+
destinationChainId: string;
|
|
1991
|
+
completedAmountRaw: string | null;
|
|
1992
|
+
errorMessage: string | null;
|
|
1993
|
+
}
|
|
1994
|
+
interface UserActivityBridge extends UserActivityBase {
|
|
1995
|
+
type: "bridge";
|
|
1996
|
+
tokenSymbol: string;
|
|
1997
|
+
amountRaw: string;
|
|
1998
|
+
sourceChainId: string;
|
|
1999
|
+
destChainId: string;
|
|
2000
|
+
sourceTxHash: string | null;
|
|
2001
|
+
destTxHash: string | null;
|
|
2002
|
+
}
|
|
2003
|
+
interface UserActivityDeposit extends UserActivityBase {
|
|
2004
|
+
type: "deposit";
|
|
2005
|
+
tokenSymbol: string;
|
|
2006
|
+
amountRaw: string;
|
|
2007
|
+
chainId: string;
|
|
2008
|
+
fromAddress: string;
|
|
2009
|
+
txHash: string;
|
|
2010
|
+
}
|
|
2011
|
+
interface UserActivityUserOp extends UserActivityBase {
|
|
2012
|
+
type: "user_op";
|
|
2013
|
+
callsId: string;
|
|
2014
|
+
chainId: string;
|
|
2015
|
+
walletAddress: string;
|
|
2016
|
+
txHash: string | null;
|
|
2017
|
+
confirmedAt: string | null;
|
|
2018
|
+
}
|
|
2019
|
+
type UserActivityItem = UserActivityTrade | UserActivityWithdrawal | UserActivityBridge | UserActivityDeposit | UserActivityUserOp;
|
|
2020
|
+
interface UserActivityQuery {
|
|
2021
|
+
type?: UserActivityType;
|
|
2022
|
+
cursor?: string;
|
|
2023
|
+
limit?: number;
|
|
2024
|
+
}
|
|
2025
|
+
interface RampQuoteRequest {
|
|
2026
|
+
sourceAmount: string;
|
|
2027
|
+
sourceCurrencyCode: string;
|
|
2028
|
+
destinationCurrencyCode: string;
|
|
2029
|
+
paymentMethodType?: string;
|
|
2030
|
+
}
|
|
2031
|
+
interface RampQuote {
|
|
2032
|
+
serviceProvider: string;
|
|
2033
|
+
transactionType: string;
|
|
2034
|
+
sourceAmount: number;
|
|
2035
|
+
sourceCurrencyCode: string;
|
|
2036
|
+
destinationAmount: number;
|
|
2037
|
+
destinationCurrencyCode: string;
|
|
2038
|
+
exchangeRate: number;
|
|
2039
|
+
totalFee: number;
|
|
2040
|
+
networkFee: number;
|
|
2041
|
+
transactionFee: number;
|
|
2042
|
+
partnerFee: number;
|
|
2043
|
+
fiatAmountWithoutFees: number;
|
|
2044
|
+
paymentMethodType: string;
|
|
2045
|
+
countryCode: string;
|
|
2046
|
+
rampScore: number;
|
|
2047
|
+
lowKyc: boolean;
|
|
2048
|
+
}
|
|
2049
|
+
interface RampSessionRequest {
|
|
2050
|
+
sourceAmount: string;
|
|
2051
|
+
sourceCurrencyCode: string;
|
|
2052
|
+
destinationCurrencyCode: string;
|
|
2053
|
+
serviceProvider: string;
|
|
2054
|
+
walletAddress: string;
|
|
2055
|
+
redirectUrl?: string;
|
|
2056
|
+
}
|
|
2057
|
+
interface RampWidgetSession {
|
|
2058
|
+
id: string;
|
|
2059
|
+
token: string;
|
|
2060
|
+
widgetUrl: string;
|
|
2061
|
+
serviceProviderWidgetUrl: string;
|
|
2062
|
+
}
|
|
2063
|
+
type SmartRouteStatus = "ok" | "infeasible" | "checker_rejected" | "solver_error" | "invalid_input" | "no_orderbooks" | "min_order_size_violated" | "insufficient_input_amount" | "engine_unavailable" | "insufficient_position" | "insufficient_depth" | "no_bids_above_min_price" | "insufficient_balance";
|
|
2064
|
+
/** A single fill at a price level within a venue. */
|
|
2065
|
+
interface SmartRouteFill {
|
|
2066
|
+
price: number;
|
|
2067
|
+
size: number;
|
|
2068
|
+
fill: number;
|
|
2069
|
+
}
|
|
2070
|
+
/** Per-venue routing result with fills and chain info. */
|
|
2071
|
+
interface SmartRouteVenueFill {
|
|
2072
|
+
venue: string;
|
|
2073
|
+
venueMarketId: string;
|
|
2074
|
+
venueMarketOutcomeId: string;
|
|
2075
|
+
chain: string;
|
|
2076
|
+
avgPrice: number;
|
|
2077
|
+
yesPrice: number;
|
|
2078
|
+
noPrice: number;
|
|
2079
|
+
fills: SmartRouteFill[];
|
|
2080
|
+
venueQty: number;
|
|
2081
|
+
}
|
|
2082
|
+
interface VenueSoloQuote {
|
|
2083
|
+
/**
|
|
2084
|
+
* Minted by the API per successful + executable solo; send this to
|
|
2085
|
+
* /execution/fill to execute single-venue. `null` when the solo is not
|
|
2086
|
+
* executable (status !== "ok", filledQty === 0, or venue not in
|
|
2087
|
+
* SUPPORTED_FILL_VENUES). FE filters on truthiness.
|
|
2088
|
+
*/
|
|
2089
|
+
quoteId: string | null;
|
|
2090
|
+
venue: string;
|
|
2091
|
+
avgPrice: number | null;
|
|
2092
|
+
filledQty: number;
|
|
2093
|
+
rawExecCost: number;
|
|
2094
|
+
estimatedPayout: number;
|
|
2095
|
+
estimatedProfit: number;
|
|
2096
|
+
returnPct: number;
|
|
2097
|
+
status: string;
|
|
2098
|
+
/** Per-price-level fills, identical shape to primary fills. Empty for non-ok statuses. */
|
|
2099
|
+
fills: SmartRouteVenueFill[];
|
|
2100
|
+
}
|
|
2101
|
+
/** @deprecated Smart-route side overrides are kept only for source compatibility. */
|
|
2102
|
+
type SmartRouteSide = "yes" | "no";
|
|
2103
|
+
/** Trade direction for order routing. "buy" (default) reads asks, "sell" reads bids. */
|
|
2104
|
+
type TradeSide = "buy" | "sell";
|
|
2105
|
+
/** Request params for GET /orderbook/:venueMarketOutcomeId/route. */
|
|
2106
|
+
interface SmartRouteParams {
|
|
2107
|
+
venueMarketOutcomeId?: string;
|
|
2108
|
+
/** @deprecated Use venueMarketOutcomeId. */
|
|
2109
|
+
venueMarketId?: string;
|
|
2110
|
+
/** @deprecated Use venueMarketOutcomeId. */
|
|
2111
|
+
outcomeId?: string;
|
|
2112
|
+
/** @deprecated Side is ignored for routing and echoed back only for legacy consumers. */
|
|
2113
|
+
side?: SmartRouteSide;
|
|
2114
|
+
/** Trade direction: "buy" (default) or "sell". */
|
|
2115
|
+
tradeSide?: TradeSide;
|
|
2116
|
+
maxSpend?: number;
|
|
2117
|
+
/** Sell only: target number of contracts to sell. Required for sell unless maxSpend is given. */
|
|
2118
|
+
sellShares?: number;
|
|
2119
|
+
chainBalances?: Record<string, number>;
|
|
2120
|
+
slipCapBps?: number;
|
|
2121
|
+
compareVenues?: boolean;
|
|
2122
|
+
}
|
|
2123
|
+
/** Response from GET /orderbook/:venueMarketOutcomeId/route. */
|
|
2124
|
+
interface SmartRouteResponse {
|
|
2125
|
+
quoteId: string;
|
|
2126
|
+
venueMarketOutcomeId: string;
|
|
2127
|
+
venueMarketId: string;
|
|
2128
|
+
estimatedCostRaw: string;
|
|
2129
|
+
expiresAt: string;
|
|
2130
|
+
status: SmartRouteStatus;
|
|
2131
|
+
fills: SmartRouteVenueFill[];
|
|
2132
|
+
totalFilled: number;
|
|
2133
|
+
rawExecCost: number;
|
|
2134
|
+
solveTimeMs: number;
|
|
2135
|
+
verifyTimeMs: number;
|
|
2136
|
+
matchedMarkets: Array<{
|
|
2137
|
+
venue: string;
|
|
2138
|
+
venueMarketId: string;
|
|
2139
|
+
}>;
|
|
2140
|
+
error?: string;
|
|
2141
|
+
message?: string;
|
|
2142
|
+
warnings?: Array<{
|
|
2143
|
+
venue: string;
|
|
2144
|
+
venueMarketOutcomeId: string;
|
|
2145
|
+
reason: string;
|
|
2146
|
+
}>;
|
|
2147
|
+
venueSoloQuotes?: VenueSoloQuote[];
|
|
2148
|
+
/** Estimated payout if the outcome wins (= totalFilled shares × $1). */
|
|
2149
|
+
estimatedPayout?: number;
|
|
2150
|
+
/** Total cost including all fees (rawExecCost + venueFees + bridgeFees + executionGas). */
|
|
2151
|
+
totalCostIncFees?: number;
|
|
2152
|
+
/** Estimated profit if the outcome wins (= estimatedPayout − totalCostIncFees). */
|
|
2153
|
+
estimatedProfit?: number;
|
|
2154
|
+
/** Return on investment percentage (= estimatedProfit / totalCostIncFees × 100). */
|
|
2155
|
+
returnPct?: number;
|
|
2156
|
+
/** Populated only when status === "insufficient_position". */
|
|
2157
|
+
positionAvailability?: {
|
|
2158
|
+
totalSellableShares: number;
|
|
2159
|
+
venueMarketOutcomes: Array<{
|
|
2160
|
+
id: string;
|
|
2161
|
+
venue: string;
|
|
2162
|
+
venueMarketId: string;
|
|
2163
|
+
availableShares: number;
|
|
2164
|
+
}>;
|
|
2165
|
+
};
|
|
2166
|
+
/** @deprecated Echoed only when the deprecated request-side override is provided. */
|
|
2167
|
+
side?: SmartRouteSide;
|
|
2168
|
+
}
|
|
2169
|
+
interface CancelManagedExecutionResponse {
|
|
2170
|
+
quoteId: string;
|
|
2171
|
+
orderIds: string[];
|
|
2172
|
+
status: "cancelled";
|
|
2173
|
+
}
|
|
2174
|
+
type PositionRedeemStatus = "eligible" | "pending" | "redeemed" | "ineligible";
|
|
2175
|
+
type RedeemLegStatus = "submitted" | "confirmed" | "ineligible" | "rejected";
|
|
2176
|
+
interface RedeemLegResult {
|
|
2177
|
+
venueMarketOutcomeId: string;
|
|
2178
|
+
status: RedeemLegStatus;
|
|
2179
|
+
callsId: string | null;
|
|
2180
|
+
pendingUserOpId: string | null;
|
|
2181
|
+
txHash: string | null;
|
|
2182
|
+
reason: string | null;
|
|
2183
|
+
}
|
|
2184
|
+
interface RedeemRequest {
|
|
2185
|
+
venueMarketOutcomeIds: string[];
|
|
2186
|
+
}
|
|
2187
|
+
interface RedeemResponse {
|
|
2188
|
+
redeemId: string;
|
|
2189
|
+
results: RedeemLegResult[];
|
|
2190
|
+
}
|
|
2191
|
+
type SearchType = "events" | "markets";
|
|
2192
|
+
interface SearchParams {
|
|
2193
|
+
q: string;
|
|
2194
|
+
type: SearchType;
|
|
2195
|
+
categoryIds?: string[];
|
|
2196
|
+
limit?: number;
|
|
2197
|
+
cursor?: string;
|
|
2198
|
+
}
|
|
2199
|
+
type SearchResponse<T> = {
|
|
2200
|
+
type: SearchType;
|
|
2201
|
+
data: T[];
|
|
2202
|
+
nextCursor: string | null;
|
|
2203
|
+
hasMore: boolean;
|
|
2204
|
+
};
|
|
2205
|
+
|
|
2206
|
+
type AuthStateListener = (authenticated: boolean) => void;
|
|
2207
|
+
type UserAuthResult = {
|
|
2208
|
+
accessToken: string;
|
|
2209
|
+
refreshToken?: string;
|
|
2210
|
+
user: UserProfile;
|
|
2211
|
+
};
|
|
2212
|
+
declare class AggClient {
|
|
2213
|
+
private appId?;
|
|
2214
|
+
private adminKey?;
|
|
2215
|
+
private apiKey?;
|
|
2216
|
+
private baseUrl;
|
|
2217
|
+
private accessToken?;
|
|
2218
|
+
private refreshTokenValue?;
|
|
2219
|
+
private currentUser?;
|
|
2220
|
+
private listeners;
|
|
2221
|
+
private storageKey;
|
|
2222
|
+
private shouldPersistSession;
|
|
2223
|
+
private authDelivery;
|
|
2224
|
+
private wsUrl?;
|
|
2225
|
+
private _authStatus;
|
|
2226
|
+
private authChannel;
|
|
2227
|
+
private authOptions?;
|
|
2228
|
+
/** In-flight refresh promise — serializes concurrent 401 retries so only one refresh runs. */
|
|
2229
|
+
private pendingRefresh;
|
|
2230
|
+
constructor(options: AggClientOptions);
|
|
2231
|
+
private withAuthPayload;
|
|
2232
|
+
private restoreSession;
|
|
2233
|
+
private persistSession;
|
|
2234
|
+
private initAuthChannel;
|
|
2235
|
+
/** Release resources (BroadcastChannel, etc.). Safe to call multiple times. */
|
|
2236
|
+
destroy(): void;
|
|
2237
|
+
/**
|
|
2238
|
+
* Generic HTTP method with automatic header injection and 401 retry.
|
|
2239
|
+
* Attaches `x-app-id`, `Authorization: Bearer`, and `x-admin-key` headers as appropriate.
|
|
2240
|
+
* On 401, attempts a single token refresh and retries the request.
|
|
2241
|
+
* @param path - API path (e.g. `/venue-events`)
|
|
2242
|
+
* @param init - Fetch init options, plus optional `query` object for URL search params
|
|
2243
|
+
*/
|
|
2244
|
+
request<T>(path: string, init?: RequestInit & {
|
|
2245
|
+
query?: Record<string, string | string[]>;
|
|
2246
|
+
}): Promise<T>;
|
|
2247
|
+
private rawFetch;
|
|
2248
|
+
private throwResponseError;
|
|
2249
|
+
/**
|
|
2250
|
+
* Deduplicates concurrent refresh attempts — if multiple requests hit 401 at the same time,
|
|
2251
|
+
* only one refresh call is made and the rest wait for it.
|
|
2252
|
+
*/
|
|
2253
|
+
private refreshWithDedup;
|
|
2254
|
+
private buildAuthRequestInit;
|
|
2255
|
+
private buildUserAuthResult;
|
|
2256
|
+
private performSignOutRequest;
|
|
2257
|
+
/** Set the user access token (for future user-tier auth). */
|
|
2258
|
+
setAccessToken(token: string): void;
|
|
2259
|
+
/** Set the current auth session tokens and optionally seed the user profile. */
|
|
2260
|
+
setSession(session: AggClientSessionInput): void;
|
|
2261
|
+
/** Clear the user access token, refresh token, and user info. Broadcasts cross-tab logout. */
|
|
2262
|
+
clearAccessToken(): void;
|
|
2263
|
+
private broadcastAuth;
|
|
2264
|
+
/** Current auth lifecycle status. */
|
|
2265
|
+
get authStatus(): AuthStatus;
|
|
2266
|
+
/** Whether a user access token is currently set. */
|
|
2267
|
+
get isAuthenticated(): boolean;
|
|
2268
|
+
/** Primary wallet address derived from the current user profile. */
|
|
2269
|
+
get address(): string | undefined;
|
|
2270
|
+
/** Subscribe to auth state changes. Returns an unsubscribe function. */
|
|
2271
|
+
onAuthStateChange(listener: AuthStateListener): () => void;
|
|
2272
|
+
private notifyListeners;
|
|
2273
|
+
/** Get the currently authenticated user, if any. */
|
|
2274
|
+
get user(): UserProfile | undefined;
|
|
2275
|
+
/** Build an EIP-4361 SIWE message string (pure formatting, no crypto). */
|
|
2276
|
+
buildSiweMessage(params: SiweMessageParams): string;
|
|
2277
|
+
/** Build a SIWS message string for Solana wallet sign-in (pure formatting, no crypto). */
|
|
2278
|
+
buildSiwsMessage(params: SiwsMessageParams): string;
|
|
2279
|
+
/** Verify a SIWE/SIWS signature with the API, store the token + user. */
|
|
2280
|
+
verify(args: AggAuthVerifyBody): Promise<UserAuthResult>;
|
|
2281
|
+
/** Backwards-compatible alias for `verify()`. */
|
|
2282
|
+
verifySignIn(args: AggAuthVerifyBody): Promise<UserAuthResult>;
|
|
2283
|
+
/** Initiate an auth flow (SIWE nonce, OAuth redirect URL, or magic link). */
|
|
2284
|
+
authStart(body: AggAuthStartBody): Promise<AggAuthStartResult>;
|
|
2285
|
+
/** Backwards-compatible alias for `authStart()`. */
|
|
2286
|
+
startAuth(body: AggAuthStartBody): Promise<AggAuthStartResult>;
|
|
2287
|
+
/**
|
|
2288
|
+
* Start an account-link flow. Requires the caller to already be signed in — sends
|
|
2289
|
+
* the bearer automatically. Response shape:
|
|
2290
|
+
* - OAuth providers → `{ type: "redirect", url }`; redirect the browser to `url`.
|
|
2291
|
+
* - Email → `{ type: "magic_link", success: true }`; check the destination inbox.
|
|
2292
|
+
*
|
|
2293
|
+
* After the provider callback runs, the browser lands back on the app's `redirectUrl`
|
|
2294
|
+
* with a `link_confirm_token` query param. Feed that token to `linkAccountConfirm()`
|
|
2295
|
+
* to persist the Account row.
|
|
2296
|
+
*
|
|
2297
|
+
* Wallet linking (siwe/siws) is not supported yet — it requires a different message
|
|
2298
|
+
* binding protocol than sign-in to be safe against signature phishing.
|
|
2299
|
+
*/
|
|
2300
|
+
linkAccount(body: AggLinkAccountBody): Promise<AggLinkAccountResult>;
|
|
2301
|
+
/**
|
|
2302
|
+
* Exchange a `link_confirm_token` for a linked `Account` row. The server matches
|
|
2303
|
+
* the current bearer's `principalId` to the token's `principalId` before writing —
|
|
2304
|
+
* this is the final ownership check.
|
|
2305
|
+
*/
|
|
2306
|
+
linkAccountConfirm(token: string): Promise<AggLinkAccountConfirmResult>;
|
|
2307
|
+
/** Exchange a one-time auth code (from OAuth/magic-link callback) for tokens. */
|
|
2308
|
+
exchangeAuthCode(code: string): Promise<UserAuthResult>;
|
|
2309
|
+
/** Refresh the access token using the stored refresh token. */
|
|
2310
|
+
refreshAccessToken(): Promise<string>;
|
|
2311
|
+
/** Get the current user's profile. */
|
|
2312
|
+
getCurrentUser(): Promise<UserProfile>;
|
|
2313
|
+
/** Update the current user (e.g. username). Requires currentUser.id; call getCurrentUser() first if needed. */
|
|
2314
|
+
updateUser(data: UpdateUserBody): Promise<UserProfile>;
|
|
2315
|
+
/** Link a partner-provided external user ID assertion to the current user. */
|
|
2316
|
+
linkExternalId(params: {
|
|
2317
|
+
externalId: string;
|
|
2318
|
+
timestamp: number;
|
|
2319
|
+
hmac: string;
|
|
2320
|
+
}): Promise<UserProfile>;
|
|
2321
|
+
/** Create a presigned avatar upload URL for the current user. */
|
|
2322
|
+
createAvatarUploadUrl(contentType: string): Promise<{
|
|
2323
|
+
uploadUrl: string;
|
|
2324
|
+
assetKey: string;
|
|
2325
|
+
cdnUrl: string;
|
|
2326
|
+
}>;
|
|
2327
|
+
/** Disconnect a linked auth provider from the current user. */
|
|
2328
|
+
disconnectAccount(provider: "wallet" | "solana_wallet" | "google" | "twitter" | "apple" | "email"): Promise<{
|
|
2329
|
+
success: true;
|
|
2330
|
+
}>;
|
|
2331
|
+
/** Sign out — revoke all tokens server-side and clear local session. */
|
|
2332
|
+
signOut(): Promise<void>;
|
|
2333
|
+
/** Get user holdings (positions) for a venue. Uses backend to resolve venue-specific identifiers. */
|
|
2334
|
+
getUserHoldings(params: {
|
|
2335
|
+
venue: Venue;
|
|
2336
|
+
venueMarketId?: string;
|
|
2337
|
+
venueEventId?: string;
|
|
2338
|
+
cursor?: string;
|
|
2339
|
+
}): Promise<PaginatedResponse<UserHolding>>;
|
|
2340
|
+
/** List trade-executor orders for the authenticated user. */
|
|
2341
|
+
getOrders(params?: OrderListQuery): Promise<TradeExecutorOrderListResponse>;
|
|
2342
|
+
/** List execution orders for the authenticated user (cursor pagination). */
|
|
2343
|
+
getExecutionOrders(params?: ExecutionOrdersQuery): Promise<PaginatedResponse<ExecutionOrderItem>>;
|
|
2344
|
+
/** Unified user activity feed (trades, deposits, withdrawals, bridges, wallet ops). */
|
|
2345
|
+
getUserActivity(params?: UserActivityQuery): Promise<PaginatedResponse<UserActivityItem>>;
|
|
2346
|
+
/** List execution positions for the authenticated user (cursor pagination). */
|
|
2347
|
+
getExecutionPositions(params?: ExecutionPositionsQuery): Promise<PaginatedResponse<ExecutionPositionGroup>>;
|
|
2348
|
+
/** Get managed wallet balances, including per-chain cash balances and per-venue position balances. */
|
|
2349
|
+
getManagedBalances(): Promise<UnifiedBalanceResponse>;
|
|
2350
|
+
/** Cancel a pending managed execution by order id. */
|
|
2351
|
+
cancelManagedOrder(orderId: string, options?: {
|
|
2352
|
+
signal?: AbortSignal;
|
|
2353
|
+
}): Promise<CancelManagedExecutionResponse>;
|
|
2354
|
+
/** List venue events with optional filters. Requires appId or admin auth. Supports cursor-based pagination. */
|
|
2355
|
+
getVenueEvents(options?: {
|
|
2356
|
+
venues?: Venue[];
|
|
2357
|
+
search?: string;
|
|
2358
|
+
categoryIds?: string[];
|
|
2359
|
+
matchStatus?: MatchStatus[];
|
|
2360
|
+
status?: MarketStatus[];
|
|
2361
|
+
sortBy?: string;
|
|
2362
|
+
sortDir?: string;
|
|
2363
|
+
limit?: number;
|
|
2364
|
+
cursor?: string;
|
|
2365
|
+
minYesPrice?: number;
|
|
2366
|
+
maxYesPrice?: number;
|
|
2367
|
+
/** ISO-8601 timestamp. Hides events with endDate <= this value. NULL-endDate events are kept. */
|
|
2368
|
+
endDateFrom?: string;
|
|
2369
|
+
}): Promise<PaginatedResponse<VenueEvent>>;
|
|
2370
|
+
/** Get a single venue event by ID. Requires appId or admin auth. */
|
|
2371
|
+
getVenueEventById(id: string, options?: {
|
|
2372
|
+
signal?: AbortSignal;
|
|
2373
|
+
}): Promise<VenueEvent>;
|
|
2374
|
+
/** List venue markets with optional filters. Requires appId or admin auth. Supports cursor-based pagination. */
|
|
2375
|
+
getVenueMarkets(options?: {
|
|
2376
|
+
venue?: Venue;
|
|
2377
|
+
venueEventId?: string;
|
|
2378
|
+
search?: string;
|
|
2379
|
+
matchStatus?: MatchStatus;
|
|
2380
|
+
status?: MarketStatus;
|
|
2381
|
+
categoryIds?: string[];
|
|
2382
|
+
limit?: number;
|
|
2383
|
+
cursor?: string;
|
|
2384
|
+
sortBy?: "volume" | "volume24hr" | "createdAt" | "yesPrice" | "updatedAt";
|
|
2385
|
+
sortDir?: "asc" | "desc";
|
|
2386
|
+
}): Promise<PaginatedResponse<VenueMarket>>;
|
|
2387
|
+
/** Get categories with cursor-based pagination. Requires appId. */
|
|
2388
|
+
getCategories(options?: {
|
|
2389
|
+
limit?: number;
|
|
2390
|
+
cursor?: string;
|
|
2391
|
+
}): Promise<PaginatedResponse<Category>>;
|
|
2392
|
+
/** Get per-app UI config (disabled venues + category presets). Requires appId. */
|
|
2393
|
+
getAppConfig(init?: RequestInit): Promise<AppClientConfigResponse>;
|
|
2394
|
+
/** Search events or markets by query string. Supports cursor-based pagination. */
|
|
2395
|
+
search<T = VenueEvent>(params: SearchParams): Promise<SearchResponse<T>>;
|
|
2396
|
+
/** Get the canonical TradingView-style bar series for a single venue market outcome. */
|
|
2397
|
+
getChartBars(params: {
|
|
2398
|
+
venueMarketOutcomeId: string;
|
|
2399
|
+
resolution?: ChartResolution;
|
|
2400
|
+
from?: number;
|
|
2401
|
+
to: number;
|
|
2402
|
+
countBack?: number;
|
|
2403
|
+
}, options?: {
|
|
2404
|
+
signal?: AbortSignal;
|
|
2405
|
+
}): Promise<ChartBarsResponse>;
|
|
2406
|
+
/** Get live per-venue orderbooks for the explicit venueMarketIds requested. */
|
|
2407
|
+
getOrderbooks(params: {
|
|
2408
|
+
venueMarketIds: string[];
|
|
2409
|
+
depth?: number;
|
|
2410
|
+
}, options?: {
|
|
2411
|
+
signal?: AbortSignal;
|
|
2412
|
+
}): Promise<BatchOrderbooksResponse>;
|
|
2413
|
+
/** Get live midpoints for the explicit venueMarketIds requested. */
|
|
2414
|
+
getMidpoints(params: {
|
|
2415
|
+
venueMarketIds: string[];
|
|
2416
|
+
}, options?: {
|
|
2417
|
+
signal?: AbortSignal;
|
|
2418
|
+
}): Promise<BatchMidpointsResponse>;
|
|
2419
|
+
getMidpoints(venueMarketIds: string[], options?: {
|
|
2420
|
+
signal?: AbortSignal;
|
|
2421
|
+
}): Promise<BatchMidpointsResponse>;
|
|
2422
|
+
/** Get a single outcome-level orderbook from the engine. */
|
|
2423
|
+
getOutcomeOrderbook(outcomeId: string, options?: {
|
|
2424
|
+
depth?: number;
|
|
2425
|
+
signal?: AbortSignal;
|
|
2426
|
+
}): Promise<OutcomeOrderbookResponse | null>;
|
|
2427
|
+
/**
|
|
2428
|
+
* Compute optimal order routing across venues via the MILP solver.
|
|
2429
|
+
* Returns a user-scoped quote with per-venue fills and verification timing.
|
|
2430
|
+
* Deprecated aliases are accepted for source compatibility during the
|
|
2431
|
+
* outcome-level migration window.
|
|
2432
|
+
*/
|
|
2433
|
+
getSmartRoute(params: SmartRouteParams, options?: {
|
|
2434
|
+
signal?: AbortSignal;
|
|
2435
|
+
}): Promise<SmartRouteResponse>;
|
|
2436
|
+
/**
|
|
2437
|
+
* Create an AggWebSocket instance configured with this client's appId and optional auth token.
|
|
2438
|
+
* Requires `wsUrl` to be set in the client options.
|
|
2439
|
+
*/
|
|
2440
|
+
createWebSocket(callbacks?: AggWebSocketCallbacks, options?: {
|
|
2441
|
+
enableLogs?: boolean;
|
|
2442
|
+
}): AggWebSocket;
|
|
2443
|
+
/** Request a quote for a managed trade. Returns quoteId (2-min TTL), execution steps, and splits. */
|
|
2444
|
+
quoteManaged(params: QuoteManagedParams): Promise<QuoteManagedResponse>;
|
|
2445
|
+
/** Execute a previously quoted managed trade. Returns pending order IDs. */
|
|
2446
|
+
executeManaged(params: ExecuteManagedParams): Promise<ExecuteManagedResponse>;
|
|
2447
|
+
/** Redeem resolved winning positions by venue market outcome ids. */
|
|
2448
|
+
redeem(body: RedeemRequest): Promise<RedeemResponse>;
|
|
2449
|
+
/** Withdraw funds from managed wallets to an external address. */
|
|
2450
|
+
withdrawManaged(params: WithdrawManagedParams): Promise<WithdrawManagedResponse>;
|
|
2451
|
+
/** Trigger an on-chain balance sync for all tracked tokens across all chains. */
|
|
2452
|
+
syncManagedBalances(): Promise<SyncBalancesResponse>;
|
|
2453
|
+
/** Get managed wallet deposit addresses (EVM + Solana). Returns 202 shape while provisioning. */
|
|
2454
|
+
getDepositAddresses(): Promise<DepositAddressesResponse>;
|
|
2455
|
+
/** Get open positions grouped by matched market with per-venue breakdown. */
|
|
2456
|
+
getPositions(params?: GetPositionsParams): Promise<PaginatedResponse<PositionGroup>>;
|
|
2457
|
+
/** Get crypto purchase quotes. */
|
|
2458
|
+
getRampQuotes(params: RampQuoteRequest): Promise<RampQuote[]>;
|
|
2459
|
+
/** Create a ramp widget session for checkout. */
|
|
2460
|
+
createRampSession(params: RampSessionRequest): Promise<RampWidgetSession>;
|
|
2461
|
+
/** Initiate KYC verification for a venue. Returns a KYC URL to redirect the user to. */
|
|
2462
|
+
initiateKyc(venue: string, redirectUri: string): Promise<{
|
|
2463
|
+
status: string;
|
|
2464
|
+
kycUrl?: string;
|
|
2465
|
+
}>;
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
declare const computeBestSplitsByAmount: typeof computeBestSplitsByAmount$1;
|
|
2469
|
+
|
|
2470
|
+
/**
|
|
2471
|
+
* Thrown when the server returns `challenge_required` during auth start.
|
|
2472
|
+
* The client should render a Cloudflare Turnstile widget using `siteKey`,
|
|
2473
|
+
* then retry the auth flow with the resulting `turnstileToken`.
|
|
2474
|
+
*/
|
|
2475
|
+
declare class TurnstileChallengeError extends Error {
|
|
2476
|
+
readonly siteKey: string;
|
|
2477
|
+
constructor(siteKey: string);
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
type CandleInterval = "1m" | "5m" | "1h" | "1d";
|
|
2481
|
+
/** Universal OHLCV candle. Chart-library-agnostic. */
|
|
2482
|
+
interface Candle {
|
|
2483
|
+
/** Interval-aligned open time in seconds. */
|
|
2484
|
+
openTime: number;
|
|
2485
|
+
o: number;
|
|
2486
|
+
h: number;
|
|
2487
|
+
l: number;
|
|
2488
|
+
c: number;
|
|
2489
|
+
/** Accumulated trade volume. 0 if no trades in interval. */
|
|
2490
|
+
v: number;
|
|
2491
|
+
tradeCount: number;
|
|
2492
|
+
isFinal: boolean;
|
|
2493
|
+
}
|
|
2494
|
+
/**
|
|
2495
|
+
* Accumulates OHLCV candles from orderbook delta midpoints and trades.
|
|
2496
|
+
* All 4 intervals computed simultaneously. onChange batched via rAF (~16ms).
|
|
2497
|
+
*/
|
|
2498
|
+
declare class CandleBuilder {
|
|
2499
|
+
private forming;
|
|
2500
|
+
private closedMap;
|
|
2501
|
+
private listeners;
|
|
2502
|
+
private _midpoint;
|
|
2503
|
+
private dirty;
|
|
2504
|
+
private scheduled;
|
|
2505
|
+
constructor();
|
|
2506
|
+
/** Feed a midpoint (from orderbook delta). Updates O/H/L/C for all intervals. */
|
|
2507
|
+
addMidpoint(midpoint: number, timestampSecs: number): void;
|
|
2508
|
+
/** Feed a trade. Updates volume + refines H/L/C from trade price. */
|
|
2509
|
+
addTrade(price: number, size: number, timestampSecs: number): void;
|
|
2510
|
+
/** Current forming candle for an interval. */
|
|
2511
|
+
getForming(interval: CandleInterval): Candle | null;
|
|
2512
|
+
/** Closed candles for an interval (ring buffer, max 500, newest last). */
|
|
2513
|
+
getClosed(interval: CandleInterval): Candle[];
|
|
2514
|
+
/** Current midpoint (latest value fed). */
|
|
2515
|
+
get midpoint(): number | null;
|
|
2516
|
+
/**
|
|
2517
|
+
* Subscribe to state changes. Returns unsubscribe function.
|
|
2518
|
+
* BATCHED: callbacks fire at most once per rAF frame (~16ms).
|
|
2519
|
+
* In non-browser environments, falls back to 16ms setTimeout.
|
|
2520
|
+
*/
|
|
2521
|
+
onChange(listener: () => void): () => void;
|
|
2522
|
+
/** Clear all state (on reconnect). */
|
|
2523
|
+
reset(): void;
|
|
2524
|
+
/** Clear all state AND unsubscribe all listeners. Called on store eviction. */
|
|
2525
|
+
dispose(): void;
|
|
2526
|
+
private updateCandle;
|
|
2527
|
+
private markDirty;
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
/**
|
|
2531
|
+
* Merge forming candles from matched venues into one aggregate.
|
|
2532
|
+
* Open/Close: volume-weighted average (simple average if all v=0).
|
|
2533
|
+
* High: max across venues. Low: min across venues. Volume: sum.
|
|
2534
|
+
*/
|
|
2535
|
+
declare function mergeCandles(candles: (Candle | null | undefined)[]): Candle | null;
|
|
2536
|
+
/**
|
|
2537
|
+
* Merge arrays of closed candles from multiple venues, aligned by openTime.
|
|
2538
|
+
* For each openTime present in ANY venue, produces one merged candle.
|
|
2539
|
+
*/
|
|
2540
|
+
declare function mergeClosedCandles(candleArrays: Candle[][]): Candle[];
|
|
2541
|
+
/** Simple average of available midpoints. */
|
|
2542
|
+
declare function aggregateMidpoint(midpoints: (number | null | undefined)[]): number | null;
|
|
2543
|
+
|
|
2544
|
+
declare function createAggClient(options: AggClientOptions): AggClient;
|
|
2545
|
+
|
|
2546
|
+
export { type Account, AccountProvider, AccountType, type AggAuthDeliveryMode, type AggAuthProviderType, type AggAuthStartBody, type AggAuthStartResult, type AggAuthVerifyBody, AggClient, type AggClientAuthOptions, type AggClientSessionInput, type AggLinkAccountBody, type AggLinkAccountConfirmResult, type AggLinkAccountResult, type AggSessionUser, AggWebSocket, type AggWebSocketCallbacks, type AggWebSocketOptions, type AggregatedOrderbookLevel, type AggregatedOrderbookResponse, type App, type AppClientConfigResponse, type AttributedOrderbook, type AttributedOrderbookLevel, type AuthCodeResponse, type AuthStatus, type AuthTokenResponse, type AuthUser, type BatchMidpointsResponse, type BatchOrderbooksResponse, CONFIRMED_MATCH_STATUSES, type CancelManagedExecutionResponse, type Candle, CandleBuilder, type CandleInterval, type Category, Chain, type ChartBarsResponse, type ChartCandle, type ChartResolution, type ChartVenueCandles, type ComputeSplitsRequest, type ComputeSplitsResponse, type ComputeSplitsSelection, type CreateApp, type DepositAddressesPendingResponse, type DepositAddressesReadyResponse, type DepositAddressesResponse, type DepositAddressesSupportedChain, type DepositAddressesToken, type DepositStep, type DiagnosticCallback, type DiagnosticEvent, type ExecuteManagedParams, type ExecuteManagedRequest, type ExecuteManagedResponse, type ExecuteTradeRequest, type ExecuteTradeResponse, type ExecutionOrderItem, type ExecutionOrdersQuery, type ExecutionPositionGroup, type ExecutionPositionsQuery, type GetBalanceQuery, type GetBalanceResponse, type GetHoldingsQuery, type GetHoldingsResponse, type GetOrdersParams, type GetOrdersQuery, type GetPositionsParams, type GetPositionsQuery, type HelloResponse, IMAGE_SIZES, ImageSize, type MarkSource, type MarketPriceHistory, MarketStatus, MatchStatus, MatchType, type MatchedMidpoint, type MatchedOrderbookMarket, type MatchingReport, type MidpointItem, type MidpointRow, type NonceResponse, type OrderListItem, type OrderListQuery, OrderStatus, type Orderbook, type OrderbookBatchItemError, type OrderbookBatchItemErrorCode, type OrderbookBatchItemStatus, type OrderbookHistoryPoint, type OrderbookHistoryResponse, type OrderbookLevel, type OrderbookQuoteFill, type OrderbookQuoteParams, type OrderbookQuoteResponse, type OrderbookServiceUnavailableError, type OrderbookState, type OrderbooksOnlyError, type OutcomeMidpoint, type OutcomeMidpointRow, type OutcomeOrderbookResponse, type PaginatedResponse, type PersistedAuthSnapshot, type PositionGroup, type PositionRedeemStatus, type PricePoint, type PricesHistoryResponse, type QuoteManagedParams, type QuoteManagedRequest, type QuoteManagedResponse, type QuoteManagedSplit, type QuoteManagedStep, type QuoteSplit, type QuoteStep, type RampQuote, type RampQuoteRequest, type RampSessionRequest, type RampWidgetSession, type RedeemLegResult, type RedeemLegStatus, type RedeemRequest, type RedeemResponse, type RequestedOrderbookMarket, type SafeParseFailure, type SafeParseResult, type SafeParseSuccess, type ServerWallet, type SettlementSource, type SetupDepositAddressStep, type SetupVenueKeyStep, type SimpleOrderbookLevel, type SmartRouteFill, type SmartRouteParams, type SmartRouteResponse, type SmartRouteSide, type SmartRouteStatus, type SmartRouteVenueFill, type SplitsByAmountResult, type SyncBalancesResponse, type TradeExecutorOrder, type TradeExecutorOrderListResponse, TradeSide$1 as TradeSide, type TradeSplit, type TradeStep, TurnstileChallengeError, type UnifiedBalanceResponse, type UpdateUserBody, type UpsertVenueKey, type UserActivityBridge, type UserActivityDeposit, type UserActivityItem, type UserActivityQuery, type UserActivityTrade, type UserActivityType, type UserActivityUserOp, type UserActivityWithdrawal, type UserHolding, type UserProfile, VENUES, type ValidateBalanceOnClientStep, type ValidateManagedParams, type ValidateManagedRequest, type ValidateManagedResponse, type ValidateTradeRequest, type ValidateTradeResponse, Venue, type VenueEvent, type VenueEventListItem, type VenueEventWithMarkets, type VenueKeySummary, type VenueMarket, type VenueMarketClusterNode, type VenueMarketListItem, type VenueMarketOutcome, type VenueMarketRef, type VenueOrderbookEntry, type VenueOrderbookLevel, type VenuePositionBalance, type VenuePriceInfo, type VenueSoloQuote, type VerifyBody, type VerifyResponse, type WalletChainBalance, type WalletTokenBalance, type WithdrawManagedParams, type WithdrawManagedRequest, type WithdrawManagedResponse, type WithdrawManagedSourceItem, type WithdrawalSource, type WsAttributedLevel, type WsAuthenticated, type WsBalanceUpdate, type WsCandleInterval, type WsClientMessage, type WsConnected, type WsError, type WsHeartbeat, type WsMarkSource, type WsMarketResolved, type WsOrderEvent, type WsOrderEventType, type WsOrderSubmitted, type WsOrderbookDelta, type WsOrderbookSnapshot, type WsRedeemEvent, type WsServerMessage, type WsSubscribed, type WsTrade, type WsUnsubscribed, type WsVenueBook, type WsVenueInfo, type WsVenueLevel, aggregateMidpoint, applyOrderbookDelta, computeBestSplitsByAmount, computeChecksum, createAggClient, enumGuard, formatMarketQuestion, formatOutcomeLabel, getWalletAddressFromUserProfile, hasShape, isEmail, isEnum, isFiniteNonNeg, isNonEmptyString, mergeCandles, mergeClosedCandles, normalizeVenueMarketCluster, optimizedImageUrl, parse, parseEmail, parseEmailStrict, safeParse, snapshotToOrderbook, sortVenues };
|