@polyester/sdk 0.35.0-devnet-20261111024759 → 0.35.0-devnet-20261111025029
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/CHANGELOG.md +3 -1
- package/dist/realtime/private-orders.d.ts.map +1 -1
- package/dist/realtime/private-orders.js +24 -3
- package/dist/realtime/private-orders.js.map +1 -1
- package/dist/services/address-book/address-book.schemas.d.ts +2 -2
- package/dist/services/candles/candles.schemas.d.ts +10 -10
- package/dist/services/checkpoints/checkpoints.schemas.d.ts +2 -2
- package/dist/services/heatmap/heatmap.schemas.d.ts +13 -13
- package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +3 -3
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +52 -52
- package/dist/services/market-overview/market-overview.schemas.d.ts +3 -3
- package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +14 -14
- package/dist/services/orders/orders-input.schemas.d.ts +1 -1
- package/dist/services/orders/orders-output.schemas.d.ts +15 -15
- package/dist/services/rewards/rewards.schemas.d.ts +3 -3
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +14 -14
- package/dist/services/trades/trades.schemas.d.ts +2 -2
- package/dist/services/triggers/trigger-input.schemas.d.ts +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +15 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @polyester/sdk
|
|
2
2
|
|
|
3
|
-
## 0.35.0-devnet-
|
|
3
|
+
## 0.35.0-devnet-20261111025029
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -44,6 +44,8 @@
|
|
|
44
44
|
|
|
45
45
|
- `auth.me()` now returns `rootSmartAccountAddress`, the caller's root smart-account address as lowercase `0x` hex, or `""` when the account has none. It was previously dropped. A new account can read `""` for a moment right after its first login, until the backend records the address. ([#239](https://github.com/Fabric-Labs/polyester-sdk-typescript/pull/239))
|
|
46
46
|
|
|
47
|
+
- Bound the private order stream's memory: frames over 4 MiB are dropped undecoded and the connection reconnects, and a snapshot staging more than 100,000 orders or 64 MiB ends its subscription with a `snapshot` error. ([#246](https://github.com/Fabric-Labs/polyester-sdk-typescript/pull/246))
|
|
48
|
+
|
|
47
49
|
- A ConnectRPC `resource_exhausted` that carries a `RateLimitDetail`, as wallet sign-in and the public catalog calls now send, maps to a `RateLimitError` with `rateLimit` set and `retryAfterMs` taken from the detail. Its `detail` is `{ service: "rate_limit", code: "RATE_LIMIT_EXCEEDED", rateLimit }`. The gateway's own refusal has no detail: `retryAfterMs` comes from `Retry-After` when present and is `undefined` for a concurrency refusal, so back off without a server hint. ([#236](https://github.com/Fabric-Labs/polyester-sdk-typescript/pull/236))
|
|
48
50
|
|
|
49
51
|
- Unsubscribing from a private channel, or from `connectPrivateOrders()`, in the same tick as subscribing without credentials no longer delivers the queued missing-authentication error to that consumer's `onError`. ([#242](https://github.com/Fabric-Labs/polyester-sdk-typescript/pull/242))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-orders.d.ts","names":[],"sources":["../../src/realtime/private-orders.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"private-orders.d.ts","names":[],"sources":["../../src/realtime/private-orders.ts"],"mappings":";;;;;KAgCY;;;EAEJ;EAAkB,QAAQ;;;;EAE1B;EAAc,MAAM;;;;;;;EAKpB;EAAe;EAAgB;;UAEtB;;EAEb;EACA,UAAU,OAAO;;EAEjB;;EAEA;EACA,WAAW,KAAK"}
|
|
@@ -12,6 +12,11 @@ const BACKOFF_MAX_MS = 1e4;
|
|
|
12
12
|
const STABLE_CONNECTION_MS = 1e4;
|
|
13
13
|
/** A malformed frame (4400) and a rejected connect token (4403) recur on every reconnect. */
|
|
14
14
|
const TERMINAL_CLOSE_CODES = /* @__PURE__ */ new Set([4400, 4403]);
|
|
15
|
+
/** Larger frames are dropped undecoded with the connection; a full 256-order page is far smaller. */
|
|
16
|
+
const MAX_PRIVATE_FRAME_BYTES = 4194304;
|
|
17
|
+
/** A snapshot staging more pages than this ends its subscription, so a snapshot never ending stays bounded. */
|
|
18
|
+
const MAX_SNAPSHOT_BYTES = 67108864;
|
|
19
|
+
const MAX_SNAPSHOT_ORDERS = 1e5;
|
|
15
20
|
/** 0.5 s doubling to 10 s, jittered over the upper half of each step. */
|
|
16
21
|
function backoffMs(attempt) {
|
|
17
22
|
const ceiling = Math.min(BACKOFF_MAX_MS, BACKOFF_BASE_MS * 2 ** (attempt + 1));
|
|
@@ -73,6 +78,7 @@ var PrivateOrderStream = class {
|
|
|
73
78
|
seq: 0n,
|
|
74
79
|
cursor: "",
|
|
75
80
|
staged: null,
|
|
81
|
+
stagedBytes: 0,
|
|
76
82
|
orders: null,
|
|
77
83
|
state: "pending",
|
|
78
84
|
stale: null,
|
|
@@ -293,6 +299,11 @@ var PrivateOrderStream = class {
|
|
|
293
299
|
this.#reportAll("decode", new RealtimeError("Expected a binary private WebSocket frame"));
|
|
294
300
|
return;
|
|
295
301
|
}
|
|
302
|
+
if (data.byteLength > 4194304) {
|
|
303
|
+
this.#reportAll("decode", new RealtimeError(`Private WebSocket frame of ${data.byteLength} bytes exceeds ${MAX_PRIVATE_FRAME_BYTES}`));
|
|
304
|
+
this.#drop(ws, 1009, "frame too large");
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
296
307
|
let msg;
|
|
297
308
|
try {
|
|
298
309
|
msg = fromBinary(ServerMessageSchema, new Uint8Array(data));
|
|
@@ -351,10 +362,20 @@ var PrivateOrderStream = class {
|
|
|
351
362
|
switch (frame.case) {
|
|
352
363
|
case "snapshotBegin":
|
|
353
364
|
s.staged = [];
|
|
365
|
+
s.stagedBytes = 0;
|
|
354
366
|
return;
|
|
355
|
-
case "snapshotPage":
|
|
356
|
-
s.staged
|
|
367
|
+
case "snapshotPage": {
|
|
368
|
+
if (!s.staged) return;
|
|
369
|
+
s.stagedBytes += data.byteLength;
|
|
370
|
+
const count = s.staged.length + frame.value.orders.length;
|
|
371
|
+
if (s.stagedBytes > 67108864 || count > 1e5) {
|
|
372
|
+
s.staged = null;
|
|
373
|
+
this.#terminate(s, "snapshot", new RealtimeError(`Private order snapshot exceeds ${MAX_SNAPSHOT_ORDERS} orders or ${MAX_SNAPSHOT_BYTES} bytes`));
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
s.staged.push(...frame.value.orders);
|
|
357
377
|
return;
|
|
378
|
+
}
|
|
358
379
|
case "snapshotEnd": {
|
|
359
380
|
const orders = s.staged;
|
|
360
381
|
s.staged = null;
|
|
@@ -589,6 +610,6 @@ var PrivateOrderStream = class {
|
|
|
589
610
|
}
|
|
590
611
|
};
|
|
591
612
|
//#endregion
|
|
592
|
-
export { PRIVATE_WS_SUBPROTOCOL, PrivateOrderStream };
|
|
613
|
+
export { MAX_PRIVATE_FRAME_BYTES, MAX_SNAPSHOT_BYTES, MAX_SNAPSHOT_ORDERS, PRIVATE_WS_SUBPROTOCOL, PrivateOrderStream };
|
|
593
614
|
|
|
594
615
|
//# sourceMappingURL=private-orders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-orders.js","names":["#config","#subs","#pending","#bySub","#unsubscribing","#catchUp","#remove","#ws","#authSent","#subscribe","#connecting","#reconnectTimer","#open","#clearRetry","#shutdown","#isCurrent","#deliverTo","#terminateAll","#generation","#authenticate","#onFrame","#onClosed","#reportAll","#scheduleReconnect","#send","#authSentAt","#armHeartbeat","#reauthenticate","#nextRequestId","#terminate","#report","#retrySubscribe","#refresh","#unsubscribe","#deliver","#onRequestError","#resubscribe","#detach","#reconnectAttempt","#heartbeatTimer","#drop","#teardown","#call","#requestSeq"],"sources":["../../src/realtime/private-orders.ts"],"sourcesContent":["import { create, fromBinary, toBinary, type MessageInitShape } from \"@bufbuild/protobuf\";\nimport type { Order } from \"../gen/orders/v1/orders_read_pb.js\";\nimport {\n Channel,\n ClientMessageSchema,\n RequestError_Code,\n ServerMessageSchema,\n type Unit,\n} from \"../gen/privatews/v1/private_ws_pb.js\";\nimport { ConfigurationError, PolyesterError, RealtimeError } from \"../shared/errors.js\";\nimport {\n createSdkSubscriptionErrorContext,\n publicationHandlerErrorContext,\n type SdkSubscriptionErrorContext,\n} from \"../shared/subscription-errors.js\";\nimport { idToBigInt } from \"../utils/base58-id.js\";\n\nexport const PRIVATE_WS_SUBPROTOCOL = \"polyester.v1.proto\";\nconst HEARTBEAT_TIMEOUT_MS = 3_000;\nconst BACKOFF_BASE_MS = 500;\nconst BACKOFF_MAX_MS = 10_000;\n/** A connection that stayed up this long resets the reconnect backoff. */\nconst STABLE_CONNECTION_MS = 10_000;\n/** A malformed frame (4400) and a rejected connect token (4403) recur on every reconnect. */\nconst TERMINAL_CLOSE_CODES = new Set([4400, 4403]);\n\n/** One delivery of an account's order stream. */\nexport type PrivateOrdersEvent =\n /** The account's full live view; replace local state with it. */\n | { type: \"snapshot\"; orders: Order[] }\n /** One change, applied whole. */\n | { type: \"unit\"; unit: Unit }\n /**\n * The account's live view is temporarily behind (`true`) or caught up (`false`).\n * `orderIds`, when set, names the only orders behind; the rest of the view is current.\n */\n | { type: \"stale\"; stale: boolean; orderIds?: bigint[] };\n\nexport interface ConnectPrivateOrdersParams {\n /** The account's base58 public ID. */\n accountId: string;\n onEvent: (event: PrivateOrdersEvent) => void;\n /** Called when the server confirms the subscription, again after each reconnect. */\n onConnected?: () => void;\n /** Called when the connection carrying the subscription drops. */\n onDisconnected?: () => void;\n onError?: (ctx: SdkSubscriptionErrorContext) => void;\n}\n\nexport interface PrivateOrderStreamConfig {\n url: string;\n fetchConnectToken: () => Promise<string>;\n fetchSubscribeToken: (channel: string) => Promise<string>;\n}\n\ntype ClientOp = MessageInitShape<typeof ClientMessageSchema>[\"op\"];\n\ninterface Consumer {\n params: ConnectPrivateOrdersParams;\n /** False until a consumer that joined a running subscription received its current state. */\n caughtUp: boolean;\n}\n\n/** One server subscription per account, shared by every consumer of that account. */\ninterface StreamSubscription {\n consumers: Set<Consumer>;\n channel: string;\n account: bigint;\n /** Server subscription ID; empty until Subscribed. */\n sub: string;\n seq: bigint;\n /** Last applied resume position, carried across resubscribes and reconnects. */\n cursor: string;\n staged: Order[] | null;\n /** The account's live view as last applied, for consumers that join later; null before the first snapshot. */\n orders: Map<bigint, Order> | null;\n /** The last connection state consumers were told about. */\n state: \"pending\" | \"connected\" | \"disconnected\";\n /** What consumers were last told is stale, until they are told it caught up. */\n stale: { orderIds?: bigint[] } | null;\n /** Subscribe attempts since the subscription last delivered data; drives retry backoff. */\n retries: number;\n retryTimer: ReturnType<typeof setTimeout> | null;\n}\n\ntype PendingRequest = { kind: \"subscribe\" | \"refresh\"; s: StreamSubscription };\n\n/** 0.5 s doubling to 10 s, jittered over the upper half of each step. */\nfunction backoffMs(attempt: number): number {\n const ceiling = Math.min(BACKOFF_MAX_MS, BACKOFF_BASE_MS * 2 ** (attempt + 1));\n return ceiling / 2 + Math.random() * (ceiling / 2);\n}\n\nfunction isTerminalTokenError(error: unknown): boolean {\n return error instanceof PolyesterError && !error.retryable;\n}\n\n/**\n * Account order streams over the private WebSocket (`/v1/ws/private`). One\n * connection carries every subscription; each resumes from its last cursor\n * after a gap, an expired token, or a reconnect.\n */\nexport class PrivateOrderStream {\n readonly #config: PrivateOrderStreamConfig;\n /** Keyed by channel. A subscription whose last consumer left stays until the next microtask. */\n readonly #subs = new Map<string, StreamSubscription>();\n readonly #pending = new Map<string, PendingRequest>();\n readonly #bySub = new Map<string, StreamSubscription>();\n /** IDs of Unsubscribe requests awaiting their answer. */\n readonly #unsubscribing = new Set<string>();\n #ws: WebSocket | null = null;\n /** A connect token fetch for the next socket is in flight. */\n #connecting = false;\n /** Bumped on shutdown so a token fetch that outlived it opens nothing. */\n #generation = 0;\n #authSent = false;\n #authSentAt = 0;\n #reconnectAttempt = 0;\n #reconnectTimer: ReturnType<typeof setTimeout> | null = null;\n #heartbeatTimer: ReturnType<typeof setTimeout> | null = null;\n #requestSeq = 0;\n\n constructor(config: PrivateOrderStreamConfig) {\n this.#config = config;\n }\n\n /** Throws ValidationError when accountId is not a base58 public ID. */\n connect(params: ConnectPrivateOrdersParams): () => void {\n const channel = `private:spot:orders:${params.accountId}`;\n const account = idToBigInt(params.accountId, \"accountId\");\n const existing = this.#subs.get(channel);\n if (existing) {\n const consumer: Consumer = { params, caughtUp: false };\n existing.consumers.add(consumer);\n queueMicrotask(() => this.#catchUp(existing, consumer));\n return () => this.#remove(existing, consumer);\n }\n const consumer: Consumer = { params, caughtUp: true };\n const s: StreamSubscription = {\n consumers: new Set([consumer]),\n channel,\n account,\n sub: \"\",\n seq: 0n,\n cursor: \"\",\n staged: null,\n orders: null,\n state: \"pending\",\n stale: null,\n retries: 0,\n retryTimer: null,\n };\n this.#subs.set(channel, s);\n if (this.#ws && this.#authSent) void this.#subscribe(this.#ws, s);\n else if (!this.#ws && !this.#connecting && !this.#reconnectTimer) this.#open();\n return () => this.#remove(s, consumer);\n }\n\n /** Closes the connection and drops every subscription without callbacks. */\n disconnect(): void {\n for (const s of this.#subs.values()) {\n this.#clearRetry(s);\n // A consumer that disconnects mid-delivery stops deliveries to the rest.\n s.consumers.clear();\n }\n this.#subs.clear();\n this.#shutdown();\n }\n\n /** Accounts with at least one consumer. */\n get activeChannels(): number {\n let count = 0;\n for (const s of this.#subs.values()) if (s.consumers.size > 0) count++;\n return count;\n }\n\n get totalConsumers(): number {\n let count = 0;\n for (const s of this.#subs.values()) count += s.consumers.size;\n return count;\n }\n\n /** Gives a consumer that joined a running subscription what the others already know. */\n #catchUp(s: StreamSubscription, c: Consumer): void {\n if (!this.#isCurrent(s) || !s.consumers.has(c)) return;\n c.caughtUp = true;\n const { params } = c;\n if (s.state === \"connected\") this.#deliverTo(s, c, () => params.onConnected?.());\n const orders = s.orders && [...s.orders.values()];\n if (orders) this.#deliverTo(s, c, () => params.onEvent({ type: \"snapshot\", orders }));\n const { stale } = s;\n if (stale)\n this.#deliverTo(s, c, () => params.onEvent({ type: \"stale\", stale: true, ...stale }));\n }\n\n /** Fetches the connect token first: the server closes a socket that sends no Auth within 5 seconds. */\n #open(): void {\n const WebSocketCtor = globalThis.WebSocket;\n if (!WebSocketCtor) {\n // Reported after connect() returns, like every other connection failure.\n queueMicrotask(() =>\n this.#terminateAll(\n \"connection_token\",\n new ConfigurationError(\"The private order stream requires a global WebSocket.\"),\n ),\n );\n return;\n }\n const generation = this.#generation;\n this.#connecting = true;\n this.#config.fetchConnectToken().then(\n (token) => {\n if (generation !== this.#generation) return;\n this.#connecting = false;\n let ws: WebSocket;\n try {\n ws = new WebSocketCtor(this.#config.url, PRIVATE_WS_SUBPROTOCOL);\n } catch (error) {\n // A bad URL or a blocked insecure socket fails the same way on every retry.\n this.#terminateAll(\"connection\", error);\n return;\n }\n ws.binaryType = \"arraybuffer\";\n this.#ws = ws;\n this.#authSent = false;\n ws.onopen = () => this.#authenticate(ws, token);\n ws.onmessage = (event: MessageEvent) => this.#onFrame(ws, event.data);\n ws.onclose = (event: CloseEvent) => this.#onClosed(ws, event.code, event.reason);\n },\n (error: unknown) => {\n if (generation !== this.#generation) return;\n this.#connecting = false;\n if (isTerminalTokenError(error)) {\n this.#terminateAll(\"connection_token\", error);\n return;\n }\n this.#reportAll(\"connection_token\", error);\n this.#scheduleReconnect();\n },\n );\n }\n\n #authenticate(ws: WebSocket, token: string): void {\n this.#send(ws, { case: \"auth\", value: { token } });\n this.#authSent = true;\n this.#authSentAt = Date.now();\n this.#armHeartbeat(ws);\n for (const s of this.#subs.values()) void this.#subscribe(ws, s);\n }\n\n async #reauthenticate(ws: WebSocket): Promise<void> {\n try {\n const token = await this.#config.fetchConnectToken();\n if (this.#ws === ws) this.#send(ws, { case: \"auth\", value: { token } });\n } catch (error) {\n if (this.#ws !== ws) return;\n if (isTerminalTokenError(error)) this.#terminateAll(\"connection_token\", error);\n else this.#reportAll(\"connection_token\", error);\n }\n }\n\n #isCurrent(s: StreamSubscription): boolean {\n return this.#subs.get(s.channel) === s;\n }\n\n async #subscribe(ws: WebSocket, s: StreamSubscription): Promise<void> {\n if (!this.#isCurrent(s)) return;\n const id = this.#nextRequestId();\n this.#pending.set(id, { kind: \"subscribe\", s });\n let token: string;\n try {\n token = await this.#config.fetchSubscribeToken(s.channel);\n } catch (error) {\n if (this.#pending.get(id)?.s !== s) return;\n this.#pending.delete(id);\n if (isTerminalTokenError(error)) {\n this.#terminate(s, \"subscription_token\", error);\n return;\n }\n this.#report(s, \"subscription_token\", error);\n this.#retrySubscribe(ws, s);\n return;\n }\n if (this.#ws !== ws || this.#pending.get(id)?.s !== s) return;\n this.#send(ws, {\n case: \"subscribe\",\n value: { id, channel: Channel.ORDERS, account: s.account, token, cursor: s.cursor },\n });\n }\n\n /** Subscribes again after a backoff that grows until the subscription delivers data. */\n #retrySubscribe(ws: WebSocket, s: StreamSubscription): void {\n this.#clearRetry(s);\n s.retryTimer = setTimeout(\n () => {\n s.retryTimer = null;\n if (this.#ws === ws && this.#isCurrent(s) && !s.sub) void this.#subscribe(ws, s);\n },\n backoffMs(s.retries++),\n );\n }\n\n #clearRetry(s: StreamSubscription): void {\n if (s.retryTimer) clearTimeout(s.retryTimer);\n s.retryTimer = null;\n }\n\n async #refresh(ws: WebSocket, s: StreamSubscription): Promise<void> {\n const sub = s.sub;\n let token: string;\n try {\n token = await this.#config.fetchSubscribeToken(s.channel);\n } catch (error) {\n // An unrefreshed subscription ends with TOKEN_EXPIRED and resubscribes.\n if (this.#ws === ws && s.sub === sub) this.#report(s, \"subscription_token\", error);\n return;\n }\n if (this.#ws !== ws || s.sub !== sub) return;\n const id = this.#nextRequestId();\n this.#pending.set(id, { kind: \"refresh\", s });\n this.#send(ws, { case: \"subscribeRefresh\", value: { id, sub, token } });\n }\n\n /**\n * Drops the server subscription and subscribes again from the last applied cursor:\n * at once the first time, then with backoff until the subscription delivers data.\n */\n #resubscribe(ws: WebSocket, s: StreamSubscription): void {\n if (s.sub) {\n this.#bySub.delete(s.sub);\n this.#unsubscribe(ws, s.sub);\n }\n s.sub = \"\";\n s.seq = 0n;\n s.staged = null;\n if (s.retries > 0) {\n this.#retrySubscribe(ws, s);\n } else {\n s.retries = 1;\n void this.#subscribe(ws, s);\n }\n // Consumers see the gap as a close and the replacement's Subscribed as a reopen.\n if (s.state === \"connected\") {\n s.state = \"disconnected\";\n this.#deliver(s, (p) => p.onDisconnected?.());\n }\n }\n\n #unsubscribe(ws: WebSocket, sub: string): void {\n const id = this.#nextRequestId();\n this.#unsubscribing.add(id);\n this.#send(ws, { case: \"unsubscribe\", value: { id, sub } });\n }\n\n #onFrame(ws: WebSocket, data: unknown): void {\n if (this.#ws !== ws) return;\n this.#armHeartbeat(ws);\n if (!(data instanceof ArrayBuffer)) {\n this.#reportAll(\n \"decode\",\n new RealtimeError(\"Expected a binary private WebSocket frame\"),\n );\n return;\n }\n let msg;\n try {\n msg = fromBinary(ServerMessageSchema, new Uint8Array(data));\n } catch (error) {\n this.#reportAll(\"decode\", error);\n return;\n }\n const frame = msg.frame;\n\n switch (frame.case) {\n case \"subscribed\": {\n const request = this.#pending.get(frame.value.id);\n if (request?.kind !== \"subscribe\") {\n // Its consumer left before the server confirmed it.\n if (msg.sub) this.#unsubscribe(ws, msg.sub);\n return;\n }\n this.#pending.delete(frame.value.id);\n const s = request.s;\n s.sub = msg.sub;\n s.seq = 0n;\n this.#bySub.set(msg.sub, s);\n if (s.state !== \"connected\") {\n s.state = \"connected\";\n this.#deliver(s, (p) => p.onConnected?.());\n }\n // A new subscription reports Unavailable itself if its view is still behind.\n if (s.stale) {\n s.stale = null;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: false }));\n }\n return;\n }\n case \"subscribeRefreshed\":\n this.#pending.delete(frame.value.id);\n return;\n case \"unsubscribed\":\n if (this.#unsubscribing.delete(frame.value.id)) return;\n break;\n case \"error\":\n this.#onRequestError(ws, msg.sub, frame.value);\n return;\n case \"tokenExpiring\":\n void this.#reauthenticate(ws);\n return;\n }\n\n const s = this.#bySub.get(msg.sub);\n if (!s) return;\n if (msg.seq > 0n) {\n if (msg.seq !== s.seq + 1n) {\n this.#resubscribe(ws, s);\n return;\n }\n s.seq = msg.seq;\n }\n\n switch (frame.case) {\n case \"snapshotBegin\":\n s.staged = [];\n return;\n case \"snapshotPage\":\n s.staged?.push(...frame.value.orders);\n return;\n case \"snapshotEnd\": {\n const orders = s.staged;\n s.staged = null;\n if (!orders || orders.length !== frame.value.count) {\n s.cursor = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n s.cursor = frame.value.cursor;\n s.retries = 0;\n s.orders = new Map(orders.map((o) => [o.orderId, o]));\n this.#deliver(s, (p) => p.onEvent({ type: \"snapshot\", orders }));\n return;\n }\n case \"unit\": {\n const unit = frame.value;\n s.cursor = unit.nextCursor;\n s.retries = 0;\n for (const o of unit.orders) s.orders?.set(o.orderId, o);\n for (const id of unit.removedOrderIds) s.orders?.delete(id);\n this.#deliver(s, (p) => p.onEvent({ type: \"unit\", unit }));\n return;\n }\n case \"covered\":\n s.cursor = frame.value.cursor;\n s.retries = 0;\n return;\n case \"ready\":\n // A resumed subscription on a quiet account delivers no data, only this.\n s.retries = 0;\n return;\n case \"unavailable\": {\n // A later Unavailable replaces the earlier one; order IDs narrow it to those orders.\n const { orderIds } = frame.value;\n const stale = orderIds.length > 0 ? { orderIds } : {};\n s.stale = stale;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: true, ...stale }));\n return;\n }\n case \"available\":\n s.stale = null;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: false }));\n return;\n case \"subscribeExpiring\":\n void this.#refresh(ws, s);\n return;\n case \"unsubscribed\":\n // The server ended it: its token expired, or for a reason this client does not know.\n this.#bySub.delete(s.sub);\n s.sub = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n }\n\n #onRequestError(\n ws: WebSocket,\n sub: string,\n error: { id: string; code: RequestError_Code; message: string },\n ): void {\n if (error.id && this.#unsubscribing.delete(error.id)) return;\n const request = error.id ? this.#pending.get(error.id) : undefined;\n // The answer to a request already answered, or whose subscription has since gone.\n if (error.id && !request) return;\n if (request) this.#pending.delete(error.id);\n const s = request?.s ?? this.#bySub.get(sub);\n const realtimeError = new RealtimeError(\n error.message ||\n `Private order stream request failed: ${RequestError_Code[error.code]}`,\n { realtimeCode: error.code },\n );\n if (!s) {\n this.#reportAll(\"request\", realtimeError);\n return;\n }\n if (request?.kind === \"subscribe\") {\n if (error.code === RequestError_Code.CURSOR_INVALID) {\n s.cursor = \"\";\n void this.#subscribe(ws, s);\n return;\n }\n this.#terminate(s, \"subscribe\", realtimeError);\n return;\n }\n if (error.code === RequestError_Code.SUBSCRIPTION_UNKNOWN && s.sub === sub) {\n this.#bySub.delete(s.sub);\n s.sub = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n this.#report(s, request?.kind ?? \"request\", realtimeError);\n }\n\n #onClosed(ws: WebSocket, code: number, reason: string): void {\n if (this.#ws !== ws) return;\n const stable = this.#authSent && Date.now() - this.#authSentAt >= STABLE_CONNECTION_MS;\n this.#detach();\n if (stable) this.#reconnectAttempt = 0;\n if (this.#subs.size === 0) return;\n\n if (TERMINAL_CLOSE_CODES.has(code)) {\n const error = new RealtimeError(\n reason || `Private WebSocket closed with code ${code}`,\n {\n realtimeCode: code,\n retryable: false,\n },\n );\n this.#terminateAll(\"disconnected\", error);\n return;\n }\n // Scheduled first, so a subscription opened from onDisconnected waits for it.\n this.#scheduleReconnect();\n // A close that reconnects is not an error, like a Centrifugo reconnect.\n for (const s of this.#subs.values()) {\n if (s.state === \"connected\") {\n s.state = \"disconnected\";\n this.#deliver(s, (p) => p.onDisconnected?.());\n }\n }\n }\n\n #scheduleReconnect(): void {\n this.#reconnectTimer = setTimeout(\n () => {\n this.#reconnectTimer = null;\n if (this.#subs.size > 0 && !this.#ws && !this.#connecting) this.#open();\n },\n backoffMs(this.#reconnectAttempt++),\n );\n }\n\n #armHeartbeat(ws: WebSocket): void {\n if (this.#heartbeatTimer) clearTimeout(this.#heartbeatTimer);\n this.#heartbeatTimer = setTimeout(\n () => this.#drop(ws, 4000, \"heartbeat timeout\"),\n HEARTBEAT_TIMEOUT_MS,\n );\n }\n\n /** Treats the socket as closed now; a stale socket may not emit close for a long time. */\n #drop(ws: WebSocket, code: number, reason: string): void {\n if (this.#ws !== ws) return;\n try {\n ws.close(code, reason);\n } catch {\n // noop\n }\n this.#onClosed(ws, code, reason);\n }\n\n #detach(): void {\n const ws = this.#ws;\n this.#ws = null;\n this.#authSent = false;\n if (this.#heartbeatTimer) clearTimeout(this.#heartbeatTimer);\n this.#heartbeatTimer = null;\n this.#pending.clear();\n this.#bySub.clear();\n this.#unsubscribing.clear();\n for (const s of this.#subs.values()) {\n this.#clearRetry(s);\n s.sub = \"\";\n s.seq = 0n;\n s.staged = null;\n }\n if (ws) {\n ws.onopen = null;\n ws.onmessage = null;\n ws.onclose = null;\n }\n }\n\n #shutdown(): void {\n const ws = this.#ws;\n this.#detach();\n this.#generation++;\n this.#connecting = false;\n if (this.#reconnectTimer) clearTimeout(this.#reconnectTimer);\n this.#reconnectTimer = null;\n this.#reconnectAttempt = 0;\n try {\n ws?.close(1000);\n } catch {\n // noop\n }\n }\n\n /** Drops a consumer; the server subscription goes a microtask later unless another joined. */\n #remove(s: StreamSubscription, c: Consumer): void {\n if (!s.consumers.delete(c) || s.consumers.size > 0) return;\n queueMicrotask(() => {\n if (s.consumers.size === 0) this.#teardown(s);\n });\n }\n\n #teardown(s: StreamSubscription): void {\n if (!this.#isCurrent(s)) return;\n this.#subs.delete(s.channel);\n s.consumers.clear();\n this.#clearRetry(s);\n const ws = this.#ws;\n if (ws && s.sub) {\n this.#bySub.delete(s.sub);\n this.#unsubscribe(ws, s.sub);\n }\n s.sub = \"\";\n for (const [id, request] of this.#pending) {\n if (request.s === s) this.#pending.delete(id);\n }\n if (this.#subs.size === 0) this.#shutdown();\n }\n\n #terminate(s: StreamSubscription, type: string, error: unknown): void {\n if (!this.#isCurrent(s)) return;\n this.#report(s, type, error);\n // Tell every consumer that has not been told it is disconnected.\n const told = s.state === \"disconnected\";\n const consumers = [...s.consumers].filter((c) => !c.caughtUp || !told);\n s.state = \"disconnected\";\n this.#teardown(s);\n for (const c of consumers) this.#call(s.channel, c, () => c.params.onDisconnected?.());\n }\n\n /** Spares subscriptions that consumers open from its callbacks. */\n #terminateAll(type: string, error: unknown): void {\n for (const s of [...this.#subs.values()]) this.#terminate(s, type, error);\n }\n\n #send(ws: WebSocket, op: ClientOp): void {\n if (ws.readyState !== 1) return;\n ws.send(toBinary(ClientMessageSchema, create(ClientMessageSchema, { op })));\n }\n\n #nextRequestId(): string {\n return String(++this.#requestSeq);\n }\n\n #report(s: StreamSubscription, type: string, error: unknown): void {\n const ctx = createSdkSubscriptionErrorContext(s.channel, type, error);\n // Only consumers present when the error happened, and still attached.\n for (const c of [...s.consumers]) {\n if (!s.consumers.has(c)) continue;\n try {\n c.params.onError?.(ctx);\n } catch {\n // Keep consumer error-handler failures isolated from the stream.\n }\n }\n }\n\n #reportAll(type: string, error: unknown): void {\n for (const s of [...this.#subs.values()]) this.#report(s, type, error);\n }\n\n /** Delivers to each caught-up consumer still attached when its turn comes. */\n #deliver(s: StreamSubscription, deliver: (params: ConnectPrivateOrdersParams) => void): void {\n for (const c of s.consumers) {\n if (c.caughtUp) this.#deliverTo(s, c, () => deliver(c.params));\n }\n }\n\n #deliverTo(s: StreamSubscription, c: Consumer, deliver: () => void): void {\n if (s.consumers.has(c)) this.#call(s.channel, c, deliver);\n }\n\n #call(channel: string, c: Consumer, deliver: () => void): void {\n try {\n deliver();\n } catch (error) {\n try {\n c.params.onError?.(publicationHandlerErrorContext(channel, error));\n } catch {\n // noop\n }\n }\n }\n}\n"],"mappings":";;;;;;AAiBA,MAAa,yBAAyB;AACtC,MAAM,uBAAuB;AAC7B,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;;AAEvB,MAAM,uBAAuB;;AAE7B,MAAM,uCAAuB,IAAI,IAAI,CAAC,MAAM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E,SAAS,GAAG,OAAO;CAC5D;CAEA,MAAM,SAAiB,GAAa,SAA2B;EAC3D,IAAI;GACA,QAAQ;EACZ,SAAS,OAAO;GACZ,IAAI;IACA,EAAE,OAAO,UAAU,+BAA+B,SAAS,KAAK,CAAC;GACrE,QAAQ,CAER;EACJ;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"private-orders.js","names":["#config","#subs","#pending","#bySub","#unsubscribing","#catchUp","#remove","#ws","#authSent","#subscribe","#connecting","#reconnectTimer","#open","#clearRetry","#shutdown","#isCurrent","#deliverTo","#terminateAll","#generation","#authenticate","#onFrame","#onClosed","#reportAll","#scheduleReconnect","#send","#authSentAt","#armHeartbeat","#reauthenticate","#nextRequestId","#terminate","#report","#retrySubscribe","#refresh","#unsubscribe","#deliver","#drop","#onRequestError","#resubscribe","#detach","#reconnectAttempt","#heartbeatTimer","#teardown","#call","#requestSeq"],"sources":["../../src/realtime/private-orders.ts"],"sourcesContent":["import { create, fromBinary, toBinary, type MessageInitShape } from \"@bufbuild/protobuf\";\nimport type { Order } from \"../gen/orders/v1/orders_read_pb.js\";\nimport {\n Channel,\n ClientMessageSchema,\n RequestError_Code,\n ServerMessageSchema,\n type Unit,\n} from \"../gen/privatews/v1/private_ws_pb.js\";\nimport { ConfigurationError, PolyesterError, RealtimeError } from \"../shared/errors.js\";\nimport {\n createSdkSubscriptionErrorContext,\n publicationHandlerErrorContext,\n type SdkSubscriptionErrorContext,\n} from \"../shared/subscription-errors.js\";\nimport { idToBigInt } from \"../utils/base58-id.js\";\n\nexport const PRIVATE_WS_SUBPROTOCOL = \"polyester.v1.proto\";\nconst HEARTBEAT_TIMEOUT_MS = 3_000;\nconst BACKOFF_BASE_MS = 500;\nconst BACKOFF_MAX_MS = 10_000;\n/** A connection that stayed up this long resets the reconnect backoff. */\nconst STABLE_CONNECTION_MS = 10_000;\n/** A malformed frame (4400) and a rejected connect token (4403) recur on every reconnect. */\nconst TERMINAL_CLOSE_CODES = new Set([4400, 4403]);\n/** Larger frames are dropped undecoded with the connection; a full 256-order page is far smaller. */\nexport const MAX_PRIVATE_FRAME_BYTES = 4 * 1024 * 1024;\n/** A snapshot staging more pages than this ends its subscription, so a snapshot never ending stays bounded. */\nexport const MAX_SNAPSHOT_BYTES = 64 * 1024 * 1024;\nexport const MAX_SNAPSHOT_ORDERS = 100_000;\n\n/** One delivery of an account's order stream. */\nexport type PrivateOrdersEvent =\n /** The account's full live view; replace local state with it. */\n | { type: \"snapshot\"; orders: Order[] }\n /** One change, applied whole. */\n | { type: \"unit\"; unit: Unit }\n /**\n * The account's live view is temporarily behind (`true`) or caught up (`false`).\n * `orderIds`, when set, names the only orders behind; the rest of the view is current.\n */\n | { type: \"stale\"; stale: boolean; orderIds?: bigint[] };\n\nexport interface ConnectPrivateOrdersParams {\n /** The account's base58 public ID. */\n accountId: string;\n onEvent: (event: PrivateOrdersEvent) => void;\n /** Called when the server confirms the subscription, again after each reconnect. */\n onConnected?: () => void;\n /** Called when the connection carrying the subscription drops. */\n onDisconnected?: () => void;\n onError?: (ctx: SdkSubscriptionErrorContext) => void;\n}\n\nexport interface PrivateOrderStreamConfig {\n url: string;\n fetchConnectToken: () => Promise<string>;\n fetchSubscribeToken: (channel: string) => Promise<string>;\n}\n\ntype ClientOp = MessageInitShape<typeof ClientMessageSchema>[\"op\"];\n\ninterface Consumer {\n params: ConnectPrivateOrdersParams;\n /** False until a consumer that joined a running subscription received its current state. */\n caughtUp: boolean;\n}\n\n/** One server subscription per account, shared by every consumer of that account. */\ninterface StreamSubscription {\n consumers: Set<Consumer>;\n channel: string;\n account: bigint;\n /** Server subscription ID; empty until Subscribed. */\n sub: string;\n seq: bigint;\n /** Last applied resume position, carried across resubscribes and reconnects. */\n cursor: string;\n staged: Order[] | null;\n /** Frame bytes of the staged pages. */\n stagedBytes: number;\n /** The account's live view as last applied, for consumers that join later; null before the first snapshot. */\n orders: Map<bigint, Order> | null;\n /** The last connection state consumers were told about. */\n state: \"pending\" | \"connected\" | \"disconnected\";\n /** What consumers were last told is stale, until they are told it caught up. */\n stale: { orderIds?: bigint[] } | null;\n /** Subscribe attempts since the subscription last delivered data; drives retry backoff. */\n retries: number;\n retryTimer: ReturnType<typeof setTimeout> | null;\n}\n\ntype PendingRequest = { kind: \"subscribe\" | \"refresh\"; s: StreamSubscription };\n\n/** 0.5 s doubling to 10 s, jittered over the upper half of each step. */\nfunction backoffMs(attempt: number): number {\n const ceiling = Math.min(BACKOFF_MAX_MS, BACKOFF_BASE_MS * 2 ** (attempt + 1));\n return ceiling / 2 + Math.random() * (ceiling / 2);\n}\n\nfunction isTerminalTokenError(error: unknown): boolean {\n return error instanceof PolyesterError && !error.retryable;\n}\n\n/**\n * Account order streams over the private WebSocket (`/v1/ws/private`). One\n * connection carries every subscription; each resumes from its last cursor\n * after a gap, an expired token, or a reconnect.\n */\nexport class PrivateOrderStream {\n readonly #config: PrivateOrderStreamConfig;\n /** Keyed by channel. A subscription whose last consumer left stays until the next microtask. */\n readonly #subs = new Map<string, StreamSubscription>();\n readonly #pending = new Map<string, PendingRequest>();\n readonly #bySub = new Map<string, StreamSubscription>();\n /** IDs of Unsubscribe requests awaiting their answer. */\n readonly #unsubscribing = new Set<string>();\n #ws: WebSocket | null = null;\n /** A connect token fetch for the next socket is in flight. */\n #connecting = false;\n /** Bumped on shutdown so a token fetch that outlived it opens nothing. */\n #generation = 0;\n #authSent = false;\n #authSentAt = 0;\n #reconnectAttempt = 0;\n #reconnectTimer: ReturnType<typeof setTimeout> | null = null;\n #heartbeatTimer: ReturnType<typeof setTimeout> | null = null;\n #requestSeq = 0;\n\n constructor(config: PrivateOrderStreamConfig) {\n this.#config = config;\n }\n\n /** Throws ValidationError when accountId is not a base58 public ID. */\n connect(params: ConnectPrivateOrdersParams): () => void {\n const channel = `private:spot:orders:${params.accountId}`;\n const account = idToBigInt(params.accountId, \"accountId\");\n const existing = this.#subs.get(channel);\n if (existing) {\n const consumer: Consumer = { params, caughtUp: false };\n existing.consumers.add(consumer);\n queueMicrotask(() => this.#catchUp(existing, consumer));\n return () => this.#remove(existing, consumer);\n }\n const consumer: Consumer = { params, caughtUp: true };\n const s: StreamSubscription = {\n consumers: new Set([consumer]),\n channel,\n account,\n sub: \"\",\n seq: 0n,\n cursor: \"\",\n staged: null,\n stagedBytes: 0,\n orders: null,\n state: \"pending\",\n stale: null,\n retries: 0,\n retryTimer: null,\n };\n this.#subs.set(channel, s);\n if (this.#ws && this.#authSent) void this.#subscribe(this.#ws, s);\n else if (!this.#ws && !this.#connecting && !this.#reconnectTimer) this.#open();\n return () => this.#remove(s, consumer);\n }\n\n /** Closes the connection and drops every subscription without callbacks. */\n disconnect(): void {\n for (const s of this.#subs.values()) {\n this.#clearRetry(s);\n // A consumer that disconnects mid-delivery stops deliveries to the rest.\n s.consumers.clear();\n }\n this.#subs.clear();\n this.#shutdown();\n }\n\n /** Accounts with at least one consumer. */\n get activeChannels(): number {\n let count = 0;\n for (const s of this.#subs.values()) if (s.consumers.size > 0) count++;\n return count;\n }\n\n get totalConsumers(): number {\n let count = 0;\n for (const s of this.#subs.values()) count += s.consumers.size;\n return count;\n }\n\n /** Gives a consumer that joined a running subscription what the others already know. */\n #catchUp(s: StreamSubscription, c: Consumer): void {\n if (!this.#isCurrent(s) || !s.consumers.has(c)) return;\n c.caughtUp = true;\n const { params } = c;\n if (s.state === \"connected\") this.#deliverTo(s, c, () => params.onConnected?.());\n const orders = s.orders && [...s.orders.values()];\n if (orders) this.#deliverTo(s, c, () => params.onEvent({ type: \"snapshot\", orders }));\n const { stale } = s;\n if (stale)\n this.#deliverTo(s, c, () => params.onEvent({ type: \"stale\", stale: true, ...stale }));\n }\n\n /** Fetches the connect token first: the server closes a socket that sends no Auth within 5 seconds. */\n #open(): void {\n const WebSocketCtor = globalThis.WebSocket;\n if (!WebSocketCtor) {\n // Reported after connect() returns, like every other connection failure.\n queueMicrotask(() =>\n this.#terminateAll(\n \"connection_token\",\n new ConfigurationError(\"The private order stream requires a global WebSocket.\"),\n ),\n );\n return;\n }\n const generation = this.#generation;\n this.#connecting = true;\n this.#config.fetchConnectToken().then(\n (token) => {\n if (generation !== this.#generation) return;\n this.#connecting = false;\n let ws: WebSocket;\n try {\n ws = new WebSocketCtor(this.#config.url, PRIVATE_WS_SUBPROTOCOL);\n } catch (error) {\n // A bad URL or a blocked insecure socket fails the same way on every retry.\n this.#terminateAll(\"connection\", error);\n return;\n }\n ws.binaryType = \"arraybuffer\";\n this.#ws = ws;\n this.#authSent = false;\n ws.onopen = () => this.#authenticate(ws, token);\n ws.onmessage = (event: MessageEvent) => this.#onFrame(ws, event.data);\n ws.onclose = (event: CloseEvent) => this.#onClosed(ws, event.code, event.reason);\n },\n (error: unknown) => {\n if (generation !== this.#generation) return;\n this.#connecting = false;\n if (isTerminalTokenError(error)) {\n this.#terminateAll(\"connection_token\", error);\n return;\n }\n this.#reportAll(\"connection_token\", error);\n this.#scheduleReconnect();\n },\n );\n }\n\n #authenticate(ws: WebSocket, token: string): void {\n this.#send(ws, { case: \"auth\", value: { token } });\n this.#authSent = true;\n this.#authSentAt = Date.now();\n this.#armHeartbeat(ws);\n for (const s of this.#subs.values()) void this.#subscribe(ws, s);\n }\n\n async #reauthenticate(ws: WebSocket): Promise<void> {\n try {\n const token = await this.#config.fetchConnectToken();\n if (this.#ws === ws) this.#send(ws, { case: \"auth\", value: { token } });\n } catch (error) {\n if (this.#ws !== ws) return;\n if (isTerminalTokenError(error)) this.#terminateAll(\"connection_token\", error);\n else this.#reportAll(\"connection_token\", error);\n }\n }\n\n #isCurrent(s: StreamSubscription): boolean {\n return this.#subs.get(s.channel) === s;\n }\n\n async #subscribe(ws: WebSocket, s: StreamSubscription): Promise<void> {\n if (!this.#isCurrent(s)) return;\n const id = this.#nextRequestId();\n this.#pending.set(id, { kind: \"subscribe\", s });\n let token: string;\n try {\n token = await this.#config.fetchSubscribeToken(s.channel);\n } catch (error) {\n if (this.#pending.get(id)?.s !== s) return;\n this.#pending.delete(id);\n if (isTerminalTokenError(error)) {\n this.#terminate(s, \"subscription_token\", error);\n return;\n }\n this.#report(s, \"subscription_token\", error);\n this.#retrySubscribe(ws, s);\n return;\n }\n if (this.#ws !== ws || this.#pending.get(id)?.s !== s) return;\n this.#send(ws, {\n case: \"subscribe\",\n value: { id, channel: Channel.ORDERS, account: s.account, token, cursor: s.cursor },\n });\n }\n\n /** Subscribes again after a backoff that grows until the subscription delivers data. */\n #retrySubscribe(ws: WebSocket, s: StreamSubscription): void {\n this.#clearRetry(s);\n s.retryTimer = setTimeout(\n () => {\n s.retryTimer = null;\n if (this.#ws === ws && this.#isCurrent(s) && !s.sub) void this.#subscribe(ws, s);\n },\n backoffMs(s.retries++),\n );\n }\n\n #clearRetry(s: StreamSubscription): void {\n if (s.retryTimer) clearTimeout(s.retryTimer);\n s.retryTimer = null;\n }\n\n async #refresh(ws: WebSocket, s: StreamSubscription): Promise<void> {\n const sub = s.sub;\n let token: string;\n try {\n token = await this.#config.fetchSubscribeToken(s.channel);\n } catch (error) {\n // An unrefreshed subscription ends with TOKEN_EXPIRED and resubscribes.\n if (this.#ws === ws && s.sub === sub) this.#report(s, \"subscription_token\", error);\n return;\n }\n if (this.#ws !== ws || s.sub !== sub) return;\n const id = this.#nextRequestId();\n this.#pending.set(id, { kind: \"refresh\", s });\n this.#send(ws, { case: \"subscribeRefresh\", value: { id, sub, token } });\n }\n\n /**\n * Drops the server subscription and subscribes again from the last applied cursor:\n * at once the first time, then with backoff until the subscription delivers data.\n */\n #resubscribe(ws: WebSocket, s: StreamSubscription): void {\n if (s.sub) {\n this.#bySub.delete(s.sub);\n this.#unsubscribe(ws, s.sub);\n }\n s.sub = \"\";\n s.seq = 0n;\n s.staged = null;\n if (s.retries > 0) {\n this.#retrySubscribe(ws, s);\n } else {\n s.retries = 1;\n void this.#subscribe(ws, s);\n }\n // Consumers see the gap as a close and the replacement's Subscribed as a reopen.\n if (s.state === \"connected\") {\n s.state = \"disconnected\";\n this.#deliver(s, (p) => p.onDisconnected?.());\n }\n }\n\n #unsubscribe(ws: WebSocket, sub: string): void {\n const id = this.#nextRequestId();\n this.#unsubscribing.add(id);\n this.#send(ws, { case: \"unsubscribe\", value: { id, sub } });\n }\n\n #onFrame(ws: WebSocket, data: unknown): void {\n if (this.#ws !== ws) return;\n this.#armHeartbeat(ws);\n if (!(data instanceof ArrayBuffer)) {\n this.#reportAll(\n \"decode\",\n new RealtimeError(\"Expected a binary private WebSocket frame\"),\n );\n return;\n }\n if (data.byteLength > MAX_PRIVATE_FRAME_BYTES) {\n this.#reportAll(\n \"decode\",\n new RealtimeError(\n `Private WebSocket frame of ${data.byteLength} bytes exceeds ${MAX_PRIVATE_FRAME_BYTES}`,\n ),\n );\n // Reconnects with backoff; dropping the socket releases every staged snapshot.\n this.#drop(ws, 1009, \"frame too large\");\n return;\n }\n let msg;\n try {\n msg = fromBinary(ServerMessageSchema, new Uint8Array(data));\n } catch (error) {\n this.#reportAll(\"decode\", error);\n return;\n }\n const frame = msg.frame;\n\n switch (frame.case) {\n case \"subscribed\": {\n const request = this.#pending.get(frame.value.id);\n if (request?.kind !== \"subscribe\") {\n // Its consumer left before the server confirmed it.\n if (msg.sub) this.#unsubscribe(ws, msg.sub);\n return;\n }\n this.#pending.delete(frame.value.id);\n const s = request.s;\n s.sub = msg.sub;\n s.seq = 0n;\n this.#bySub.set(msg.sub, s);\n if (s.state !== \"connected\") {\n s.state = \"connected\";\n this.#deliver(s, (p) => p.onConnected?.());\n }\n // A new subscription reports Unavailable itself if its view is still behind.\n if (s.stale) {\n s.stale = null;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: false }));\n }\n return;\n }\n case \"subscribeRefreshed\":\n this.#pending.delete(frame.value.id);\n return;\n case \"unsubscribed\":\n if (this.#unsubscribing.delete(frame.value.id)) return;\n break;\n case \"error\":\n this.#onRequestError(ws, msg.sub, frame.value);\n return;\n case \"tokenExpiring\":\n void this.#reauthenticate(ws);\n return;\n }\n\n const s = this.#bySub.get(msg.sub);\n if (!s) return;\n if (msg.seq > 0n) {\n if (msg.seq !== s.seq + 1n) {\n this.#resubscribe(ws, s);\n return;\n }\n s.seq = msg.seq;\n }\n\n switch (frame.case) {\n case \"snapshotBegin\":\n s.staged = [];\n s.stagedBytes = 0;\n return;\n case \"snapshotPage\": {\n if (!s.staged) return;\n s.stagedBytes += data.byteLength;\n const count = s.staged.length + frame.value.orders.length;\n if (s.stagedBytes > MAX_SNAPSHOT_BYTES || count > MAX_SNAPSHOT_ORDERS) {\n s.staged = null;\n // The same account sends the same snapshot again, so retrying cannot help.\n this.#terminate(\n s,\n \"snapshot\",\n new RealtimeError(\n `Private order snapshot exceeds ${MAX_SNAPSHOT_ORDERS} orders or ${MAX_SNAPSHOT_BYTES} bytes`,\n ),\n );\n return;\n }\n s.staged.push(...frame.value.orders);\n return;\n }\n case \"snapshotEnd\": {\n const orders = s.staged;\n s.staged = null;\n if (!orders || orders.length !== frame.value.count) {\n s.cursor = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n s.cursor = frame.value.cursor;\n s.retries = 0;\n s.orders = new Map(orders.map((o) => [o.orderId, o]));\n this.#deliver(s, (p) => p.onEvent({ type: \"snapshot\", orders }));\n return;\n }\n case \"unit\": {\n const unit = frame.value;\n s.cursor = unit.nextCursor;\n s.retries = 0;\n for (const o of unit.orders) s.orders?.set(o.orderId, o);\n for (const id of unit.removedOrderIds) s.orders?.delete(id);\n this.#deliver(s, (p) => p.onEvent({ type: \"unit\", unit }));\n return;\n }\n case \"covered\":\n s.cursor = frame.value.cursor;\n s.retries = 0;\n return;\n case \"ready\":\n // A resumed subscription on a quiet account delivers no data, only this.\n s.retries = 0;\n return;\n case \"unavailable\": {\n // A later Unavailable replaces the earlier one; order IDs narrow it to those orders.\n const { orderIds } = frame.value;\n const stale = orderIds.length > 0 ? { orderIds } : {};\n s.stale = stale;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: true, ...stale }));\n return;\n }\n case \"available\":\n s.stale = null;\n this.#deliver(s, (p) => p.onEvent({ type: \"stale\", stale: false }));\n return;\n case \"subscribeExpiring\":\n void this.#refresh(ws, s);\n return;\n case \"unsubscribed\":\n // The server ended it: its token expired, or for a reason this client does not know.\n this.#bySub.delete(s.sub);\n s.sub = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n }\n\n #onRequestError(\n ws: WebSocket,\n sub: string,\n error: { id: string; code: RequestError_Code; message: string },\n ): void {\n if (error.id && this.#unsubscribing.delete(error.id)) return;\n const request = error.id ? this.#pending.get(error.id) : undefined;\n // The answer to a request already answered, or whose subscription has since gone.\n if (error.id && !request) return;\n if (request) this.#pending.delete(error.id);\n const s = request?.s ?? this.#bySub.get(sub);\n const realtimeError = new RealtimeError(\n error.message ||\n `Private order stream request failed: ${RequestError_Code[error.code]}`,\n { realtimeCode: error.code },\n );\n if (!s) {\n this.#reportAll(\"request\", realtimeError);\n return;\n }\n if (request?.kind === \"subscribe\") {\n if (error.code === RequestError_Code.CURSOR_INVALID) {\n s.cursor = \"\";\n void this.#subscribe(ws, s);\n return;\n }\n this.#terminate(s, \"subscribe\", realtimeError);\n return;\n }\n if (error.code === RequestError_Code.SUBSCRIPTION_UNKNOWN && s.sub === sub) {\n this.#bySub.delete(s.sub);\n s.sub = \"\";\n this.#resubscribe(ws, s);\n return;\n }\n this.#report(s, request?.kind ?? \"request\", realtimeError);\n }\n\n #onClosed(ws: WebSocket, code: number, reason: string): void {\n if (this.#ws !== ws) return;\n const stable = this.#authSent && Date.now() - this.#authSentAt >= STABLE_CONNECTION_MS;\n this.#detach();\n if (stable) this.#reconnectAttempt = 0;\n if (this.#subs.size === 0) return;\n\n if (TERMINAL_CLOSE_CODES.has(code)) {\n const error = new RealtimeError(\n reason || `Private WebSocket closed with code ${code}`,\n {\n realtimeCode: code,\n retryable: false,\n },\n );\n this.#terminateAll(\"disconnected\", error);\n return;\n }\n // Scheduled first, so a subscription opened from onDisconnected waits for it.\n this.#scheduleReconnect();\n // A close that reconnects is not an error, like a Centrifugo reconnect.\n for (const s of this.#subs.values()) {\n if (s.state === \"connected\") {\n s.state = \"disconnected\";\n this.#deliver(s, (p) => p.onDisconnected?.());\n }\n }\n }\n\n #scheduleReconnect(): void {\n this.#reconnectTimer = setTimeout(\n () => {\n this.#reconnectTimer = null;\n if (this.#subs.size > 0 && !this.#ws && !this.#connecting) this.#open();\n },\n backoffMs(this.#reconnectAttempt++),\n );\n }\n\n #armHeartbeat(ws: WebSocket): void {\n if (this.#heartbeatTimer) clearTimeout(this.#heartbeatTimer);\n this.#heartbeatTimer = setTimeout(\n () => this.#drop(ws, 4000, \"heartbeat timeout\"),\n HEARTBEAT_TIMEOUT_MS,\n );\n }\n\n /** Treats the socket as closed now; a stale socket may not emit close for a long time. */\n #drop(ws: WebSocket, code: number, reason: string): void {\n if (this.#ws !== ws) return;\n try {\n ws.close(code, reason);\n } catch {\n // noop\n }\n this.#onClosed(ws, code, reason);\n }\n\n #detach(): void {\n const ws = this.#ws;\n this.#ws = null;\n this.#authSent = false;\n if (this.#heartbeatTimer) clearTimeout(this.#heartbeatTimer);\n this.#heartbeatTimer = null;\n this.#pending.clear();\n this.#bySub.clear();\n this.#unsubscribing.clear();\n for (const s of this.#subs.values()) {\n this.#clearRetry(s);\n s.sub = \"\";\n s.seq = 0n;\n s.staged = null;\n }\n if (ws) {\n ws.onopen = null;\n ws.onmessage = null;\n ws.onclose = null;\n }\n }\n\n #shutdown(): void {\n const ws = this.#ws;\n this.#detach();\n this.#generation++;\n this.#connecting = false;\n if (this.#reconnectTimer) clearTimeout(this.#reconnectTimer);\n this.#reconnectTimer = null;\n this.#reconnectAttempt = 0;\n try {\n ws?.close(1000);\n } catch {\n // noop\n }\n }\n\n /** Drops a consumer; the server subscription goes a microtask later unless another joined. */\n #remove(s: StreamSubscription, c: Consumer): void {\n if (!s.consumers.delete(c) || s.consumers.size > 0) return;\n queueMicrotask(() => {\n if (s.consumers.size === 0) this.#teardown(s);\n });\n }\n\n #teardown(s: StreamSubscription): void {\n if (!this.#isCurrent(s)) return;\n this.#subs.delete(s.channel);\n s.consumers.clear();\n this.#clearRetry(s);\n const ws = this.#ws;\n if (ws && s.sub) {\n this.#bySub.delete(s.sub);\n this.#unsubscribe(ws, s.sub);\n }\n s.sub = \"\";\n for (const [id, request] of this.#pending) {\n if (request.s === s) this.#pending.delete(id);\n }\n if (this.#subs.size === 0) this.#shutdown();\n }\n\n #terminate(s: StreamSubscription, type: string, error: unknown): void {\n if (!this.#isCurrent(s)) return;\n this.#report(s, type, error);\n // Tell every consumer that has not been told it is disconnected.\n const told = s.state === \"disconnected\";\n const consumers = [...s.consumers].filter((c) => !c.caughtUp || !told);\n s.state = \"disconnected\";\n this.#teardown(s);\n for (const c of consumers) this.#call(s.channel, c, () => c.params.onDisconnected?.());\n }\n\n /** Spares subscriptions that consumers open from its callbacks. */\n #terminateAll(type: string, error: unknown): void {\n for (const s of [...this.#subs.values()]) this.#terminate(s, type, error);\n }\n\n #send(ws: WebSocket, op: ClientOp): void {\n if (ws.readyState !== 1) return;\n ws.send(toBinary(ClientMessageSchema, create(ClientMessageSchema, { op })));\n }\n\n #nextRequestId(): string {\n return String(++this.#requestSeq);\n }\n\n #report(s: StreamSubscription, type: string, error: unknown): void {\n const ctx = createSdkSubscriptionErrorContext(s.channel, type, error);\n // Only consumers present when the error happened, and still attached.\n for (const c of [...s.consumers]) {\n if (!s.consumers.has(c)) continue;\n try {\n c.params.onError?.(ctx);\n } catch {\n // Keep consumer error-handler failures isolated from the stream.\n }\n }\n }\n\n #reportAll(type: string, error: unknown): void {\n for (const s of [...this.#subs.values()]) this.#report(s, type, error);\n }\n\n /** Delivers to each caught-up consumer still attached when its turn comes. */\n #deliver(s: StreamSubscription, deliver: (params: ConnectPrivateOrdersParams) => void): void {\n for (const c of s.consumers) {\n if (c.caughtUp) this.#deliverTo(s, c, () => deliver(c.params));\n }\n }\n\n #deliverTo(s: StreamSubscription, c: Consumer, deliver: () => void): void {\n if (s.consumers.has(c)) this.#call(s.channel, c, deliver);\n }\n\n #call(channel: string, c: Consumer, deliver: () => void): void {\n try {\n deliver();\n } catch (error) {\n try {\n c.params.onError?.(publicationHandlerErrorContext(channel, error));\n } catch {\n // noop\n }\n }\n }\n}\n"],"mappings":";;;;;;AAiBA,MAAa,yBAAyB;AACtC,MAAM,uBAAuB;AAC7B,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;;AAEvB,MAAM,uBAAuB;;AAE7B,MAAM,uCAAuB,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC;;AAEjD,MAAa,0BAA0B;;AAEvC,MAAa,qBAAqB;AAClC,MAAa,sBAAsB;;AAkEnC,SAAS,UAAU,SAAyB;CACxC,MAAM,UAAU,KAAK,IAAI,gBAAgB,kBAAkB,MAAM,UAAU,EAAE;CAC7E,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,UAAU;AACpD;AAEA,SAAS,qBAAqB,OAAyB;CACnD,OAAO,iBAAiB,kBAAkB,CAAC,MAAM;AACrD;;;;;;AAOA,IAAa,qBAAb,MAAgC;CAC5B;;CAEA,wBAAiB,IAAI,IAAgC;CACrD,2BAAoB,IAAI,IAA4B;CACpD,yBAAkB,IAAI,IAAgC;;CAEtD,iCAA0B,IAAI,IAAY;CAC1C,MAAwB;;CAExB,cAAc;;CAEd,cAAc;CACd,YAAY;CACZ,cAAc;CACd,oBAAoB;CACpB,kBAAwD;CACxD,kBAAwD;CACxD,cAAc;CAEd,YAAY,QAAkC;EAC1C,KAAKA,UAAU;CACnB;;CAGA,QAAQ,QAAgD;EACpD,MAAM,UAAU,uBAAuB,OAAO;EAC9C,MAAM,UAAU,WAAW,OAAO,WAAW,WAAW;EACxD,MAAM,WAAW,KAAKC,MAAM,IAAI,OAAO;EACvC,IAAI,UAAU;GACV,MAAM,WAAqB;IAAE;IAAQ,UAAU;GAAM;GACrD,SAAS,UAAU,IAAI,QAAQ;GAC/B,qBAAqB,KAAKI,SAAS,UAAU,QAAQ,CAAC;GACtD,aAAa,KAAKC,QAAQ,UAAU,QAAQ;EAChD;EAC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AM,IAAe,IAAoB;EACrC,IAAI,GAAG,eAAe,GAAG;EACzB,GAAG,KAAK,SAAS,qBAAqB,OAAO,qBAAqB,EAAE,GAAG,CAAC,CAAC,CAAC;CAC9E;CAEA,iBAAyB;EACrB,OAAO,OAAO,EAAE,KAAKc,WAAW;CACpC;CAEA,QAAQ,GAAuB,MAAc,OAAsB;EAC/D,MAAM,MAAM,kCAAkC,EAAE,SAAS,MAAM,KAAK;EAEpE,KAAK,MAAM,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG;GAC9B,IAAI,CAAC,EAAE,UAAU,IAAI,CAAC,GAAG;GACzB,IAAI;IACA,EAAE,OAAO,UAAU,GAAG;GAC1B,QAAQ,CAER;EACJ;CACJ;CAEA,WAAW,MAAc,OAAsB;EAC3C,KAAK,MAAM,KAAK,CAAC,GAAG,KAAK1C,MAAM,OAAO,CAAC,GAAG,KAAK6B,QAAQ,GAAG,MAAM,KAAK;CACzE;;CAGA,SAAS,GAAuB,SAA6D;EACzF,KAAK,MAAM,KAAK,EAAE,WACd,IAAI,EAAE,UAAU,KAAKd,WAAW,GAAG,SAAS,QAAQ,EAAE,MAAM,CAAC;CAErE;CAEA,WAAW,GAAuB,GAAa,SAA2B;EACtE,IAAI,EAAE,UAAU,IAAI,CAAC,GAAG,KAAK0B,MAAM,EAAE,SAAS,GAAG,OAAO;CAC5D;CAEA,MAAM,SAAiB,GAAa,SAA2B;EAC3D,IAAI;GACA,QAAQ;EACZ,SAAS,OAAO;GACZ,IAAI;IACA,EAAE,OAAO,UAAU,+BAA+B,SAAS,KAAK,CAAC;GACrE,QAAQ,CAER;EACJ;CACJ;AACJ"}
|
|
@@ -297,7 +297,7 @@ declare const AddressBookSchema: v.ObjectSchema<{
|
|
|
297
297
|
rootAccountId: string;
|
|
298
298
|
subaccountId: bigint;
|
|
299
299
|
}, AddressBookAccountScope>]>, undefined>;
|
|
300
|
-
readonly callerRole: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "
|
|
300
|
+
readonly callerRole: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified">]>;
|
|
301
301
|
readonly label: v.StringSchema<undefined>;
|
|
302
302
|
readonly ownerUsername: v.StringSchema<undefined>;
|
|
303
303
|
readonly smartAccountAddress: v.StringSchema<undefined>;
|
|
@@ -1102,7 +1102,7 @@ declare const AddressBookViewSchema: v.ObjectSchema<{
|
|
|
1102
1102
|
rootAccountId: string;
|
|
1103
1103
|
subaccountId: bigint;
|
|
1104
1104
|
}, AddressBookAccountScope>]>, undefined>;
|
|
1105
|
-
readonly callerRole: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "
|
|
1105
|
+
readonly callerRole: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "owner" | "admin" | "treasury" | "leveraged_trader" | "trader" | "viewer" | "unspecified">]>;
|
|
1106
1106
|
readonly label: v.StringSchema<undefined>;
|
|
1107
1107
|
readonly ownerUsername: v.StringSchema<undefined>;
|
|
1108
1108
|
readonly smartAccountAddress: v.StringSchema<undefined>;
|
|
@@ -11,7 +11,7 @@ type TimestampInit = {
|
|
|
11
11
|
};
|
|
12
12
|
declare function createCandleRowSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
13
13
|
readonly symbolId: v.NumberSchema<undefined>;
|
|
14
|
-
readonly timeframe: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1d" | "
|
|
14
|
+
readonly timeframe: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo">>]>;
|
|
15
15
|
readonly tsSec: v.BigintSchema<undefined>;
|
|
16
16
|
readonly open: v.BigintSchema<undefined>;
|
|
17
17
|
readonly high: v.BigintSchema<undefined>;
|
|
@@ -22,7 +22,7 @@ declare function createCandleRowSchema(scales: SdkScales): v.SchemaWithPipe<read
|
|
|
22
22
|
readonly isClosed: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
23
23
|
}, undefined>, v.TransformAction<{
|
|
24
24
|
symbolId: number;
|
|
25
|
-
timeframe: DecodedEnum<"1d" | "
|
|
25
|
+
timeframe: DecodedEnum<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo">;
|
|
26
26
|
tsSec: bigint;
|
|
27
27
|
open: bigint;
|
|
28
28
|
high: bigint;
|
|
@@ -33,7 +33,7 @@ declare function createCandleRowSchema(scales: SdkScales): v.SchemaWithPipe<read
|
|
|
33
33
|
isClosed: boolean;
|
|
34
34
|
}, {
|
|
35
35
|
symbolId: number;
|
|
36
|
-
timeframe: DecodedEnum<"1d" | "
|
|
36
|
+
timeframe: DecodedEnum<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo">;
|
|
37
37
|
time: number;
|
|
38
38
|
open: string;
|
|
39
39
|
high: string;
|
|
@@ -46,7 +46,7 @@ declare function createCandleRowSchema(scales: SdkScales): v.SchemaWithPipe<read
|
|
|
46
46
|
declare const createCandleRowIntSchema: typeof createCandleRowSchema;
|
|
47
47
|
declare function createCandleColumnarSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
48
48
|
readonly symbolId: v.NumberSchema<undefined>;
|
|
49
|
-
readonly timeframe: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1d" | "
|
|
49
|
+
readonly timeframe: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo">>]>;
|
|
50
50
|
readonly tsSec: v.ArraySchema<v.BigintSchema<undefined>, undefined>;
|
|
51
51
|
readonly open: v.ArraySchema<v.BigintSchema<undefined>, undefined>;
|
|
52
52
|
readonly high: v.ArraySchema<v.BigintSchema<undefined>, undefined>;
|
|
@@ -63,7 +63,7 @@ declare function createCandleColumnarSchema(scales: SdkScales): v.SchemaWithPipe
|
|
|
63
63
|
readonly nextPageToken: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
64
64
|
}, undefined>, v.TransformAction<{
|
|
65
65
|
symbolId: number;
|
|
66
|
-
timeframe: DecodedEnum<"1d" | "
|
|
66
|
+
timeframe: DecodedEnum<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo">;
|
|
67
67
|
tsSec: bigint[];
|
|
68
68
|
open: bigint[];
|
|
69
69
|
high: bigint[];
|
|
@@ -80,7 +80,7 @@ declare function createCandleColumnarSchema(scales: SdkScales): v.SchemaWithPipe
|
|
|
80
80
|
nextPageToken: string;
|
|
81
81
|
}, {
|
|
82
82
|
symbolId: number;
|
|
83
|
-
timeframe: DecodedEnum<"1d" | "
|
|
83
|
+
timeframe: DecodedEnum<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo">;
|
|
84
84
|
time: number[];
|
|
85
85
|
open: string[];
|
|
86
86
|
high: string[];
|
|
@@ -100,7 +100,7 @@ declare function createCandleColumnarSchema(scales: SdkScales): v.SchemaWithPipe
|
|
|
100
100
|
}>]>;
|
|
101
101
|
declare function createCandleColumnarIntSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
102
102
|
readonly symbolId: v.NumberSchema<undefined>;
|
|
103
|
-
readonly timeframe: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1d" | "
|
|
103
|
+
readonly timeframe: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo">>]>;
|
|
104
104
|
readonly tsSec: v.ArraySchema<v.BigintSchema<undefined>, undefined>;
|
|
105
105
|
readonly open: v.ArraySchema<v.BigintSchema<undefined>, undefined>;
|
|
106
106
|
readonly high: v.ArraySchema<v.BigintSchema<undefined>, undefined>;
|
|
@@ -117,7 +117,7 @@ declare function createCandleColumnarIntSchema(scales: SdkScales): v.SchemaWithP
|
|
|
117
117
|
readonly nextPageToken: v.OptionalSchema<v.StringSchema<undefined>, "">;
|
|
118
118
|
}, undefined>, v.TransformAction<{
|
|
119
119
|
symbolId: number;
|
|
120
|
-
timeframe: DecodedEnum<"1d" | "
|
|
120
|
+
timeframe: DecodedEnum<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo">;
|
|
121
121
|
tsSec: bigint[];
|
|
122
122
|
open: bigint[];
|
|
123
123
|
high: bigint[];
|
|
@@ -134,7 +134,7 @@ declare function createCandleColumnarIntSchema(scales: SdkScales): v.SchemaWithP
|
|
|
134
134
|
nextPageToken: string;
|
|
135
135
|
}, {
|
|
136
136
|
symbolId: number;
|
|
137
|
-
timeframe: DecodedEnum<"1d" | "
|
|
137
|
+
timeframe: DecodedEnum<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo">;
|
|
138
138
|
tsSec: number[];
|
|
139
139
|
open: string[];
|
|
140
140
|
high: string[];
|
|
@@ -158,7 +158,7 @@ type CandleColumnar = v.InferOutput<ReturnType<typeof createCandleColumnarSchema
|
|
|
158
158
|
type CandleColumnarInt = v.InferOutput<ReturnType<typeof createCandleColumnarIntSchema>>;
|
|
159
159
|
declare function createListCandlesInputSchema(): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
160
160
|
readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
161
|
-
readonly timeframe: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["1s", "1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "6h", "8h", "12h", "1d", "3d", "1w", "1mo"], undefined>, v.TransformAction<"1d" | "
|
|
161
|
+
readonly timeframe: v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["1s", "1m", "3m", "5m", "15m", "30m", "1h", "2h", "4h", "6h", "8h", "12h", "1d", "3d", "1w", "1mo"], undefined>, v.TransformAction<"1d" | "1s" | "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "3d" | "1w" | "1mo", Timeframe$1.SEC_1 | Timeframe$1.MIN_1 | Timeframe$1.MIN_3 | Timeframe$1.MIN_5 | Timeframe$1.MIN_15 | Timeframe$1.MIN_30 | Timeframe$1.HOUR_1 | Timeframe$1.HOUR_2 | Timeframe$1.HOUR_4 | Timeframe$1.HOUR_6 | Timeframe$1.HOUR_8 | Timeframe$1.HOUR_12 | Timeframe$1.DAY_1 | Timeframe$1.DAY_3 | Timeframe$1.WEEK_1 | Timeframe$1.MONTH_1>]>;
|
|
162
162
|
readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 10000, undefined>]>, undefined>;
|
|
163
163
|
readonly includeIncomplete: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
164
164
|
readonly includeReference: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
@@ -49,7 +49,7 @@ declare const CheckpointBiggestTradeSchema: v.SchemaWithPipe<readonly [v.ObjectS
|
|
|
49
49
|
side: number;
|
|
50
50
|
at: number;
|
|
51
51
|
}, {
|
|
52
|
-
side: "
|
|
52
|
+
side: "unspecified" | "buy" | "sell";
|
|
53
53
|
symbolId: number;
|
|
54
54
|
symbol: string;
|
|
55
55
|
at: number;
|
|
@@ -229,7 +229,7 @@ declare const CheckpointSchema: v.ObjectSchema<{
|
|
|
229
229
|
side: number;
|
|
230
230
|
at: number;
|
|
231
231
|
}, {
|
|
232
|
-
side: "
|
|
232
|
+
side: "unspecified" | "buy" | "sell";
|
|
233
233
|
symbolId: number;
|
|
234
234
|
symbol: string;
|
|
235
235
|
at: number;
|
|
@@ -13,8 +13,8 @@ type TimestampInit = {
|
|
|
13
13
|
};
|
|
14
14
|
declare const GetOrderbookHeatmapInputSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
15
15
|
readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
16
|
-
readonly interval: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["1s", "1m", "5m", "1h"], undefined>, "1s">, v.TransformAction<"
|
|
17
|
-
readonly depth: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly [1, 5, 10, 20, 50, 100, 200, 500, 1000], undefined>, 50>, v.TransformAction<1 | 5 | 10 | 20 | 100 | 500 |
|
|
16
|
+
readonly interval: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["1s", "1m", "5m", "1h"], undefined>, "1s">, v.TransformAction<"1s" | "1m" | "5m" | "1h", HeatmapInterval>]>;
|
|
17
|
+
readonly depth: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly [1, 5, 10, 20, 50, 100, 200, 500, 1000], undefined>, 50>, v.TransformAction<1 | 5 | 10 | 20 | 100 | 500 | 200 | 50 | 1000, HeatmapDepth>]>;
|
|
18
18
|
readonly quantityMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["close", "peak"], undefined>, "close">, v.TransformAction<"close" | "peak", HeatmapQuantityMode>]>;
|
|
19
19
|
readonly limit: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 20000, undefined>]>;
|
|
20
20
|
readonly startTsSec: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, number, undefined>, v.TransformAction<number, bigint>]>, undefined>;
|
|
@@ -122,7 +122,7 @@ declare function convertHeatmapDeltaBucket(bucket: OrderbookHeatmapDeltaBucketRa
|
|
|
122
122
|
type OrderbookHeatmapDeltaBucket = ReturnType<typeof convertHeatmapDeltaBucket>;
|
|
123
123
|
declare const OrderbookHeatmapLiveBucketRawSchema: v.ObjectSchema<{
|
|
124
124
|
readonly symbolId: v.NumberSchema<undefined>;
|
|
125
|
-
readonly interval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"
|
|
125
|
+
readonly interval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1s" | "1m" | "5m" | "1h">>]>;
|
|
126
126
|
readonly tsSec: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, number>]>;
|
|
127
127
|
readonly isFinal: v.BooleanSchema<undefined>;
|
|
128
128
|
readonly bids: v.OptionalSchema<v.ObjectSchema<{
|
|
@@ -142,7 +142,7 @@ declare const OrderbookHeatmapLiveBucketRawSchema: v.ObjectSchema<{
|
|
|
142
142
|
type OrderbookHeatmapLiveBucketRaw = v.InferOutput<typeof OrderbookHeatmapLiveBucketRawSchema>;
|
|
143
143
|
declare function convertHeatmapLiveBucket(bucket: OrderbookHeatmapLiveBucketRaw, scales: SdkScales): {
|
|
144
144
|
symbolId: number;
|
|
145
|
-
interval: DecodedEnum<"
|
|
145
|
+
interval: DecodedEnum<"1s" | "1m" | "5m" | "1h">;
|
|
146
146
|
tsSec: number;
|
|
147
147
|
isFinal: boolean;
|
|
148
148
|
bids: {
|
|
@@ -226,8 +226,8 @@ declare function convertHeatmapDeltaChain(chain: OrderbookHeatmapDeltaChainRaw,
|
|
|
226
226
|
type OrderbookHeatmapDeltaChain = ReturnType<typeof convertHeatmapDeltaChain>;
|
|
227
227
|
declare function createOrderbookHeatmapResponseSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
228
228
|
readonly symbolId: v.NumberSchema<undefined>;
|
|
229
|
-
readonly interval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"
|
|
230
|
-
readonly depth: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, 1 | 5 | 10 | 20 |
|
|
229
|
+
readonly interval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1s" | "1m" | "5m" | "1h">>]>;
|
|
230
|
+
readonly depth: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, 1 | "unspecified" | 5 | 10 | 20 | 100 | 500 | 200 | 50 | 1000>]>;
|
|
231
231
|
readonly chain: v.OptionalSchema<v.ObjectSchema<{
|
|
232
232
|
readonly baseKeyframe: v.OptionalSchema<v.ObjectSchema<{
|
|
233
233
|
readonly tsSec: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, number>]>;
|
|
@@ -267,7 +267,7 @@ declare function createOrderbookHeatmapResponseSchema(scales: SdkScales): v.Sche
|
|
|
267
267
|
readonly quantityMode: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"close" | "peak">>]>;
|
|
268
268
|
readonly liveBucket: v.OptionalSchema<v.ObjectSchema<{
|
|
269
269
|
readonly symbolId: v.NumberSchema<undefined>;
|
|
270
|
-
readonly interval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"
|
|
270
|
+
readonly interval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, DecodedEnum<"1s" | "1m" | "5m" | "1h">>]>;
|
|
271
271
|
readonly tsSec: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, number>]>;
|
|
272
272
|
readonly isFinal: v.BooleanSchema<undefined>;
|
|
273
273
|
readonly bids: v.OptionalSchema<v.ObjectSchema<{
|
|
@@ -286,8 +286,8 @@ declare function createOrderbookHeatmapResponseSchema(scales: SdkScales): v.Sche
|
|
|
286
286
|
}, undefined>, undefined>;
|
|
287
287
|
}, undefined>, v.TransformAction<{
|
|
288
288
|
symbolId: number;
|
|
289
|
-
interval: DecodedEnum<"
|
|
290
|
-
depth: 1 | 5 | 10 | 20 |
|
|
289
|
+
interval: DecodedEnum<"1s" | "1m" | "5m" | "1h">;
|
|
290
|
+
depth: 1 | "unspecified" | 5 | 10 | 20 | 100 | 500 | 200 | 50 | 1000;
|
|
291
291
|
chain?: {
|
|
292
292
|
baseKeyframe?: {
|
|
293
293
|
tsSec: number;
|
|
@@ -327,7 +327,7 @@ declare function createOrderbookHeatmapResponseSchema(scales: SdkScales): v.Sche
|
|
|
327
327
|
quantityMode: DecodedEnum<"close" | "peak">;
|
|
328
328
|
liveBucket?: {
|
|
329
329
|
symbolId: number;
|
|
330
|
-
interval: DecodedEnum<"
|
|
330
|
+
interval: DecodedEnum<"1s" | "1m" | "5m" | "1h">;
|
|
331
331
|
tsSec: number;
|
|
332
332
|
isFinal: boolean;
|
|
333
333
|
bids?: {
|
|
@@ -346,8 +346,8 @@ declare function createOrderbookHeatmapResponseSchema(scales: SdkScales): v.Sche
|
|
|
346
346
|
} | undefined;
|
|
347
347
|
}, {
|
|
348
348
|
symbolId: number;
|
|
349
|
-
interval: DecodedEnum<"
|
|
350
|
-
depth: 1 | 5 | 10 | 20 |
|
|
349
|
+
interval: DecodedEnum<"1s" | "1m" | "5m" | "1h">;
|
|
350
|
+
depth: 1 | "unspecified" | 5 | 10 | 20 | 100 | 500 | 200 | 50 | 1000;
|
|
351
351
|
chain: {
|
|
352
352
|
baseKeyframe: {
|
|
353
353
|
tsSec: number;
|
|
@@ -387,7 +387,7 @@ declare function createOrderbookHeatmapResponseSchema(scales: SdkScales): v.Sche
|
|
|
387
387
|
quantityMode: DecodedEnum<"close" | "peak">;
|
|
388
388
|
liveBucket: {
|
|
389
389
|
symbolId: number;
|
|
390
|
-
interval: DecodedEnum<"
|
|
390
|
+
interval: DecodedEnum<"1s" | "1m" | "5m" | "1h">;
|
|
391
391
|
tsSec: number;
|
|
392
392
|
isFinal: boolean;
|
|
393
393
|
bids: {
|
|
@@ -138,7 +138,7 @@ declare function createCreateInternalTransferResultSchema(): v.SchemaWithPipe<re
|
|
|
138
138
|
subaccountId: string | undefined;
|
|
139
139
|
smartAccountAddress: string | undefined;
|
|
140
140
|
}>]>, undefined>;
|
|
141
|
-
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
141
|
+
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "failed" | "accepted" | "rejected">]>;
|
|
142
142
|
}, undefined>, v.TransformAction<{
|
|
143
143
|
requestId: string;
|
|
144
144
|
transferId: string;
|
|
@@ -155,7 +155,7 @@ declare function createCreateInternalTransferResultSchema(): v.SchemaWithPipe<re
|
|
|
155
155
|
subaccountId: string | undefined;
|
|
156
156
|
smartAccountAddress: string | undefined;
|
|
157
157
|
} | undefined;
|
|
158
|
-
status: "unspecified" | "
|
|
158
|
+
status: "unspecified" | "failed" | "accepted" | "rejected";
|
|
159
159
|
}, {
|
|
160
160
|
acceptedAtUnixMs: number;
|
|
161
161
|
quantity: string;
|
|
@@ -169,7 +169,7 @@ declare function createCreateInternalTransferResultSchema(): v.SchemaWithPipe<re
|
|
|
169
169
|
subaccountId: string | undefined;
|
|
170
170
|
smartAccountAddress: string | undefined;
|
|
171
171
|
} | undefined;
|
|
172
|
-
status: "unspecified" | "
|
|
172
|
+
status: "unspecified" | "failed" | "accepted" | "rejected";
|
|
173
173
|
}>]>;
|
|
174
174
|
type CreateInternalTransferResult = v.InferOutput<ReturnType<typeof createCreateInternalTransferResultSchema>>;
|
|
175
175
|
//#endregion
|