@polyester/sdk 0.36.0-devnet-20261119010940 → 0.36.0-devnet-20261119181946
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 +13 -1
- package/dist/services/account-activity/account-activity.schemas.d.ts +2 -2
- package/dist/services/address-book/address-book.schemas.d.ts +2 -2
- package/dist/services/api-keys/api-keys.schemas.d.ts +6 -6
- package/dist/services/assistant/assistant-events.schemas.d.ts +23 -52
- package/dist/services/assistant/assistant-events.schemas.d.ts.map +1 -1
- package/dist/services/assistant/assistant.schemas.d.ts +1 -1
- package/dist/services/auth/account-signer-auth.d.ts.map +1 -1
- package/dist/services/auth/account-signer-auth.js +10 -2
- package/dist/services/auth/account-signer-auth.js.map +1 -1
- package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts +19 -19
- package/dist/services/changelog/changelog.schemas.d.ts +23 -18
- package/dist/services/changelog/changelog.schemas.d.ts.map +1 -1
- package/dist/services/changelog/changelog.schemas.js +6 -1
- package/dist/services/changelog/changelog.schemas.js.map +1 -1
- package/dist/services/checkpoints/checkpoints.schemas.d.ts +1 -1
- package/dist/services/heatmap/heatmap.schemas.d.ts +4 -4
- package/dist/services/internal-transfers/internal-transfers.d.ts +4 -3
- package/dist/services/internal-transfers/internal-transfers.d.ts.map +1 -1
- package/dist/services/internal-transfers/internal-transfers.js +4 -3
- package/dist/services/internal-transfers/internal-transfers.js.map +1 -1
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +64 -64
- package/dist/services/market-overview/market-overview.js +8 -1
- package/dist/services/market-overview/market-overview.js.map +1 -1
- package/dist/services/orderbook/orderbook.d.ts +1 -1
- package/dist/services/orderbook/orderbook.js +8 -2
- package/dist/services/orderbook/orderbook.js.map +1 -1
- package/dist/services/orders/orders-batch.schemas.d.ts +8 -8
- package/dist/services/orders/orders-identifiers.schemas.js +2 -2
- package/dist/services/orders/orders-identifiers.schemas.js.map +1 -1
- package/dist/services/orders/orders-input.schemas.d.ts +9 -9
- package/dist/services/orders/orders-modify.schemas.d.ts +3 -3
- package/dist/services/orders/orders-output.schemas.d.ts +6 -6
- package/dist/services/price-alerts/price-alerts.schemas.d.ts +11 -11
- package/dist/services/social-verification/social-verification.schemas.d.ts +2 -2
- package/dist/services/statement-exports/statement-exports.schemas.d.ts +6 -6
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +13 -13
- package/dist/services/system/system.schemas.d.ts +13 -13
- package/dist/services/trades/trades.schemas.d.ts +1 -1
- package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
- package/dist/services/triggers/triggers-output.schemas.d.ts +25 -25
- package/dist/services/vip/vip.schemas.d.ts +3 -3
- package/dist/shared/connect-error-mapping.js +17 -1
- package/dist/shared/connect-error-mapping.js.map +1 -1
- package/dist/shared/errors.d.ts +4 -1
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/errors.js +4 -1
- package/dist/shared/errors.js.map +1 -1
- package/dist/utils/connect-mfa-errors.d.ts +2 -2
- package/dist/utils/connect-mfa-errors.js +2 -2
- package/dist/utils/connect-mfa-errors.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market-overview.js","names":["#client","Proto.MarketOverviewService","#realtime","#scales","#marketOverviewSchema","#decodeMarkets","Proto.MarketOverviewBatchSchema"],"sources":["../../../src/services/market-overview/market-overview.ts"],"sourcesContent":["import * as Proto from \"../../gen/marketoverview/v1/marketoverview_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport { parse } from \"../../shared/validation.js\";\nimport { CatalogLookupError } from \"../../catalogs/types.js\";\nimport { isDev } from \"../../utils/is-dev.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport { snapshotThenStream } from \"../../realtime/snapshot-then-stream.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { PublicApiTransports } from \"../../shared/transports.js\";\nimport {\n CurrencyConversionConfigSchema,\n CurrencyConversionRatesSchema,\n type CurrencyConversionConfig,\n type CurrencyConversionRates,\n SpotVolumeHistoryInputSchema,\n SpotVolumeHistoryResponseSchema,\n type SpotVolumeHistoryInput,\n type SpotVolumeHistoryResponse,\n ListMarketOverviewInputSchema,\n createMarketOverviewSchema,\n type SparklineIntervalName,\n type ListMarketOverviewInput,\n type MarketOverview,\n} from \"./market-overview.schemas.js\";\n\ninterface SubscribeMarketOverviewInput extends BaseSubscribeInput<MarketOverview[]> {\n symbolIds?: number[];\n includeSparklines?: boolean;\n sparklineIntervals?: SparklineIntervalName[];\n}\n\n/**\n * Provides ticker-style per-market stats and a live merged overview stream.\n */\nexport class MarketOverviewService {\n #client: Client<typeof Proto.MarketOverviewService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n #marketOverviewSchema: ReturnType<typeof createMarketOverviewSchema>;\n\n constructor(transports: PublicApiTransports, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.MarketOverviewService, transports.publicApi);\n this.#realtime = realtime;\n this.#scales = scales;\n this.#marketOverviewSchema = createMarketOverviewSchema(scales);\n }\n\n /**\n * Returns market overview rows with last and index prices, 24h stats, top-of-book values, listing timestamp, and optional sparklines. Supports symbol ID filtering, sorting, pagination, and sparkline interval selection. A symbol ID that names no configured market is rejected as an invalid argument instead of returning an empty page.\n */\n async list(\n input: ListMarketOverviewInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<{ markets: MarketOverview[]; nextPageToken: string }> {\n const validatedInput = parse(ListMarketOverviewInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.listMarketOverview(\n validatedInput,\n toConnectCallOptions(options),\n );\n return {\n markets: this.#decodeMarkets(res.markets),\n nextPageToken: res.nextPageToken,\n };\n }\n\n /**\n * Returns 97 aligned trailing-24h USD volume samples at 15-minute intervals.\n * Empty symbolIds selects all pairs. Samples overlap and must not be summed\n * as period volume. Unavailable valuations reject the request.\n */\n async getSpotVolumeHistory(\n input: SpotVolumeHistoryInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<SpotVolumeHistoryResponse> {\n const validated = parse(SpotVolumeHistoryInputSchema, input);\n const response = await this.#client.getSpotVolumeHistory(\n validated,\n toConnectCallOptions(options),\n );\n return parse(SpotVolumeHistoryResponseSchema, response);\n }\n\n /** Returns cacheable display metadata, even before rates have been observed. */\n async getCurrencyConversionConfig(\n options?: PolyesterRequestOptions,\n ): Promise<CurrencyConversionConfig> {\n const response = await this.#client.getCurrencyConversionConfig(\n {},\n toConnectCallOptions(options),\n );\n return parse(CurrencyConversionConfigSchema, response);\n }\n\n /**\n * Returns exact decimal rates with observation times and backend staleness flags.\n * Fiat is units per USD; stablecoins are USD per unit. Unobserved rates remain absent.\n * Rejects as unavailable before any observation exists.\n */\n async getCurrencyConversionRates(\n options?: PolyesterRequestOptions,\n ): Promise<CurrencyConversionRates> {\n const response = await this.#client.getCurrencyConversionRates(\n {},\n toConnectCallOptions(options),\n );\n return parse(CurrencyConversionRatesSchema, response);\n }\n\n /**\n * Decodes market rows, skipping any whose symbolId the catalog cannot resolve\n * (unknown or disabled pairs the backend still reports). Other errors propagate.\n */\n #decodeMarkets(markets: readonly Proto.MarketOverview[]): MarketOverview[] {\n const decoded: MarketOverview[] = [];\n const skipped: number[] = [];\n for (const m of markets) {\n try {\n decoded.push(parse(this.#marketOverviewSchema, m));\n } catch (error) {\n if (\n error instanceof CatalogLookupError &&\n error.domain === \"market\" &&\n error.lookup === \"symbolId\"\n ) {\n skipped.push(m.symbolId);\n continue;\n }\n throw error;\n }\n }\n if (skipped.length > 0 && isDev()) {\n console.warn(\n `[market-overview] skipped ${skipped.length} row(s) with unknown symbolId: ${skipped.join(\", \")}`,\n );\n }\n return decoded;\n }\n\n /**\n * Subscribes to public:spot:market_overview:updates:proto, fetches an initial snapshot, buffers updates until ready, and emits the merged set of latest market rows. On reconnect it refetches the snapshot before resuming updates.\n */\n subscribe(input: SubscribeMarketOverviewInput): () => void {\n const channel = \"public:spot:market_overview:updates:proto\";\n const bySymbolId = new Map<number, MarketOverview>();\n const symbolIds = new Set(input.symbolIds);\n const includeSparklines = input.includeSparklines ?? true;\n const sparklineIntervals = input.sparklineIntervals ?? [\"24h\"];\n const listMarketOverview = this.list.bind(this);\n const parseMarkets = this.#decodeMarkets.bind(this);\n function emit(): void {\n input.onEvent(Array.from(bySymbolId.values()));\n }\n\n function matchesSymbol(market: { symbolId: number }): boolean {\n return symbolIds.size === 0 || symbolIds.has(market.symbolId);\n }\n\n function applyMarkets(markets: readonly MarketOverview[]): void {\n for (const market of markets) {\n if (matchesSymbol(market)) bySymbolId.set(market.symbolId, market);\n }\n }\n\n async function fetchSnapshot(): Promise<MarketOverview[]> {\n const result = await listMarketOverview({\n symbolIds: input.symbolIds,\n includeSparklines,\n sparklineIntervals,\n });\n return result.markets;\n }\n\n const stream = snapshotThenStream({\n realtime: this.#realtime,\n channel,\n schema: Proto.MarketOverviewBatchSchema,\n maxBufferedPublications: 2000,\n snapshotErrorLog: \"Failed to fetch market overview\",\n fetchSnapshot,\n readPublication: (batch) => batch.markets.filter(matchesSymbol),\n bufferPublicationKey: (market) => market.symbolId,\n applySnapshot: (markets, bufferedMarkets) => {\n bySymbolId.clear();\n applyMarkets(markets);\n applyMarkets(parseMarkets(bufferedMarkets));\n emit();\n },\n applyLivePublications: (markets) => {\n applyMarkets(parseMarkets(markets));\n emit();\n },\n onOpen: input.onOpen,\n onClose: input.onClose,\n onError: input.onError,\n });\n\n function dispose(): void {\n stream.unsubscribe();\n }\n\n return dispose;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAuCA,IAAa,wBAAb,MAAmC;CAC/B;CACA;CACA;CACA;CAEA,YAAY,YAAiC,UAA6B,QAAmB;EACzF,KAAKA,UAAU,aAAaC,yBAA6B,WAAW,SAAS;EAC7E,KAAKC,YAAY;EACjB,KAAKC,U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O;CACX;;;;CAKA,UAAU,OAAiD;EACvD,MAAM,UAAU;EAChB,MAAM,6BAAa,IAAI,IAA4B;EACnD,MAAM,YAAY,IAAI,IAAI,MAAM,SAAS;EACzC,MAAM,oBAAoB,MAAM,qBAAqB;EACrD,MAAM,qBAAqB,MAAM,sBAAsB,CAAC,KAAK;EAC7D,MAAM,qBAAqB,KAAK,KAAK,KAAK,IAAI;EAC9C,MAAM,eAAe,KAAKC,eAAe,KAAK,IAAI;EAClD,SAAS,OAAa;GAClB,MAAM,QAAQ,MAAM,KAAK,WAAW,OAAO,CAAC,CAAC;EACjD;EAEA,SAAS,cAAc,QAAuC;GAC1D,OAAO,UAAU,SAAS,KAAK,UAAU,IAAI,OAAO,QAAQ;EAChE;EAEA,SAAS,aAAa,SAA0C;GAC5D,KAAK,MAAM,UAAU,SACjB,IAAI,cAAc,MAAM,GAAG,WAAW,IAAI,OAAO,UAAU,MAAM;EAEzE;EAEA,eAAe,gBAA2C;GAMtD,QAAO,MALc,mBAAmB;IACpC,WAAW,MAAM;IACjB;IACA;GACJ,CAAC,EAAA,CACa;EAClB;EAEA,MAAM,SAAS,mBAAmB;GAC9B,UAAU,KAAKH;GACf;GACA,QAAQI;GACR,yBAAyB;GACzB,kBAAkB;GAClB;GACA,kBAAkB,UAAU,MAAM,QAAQ,OAAO,aAAa;GAC9D,uBAAuB,WAAW,OAAO;GACzC,gBAAgB,SAAS,oBAAoB;IACzC,WAAW,MAAM;IACjB,aAAa,OAAO;IACpB,aAAa,aAAa,eAAe,CAAC;IAC1C,KAAK;GACT;GACA,wBAAwB,YAAY;IAChC,aAAa,aAAa,OAAO,CAAC;IAClC,KAAK;GACT;GACA,QAAQ,MAAM;GACd,SAAS,MAAM;GACf,SAAS,MAAM;EACnB,CAAC;EAED,SAAS,UAAgB;GACrB,OAAO,YAAY;EACvB;EAEA,OAAO;CACX;AACJ"}
|
|
1
|
+
{"version":3,"file":"market-overview.js","names":["#client","Proto.MarketOverviewService","#realtime","#scales","#marketOverviewSchema","#decodeMarkets","Proto.MarketOverviewBatchSchema"],"sources":["../../../src/services/market-overview/market-overview.ts"],"sourcesContent":["import * as Proto from \"../../gen/marketoverview/v1/marketoverview_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport { parse } from \"../../shared/validation.js\";\nimport { CatalogLookupError } from \"../../catalogs/types.js\";\nimport { isDev } from \"../../utils/is-dev.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport { snapshotThenStream } from \"../../realtime/snapshot-then-stream.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport type { SdkScales } from \"../../shared/decimal-surface.js\";\nimport type { PublicApiTransports } from \"../../shared/transports.js\";\nimport {\n CurrencyConversionConfigSchema,\n CurrencyConversionRatesSchema,\n type CurrencyConversionConfig,\n type CurrencyConversionRates,\n SpotVolumeHistoryInputSchema,\n SpotVolumeHistoryResponseSchema,\n type SpotVolumeHistoryInput,\n type SpotVolumeHistoryResponse,\n ListMarketOverviewInputSchema,\n createMarketOverviewSchema,\n type SparklineIntervalName,\n type ListMarketOverviewInput,\n type MarketOverview,\n} from \"./market-overview.schemas.js\";\n\ninterface SubscribeMarketOverviewInput extends BaseSubscribeInput<MarketOverview[]> {\n symbolIds?: number[];\n includeSparklines?: boolean;\n sparklineIntervals?: SparklineIntervalName[];\n}\n\n/**\n * Provides ticker-style per-market stats and a live merged overview stream.\n */\nexport class MarketOverviewService {\n #client: Client<typeof Proto.MarketOverviewService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n #marketOverviewSchema: ReturnType<typeof createMarketOverviewSchema>;\n\n constructor(transports: PublicApiTransports, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.MarketOverviewService, transports.publicApi);\n this.#realtime = realtime;\n this.#scales = scales;\n this.#marketOverviewSchema = createMarketOverviewSchema(scales);\n }\n\n /**\n * Returns market overview rows with last and index prices, 24h stats, top-of-book values, listing timestamp, and optional sparklines. Supports symbol ID filtering, sorting, pagination, and sparkline interval selection. A symbol ID that names no configured market is rejected as an invalid argument instead of returning an empty page.\n */\n async list(\n input: ListMarketOverviewInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<{ markets: MarketOverview[]; nextPageToken: string }> {\n const validatedInput = parse(ListMarketOverviewInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.listMarketOverview(\n validatedInput,\n toConnectCallOptions(options),\n );\n return {\n markets: this.#decodeMarkets(res.markets),\n nextPageToken: res.nextPageToken,\n };\n }\n\n /**\n * Returns 97 aligned trailing-24h USD volume samples at 15-minute intervals.\n * Empty symbolIds selects all pairs. Samples overlap and must not be summed\n * as period volume. Unavailable valuations reject the request.\n */\n async getSpotVolumeHistory(\n input: SpotVolumeHistoryInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<SpotVolumeHistoryResponse> {\n const validated = parse(SpotVolumeHistoryInputSchema, input);\n const response = await this.#client.getSpotVolumeHistory(\n validated,\n toConnectCallOptions(options),\n );\n return parse(SpotVolumeHistoryResponseSchema, response);\n }\n\n /** Returns cacheable display metadata, even before rates have been observed. */\n async getCurrencyConversionConfig(\n options?: PolyesterRequestOptions,\n ): Promise<CurrencyConversionConfig> {\n const response = await this.#client.getCurrencyConversionConfig(\n {},\n toConnectCallOptions(options),\n );\n return parse(CurrencyConversionConfigSchema, response);\n }\n\n /**\n * Returns exact decimal rates with observation times and backend staleness flags.\n * Fiat is units per USD; stablecoins are USD per unit. Unobserved rates remain absent.\n * Rejects as unavailable before any observation exists.\n */\n async getCurrencyConversionRates(\n options?: PolyesterRequestOptions,\n ): Promise<CurrencyConversionRates> {\n const response = await this.#client.getCurrencyConversionRates(\n {},\n toConnectCallOptions(options),\n );\n return parse(CurrencyConversionRatesSchema, response);\n }\n\n /**\n * Decodes market rows, skipping any whose symbolId the catalog cannot resolve\n * (unknown or disabled pairs the backend still reports). Other errors propagate.\n */\n #decodeMarkets(markets: readonly Proto.MarketOverview[]): MarketOverview[] {\n const decoded: MarketOverview[] = [];\n const skipped: number[] = [];\n for (const m of markets) {\n try {\n decoded.push(parse(this.#marketOverviewSchema, m));\n } catch (error) {\n if (\n error instanceof CatalogLookupError &&\n error.domain === \"market\" &&\n error.lookup === \"symbolId\"\n ) {\n skipped.push(m.symbolId);\n continue;\n }\n throw error;\n }\n }\n if (skipped.length > 0 && isDev()) {\n console.warn(\n `[market-overview] skipped ${skipped.length} row(s) with unknown symbolId: ${skipped.join(\", \")}`,\n );\n }\n return decoded;\n }\n\n /**\n * Subscribes to public:spot:market_overview:updates:proto, fetches an initial snapshot, buffers updates until ready, and emits the merged set of latest market rows. On reconnect it refetches the snapshot before resuming updates.\n */\n subscribe(input: SubscribeMarketOverviewInput): () => void {\n const channel = \"public:spot:market_overview:updates:proto\";\n const bySymbolId = new Map<number, MarketOverview>();\n const symbolIds = new Set(input.symbolIds);\n const includeSparklines = input.includeSparklines ?? true;\n const sparklineIntervals = input.sparklineIntervals ?? [\"24h\"];\n const listMarketOverview = this.list.bind(this);\n const parseMarkets = this.#decodeMarkets.bind(this);\n function emit(): void {\n input.onEvent(Array.from(bySymbolId.values()));\n }\n\n function matchesSymbol(market: { symbolId: number }): boolean {\n return symbolIds.size === 0 || symbolIds.has(market.symbolId);\n }\n\n function applyMarkets(markets: readonly MarketOverview[]): void {\n for (const market of markets) {\n if (!matchesSymbol(market)) continue;\n // The live channel carries no sparklines; keep the snapshot's.\n const sparklines = bySymbolId.get(market.symbolId)?.sparklines;\n bySymbolId.set(\n market.symbolId,\n market.sparklines.length === 0 && sparklines\n ? { ...market, sparklines }\n : market,\n );\n }\n }\n\n async function fetchSnapshot(): Promise<MarketOverview[]> {\n const result = await listMarketOverview({\n symbolIds: input.symbolIds,\n includeSparklines,\n sparklineIntervals,\n });\n return result.markets;\n }\n\n const stream = snapshotThenStream({\n realtime: this.#realtime,\n channel,\n schema: Proto.MarketOverviewBatchSchema,\n maxBufferedPublications: 2000,\n snapshotErrorLog: \"Failed to fetch market overview\",\n fetchSnapshot,\n readPublication: (batch) => batch.markets.filter(matchesSymbol),\n bufferPublicationKey: (market) => market.symbolId,\n applySnapshot: (markets, bufferedMarkets) => {\n bySymbolId.clear();\n applyMarkets(markets);\n applyMarkets(parseMarkets(bufferedMarkets));\n emit();\n },\n applyLivePublications: (markets) => {\n applyMarkets(parseMarkets(markets));\n emit();\n },\n onOpen: input.onOpen,\n onClose: input.onClose,\n onError: input.onError,\n });\n\n function dispose(): void {\n stream.unsubscribe();\n }\n\n return dispose;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAuCA,IAAa,wBAAb,MAAmC;CAC/B;CACA;CACA;CACA;CAEA,YAAY,YAAiC,UAA6B,QAAmB;EACzF,KAAKA,UAAU,aAAaC,yBAA6B,WAAW,SAAS;EAC7E,KAAKC,YAAY;EACjB,KAAKC,UAAU;EACf,KAAKC,wBAAwB,2BAA2B,MAAM;CAClE;;;;CAKA,MAAM,KACF,QAAiC,CAAC,GAClC,SAC6D;EAC7D,MAAM,iBAAiB,MAAM,+BAA+B,KAAK;EACjE,MAAM,KAAKD,QAAQ,MAAM;EACzB,MAAM,MAAM,MAAM,KAAKH,QAAQ,mBAC3B,gBACA,qBAAqB,OAAO,CAChC;EACA,OAAO;GACH,SAAS,KAAKK,eAAe,IAAI,OAAO;GACxC,eAAe,IAAI;EACvB;CACJ;;;;;;CAOA,MAAM,qBACF,QAAgC,CAAC,GACjC,SACkC;EAClC,MAAM,YAAY,MAAM,8BAA8B,KAAK;EAC3D,MAAM,WAAW,MAAM,KAAKL,QAAQ,qBAChC,WACA,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,iCAAiC,QAAQ;CAC1D;;CAGA,MAAM,4BACF,SACiC;EACjC,MAAM,WAAW,MAAM,KAAKA,QAAQ,4BAChC,CAAC,GACD,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,gCAAgC,QAAQ;CACzD;;;;;;CAOA,MAAM,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,GAAG;KAAQ;IAAW,IACxB,MACV;GACJ;EACJ;EAEA,eAAe,gBAA2C;GAMtD,QAAO,MALc,mBAAmB;IACpC,WAAW,MAAM;IACjB;IACA;GACJ,CAAC,EAAA,CACa;EAClB;EAEA,MAAM,SAAS,mBAAmB;GAC9B,UAAU,KAAKH;GACf;GACA,QAAQI;GACR,yBAAyB;GACzB,kBAAkB;GAClB;GACA,kBAAkB,UAAU,MAAM,QAAQ,OAAO,aAAa;GAC9D,uBAAuB,WAAW,OAAO;GACzC,gBAAgB,SAAS,oBAAoB;IACzC,WAAW,MAAM;IACjB,aAAa,OAAO;IACpB,aAAa,aAAa,eAAe,CAAC;IAC1C,KAAK;GACT;GACA,wBAAwB,YAAY;IAChC,aAAa,aAAa,OAAO,CAAC;IAClC,KAAK;GACT;GACA,QAAQ,MAAM;GACd,SAAS,MAAM;GACf,SAAS,MAAM;EACnB,CAAC;EAED,SAAS,UAAgB;GACrB,OAAO,YAAY;EACvB;EAEA,OAAO;CACX;AACJ"}
|
|
@@ -33,7 +33,7 @@ declare class OrderbookService {
|
|
|
33
33
|
*/
|
|
34
34
|
subscribe(input: SubscribeOrderbookInput): () => void;
|
|
35
35
|
/**
|
|
36
|
-
* Creates a stateful order book subscription that first fetches a snapshot, buffers proto deltas from public:spot:orderbook:deltas:depth:{depth}:{symbolId}:proto, applies each delta only when it chains onto the book, and refetches on reconnects. After a sequence gap the book holds its last state until the server's next reset, sent about every 30 seconds and after gaps. A snapshot whose book is not available fails with ServiceUnavailableError through onError and is retried
|
|
36
|
+
* Creates a stateful order book subscription that first fetches a snapshot, buffers proto deltas from public:spot:orderbook:deltas:depth:{depth}:{symbolId}:proto, applies each delta only when it chains onto the book, and refetches on reconnects. After a sequence gap the book holds its last state until the server's next reset, sent about every 30 seconds and after gaps. A snapshot whose book is not available fails with ServiceUnavailableError through onError and is retried. A snapshot error that is not retried (such as a 500) leaves the book to the server's next reset, which rebuilds it. The snapshot is fetched once the channel opens, so a socket that cannot connect reports a retryable RealtimeError with type "transport" through onError instead, once per outage; onOpen follows when it recovers. The returned handle can unsubscribe or change local price bucket aggregation without reconnecting.
|
|
37
37
|
*
|
|
38
38
|
* `depth` above 500 throws ValidationError, since only REST serves 1000 and 5000; other depths ride the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.
|
|
39
39
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServiceUnavailableError, ValidationError } from "../../shared/errors.js";
|
|
1
|
+
import { PolyesterError, ServiceUnavailableError, ValidationError } from "../../shared/errors.js";
|
|
2
2
|
import { parse } from "../../shared/validation.js";
|
|
3
3
|
import { toConnectCallOptions } from "../../shared/request-options.js";
|
|
4
4
|
import { publicationHandlerErrorContext } from "../../shared/subscription-errors.js";
|
|
@@ -54,7 +54,7 @@ var OrderbookService = class {
|
|
|
54
54
|
return this.createSubscription(input).unsubscribe;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* Creates a stateful order book subscription that first fetches a snapshot, buffers proto deltas from public:spot:orderbook:deltas:depth:{depth}:{symbolId}:proto, applies each delta only when it chains onto the book, and refetches on reconnects. After a sequence gap the book holds its last state until the server's next reset, sent about every 30 seconds and after gaps. A snapshot whose book is not available fails with ServiceUnavailableError through onError and is retried
|
|
57
|
+
* Creates a stateful order book subscription that first fetches a snapshot, buffers proto deltas from public:spot:orderbook:deltas:depth:{depth}:{symbolId}:proto, applies each delta only when it chains onto the book, and refetches on reconnects. After a sequence gap the book holds its last state until the server's next reset, sent about every 30 seconds and after gaps. A snapshot whose book is not available fails with ServiceUnavailableError through onError and is retried. A snapshot error that is not retried (such as a 500) leaves the book to the server's next reset, which rebuilds it. The snapshot is fetched once the channel opens, so a socket that cannot connect reports a retryable RealtimeError with type "transport" through onError instead, once per outage; onOpen follows when it recovers. The returned handle can unsubscribe or change local price bucket aggregation without reconnecting.
|
|
58
58
|
*
|
|
59
59
|
* `depth` above 500 throws ValidationError, since only REST serves 1000 and 5000; other depths ride the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.
|
|
60
60
|
*
|
|
@@ -191,6 +191,12 @@ var OrderbookService = class {
|
|
|
191
191
|
delayMs: 1e3,
|
|
192
192
|
maxDelayMs: 8e3
|
|
193
193
|
},
|
|
194
|
+
snapshotFailureMode: (error) => {
|
|
195
|
+
if (!(error instanceof PolyesterError) || error.retryable) return "wait";
|
|
196
|
+
currentBookSeq = 0n;
|
|
197
|
+
awaitingReset = true;
|
|
198
|
+
return "live";
|
|
199
|
+
},
|
|
194
200
|
fetchSnapshot: inputServiceFetch,
|
|
195
201
|
readPublication: (delta) => [delta],
|
|
196
202
|
applySnapshot: (snapshot, bufferedDeltas) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orderbook.js","names":["#client","Proto.OrderbookService","#realtime","#scales","Proto.GetOrderBookResponseSchema","Proto.OrderBookDeltaSchema"],"sources":["../../../src/services/orderbook/orderbook.ts"],"sourcesContent":["import { create } from \"@bufbuild/protobuf\";\nimport * as Proto from \"../../gen/orderbook/v1/orderbook_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport { publicationHandlerErrorContext } from \"../../shared/subscription-errors.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport {\n snapshotThenStream,\n type SnapshotThenStreamSubscription,\n} from \"../../realtime/snapshot-then-stream.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { decimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n formatOrderbookLevel,\n GetOrderbookInputSchema,\n createOrderbookDataSchema,\n type OrderbookLevel,\n type OrderbookData,\n} from \"./orderbook.schemas.js\";\nimport { orderbookWsChannelDepth } from \"./orderbook.codecs.js\";\nimport { DepthTierCodec } from \"../../shared/depth-tier.js\";\nimport { isResourceNotFoundError } from \"../../utils/errors.js\";\nimport { ServiceUnavailableError, ValidationError } from \"../../shared/errors.js\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PublicApiTransports } from \"../../shared/transports.js\";\n\ninterface SubscribeOrderbookInput extends BaseSubscribeInput<OrderbookData> {\n symbolId: number;\n depth?: number;\n bucket?: string | null;\n}\n\nexport interface OrderbookStreamHandlers extends BaseSubscribeInput<OrderbookData> {}\n\nexport interface OrderbookSubscription {\n unsubscribe: () => void;\n setBucket: (bucket: string | null | undefined) => void;\n}\n\nexport interface CreateOrderbookSubscriptionInput\n extends\n OrderbookStreamHandlers,\n Pick<SubscribeOrderbookInput, \"symbolId\" | \"depth\" | \"bucket\"> {}\n\ntype BookSide = Map<bigint, bigint>;\n\n/**\n * Reads spot order book snapshots and maintains realtime local order book state from public delta channels.\n */\nexport class OrderbookService {\n #client: Client<typeof Proto.OrderbookService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n\n constructor(transports: PublicApiTransports, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.OrderbookService, transports.publicApi);\n this.#realtime = realtime;\n this.#scales = scales;\n }\n\n /**\n * Fetches a spot order book depth snapshot for a symbol ID and depth tier (`DEPTH_TIER_VALUES`, default 50), returning best bids and asks with the backend book sequence.\n * When `available` is false the book is being built or was invalidated: its levels are unknown, not empty, so read it again later instead of treating empty sides as no liquidity.\n */\n async get(\n input: v.InferInput<typeof GetOrderbookInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<OrderbookData> {\n const validated = parse(GetOrderbookInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getOrderBook(\n { symbolId: validated.symbolId, depth: DepthTierCodec.inputToProto[validated.depth] },\n toConnectCallOptions(options),\n );\n // Servers that predate the served tier leave it unset; they served the requested one.\n const served = DepthTierCodec.protoToOutput[res.depth];\n return parse(createOrderbookDataSchema(this.#scales, validated.symbolId), {\n symbolId: res.symbolId,\n depth: typeof served === \"number\" ? served : validated.depth,\n bookSeq: res.bookSeq,\n bookEpoch: res.bookEpoch,\n available: isBookAvailable(res),\n bids: res.bids,\n asks: res.asks,\n ts: res.ts,\n });\n }\n\n /**\n * Subscribes to the managed order book stream for a symbol ID and forwards reconstructed snapshots to onEvent. This is a convenience wrapper around createSubscription().unsubscribe.\n */\n subscribe(input: SubscribeOrderbookInput): () => void {\n return this.createSubscription(input).unsubscribe;\n }\n\n /**\n * Creates a stateful order book subscription that first fetches a snapshot, buffers proto deltas from public:spot:orderbook:deltas:depth:{depth}:{symbolId}:proto, applies each delta only when it chains onto the book, and refetches on reconnects. After a sequence gap the book holds its last state until the server's next reset, sent about every 30 seconds and after gaps. A snapshot whose book is not available fails with ServiceUnavailableError through onError and is retried; no event is emitted until a snapshot is available. The snapshot is fetched once the channel opens, so a socket that cannot connect reports a retryable RealtimeError with type \"transport\" through onError instead, once per outage; onOpen follows when it recovers. The returned handle can unsubscribe or change local price bucket aggregation without reconnecting.\n *\n * `depth` above 500 throws ValidationError, since only REST serves 1000 and 5000; other depths ride the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.\n *\n * A refetched snapshot from an older `bookEpoch` than the book's is discarded and retried.\n *\n * Refetching is driven by reconnect events only. A feed that stays subscribed but stops publishing is indistinguishable from a quiet market, so it does not trigger onError or a refetch. Callers that must detect a stalled book need their own idle watchdog plus a REST refetch.\n */\n createSubscription(input: CreateOrderbookSubscriptionInput): OrderbookSubscription {\n const { symbolId, depth } = parse(GetOrderbookInputSchema, {\n symbolId: input.symbolId,\n depth: input.depth,\n });\n if (depth > 500) {\n throw new ValidationError(\n `depth must be at most 500 for a managed order book, got ${depth}`,\n );\n }\n const channelDepth = orderbookWsChannelDepth(depth);\n const channel = `public:spot:orderbook:deltas:depth:${channelDepth}:${symbolId}:proto`;\n\n const client = this.#client;\n const scales = this.#scales;\n let bidsMap: BookSide = new Map();\n let asksMap: BookSide = new Map();\n let currentBookSeq = 0n;\n let currentBookEpoch = 0n;\n // Set when a delta does not chain onto the book; only the next reset recovers it.\n let awaitingReset = false;\n let bucketTicks: bigint | null = null;\n let stream: SnapshotThenStreamSubscription | undefined;\n\n function levelsToMap(levels: Proto.PriceLevel[] | undefined): BookSide {\n const map: BookSide = new Map();\n for (const l of levels ?? []) {\n if (l.qtyScaled === 0n) continue;\n map.set(l.priceTicks, l.qtyScaled);\n }\n return map;\n }\n\n function applySideDelta(map: BookSide, levels: Proto.PriceLevel[] | undefined): void {\n for (const l of levels ?? []) {\n if (l.qtyScaled === 0n) map.delete(l.priceTicks);\n else map.set(l.priceTicks, l.qtyScaled);\n }\n }\n\n function sideToUI(map: BookSide, side: \"bids\" | \"asks\", limit: number): OrderbookLevel[] {\n const entries = Array.from(map.entries());\n entries.sort(([pa], [pb]) => {\n if (pa === pb) return 0;\n return side === \"bids\" ? (pa > pb ? -1 : 1) : pa < pb ? -1 : 1;\n });\n return entries\n .slice(0, limit)\n .map(([priceTicks, qtyScaled]) =>\n formatOrderbookLevel({ priceTicks, qtyScaled }, scales, symbolId),\n );\n }\n\n function sideToUIBucketed(\n map: BookSide,\n side: \"bids\" | \"asks\",\n limit: number,\n bucket: bigint | null,\n ): OrderbookLevel[] {\n if (!bucket || bucket <= 0n) return sideToUI(map, side, limit);\n\n const agg: BookSide = new Map();\n for (const [priceTicks, qtyScaled] of map.entries()) {\n if (qtyScaled <= 0n) continue;\n const bucketFloor = (priceTicks / bucket) * bucket;\n const bucketPrice =\n side === \"asks\" && bucketFloor !== priceTicks\n ? bucketFloor + bucket\n : bucketFloor;\n agg.set(bucketPrice, (agg.get(bucketPrice) ?? 0n) + qtyScaled);\n }\n return sideToUI(agg, side, limit);\n }\n\n function emit(): void {\n try {\n input.onEvent({\n symbolId,\n depth,\n bookSeq: currentBookSeq.toString(),\n bookEpoch: currentBookEpoch.toString(),\n available: true,\n bids: sideToUIBucketed(bidsMap, \"bids\", depth, bucketTicks),\n asks: sideToUIBucketed(asksMap, \"asks\", depth, bucketTicks),\n });\n } catch (error) {\n input.onError?.(publicationHandlerErrorContext(channel, error));\n }\n }\n\n function setBucket(bucket: string | null | undefined): void {\n if (!bucket) {\n bucketTicks = null;\n } else {\n try {\n bucketTicks = decimalInputToScaled(\"bucket\", bucket, scales.price());\n } catch {\n bucketTicks = null;\n }\n }\n if (stream?.isReady()) emit();\n }\n\n async function inputServiceFetch(): Promise<Proto.GetOrderBookResponse> {\n await scales.ready();\n let res: Proto.GetOrderBookResponse;\n try {\n res = await client.getOrderBook({\n symbolId,\n depth: DepthTierCodec.inputToProto[channelDepth],\n });\n } catch (error: unknown) {\n if (!isResourceNotFoundError(error)) throw error;\n\n return create(Proto.GetOrderBookResponseSchema, {\n symbolId,\n bookSeq: 0n,\n available: true,\n bids: [],\n asks: [],\n });\n }\n // An unavailable book's levels are unknown, not empty: fail the snapshot so it is retried.\n if (!isBookAvailable(res)) {\n throw new ServiceUnavailableError(\n `Order book for symbol ${symbolId} is not available yet`,\n );\n }\n if (res.bookEpoch < currentBookEpoch) {\n throw new ServiceUnavailableError(\n `Order book snapshot for symbol ${symbolId} is from an older epoch`,\n );\n }\n return res;\n }\n\n /**\n * Applies a delta only when it chains onto the current book (`bookSeqStart` equals the\n * last applied `bookSeqEnd`) or is a reset. A delta that does not chain leaves the book\n * waiting for the next reset, which the server sends periodically and after a gap.\n */\n function handleDelta(delta: Proto.OrderBookDelta): void {\n if (delta.bookSeqEnd <= currentBookSeq) return;\n\n if (delta.reset) {\n bidsMap.clear();\n asksMap.clear();\n awaitingReset = false;\n } else if (awaitingReset || delta.bookSeqStart !== currentBookSeq) {\n awaitingReset = true;\n return;\n }\n\n applySideDelta(bidsMap, delta.bids);\n applySideDelta(asksMap, delta.asks);\n\n currentBookSeq = delta.bookSeqEnd;\n emit();\n }\n\n setBucket(input.bucket);\n stream = snapshotThenStream({\n realtime: this.#realtime,\n channel,\n schema: Proto.OrderBookDeltaSchema,\n maxBufferedPublications: 200,\n snapshotErrorLog: \"Failed to fetch orderbook\",\n // GetOrderBook answers unavailable while the book is (re)built; keep asking until it is ready.\n snapshotRetry: {\n maxAttempts: Number.POSITIVE_INFINITY,\n delayMs: 1_000,\n maxDelayMs: 8_000,\n },\n fetchSnapshot: inputServiceFetch,\n readPublication: (delta) => [delta],\n applySnapshot: (snapshot, bufferedDeltas) => {\n bidsMap = levelsToMap(snapshot.bids);\n asksMap = levelsToMap(snapshot.asks);\n currentBookSeq = snapshot.bookSeq;\n currentBookEpoch = snapshot.bookEpoch;\n awaitingReset = false;\n emit();\n for (const delta of bufferedDeltas) {\n if (stream?.isDisposed()) return;\n handleDelta(delta);\n }\n },\n applyLivePublications: (deltas) => {\n for (const delta of deltas) {\n if (stream?.isDisposed()) return;\n handleDelta(delta);\n }\n },\n onOpen: input.onOpen,\n onClose: input.onClose,\n onError: input.onError,\n });\n\n function dispose(): void {\n stream?.unsubscribe();\n }\n\n return { unsubscribe: dispose, setBucket };\n }\n}\n\n/**\n * Whether a snapshot's levels are the book. A snapshot carrying levels is current even with\n * `available` false, which is how servers that predate the field encode every snapshot.\n */\nfunction isBookAvailable(res: Proto.GetOrderBookResponse): boolean {\n return res.available || res.bids.length > 0 || res.asks.length > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqDA,IAAa,mBAAb,MAA8B;CAC1B;CACA;CACA;CAEA,YAAY,YAAiC,UAA6B,QAAmB;EACzF,KAAKA,UAAU,aAAaC,oBAAwB,WAAW,SAAS;EACxE,KAAKC,YAAY;EACjB,KAAKC,UAAU;CACnB;;;;;CAMA,MAAM,IACF,OACA,SACsB;EACtB,MAAM,YAAY,MAAM,yBAAyB,KAAK;EACtD,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,MAAM,MAAM,KAAKH,QAAQ,aAC3B;GAAE,UAAU,UAAU;GAAU,OAAO,eAAe,aAAa,UAAU;EAAO,GACpF,qBAAqB,OAAO,CAChC;EAEA,MAAM,SAAS,eAAe,cAAc,IAAI;EAChD,OAAO,MAAM,0B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AAM,SAAS,QAAQ;KACxB,IAAI,QAAQ,WAAW,GAAG;KAC1B,YAAY,KAAK;IACrB;GACJ;GACA,QAAQ,MAAM;GACd,SAAS,MAAM;GACf,SAAS,MAAM;EACnB,CAAC;EAED,SAAS,UAAgB;GACrB,QAAQ,YAAY;EACxB;EAEA,OAAO;GAAE,aAAa;GAAS;EAAU;CAC7C;AACJ;;;;;AAMA,SAAS,gBAAgB,KAA0C;CAC/D,OAAO,IAAI,aAAa,IAAI,KAAK,SAAS,KAAK,IAAI,KAAK,SAAS;AACrE"}
|
|
1
|
+
{"version":3,"file":"orderbook.js","names":["#client","Proto.OrderbookService","#realtime","#scales","Proto.GetOrderBookResponseSchema","Proto.OrderBookDeltaSchema"],"sources":["../../../src/services/orderbook/orderbook.ts"],"sourcesContent":["import { create } from \"@bufbuild/protobuf\";\nimport * as Proto from \"../../gen/orderbook/v1/orderbook_pb.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport { publicationHandlerErrorContext } from \"../../shared/subscription-errors.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport {\n snapshotThenStream,\n type SnapshotThenStreamSubscription,\n} from \"../../realtime/snapshot-then-stream.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport {\n toConnectCallOptions,\n type PolyesterRequestOptions,\n} from \"../../shared/request-options.js\";\nimport { decimalInputToScaled, type SdkScales } from \"../../shared/decimal-surface.js\";\nimport {\n formatOrderbookLevel,\n GetOrderbookInputSchema,\n createOrderbookDataSchema,\n type OrderbookLevel,\n type OrderbookData,\n} from \"./orderbook.schemas.js\";\nimport { orderbookWsChannelDepth } from \"./orderbook.codecs.js\";\nimport { DepthTierCodec } from \"../../shared/depth-tier.js\";\nimport { isResourceNotFoundError } from \"../../utils/errors.js\";\nimport { PolyesterError, ServiceUnavailableError, ValidationError } from \"../../shared/errors.js\";\nimport type * as v from \"valibot\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { PublicApiTransports } from \"../../shared/transports.js\";\n\ninterface SubscribeOrderbookInput extends BaseSubscribeInput<OrderbookData> {\n symbolId: number;\n depth?: number;\n bucket?: string | null;\n}\n\nexport interface OrderbookStreamHandlers extends BaseSubscribeInput<OrderbookData> {}\n\nexport interface OrderbookSubscription {\n unsubscribe: () => void;\n setBucket: (bucket: string | null | undefined) => void;\n}\n\nexport interface CreateOrderbookSubscriptionInput\n extends\n OrderbookStreamHandlers,\n Pick<SubscribeOrderbookInput, \"symbolId\" | \"depth\" | \"bucket\"> {}\n\ntype BookSide = Map<bigint, bigint>;\n\n/**\n * Reads spot order book snapshots and maintains realtime local order book state from public delta channels.\n */\nexport class OrderbookService {\n #client: Client<typeof Proto.OrderbookService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n\n constructor(transports: PublicApiTransports, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.OrderbookService, transports.publicApi);\n this.#realtime = realtime;\n this.#scales = scales;\n }\n\n /**\n * Fetches a spot order book depth snapshot for a symbol ID and depth tier (`DEPTH_TIER_VALUES`, default 50), returning best bids and asks with the backend book sequence.\n * When `available` is false the book is being built or was invalidated: its levels are unknown, not empty, so read it again later instead of treating empty sides as no liquidity.\n */\n async get(\n input: v.InferInput<typeof GetOrderbookInputSchema>,\n options?: PolyesterRequestOptions,\n ): Promise<OrderbookData> {\n const validated = parse(GetOrderbookInputSchema, input);\n await this.#scales.ready();\n const res = await this.#client.getOrderBook(\n { symbolId: validated.symbolId, depth: DepthTierCodec.inputToProto[validated.depth] },\n toConnectCallOptions(options),\n );\n // Servers that predate the served tier leave it unset; they served the requested one.\n const served = DepthTierCodec.protoToOutput[res.depth];\n return parse(createOrderbookDataSchema(this.#scales, validated.symbolId), {\n symbolId: res.symbolId,\n depth: typeof served === \"number\" ? served : validated.depth,\n bookSeq: res.bookSeq,\n bookEpoch: res.bookEpoch,\n available: isBookAvailable(res),\n bids: res.bids,\n asks: res.asks,\n ts: res.ts,\n });\n }\n\n /**\n * Subscribes to the managed order book stream for a symbol ID and forwards reconstructed snapshots to onEvent. This is a convenience wrapper around createSubscription().unsubscribe.\n */\n subscribe(input: SubscribeOrderbookInput): () => void {\n return this.createSubscription(input).unsubscribe;\n }\n\n /**\n * Creates a stateful order book subscription that first fetches a snapshot, buffers proto deltas from public:spot:orderbook:deltas:depth:{depth}:{symbolId}:proto, applies each delta only when it chains onto the book, and refetches on reconnects. After a sequence gap the book holds its last state until the server's next reset, sent about every 30 seconds and after gaps. A snapshot whose book is not available fails with ServiceUnavailableError through onError and is retried. A snapshot error that is not retried (such as a 500) leaves the book to the server's next reset, which rebuilds it. The snapshot is fetched once the channel opens, so a socket that cannot connect reports a retryable RealtimeError with type \"transport\" through onError instead, once per outage; onOpen follows when it recovers. The returned handle can unsubscribe or change local price bucket aggregation without reconnecting.\n *\n * `depth` above 500 throws ValidationError, since only REST serves 1000 and 5000; other depths ride the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.\n *\n * A refetched snapshot from an older `bookEpoch` than the book's is discarded and retried.\n *\n * Refetching is driven by reconnect events only. A feed that stays subscribed but stops publishing is indistinguishable from a quiet market, so it does not trigger onError or a refetch. Callers that must detect a stalled book need their own idle watchdog plus a REST refetch.\n */\n createSubscription(input: CreateOrderbookSubscriptionInput): OrderbookSubscription {\n const { symbolId, depth } = parse(GetOrderbookInputSchema, {\n symbolId: input.symbolId,\n depth: input.depth,\n });\n if (depth > 500) {\n throw new ValidationError(\n `depth must be at most 500 for a managed order book, got ${depth}`,\n );\n }\n const channelDepth = orderbookWsChannelDepth(depth);\n const channel = `public:spot:orderbook:deltas:depth:${channelDepth}:${symbolId}:proto`;\n\n const client = this.#client;\n const scales = this.#scales;\n let bidsMap: BookSide = new Map();\n let asksMap: BookSide = new Map();\n let currentBookSeq = 0n;\n let currentBookEpoch = 0n;\n // Set when a delta does not chain onto the book; only the next reset recovers it.\n let awaitingReset = false;\n let bucketTicks: bigint | null = null;\n let stream: SnapshotThenStreamSubscription | undefined;\n\n function levelsToMap(levels: Proto.PriceLevel[] | undefined): BookSide {\n const map: BookSide = new Map();\n for (const l of levels ?? []) {\n if (l.qtyScaled === 0n) continue;\n map.set(l.priceTicks, l.qtyScaled);\n }\n return map;\n }\n\n function applySideDelta(map: BookSide, levels: Proto.PriceLevel[] | undefined): void {\n for (const l of levels ?? []) {\n if (l.qtyScaled === 0n) map.delete(l.priceTicks);\n else map.set(l.priceTicks, l.qtyScaled);\n }\n }\n\n function sideToUI(map: BookSide, side: \"bids\" | \"asks\", limit: number): OrderbookLevel[] {\n const entries = Array.from(map.entries());\n entries.sort(([pa], [pb]) => {\n if (pa === pb) return 0;\n return side === \"bids\" ? (pa > pb ? -1 : 1) : pa < pb ? -1 : 1;\n });\n return entries\n .slice(0, limit)\n .map(([priceTicks, qtyScaled]) =>\n formatOrderbookLevel({ priceTicks, qtyScaled }, scales, symbolId),\n );\n }\n\n function sideToUIBucketed(\n map: BookSide,\n side: \"bids\" | \"asks\",\n limit: number,\n bucket: bigint | null,\n ): OrderbookLevel[] {\n if (!bucket || bucket <= 0n) return sideToUI(map, side, limit);\n\n const agg: BookSide = new Map();\n for (const [priceTicks, qtyScaled] of map.entries()) {\n if (qtyScaled <= 0n) continue;\n const bucketFloor = (priceTicks / bucket) * bucket;\n const bucketPrice =\n side === \"asks\" && bucketFloor !== priceTicks\n ? bucketFloor + bucket\n : bucketFloor;\n agg.set(bucketPrice, (agg.get(bucketPrice) ?? 0n) + qtyScaled);\n }\n return sideToUI(agg, side, limit);\n }\n\n function emit(): void {\n try {\n input.onEvent({\n symbolId,\n depth,\n bookSeq: currentBookSeq.toString(),\n bookEpoch: currentBookEpoch.toString(),\n available: true,\n bids: sideToUIBucketed(bidsMap, \"bids\", depth, bucketTicks),\n asks: sideToUIBucketed(asksMap, \"asks\", depth, bucketTicks),\n });\n } catch (error) {\n input.onError?.(publicationHandlerErrorContext(channel, error));\n }\n }\n\n function setBucket(bucket: string | null | undefined): void {\n if (!bucket) {\n bucketTicks = null;\n } else {\n try {\n bucketTicks = decimalInputToScaled(\"bucket\", bucket, scales.price());\n } catch {\n bucketTicks = null;\n }\n }\n if (stream?.isReady()) emit();\n }\n\n async function inputServiceFetch(): Promise<Proto.GetOrderBookResponse> {\n await scales.ready();\n let res: Proto.GetOrderBookResponse;\n try {\n res = await client.getOrderBook({\n symbolId,\n depth: DepthTierCodec.inputToProto[channelDepth],\n });\n } catch (error: unknown) {\n if (!isResourceNotFoundError(error)) throw error;\n\n return create(Proto.GetOrderBookResponseSchema, {\n symbolId,\n bookSeq: 0n,\n available: true,\n bids: [],\n asks: [],\n });\n }\n // An unavailable book's levels are unknown, not empty: fail the snapshot so it is retried.\n if (!isBookAvailable(res)) {\n throw new ServiceUnavailableError(\n `Order book for symbol ${symbolId} is not available yet`,\n );\n }\n if (res.bookEpoch < currentBookEpoch) {\n throw new ServiceUnavailableError(\n `Order book snapshot for symbol ${symbolId} is from an older epoch`,\n );\n }\n return res;\n }\n\n /**\n * Applies a delta only when it chains onto the current book (`bookSeqStart` equals the\n * last applied `bookSeqEnd`) or is a reset. A delta that does not chain leaves the book\n * waiting for the next reset, which the server sends periodically and after a gap.\n */\n function handleDelta(delta: Proto.OrderBookDelta): void {\n if (delta.bookSeqEnd <= currentBookSeq) return;\n\n if (delta.reset) {\n bidsMap.clear();\n asksMap.clear();\n awaitingReset = false;\n } else if (awaitingReset || delta.bookSeqStart !== currentBookSeq) {\n awaitingReset = true;\n return;\n }\n\n applySideDelta(bidsMap, delta.bids);\n applySideDelta(asksMap, delta.asks);\n\n currentBookSeq = delta.bookSeqEnd;\n emit();\n }\n\n setBucket(input.bucket);\n stream = snapshotThenStream({\n realtime: this.#realtime,\n channel,\n schema: Proto.OrderBookDeltaSchema,\n maxBufferedPublications: 200,\n snapshotErrorLog: \"Failed to fetch orderbook\",\n // GetOrderBook answers unavailable while the book is (re)built; keep asking until it is ready.\n snapshotRetry: {\n maxAttempts: Number.POSITIVE_INFINITY,\n delayMs: 1_000,\n maxDelayMs: 8_000,\n },\n // A snapshot error that is not retried (a 500) leaves the book to the server's next\n // reset; seq 0 accepts that reset even from a new epoch. Retried errors keep buffering.\n snapshotFailureMode: (error) => {\n if (!(error instanceof PolyesterError) || error.retryable) return \"wait\";\n currentBookSeq = 0n;\n awaitingReset = true;\n return \"live\";\n },\n fetchSnapshot: inputServiceFetch,\n readPublication: (delta) => [delta],\n applySnapshot: (snapshot, bufferedDeltas) => {\n bidsMap = levelsToMap(snapshot.bids);\n asksMap = levelsToMap(snapshot.asks);\n currentBookSeq = snapshot.bookSeq;\n currentBookEpoch = snapshot.bookEpoch;\n awaitingReset = false;\n emit();\n for (const delta of bufferedDeltas) {\n if (stream?.isDisposed()) return;\n handleDelta(delta);\n }\n },\n applyLivePublications: (deltas) => {\n for (const delta of deltas) {\n if (stream?.isDisposed()) return;\n handleDelta(delta);\n }\n },\n onOpen: input.onOpen,\n onClose: input.onClose,\n onError: input.onError,\n });\n\n function dispose(): void {\n stream?.unsubscribe();\n }\n\n return { unsubscribe: dispose, setBucket };\n }\n}\n\n/**\n * Whether a snapshot's levels are the book. A snapshot carrying levels is current even with\n * `available` false, which is how servers that predate the field encode every snapshot.\n */\nfunction isBookAvailable(res: Proto.GetOrderBookResponse): boolean {\n return res.available || res.bids.length > 0 || res.asks.length > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqDA,IAAa,mBAAb,MAA8B;CAC1B;CACA;CACA;CAEA,YAAY,YAAiC,UAA6B,QAAmB;EACzF,KAAKA,UAAU,aAAaC,oBAAwB,WAAW,SAAS;EACxE,KAAKC,YAAY;EACjB,KAAKC,UAAU;CACnB;;;;;CAMA,MAAM,IACF,OACA,SACsB;EACtB,MAAM,YAAY,MAAM,yBAAyB,KAAK;EACtD,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,MAAM,MAAM,KAAKH,QAAQ,aAC3B;GAAE,UAAU,UAAU;GAAU,OAAO,eAAe,aAAa,UAAU;EAAO,GACpF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;IACnC,iBAAiB,SAAS;IAC1B,mBAAmB,SAAS;IAC5B,gBAAgB;IAChB,KAAK;IACL,KAAK,MAAM,SAAS,gBAAgB;KAChC,IAAI,QAAQ,WAAW,GAAG;KAC1B,YAAY,KAAK;IACrB;GACJ;GACA,wBAAwB,WAAW;IAC/B,KAAK,MAAM,SAAS,QAAQ;KACxB,IAAI,QAAQ,WAAW,GAAG;KAC1B,YAAY,KAAK;IACrB;GACJ;GACA,QAAQ,MAAM;GACd,SAAS,MAAM;GACf,SAAS,MAAM;EACnB,CAAC;EAED,SAAS,UAAgB;GACrB,QAAQ,YAAY;EACxB;EAEA,OAAO;GAAE,aAAa;GAAS;EAAU;CAC7C;AACJ;;;;;AAMA,SAAS,gBAAgB,KAA0C;CAC/D,OAAO,IAAI,aAAa,IAAI,KAAK,SAAS,KAAK,IAAI,KAAK,SAAS;AACrE"}
|
|
@@ -10,7 +10,7 @@ declare const CancelAllAfterInputSchema: v.SchemaWithPipe<readonly [v.StrictObje
|
|
|
10
10
|
readonly side: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<["buy", "sell"], undefined>, undefined>, v.TransformAction<"buy" | "sell" | undefined, Side.BUY | Side.SELL | undefined>]>;
|
|
11
11
|
/** On expiry, also stop the triggers in scope created before the expiry time. Each arm or refresh sets it again. */
|
|
12
12
|
readonly includeTriggers: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
13
|
-
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
13
|
+
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.RegexAction<string, "requestId has an invalid format">]>, undefined>;
|
|
14
14
|
readonly account: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["active", "main"], undefined>, v.StrictObjectSchema<{
|
|
15
15
|
readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
16
16
|
}, undefined>], undefined>, undefined>;
|
|
@@ -67,7 +67,7 @@ declare const CancelAllAfterResultSchema: v.SchemaWithPipe<readonly [v.ObjectSch
|
|
|
67
67
|
}>]>;
|
|
68
68
|
type CancelAllAfterResult = v.InferOutput<typeof CancelAllAfterResultSchema>;
|
|
69
69
|
declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
70
|
-
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
70
|
+
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.RegexAction<string, "requestId has an invalid format">]>, undefined>;
|
|
71
71
|
readonly items: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.UnionSchema<[v.StrictObjectSchema<{
|
|
72
72
|
readonly qty: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
73
73
|
readonly maxQuoteDebit: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
@@ -150,7 +150,7 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
150
150
|
case: "limitFok";
|
|
151
151
|
value: LimitFok;
|
|
152
152
|
}>]>], undefined>;
|
|
153
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
153
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, undefined>;
|
|
154
154
|
readonly feeAsset: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["quote", "base"], undefined>, undefined>, v.TransformAction<"quote" | "base" | undefined, FeeAsset.QUOTE | FeeAsset.BASE | undefined>]>;
|
|
155
155
|
readonly selfTradePreventionMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["expire_taker", "expire_maker", "expire_both", "decrement"], undefined>, undefined>, v.TransformAction<"expire_taker" | "expire_maker" | "expire_both" | "decrement" | undefined, SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH | SelfTradePreventionMode.DECREMENT | undefined>]>;
|
|
156
156
|
readonly risk: v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -740,7 +740,7 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
740
740
|
case: "limitFok";
|
|
741
741
|
value: LimitFok;
|
|
742
742
|
}>]>], undefined>;
|
|
743
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
743
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, undefined>;
|
|
744
744
|
readonly feeAsset: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["quote", "base"], undefined>, undefined>, v.TransformAction<"quote" | "base" | undefined, FeeAsset.QUOTE | FeeAsset.BASE | undefined>]>;
|
|
745
745
|
readonly selfTradePreventionMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["expire_taker", "expire_maker", "expire_both", "decrement"], undefined>, undefined>, v.TransformAction<"expire_taker" | "expire_maker" | "expire_both" | "decrement" | undefined, SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH | SelfTradePreventionMode.DECREMENT | undefined>]>;
|
|
746
746
|
readonly risk: v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -1330,7 +1330,7 @@ declare function createBatchCreateOrdersInputSchema(scales: SdkScales): v.Schema
|
|
|
1330
1330
|
case: "limitFok";
|
|
1331
1331
|
value: LimitFok;
|
|
1332
1332
|
}>]>], undefined>;
|
|
1333
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
1333
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, undefined>;
|
|
1334
1334
|
readonly feeAsset: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["quote", "base"], undefined>, undefined>, v.TransformAction<"quote" | "base" | undefined, FeeAsset.QUOTE | FeeAsset.BASE | undefined>]>;
|
|
1335
1335
|
readonly selfTradePreventionMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["expire_taker", "expire_maker", "expire_both", "decrement"], undefined>, undefined>, v.TransformAction<"expire_taker" | "expire_maker" | "expire_both" | "decrement" | undefined, SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH | SelfTradePreventionMode.DECREMENT | undefined>]>;
|
|
1336
1336
|
readonly risk: v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -6326,7 +6326,7 @@ declare const BatchCancelOrderInputSchema: v.UnionSchema<[v.SchemaWithPipe<reado
|
|
|
6326
6326
|
symbolId: number | undefined;
|
|
6327
6327
|
}>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
6328
6328
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
6329
|
-
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
6329
|
+
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, v.MinLengthAction<string, 1, undefined>]>;
|
|
6330
6330
|
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
|
|
6331
6331
|
}, undefined>, v.TransformAction<{
|
|
6332
6332
|
orderId?: undefined;
|
|
@@ -6338,7 +6338,7 @@ declare const BatchCancelOrderInputSchema: v.UnionSchema<[v.SchemaWithPipe<reado
|
|
|
6338
6338
|
}>]>], undefined>;
|
|
6339
6339
|
type BatchCancelOrderInput = v.InferInput<typeof BatchCancelOrderInputSchema>;
|
|
6340
6340
|
declare const BatchCancelOrdersInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
6341
|
-
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
6341
|
+
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.RegexAction<string, "requestId has an invalid format">]>, undefined>;
|
|
6342
6342
|
readonly items: v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
6343
6343
|
readonly orderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
|
|
6344
6344
|
readonly clientOrderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
@@ -6352,7 +6352,7 @@ declare const BatchCancelOrdersInputSchema: v.SchemaWithPipe<readonly [v.StrictO
|
|
|
6352
6352
|
symbolId: number | undefined;
|
|
6353
6353
|
}>]>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
6354
6354
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
6355
|
-
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
6355
|
+
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, v.MinLengthAction<string, 1, undefined>]>;
|
|
6356
6356
|
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
|
|
6357
6357
|
}, undefined>, v.TransformAction<{
|
|
6358
6358
|
orderId?: undefined;
|
|
@@ -3,14 +3,14 @@ import * as v from "valibot";
|
|
|
3
3
|
//#region src/services/orders/orders-identifiers.schemas.ts
|
|
4
4
|
/** Characters a client order ID or client OCO ID may use. */
|
|
5
5
|
const OrderIdempotencyKeyPattern = /^[A-Za-z0-9._:/-]*$/;
|
|
6
|
-
const ClientOrderIdWireInputSchema = v.pipe(v.string(), v.
|
|
6
|
+
const ClientOrderIdWireInputSchema = v.pipe(v.string(), v.maxLength(36), v.regex(OrderIdempotencyKeyPattern, "clientOrderId has an invalid format"));
|
|
7
7
|
const ClientOrderIdInputSchema = v.pipe(ClientOrderIdWireInputSchema, v.minLength(1));
|
|
8
8
|
const OptionalClientOrderIdInputSchema = v.optional(ClientOrderIdWireInputSchema);
|
|
9
9
|
function positiveOrderIdInputSchema(fieldName = "orderId") {
|
|
10
10
|
return v.pipe(idInputSchema(fieldName), v.check((value) => value > 0n, `${fieldName} must be greater than zero`));
|
|
11
11
|
}
|
|
12
12
|
const OrderIdInputSchema = positiveOrderIdInputSchema();
|
|
13
|
-
const OrderRequestIdInputSchema = v.pipe(v.string(), v.
|
|
13
|
+
const OrderRequestIdInputSchema = v.pipe(v.string(), v.minLength(1), v.maxLength(64), v.regex(OrderIdempotencyKeyPattern, "requestId has an invalid format"));
|
|
14
14
|
//#endregion
|
|
15
15
|
export { ClientOrderIdInputSchema, OptionalClientOrderIdInputSchema, OrderIdInputSchema, OrderIdempotencyKeyPattern, OrderRequestIdInputSchema, positiveOrderIdInputSchema };
|
|
16
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders-identifiers.schemas.js","names":[],"sources":["../../../src/services/orders/orders-identifiers.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { idInputSchema } from \"../../shared/schemas.js\";\n\n/** Characters a client order ID or client OCO ID may use. */\nexport const OrderIdempotencyKeyPattern = /^[A-Za-z0-9._:/-]*$/;\n\nconst ClientOrderIdWireInputSchema = v.pipe(\n v.string(),\n v.
|
|
1
|
+
{"version":3,"file":"orders-identifiers.schemas.js","names":[],"sources":["../../../src/services/orders/orders-identifiers.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { idInputSchema } from \"../../shared/schemas.js\";\n\n/** Characters a client order ID or client OCO ID may use. */\nexport const OrderIdempotencyKeyPattern = /^[A-Za-z0-9._:/-]*$/;\n\n// Sent as given: the format refuses whitespace instead of trimming it away.\nconst ClientOrderIdWireInputSchema = v.pipe(\n v.string(),\n v.maxLength(36),\n v.regex(OrderIdempotencyKeyPattern, \"clientOrderId has an invalid format\"),\n);\n\nexport const ClientOrderIdInputSchema = v.pipe(ClientOrderIdWireInputSchema, v.minLength(1));\n\nexport const OptionalClientOrderIdInputSchema = v.optional(ClientOrderIdWireInputSchema);\n\nexport function positiveOrderIdInputSchema(fieldName = \"orderId\") {\n return v.pipe(\n idInputSchema(fieldName),\n v.check((value) => value > 0n, `${fieldName} must be greater than zero`),\n );\n}\n\nexport const OrderIdInputSchema = positiveOrderIdInputSchema();\n\nexport const OrderRequestIdInputSchema = v.pipe(\n v.string(),\n v.minLength(1),\n v.maxLength(64),\n v.regex(OrderIdempotencyKeyPattern, \"requestId has an invalid format\"),\n);\n"],"mappings":";;;;AAIA,MAAa,6BAA6B;AAG1C,MAAM,+BAA+B,EAAE,KACnC,EAAE,OAAO,GACT,EAAE,UAAU,EAAE,GACd,EAAE,MAAM,4BAA4B,qCAAqC,CAC7E;AAEA,MAAa,2BAA2B,EAAE,KAAK,8BAA8B,EAAE,UAAU,CAAC,CAAC;AAE3F,MAAa,mCAAmC,EAAE,SAAS,4BAA4B;AAEvF,SAAgB,2BAA2B,YAAY,WAAW;CAC9D,OAAO,EAAE,KACL,cAAc,SAAS,GACvB,EAAE,OAAO,UAAU,QAAQ,IAAI,GAAG,UAAU,2BAA2B,CAC3E;AACJ;AAEA,MAAa,qBAAqB,2BAA2B;AAE7D,MAAa,4BAA4B,EAAE,KACvC,EAAE,OAAO,GACT,EAAE,UAAU,CAAC,GACb,EAAE,UAAU,EAAE,GACd,EAAE,MAAM,4BAA4B,iCAAiC,CACzE"}
|
|
@@ -163,7 +163,7 @@ declare function createOrderIntentInputSchema(scales: SdkScales): v.SchemaWithPi
|
|
|
163
163
|
case: "limitFok";
|
|
164
164
|
value: LimitFok;
|
|
165
165
|
}>]>], undefined>;
|
|
166
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
166
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, undefined>;
|
|
167
167
|
readonly feeAsset: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["quote", "base"], undefined>, undefined>, v.TransformAction<"quote" | "base" | undefined, FeeAsset.QUOTE | FeeAsset.BASE | undefined>]>;
|
|
168
168
|
readonly selfTradePreventionMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["expire_taker", "expire_maker", "expire_both", "decrement"], undefined>, undefined>, v.TransformAction<"expire_taker" | "expire_maker" | "expire_both" | "decrement" | undefined, SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH | SelfTradePreventionMode.DECREMENT | undefined>]>;
|
|
169
169
|
readonly risk: v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -757,7 +757,7 @@ declare function createOrderIntentInputSchema(scales: SdkScales): v.SchemaWithPi
|
|
|
757
757
|
case: "limitFok";
|
|
758
758
|
value: LimitFok;
|
|
759
759
|
}>]>], undefined>;
|
|
760
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
760
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, undefined>;
|
|
761
761
|
readonly feeAsset: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["quote", "base"], undefined>, undefined>, v.TransformAction<"quote" | "base" | undefined, FeeAsset.QUOTE | FeeAsset.BASE | undefined>]>;
|
|
762
762
|
readonly selfTradePreventionMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["expire_taker", "expire_maker", "expire_both", "decrement"], undefined>, undefined>, v.TransformAction<"expire_taker" | "expire_maker" | "expire_both" | "decrement" | undefined, SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH | SelfTradePreventionMode.DECREMENT | undefined>]>;
|
|
763
763
|
readonly risk: v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -1352,7 +1352,7 @@ declare function createOrderIntentInputSchema(scales: SdkScales): v.SchemaWithPi
|
|
|
1352
1352
|
case: "limitFok";
|
|
1353
1353
|
value: LimitFok;
|
|
1354
1354
|
}>]>], undefined>;
|
|
1355
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
1355
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, undefined>;
|
|
1356
1356
|
readonly feeAsset: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["quote", "base"], undefined>, undefined>, v.TransformAction<"quote" | "base" | undefined, FeeAsset.QUOTE | FeeAsset.BASE | undefined>]>;
|
|
1357
1357
|
readonly selfTradePreventionMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["expire_taker", "expire_maker", "expire_both", "decrement"], undefined>, undefined>, v.TransformAction<"expire_taker" | "expire_maker" | "expire_both" | "decrement" | undefined, SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH | SelfTradePreventionMode.DECREMENT | undefined>]>;
|
|
1358
1358
|
readonly risk: v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -4123,7 +4123,7 @@ declare function createNewOrderInputSchema(scales: SdkScales): v.SchemaWithPipe<
|
|
|
4123
4123
|
case: "limitFok";
|
|
4124
4124
|
value: LimitFok;
|
|
4125
4125
|
}>]>], undefined>;
|
|
4126
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
4126
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, undefined>;
|
|
4127
4127
|
readonly feeAsset: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["quote", "base"], undefined>, undefined>, v.TransformAction<"quote" | "base" | undefined, FeeAsset.QUOTE | FeeAsset.BASE | undefined>]>;
|
|
4128
4128
|
readonly selfTradePreventionMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["expire_taker", "expire_maker", "expire_both", "decrement"], undefined>, undefined>, v.TransformAction<"expire_taker" | "expire_maker" | "expire_both" | "decrement" | undefined, SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH | SelfTradePreventionMode.DECREMENT | undefined>]>;
|
|
4129
4129
|
readonly risk: v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -4720,7 +4720,7 @@ declare function createNewOrderInputSchema(scales: SdkScales): v.SchemaWithPipe<
|
|
|
4720
4720
|
case: "limitFok";
|
|
4721
4721
|
value: LimitFok;
|
|
4722
4722
|
}>]>], undefined>;
|
|
4723
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
4723
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, undefined>;
|
|
4724
4724
|
readonly feeAsset: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["quote", "base"], undefined>, undefined>, v.TransformAction<"quote" | "base" | undefined, FeeAsset.QUOTE | FeeAsset.BASE | undefined>]>;
|
|
4725
4725
|
readonly selfTradePreventionMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["expire_taker", "expire_maker", "expire_both", "decrement"], undefined>, undefined>, v.TransformAction<"expire_taker" | "expire_maker" | "expire_both" | "decrement" | undefined, SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH | SelfTradePreventionMode.DECREMENT | undefined>]>;
|
|
4726
4726
|
readonly risk: v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -5318,7 +5318,7 @@ declare function createNewOrderInputSchema(scales: SdkScales): v.SchemaWithPipe<
|
|
|
5318
5318
|
case: "limitFok";
|
|
5319
5319
|
value: LimitFok;
|
|
5320
5320
|
}>]>], undefined>;
|
|
5321
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
5321
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, undefined>;
|
|
5322
5322
|
readonly feeAsset: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["quote", "base"], undefined>, undefined>, v.TransformAction<"quote" | "base" | undefined, FeeAsset.QUOTE | FeeAsset.BASE | undefined>]>;
|
|
5323
5323
|
readonly selfTradePreventionMode: v.SchemaWithPipe<readonly [v.OptionalSchema<v.PicklistSchema<readonly ["expire_taker", "expire_maker", "expire_both", "decrement"], undefined>, undefined>, v.TransformAction<"expire_taker" | "expire_maker" | "expire_both" | "decrement" | undefined, SelfTradePreventionMode.EXPIRE_MAKER | SelfTradePreventionMode.EXPIRE_TAKER | SelfTradePreventionMode.EXPIRE_BOTH | SelfTradePreventionMode.DECREMENT | undefined>]>;
|
|
5324
5324
|
readonly risk: v.SchemaWithPipe<readonly [v.OptionalSchema<v.UnionSchema<[v.StrictObjectSchema<{
|
|
@@ -8082,7 +8082,7 @@ declare const CancelOrderInputSchema: v.SchemaWithPipe<readonly [v.UnionSchema<[
|
|
|
8082
8082
|
readonly symbolId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>, undefined>;
|
|
8083
8083
|
}, undefined>, v.StrictObjectSchema<{
|
|
8084
8084
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
8085
|
-
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
8085
|
+
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, v.MinLengthAction<string, 1, undefined>]>;
|
|
8086
8086
|
readonly account: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["active", "main"], undefined>, v.StrictObjectSchema<{
|
|
8087
8087
|
readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
8088
8088
|
}, undefined>], undefined>, undefined>;
|
|
@@ -8144,7 +8144,7 @@ declare const CancelAllOrdersInputSchema: v.SchemaWithPipe<readonly [v.StrictObj
|
|
|
8144
8144
|
readonly dryRun: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
8145
8145
|
/** Also stop the matched triggers, ending each canceled with reason `cancel_all`. Part of the criteria a retry must keep. */
|
|
8146
8146
|
readonly includeTriggers: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
|
|
8147
|
-
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
8147
|
+
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.RegexAction<string, "requestId has an invalid format">]>, undefined>;
|
|
8148
8148
|
readonly account: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["active", "main"], undefined>, v.StrictObjectSchema<{
|
|
8149
8149
|
readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
8150
8150
|
}, undefined>], undefined>, undefined>;
|
|
@@ -8222,7 +8222,7 @@ declare const GetOrderDetailsInputSchema: v.SchemaWithPipe<readonly [v.StrictObj
|
|
|
8222
8222
|
readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
8223
8223
|
}, undefined>], undefined>, undefined>;
|
|
8224
8224
|
readonly orderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>, undefined>;
|
|
8225
|
-
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
8225
|
+
readonly clientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
8226
8226
|
}, undefined>, v.CheckAction<{
|
|
8227
8227
|
includeExecutionHistory?: boolean | undefined;
|
|
8228
8228
|
limit?: number | undefined;
|
|
@@ -3,14 +3,14 @@ import { SdkScales } from "../../shared/decimal-surface.js";
|
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
//#region src/services/orders/orders-modify.schemas.d.ts
|
|
5
5
|
declare function createModifyOrderInputSchema(scales: SdkScales): v.SchemaWithPipe<readonly [v.IntersectSchema<[v.ObjectSchema<{
|
|
6
|
-
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
6
|
+
readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.RegexAction<string, "requestId has an invalid format">]>, undefined>;
|
|
7
7
|
readonly account: v.OptionalSchema<v.UnionSchema<[v.PicklistSchema<["active", "main"], undefined>, v.StrictObjectSchema<{
|
|
8
8
|
readonly subaccountId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>;
|
|
9
9
|
}, undefined>], undefined>, undefined>;
|
|
10
10
|
}, undefined>, v.IntersectSchema<[v.ObjectSchema<{
|
|
11
11
|
readonly symbolId: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.GtValueAction<number, 0, undefined>, v.MaxValueAction<number, 4294967295, undefined>]>;
|
|
12
12
|
readonly behavior: v.OptionalSchema<v.PicklistSchema<readonly ["amend_or_replace", "amend_only", "replace_only"], undefined>, undefined>;
|
|
13
|
-
readonly newClientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
13
|
+
readonly newClientOrderId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
14
14
|
}, undefined>, v.UnionSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
15
15
|
readonly orderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than zero`>]>;
|
|
16
16
|
readonly clientOrderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
@@ -24,7 +24,7 @@ declare function createModifyOrderInputSchema(scales: SdkScales): v.SchemaWithPi
|
|
|
24
24
|
};
|
|
25
25
|
}>]>, v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
26
26
|
readonly orderId: v.OptionalSchema<v.NeverSchema<undefined>, undefined>;
|
|
27
|
-
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
27
|
+
readonly clientOrderId: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 36, undefined>, v.RegexAction<string, "clientOrderId has an invalid format">]>, v.MinLengthAction<string, 1, undefined>]>;
|
|
28
28
|
}, undefined>, v.TransformAction<{
|
|
29
29
|
orderId?: undefined;
|
|
30
30
|
clientOrderId: string;
|
|
@@ -289,7 +289,7 @@ declare function createOrderSchema(scales: SdkScales): v.SchemaWithPipe<readonly
|
|
|
289
289
|
attachedRisk: {
|
|
290
290
|
takeProfit: {
|
|
291
291
|
state: {
|
|
292
|
-
status: "unspecified" | "created" | "failed" | "canceled" | "
|
|
292
|
+
status: "unspecified" | "created" | "failed" | "canceled" | "completed" | "paused" | "armed" | "running" | "not_configured";
|
|
293
293
|
armedTs: number | undefined;
|
|
294
294
|
armedTsNs: string | undefined;
|
|
295
295
|
terminalTs: number | undefined;
|
|
@@ -309,7 +309,7 @@ declare function createOrderSchema(scales: SdkScales): v.SchemaWithPipe<readonly
|
|
|
309
309
|
} | undefined;
|
|
310
310
|
stopLoss: {
|
|
311
311
|
state: {
|
|
312
|
-
status: "unspecified" | "created" | "failed" | "canceled" | "
|
|
312
|
+
status: "unspecified" | "created" | "failed" | "canceled" | "completed" | "paused" | "armed" | "running" | "not_configured";
|
|
313
313
|
armedTs: number | undefined;
|
|
314
314
|
armedTsNs: string | undefined;
|
|
315
315
|
terminalTs: number | undefined;
|
|
@@ -329,7 +329,7 @@ declare function createOrderSchema(scales: SdkScales): v.SchemaWithPipe<readonly
|
|
|
329
329
|
} | undefined;
|
|
330
330
|
trailingStop: {
|
|
331
331
|
state: {
|
|
332
|
-
status: "unspecified" | "created" | "failed" | "canceled" | "
|
|
332
|
+
status: "unspecified" | "created" | "failed" | "canceled" | "completed" | "paused" | "armed" | "running" | "not_configured";
|
|
333
333
|
armedTs: number | undefined;
|
|
334
334
|
armedTsNs: string | undefined;
|
|
335
335
|
terminalTs: number | undefined;
|
|
@@ -719,7 +719,7 @@ declare function createOrderDetailsSchema(scales: SdkScales): v.ObjectSchema<{
|
|
|
719
719
|
attachedRisk: {
|
|
720
720
|
takeProfit: {
|
|
721
721
|
state: {
|
|
722
|
-
status: "unspecified" | "created" | "failed" | "canceled" | "
|
|
722
|
+
status: "unspecified" | "created" | "failed" | "canceled" | "completed" | "paused" | "armed" | "running" | "not_configured";
|
|
723
723
|
armedTs: number | undefined;
|
|
724
724
|
armedTsNs: string | undefined;
|
|
725
725
|
terminalTs: number | undefined;
|
|
@@ -739,7 +739,7 @@ declare function createOrderDetailsSchema(scales: SdkScales): v.ObjectSchema<{
|
|
|
739
739
|
} | undefined;
|
|
740
740
|
stopLoss: {
|
|
741
741
|
state: {
|
|
742
|
-
status: "unspecified" | "created" | "failed" | "canceled" | "
|
|
742
|
+
status: "unspecified" | "created" | "failed" | "canceled" | "completed" | "paused" | "armed" | "running" | "not_configured";
|
|
743
743
|
armedTs: number | undefined;
|
|
744
744
|
armedTsNs: string | undefined;
|
|
745
745
|
terminalTs: number | undefined;
|
|
@@ -759,7 +759,7 @@ declare function createOrderDetailsSchema(scales: SdkScales): v.ObjectSchema<{
|
|
|
759
759
|
} | undefined;
|
|
760
760
|
trailingStop: {
|
|
761
761
|
state: {
|
|
762
|
-
status: "unspecified" | "created" | "failed" | "canceled" | "
|
|
762
|
+
status: "unspecified" | "created" | "failed" | "canceled" | "completed" | "paused" | "armed" | "running" | "not_configured";
|
|
763
763
|
armedTs: number | undefined;
|
|
764
764
|
armedTsNs: string | undefined;
|
|
765
765
|
terminalTs: number | undefined;
|
|
@@ -8,7 +8,7 @@ declare const CreatePriceAlertInputSchema: v.SchemaWithPipe<readonly [v.StrictOb
|
|
|
8
8
|
readonly priceSource: v.OptionalSchema<v.PicklistSchema<readonly ["last_price", "index_price"], undefined>, undefined>;
|
|
9
9
|
/** Alert price as a decimal string, e.g. `"90000"`. */
|
|
10
10
|
readonly price: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, bigint>]>;
|
|
11
|
-
readonly channels: v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["in_app", "telegram"], undefined>, undefined>, v.MinLengthAction<("
|
|
11
|
+
readonly channels: v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["in_app", "telegram"], undefined>, undefined>, v.MinLengthAction<("telegram" | "in_app")[], 1, "At least one channel is required.">, v.MaxLengthAction<("telegram" | "in_app")[], 2, "At most two channels are allowed.">, v.CheckAction<("telegram" | "in_app")[], "Channels must be distinct.">, v.TransformAction<("telegram" | "in_app")[], (AlertChannel.IN_APP | AlertChannel.TELEGRAM)[]>]>;
|
|
12
12
|
/** Reusing a key with the same request returns the alert it created. */
|
|
13
13
|
readonly idempotencyKey: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
14
14
|
}, undefined>, v.TransformAction<{
|
|
@@ -54,7 +54,7 @@ declare const UpdatePriceAlertInputSchema: v.SchemaWithPipe<readonly [v.StrictOb
|
|
|
54
54
|
readonly expectedRevision: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction]>, v.RegexAction<string, `${string} must be a decimal integer`>, v.TransformAction<string, bigint>]>, v.CheckAction<bigint, `${string} must be greater than 0`>]>, v.MaxValueAction<bigint, 18446744073709551615n, "expectedRevision exceeds the uint64 range">]>;
|
|
55
55
|
readonly direction: v.OptionalSchema<v.PicklistSchema<readonly ["above", "below"], undefined>, undefined>;
|
|
56
56
|
readonly price: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TransformAction<string, bigint>]>, undefined>;
|
|
57
|
-
readonly channels: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["in_app", "telegram"], undefined>, undefined>, v.MinLengthAction<("
|
|
57
|
+
readonly channels: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["in_app", "telegram"], undefined>, undefined>, v.MinLengthAction<("telegram" | "in_app")[], 1, "At least one channel is required.">, v.MaxLengthAction<("telegram" | "in_app")[], 2, "At most two channels are allowed.">, v.CheckAction<("telegram" | "in_app")[], "Channels must be distinct.">, v.TransformAction<("telegram" | "in_app")[], (AlertChannel.IN_APP | AlertChannel.TELEGRAM)[]>]>, undefined>;
|
|
58
58
|
readonly idempotencyKey: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
59
59
|
}, undefined>, v.TransformAction<{
|
|
60
60
|
alertId: bigint;
|
|
@@ -93,7 +93,7 @@ declare const PriceAlertSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
93
93
|
readonly referencePriceTicks: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
94
94
|
readonly armed: v.BooleanSchema<undefined>;
|
|
95
95
|
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "active" | "canceled" | "triggered">]>;
|
|
96
|
-
readonly channels: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
96
|
+
readonly channels: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "telegram" | "in_app">]>, undefined>;
|
|
97
97
|
readonly revision: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
98
98
|
readonly createdAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
99
99
|
readonly seconds: v.BigintSchema<undefined>;
|
|
@@ -126,7 +126,7 @@ declare const PriceAlertSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
126
126
|
referencePriceTicks: string;
|
|
127
127
|
armed: boolean;
|
|
128
128
|
status: "unspecified" | "active" | "canceled" | "triggered";
|
|
129
|
-
channels: ("unspecified" | "
|
|
129
|
+
channels: ("unspecified" | "telegram" | "in_app")[];
|
|
130
130
|
revision: string;
|
|
131
131
|
createdAt?: number | undefined;
|
|
132
132
|
updatedAt?: number | undefined;
|
|
@@ -144,7 +144,7 @@ declare const PriceAlertSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
144
144
|
/** False while an alert created past its price waits for the price to move back first. */
|
|
145
145
|
armed: boolean;
|
|
146
146
|
status: "unspecified" | "active" | "canceled" | "triggered";
|
|
147
|
-
channels: ("unspecified" | "
|
|
147
|
+
channels: ("unspecified" | "telegram" | "in_app")[];
|
|
148
148
|
/** Pass as `expectedRevision` to `update`. */
|
|
149
149
|
revision: string;
|
|
150
150
|
createdAt: number | null;
|
|
@@ -165,7 +165,7 @@ declare const ListPriceAlertsResultSchema: v.ObjectSchema<{
|
|
|
165
165
|
readonly referencePriceTicks: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
166
166
|
readonly armed: v.BooleanSchema<undefined>;
|
|
167
167
|
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "active" | "canceled" | "triggered">]>;
|
|
168
|
-
readonly channels: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
168
|
+
readonly channels: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "telegram" | "in_app">]>, undefined>;
|
|
169
169
|
readonly revision: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
170
170
|
readonly createdAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
171
171
|
readonly seconds: v.BigintSchema<undefined>;
|
|
@@ -198,7 +198,7 @@ declare const ListPriceAlertsResultSchema: v.ObjectSchema<{
|
|
|
198
198
|
referencePriceTicks: string;
|
|
199
199
|
armed: boolean;
|
|
200
200
|
status: "unspecified" | "active" | "canceled" | "triggered";
|
|
201
|
-
channels: ("unspecified" | "
|
|
201
|
+
channels: ("unspecified" | "telegram" | "in_app")[];
|
|
202
202
|
revision: string;
|
|
203
203
|
createdAt?: number | undefined;
|
|
204
204
|
updatedAt?: number | undefined;
|
|
@@ -216,7 +216,7 @@ declare const ListPriceAlertsResultSchema: v.ObjectSchema<{
|
|
|
216
216
|
/** False while an alert created past its price waits for the price to move back first. */
|
|
217
217
|
armed: boolean;
|
|
218
218
|
status: "unspecified" | "active" | "canceled" | "triggered";
|
|
219
|
-
channels: ("unspecified" | "
|
|
219
|
+
channels: ("unspecified" | "telegram" | "in_app")[];
|
|
220
220
|
/** Pass as `expectedRevision` to `update`. */
|
|
221
221
|
revision: string;
|
|
222
222
|
createdAt: number | null;
|
|
@@ -240,7 +240,7 @@ declare const UpdatePriceAlertResultSchema: v.ObjectSchema<{
|
|
|
240
240
|
readonly referencePriceTicks: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
241
241
|
readonly armed: v.BooleanSchema<undefined>;
|
|
242
242
|
readonly status: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "active" | "canceled" | "triggered">]>;
|
|
243
|
-
readonly channels: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "
|
|
243
|
+
readonly channels: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.TransformAction<number, "unspecified" | "telegram" | "in_app">]>, undefined>;
|
|
244
244
|
readonly revision: v.SchemaWithPipe<readonly [v.BigintSchema<undefined>, v.TransformAction<bigint, string>]>;
|
|
245
245
|
readonly createdAt: v.SchemaWithPipe<readonly [v.OptionalSchema<v.ObjectSchema<{
|
|
246
246
|
readonly seconds: v.BigintSchema<undefined>;
|
|
@@ -273,7 +273,7 @@ declare const UpdatePriceAlertResultSchema: v.ObjectSchema<{
|
|
|
273
273
|
referencePriceTicks: string;
|
|
274
274
|
armed: boolean;
|
|
275
275
|
status: "unspecified" | "active" | "canceled" | "triggered";
|
|
276
|
-
channels: ("unspecified" | "
|
|
276
|
+
channels: ("unspecified" | "telegram" | "in_app")[];
|
|
277
277
|
revision: string;
|
|
278
278
|
createdAt?: number | undefined;
|
|
279
279
|
updatedAt?: number | undefined;
|
|
@@ -291,7 +291,7 @@ declare const UpdatePriceAlertResultSchema: v.ObjectSchema<{
|
|
|
291
291
|
/** False while an alert created past its price waits for the price to move back first. */
|
|
292
292
|
armed: boolean;
|
|
293
293
|
status: "unspecified" | "active" | "canceled" | "triggered";
|
|
294
|
-
channels: ("unspecified" | "
|
|
294
|
+
channels: ("unspecified" | "telegram" | "in_app")[];
|
|
295
295
|
/** Pass as `expectedRevision` to `update`. */
|
|
296
296
|
revision: string;
|
|
297
297
|
createdAt: number | null;
|