@polyester/sdk 0.36.0-devnet-20261112202000 → 0.36.0-devnet-20261114152753
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 +33 -1
- package/dist/catalogs/index.d.ts +2 -2
- package/dist/catalogs/snapshot-validation.js +3 -1
- package/dist/catalogs/snapshot-validation.js.map +1 -1
- package/dist/catalogs/zipper-catalog.d.ts +2 -0
- package/dist/catalogs/zipper-catalog.d.ts.map +1 -1
- package/dist/catalogs/zipper-catalog.js.map +1 -1
- package/dist/gen/ai/v1/assistant_pb.d.ts +211 -9
- package/dist/gen/ai/v1/assistant_pb.d.ts.map +1 -1
- package/dist/gen/ai/v1/assistant_pb.js +163 -73
- package/dist/gen/ai/v1/assistant_pb.js.map +1 -1
- package/dist/gen/auth/v1/api_keys_pb.d.ts +62 -5
- package/dist/gen/auth/v1/api_keys_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/api_keys_pb.js +50 -2
- package/dist/gen/auth/v1/api_keys_pb.js.map +1 -1
- package/dist/gen/auth/v1/policies_pb.d.ts +9 -1
- package/dist/gen/auth/v1/policies_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/policies_pb.js +9 -1
- package/dist/gen/auth/v1/policies_pb.js.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.d.ts +7 -1
- package/dist/gen/auth/v1/subaccounts_pb.d.ts.map +1 -1
- package/dist/gen/auth/v1/subaccounts_pb.js +7 -1
- package/dist/gen/auth/v1/subaccounts_pb.js.map +1 -1
- package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.d.ts +10 -2
- package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.d.ts.map +1 -1
- package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.js.map +1 -1
- package/dist/gen/chain/lifecycle/v1/types_pb.d.ts +10 -5
- package/dist/gen/chain/lifecycle/v1/types_pb.d.ts.map +1 -1
- package/dist/gen/chain/lifecycle/v1/types_pb.js +10 -5
- package/dist/gen/chain/lifecycle/v1/types_pb.js.map +1 -1
- package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.d.ts +6 -1
- package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.d.ts.map +1 -1
- package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.js.map +1 -1
- package/dist/gen/chain/zipper/v1/reason_pb.d.ts +6 -2
- package/dist/gen/chain/zipper/v1/reason_pb.d.ts.map +1 -1
- package/dist/gen/chain/zipper/v1/reason_pb.js.map +1 -1
- package/dist/gen/chain/zipper/v1/zipper_pb.d.ts +47 -2
- package/dist/gen/chain/zipper/v1/zipper_pb.d.ts.map +1 -1
- package/dist/gen/chain/zipper/v1/zipper_pb.js +36 -2
- package/dist/gen/chain/zipper/v1/zipper_pb.js.map +1 -1
- package/dist/gen/changelog/v1/changelog_pb.d.ts +488 -5
- package/dist/gen/changelog/v1/changelog_pb.d.ts.map +1 -1
- package/dist/gen/changelog/v1/changelog_pb.js +159 -15
- package/dist/gen/changelog/v1/changelog_pb.js.map +1 -1
- package/dist/gen/index.d.ts +2 -1
- package/dist/gen/index.js +2 -1
- package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts +128 -5
- package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts.map +1 -1
- package/dist/gen/ledger/read/v1/ledger_read_pb.js +17 -3
- package/dist/gen/ledger/read/v1/ledger_read_pb.js.map +1 -1
- package/dist/gen/ledger/v1/catalog_pb.d.ts +11 -4
- package/dist/gen/ledger/v1/catalog_pb.d.ts.map +1 -1
- package/dist/gen/ledger/v1/catalog_pb.js +11 -4
- package/dist/gen/ledger/v1/catalog_pb.js.map +1 -1
- package/dist/gen/marketdata/v1/asset_info_pb.d.ts +178 -0
- package/dist/gen/marketdata/v1/asset_info_pb.d.ts.map +1 -0
- package/dist/gen/marketdata/v1/asset_info_pb.js +45 -0
- package/dist/gen/marketdata/v1/asset_info_pb.js.map +1 -0
- package/dist/gen/marketdata/v1/marketdata_pb.d.ts +12 -0
- package/dist/gen/marketdata/v1/marketdata_pb.d.ts.map +1 -1
- package/dist/gen/marketdata/v1/marketdata_pb.js +6 -1
- package/dist/gen/marketdata/v1/marketdata_pb.js.map +1 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts +3 -2
- package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts.map +1 -1
- package/dist/gen/marketoverview/v1/marketoverview_pb.js.map +1 -1
- package/dist/gen/notifications/v1/notifications_pb.d.ts +154 -3
- package/dist/gen/notifications/v1/notifications_pb.d.ts.map +1 -1
- package/dist/gen/notifications/v1/notifications_pb.js +102 -15
- package/dist/gen/notifications/v1/notifications_pb.js.map +1 -1
- package/dist/gen/orderbook/v1/orderbook_pb.d.ts +18 -10
- package/dist/gen/orderbook/v1/orderbook_pb.d.ts.map +1 -1
- package/dist/gen/orderbook/v1/orderbook_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_pb.d.ts +12 -1
- package/dist/gen/orders/v1/orders_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_pb.js +12 -1
- package/dist/gen/orders/v1/orders_pb.js.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.d.ts +6 -1
- package/dist/gen/orders/v1/orders_read_pb.d.ts.map +1 -1
- package/dist/gen/orders/v1/orders_read_pb.js.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts +12 -0
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js +12 -0
- package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.js.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts +13 -9
- package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_pb.js +10 -7
- package/dist/gen/swap/quickswap/v1/quickswap_pb.js.map +1 -1
- package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.d.ts +2 -2
- package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.js.map +1 -1
- package/dist/gen/system/v1/system_pb.d.ts +408 -3
- package/dist/gen/system/v1/system_pb.d.ts.map +1 -1
- package/dist/gen/system/v1/system_pb.js +221 -3
- package/dist/gen/system/v1/system_pb.js.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.d.ts +12 -4
- package/dist/gen/triggers/v1/triggers_pb.d.ts.map +1 -1
- package/dist/gen/triggers/v1/triggers_pb.js +6 -4
- package/dist/gen/triggers/v1/triggers_pb.js.map +1 -1
- package/dist/index.d.ts +13 -9
- package/dist/services/api-keys/api-keys.codecs.d.ts +14 -0
- package/dist/services/api-keys/api-keys.codecs.d.ts.map +1 -0
- package/dist/services/api-keys/api-keys.codecs.js +13 -1
- package/dist/services/api-keys/api-keys.codecs.js.map +1 -1
- package/dist/services/api-keys/api-keys.d.ts +2 -2
- package/dist/services/api-keys/api-keys.js +2 -2
- package/dist/services/api-keys/api-keys.js.map +1 -1
- package/dist/services/api-keys/api-keys.schemas.d.ts +46 -12
- package/dist/services/api-keys/api-keys.schemas.d.ts.map +1 -1
- package/dist/services/api-keys/api-keys.schemas.js +10 -4
- package/dist/services/api-keys/api-keys.schemas.js.map +1 -1
- package/dist/services/api-keys/api-keys.types.d.ts +2 -1
- package/dist/services/assistant/assistant-events.schemas.d.ts +131 -71
- package/dist/services/assistant/assistant-events.schemas.d.ts.map +1 -1
- package/dist/services/assistant/assistant-events.schemas.js +20 -2
- package/dist/services/assistant/assistant-events.schemas.js.map +1 -1
- package/dist/services/assistant/assistant.codecs.d.ts +10 -1
- package/dist/services/assistant/assistant.codecs.d.ts.map +1 -1
- package/dist/services/assistant/assistant.codecs.js +41 -1
- package/dist/services/assistant/assistant.codecs.js.map +1 -1
- package/dist/services/assistant/assistant.schemas.d.ts +22 -4
- package/dist/services/assistant/assistant.schemas.d.ts.map +1 -1
- package/dist/services/assistant/assistant.schemas.js +27 -4
- package/dist/services/assistant/assistant.schemas.js.map +1 -1
- package/dist/services/assistant/assistant.types.d.ts +2 -2
- package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts +19 -19
- package/dist/services/balances/balances.d.ts +12 -1
- package/dist/services/balances/balances.d.ts.map +1 -1
- package/dist/services/balances/balances.js +37 -1
- package/dist/services/balances/balances.js.map +1 -1
- package/dist/services/balances/balances.schemas.d.ts +55 -1
- package/dist/services/balances/balances.schemas.d.ts.map +1 -1
- package/dist/services/balances/balances.schemas.js +22 -1
- package/dist/services/balances/balances.schemas.js.map +1 -1
- package/dist/services/balances/balances.types.d.ts +2 -2
- package/dist/services/changelog/changelog.codecs.d.ts +10 -1
- package/dist/services/changelog/changelog.codecs.d.ts.map +1 -1
- package/dist/services/changelog/changelog.codecs.js +13 -1
- package/dist/services/changelog/changelog.codecs.js.map +1 -1
- package/dist/services/changelog/changelog.d.ts +14 -1
- package/dist/services/changelog/changelog.d.ts.map +1 -1
- package/dist/services/changelog/changelog.js +22 -1
- package/dist/services/changelog/changelog.js.map +1 -1
- package/dist/services/changelog/changelog.schemas.d.ts +445 -19
- package/dist/services/changelog/changelog.schemas.d.ts.map +1 -1
- package/dist/services/changelog/changelog.schemas.js +94 -5
- package/dist/services/changelog/changelog.schemas.js.map +1 -1
- package/dist/services/changelog/changelog.types.d.ts +3 -3
- package/dist/services/checkpoints/checkpoints.schemas.d.ts +3 -3
- package/dist/services/claims/claims.schemas.d.ts +2 -2
- package/dist/services/heatmap/heatmap.schemas.d.ts +4 -4
- package/dist/services/lifecycle/lifecycle.codecs.d.ts +8 -1
- package/dist/services/lifecycle/lifecycle.codecs.d.ts.map +1 -1
- package/dist/services/lifecycle/lifecycle.codecs.js +62 -1
- package/dist/services/lifecycle/lifecycle.codecs.js.map +1 -1
- package/dist/services/lifecycle/lifecycle.schemas.d.ts +64 -63
- package/dist/services/lifecycle/lifecycle.schemas.d.ts.map +1 -1
- package/dist/services/lifecycle/lifecycle.schemas.js +2 -2
- package/dist/services/lifecycle/lifecycle.schemas.js.map +1 -1
- package/dist/services/lifecycle/lifecycle.types.d.ts +2 -2
- package/dist/services/market-data/market-data.d.ts +7 -1
- package/dist/services/market-data/market-data.d.ts.map +1 -1
- package/dist/services/market-data/market-data.js +12 -1
- package/dist/services/market-data/market-data.js.map +1 -1
- package/dist/services/market-data/market-data.schemas.d.ts +108 -1
- package/dist/services/market-data/market-data.schemas.d.ts.map +1 -1
- package/dist/services/market-data/market-data.schemas.js +42 -2
- package/dist/services/market-data/market-data.schemas.js.map +1 -1
- package/dist/services/market-data/market-data.types.d.ts +2 -2
- package/dist/services/market-overview/market-overview.d.ts +1 -1
- package/dist/services/market-overview/market-overview.js +1 -1
- package/dist/services/market-overview/market-overview.js.map +1 -1
- package/dist/services/notifications/notifications.codecs.d.ts +8 -2
- package/dist/services/notifications/notifications.codecs.d.ts.map +1 -1
- package/dist/services/notifications/notifications.codecs.js +14 -2
- package/dist/services/notifications/notifications.codecs.js.map +1 -1
- package/dist/services/notifications/notifications.schemas.d.ts +91 -2
- package/dist/services/notifications/notifications.schemas.d.ts.map +1 -1
- package/dist/services/notifications/notifications.schemas.js +25 -1
- package/dist/services/notifications/notifications.schemas.js.map +1 -1
- package/dist/services/notifications/notifications.types.d.ts +2 -2
- package/dist/services/orderbook/orderbook.d.ts +2 -2
- package/dist/services/orderbook/orderbook.js +17 -12
- package/dist/services/orderbook/orderbook.js.map +1 -1
- package/dist/services/orderbook/orderbook.schemas.d.ts +1 -1
- package/dist/services/orders/order-errors.schemas.d.ts +2 -2
- package/dist/services/orders/orders-batch.schemas.d.ts +47 -47
- package/dist/services/orders/orders-input.schemas.d.ts +6 -6
- package/dist/services/orders/orders-output.schemas.d.ts +21 -21
- package/dist/services/policies/api-key-policies/api-key-policies.schemas.d.ts +15 -15
- package/dist/services/policies/shared.codecs.js +6 -3
- package/dist/services/policies/shared.codecs.js.map +1 -1
- package/dist/services/policies/shared.d.ts +1 -1
- package/dist/services/policies/subaccount-policies/subaccount-policies.schemas.d.ts +3 -3
- package/dist/services/price-alerts/price-alerts.schemas.d.ts +10 -10
- package/dist/services/rewards/rewards.schemas.d.ts +4 -4
- package/dist/services/subaccounts/subaccounts.codecs.js +2 -1
- package/dist/services/subaccounts/subaccounts.codecs.js.map +1 -1
- package/dist/services/subaccounts/subaccounts.schemas.d.ts +13 -13
- package/dist/services/system/system.codecs.d.ts +20 -0
- package/dist/services/system/system.codecs.d.ts.map +1 -0
- package/dist/services/system/system.codecs.js +57 -0
- package/dist/services/system/system.codecs.js.map +1 -0
- package/dist/services/system/system.d.ts +7 -0
- package/dist/services/system/system.d.ts.map +1 -1
- package/dist/services/system/system.js +13 -0
- package/dist/services/system/system.js.map +1 -1
- package/dist/services/system/system.schemas.d.ts +234 -0
- package/dist/services/system/system.schemas.d.ts.map +1 -0
- package/dist/services/system/system.schemas.js +78 -0
- package/dist/services/system/system.schemas.js.map +1 -0
- package/dist/services/system/system.types.d.ts +4 -0
- package/dist/services/trades/trades.schemas.d.ts +2 -2
- package/dist/services/triggers/trigger-input.schemas.d.ts +1 -1
- package/dist/services/triggers/triggers-output.schemas.d.ts +47 -47
- package/dist/services/triggers/triggers.d.ts +1 -1
- package/dist/services/triggers/triggers.js +1 -1
- package/dist/services/triggers/triggers.js.map +1 -1
- package/dist/services/zipper/zipper.schemas.d.ts +2 -2
- package/dist/services/zipper/zipper.schemas.d.ts.map +1 -1
- package/dist/services/zipper/zipper.schemas.js +9 -2
- package/dist/services/zipper/zipper.schemas.js.map +1 -1
- package/dist/services/zipper/zipper.types.d.ts +2 -2
- package/dist/shared/catalog-config.d.ts +13 -1
- package/dist/shared/catalog-config.d.ts.map +1 -1
- package/dist/shared/catalog-config.js +6 -1
- package/dist/shared/catalog-config.js.map +1 -1
- package/dist/shared/ledger-codes.d.ts +5 -3
- package/dist/shared/ledger-codes.d.ts.map +1 -1
- package/dist/shared/ledger-codes.js.map +1 -1
- package/dist/shared/rate-limit.schemas.d.ts +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.\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,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,2BACF,SACgC;EAChC,MAAM,WAAW,MAAM,KAAKA,QAAQ,2BAChC,CAAC,GACD,qBAAqB,OAAO,C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;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)) 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,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;;;;;;CAO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AQ,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,6 +1,6 @@
|
|
|
1
1
|
import "../../gen/notifications/v1/notifications_pb.js";
|
|
2
2
|
//#region src/services/notifications/notifications.codecs.d.ts
|
|
3
|
-
declare const NOTIFICATION_TYPE_VALUES: readonly ["price_alert", "telegram_approval"];
|
|
3
|
+
declare const NOTIFICATION_TYPE_VALUES: readonly ["price_alert", "telegram_approval", "broker_allowlist_change"];
|
|
4
4
|
/** What a notification reports; each type belongs to one category. */
|
|
5
5
|
type NotificationType = (typeof NOTIFICATION_TYPE_VALUES)[number];
|
|
6
6
|
declare const NOTIFICATION_CATEGORY_VALUES: readonly ["alerts", "security"];
|
|
@@ -11,6 +11,12 @@ type NotificationReadState = (typeof NOTIFICATION_READ_STATE_VALUES)[number];
|
|
|
11
11
|
declare const TELEGRAM_APPROVAL_ACTION_VALUES: readonly ["place_order", "place_orders", "modify_orders", "cancel_order", "cancel_all_orders", "modify_trigger", "pause_trigger", "resume_trigger", "swap"];
|
|
12
12
|
/** What an approval from the linked Telegram account approved. */
|
|
13
13
|
type TelegramApprovalAction = (typeof TELEGRAM_APPROVAL_ACTION_VALUES)[number];
|
|
14
|
+
declare const BROKER_ALLOWLIST_EVENT_VALUES: readonly ["change_requested", "change_applied", "change_not_applied"];
|
|
15
|
+
/** What happened to a broker vault payout address change. `change_not_applied` is final. */
|
|
16
|
+
type BrokerAllowlistEvent = (typeof BROKER_ALLOWLIST_EVENT_VALUES)[number];
|
|
17
|
+
declare const BROKER_ALLOWLIST_ACTION_VALUES: readonly ["add_destination", "remove_destination"];
|
|
18
|
+
/** Whether a broker vault payout address change adds or removes the address. */
|
|
19
|
+
type BrokerAllowlistAction = (typeof BROKER_ALLOWLIST_ACTION_VALUES)[number];
|
|
14
20
|
//#endregion
|
|
15
|
-
export { NOTIFICATION_CATEGORY_VALUES, NOTIFICATION_READ_STATE_VALUES, NOTIFICATION_TYPE_VALUES, NotificationCategory, NotificationReadState, NotificationType, TELEGRAM_APPROVAL_ACTION_VALUES, TelegramApprovalAction };
|
|
21
|
+
export { BROKER_ALLOWLIST_ACTION_VALUES, BROKER_ALLOWLIST_EVENT_VALUES, BrokerAllowlistAction, BrokerAllowlistEvent, NOTIFICATION_CATEGORY_VALUES, NOTIFICATION_READ_STATE_VALUES, NOTIFICATION_TYPE_VALUES, NotificationCategory, NotificationReadState, NotificationType, TELEGRAM_APPROVAL_ACTION_VALUES, TelegramApprovalAction };
|
|
16
22
|
//# sourceMappingURL=notifications.codecs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.codecs.d.ts","names":[],"sources":["../../../src/services/notifications/notifications.codecs.ts"],"mappings":";;cAGa;;
|
|
1
|
+
{"version":3,"file":"notifications.codecs.d.ts","names":[],"sources":["../../../src/services/notifications/notifications.codecs.ts"],"mappings":";;cAGa;;KAMD,2BAA2B;cAE1B;;KAED,+BAA+B;cAE9B;KACD,gCAAgC;cAE/B;;KAYD,iCAAiC;cAEhC;;KAMD,+BAA+B;cAE9B;;KAED,gCAAgC"}
|
|
@@ -5,7 +5,8 @@ const NOTIFICATION_READ_STATE_VALUES = ["unread", "read"];
|
|
|
5
5
|
const NotificationTypeCodec = { protoToOutput: {
|
|
6
6
|
[0]: "unspecified",
|
|
7
7
|
[1]: "price_alert",
|
|
8
|
-
[2]: "telegram_approval"
|
|
8
|
+
[2]: "telegram_approval",
|
|
9
|
+
[3]: "broker_allowlist_change"
|
|
9
10
|
} };
|
|
10
11
|
const NotificationCategoryCodec = {
|
|
11
12
|
inputToProto: {
|
|
@@ -34,7 +35,18 @@ const TelegramApprovalActionCodec = { protoToOutput: {
|
|
|
34
35
|
[8]: "resume_trigger",
|
|
35
36
|
[9]: "swap"
|
|
36
37
|
} };
|
|
38
|
+
const BrokerAllowlistEventCodec = { protoToOutput: {
|
|
39
|
+
[0]: "unspecified",
|
|
40
|
+
[1]: "change_requested",
|
|
41
|
+
[2]: "change_applied",
|
|
42
|
+
[3]: "change_not_applied"
|
|
43
|
+
} };
|
|
44
|
+
const BrokerAllowlistActionCodec = { protoToOutput: {
|
|
45
|
+
[0]: "unspecified",
|
|
46
|
+
[1]: "add_destination",
|
|
47
|
+
[2]: "remove_destination"
|
|
48
|
+
} };
|
|
37
49
|
//#endregion
|
|
38
|
-
export { NOTIFICATION_CATEGORY_VALUES, NOTIFICATION_READ_STATE_VALUES, NotificationCategoryCodec, NotificationReadStateCodec, NotificationTypeCodec, TelegramApprovalActionCodec };
|
|
50
|
+
export { BrokerAllowlistActionCodec, BrokerAllowlistEventCodec, NOTIFICATION_CATEGORY_VALUES, NOTIFICATION_READ_STATE_VALUES, NotificationCategoryCodec, NotificationReadStateCodec, NotificationTypeCodec, TelegramApprovalActionCodec };
|
|
39
51
|
|
|
40
52
|
//# sourceMappingURL=notifications.codecs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.codecs.js","names":[],"sources":["../../../src/services/notifications/notifications.codecs.ts"],"sourcesContent":["import * as Proto from \"../../gen/notifications/v1/notifications_pb.js\";\nimport type { InputToProto, ProtoToOutput } from \"../../utils/types.js\";\n\nexport const NOTIFICATION_TYPE_VALUES = [\"price_alert\"
|
|
1
|
+
{"version":3,"file":"notifications.codecs.js","names":[],"sources":["../../../src/services/notifications/notifications.codecs.ts"],"sourcesContent":["import * as Proto from \"../../gen/notifications/v1/notifications_pb.js\";\nimport type { InputToProto, ProtoToOutput } from \"../../utils/types.js\";\n\nexport const NOTIFICATION_TYPE_VALUES = [\n \"price_alert\",\n \"telegram_approval\",\n \"broker_allowlist_change\",\n] as const;\n/** What a notification reports; each type belongs to one category. */\nexport type NotificationType = (typeof NOTIFICATION_TYPE_VALUES)[number];\n\nexport const NOTIFICATION_CATEGORY_VALUES = [\"alerts\", \"security\"] as const;\n/** `alerts` holds alerts the caller set; `security` holds account security events. */\nexport type NotificationCategory = (typeof NOTIFICATION_CATEGORY_VALUES)[number];\n\nexport const NOTIFICATION_READ_STATE_VALUES = [\"unread\", \"read\"] as const;\nexport type NotificationReadState = (typeof NOTIFICATION_READ_STATE_VALUES)[number];\n\nexport const TELEGRAM_APPROVAL_ACTION_VALUES = [\n \"place_order\",\n \"place_orders\",\n \"modify_orders\",\n \"cancel_order\",\n \"cancel_all_orders\",\n \"modify_trigger\",\n \"pause_trigger\",\n \"resume_trigger\",\n \"swap\",\n] as const;\n/** What an approval from the linked Telegram account approved. */\nexport type TelegramApprovalAction = (typeof TELEGRAM_APPROVAL_ACTION_VALUES)[number];\n\nexport const BROKER_ALLOWLIST_EVENT_VALUES = [\n \"change_requested\",\n \"change_applied\",\n \"change_not_applied\",\n] as const;\n/** What happened to a broker vault payout address change. `change_not_applied` is final. */\nexport type BrokerAllowlistEvent = (typeof BROKER_ALLOWLIST_EVENT_VALUES)[number];\n\nexport const BROKER_ALLOWLIST_ACTION_VALUES = [\"add_destination\", \"remove_destination\"] as const;\n/** Whether a broker vault payout address change adds or removes the address. */\nexport type BrokerAllowlistAction = (typeof BROKER_ALLOWLIST_ACTION_VALUES)[number];\n\nexport const NotificationTypeCodec = {\n protoToOutput: {\n [Proto.NotificationType.TYPE_UNSPECIFIED]: \"unspecified\",\n [Proto.NotificationType.PRICE_ALERT]: \"price_alert\",\n [Proto.NotificationType.TELEGRAM_APPROVAL]: \"telegram_approval\",\n [Proto.NotificationType.BROKER_ALLOWLIST_CHANGE]: \"broker_allowlist_change\",\n } satisfies ProtoToOutput<Proto.NotificationType, NotificationType>,\n} as const;\n\nexport const NotificationCategoryCodec = {\n inputToProto: {\n alerts: Proto.NotificationCategory.ALERTS,\n security: Proto.NotificationCategory.SECURITY,\n } satisfies InputToProto<NotificationCategory, Proto.NotificationCategory>,\n protoToOutput: {\n [Proto.NotificationCategory.CATEGORY_UNSPECIFIED]: \"unspecified\",\n [Proto.NotificationCategory.ALERTS]: \"alerts\",\n [Proto.NotificationCategory.SECURITY]: \"security\",\n } satisfies ProtoToOutput<Proto.NotificationCategory, NotificationCategory>,\n} as const;\n\nexport const NotificationReadStateCodec = {\n inputToProto: {\n unread: Proto.ReadState.UNREAD,\n read: Proto.ReadState.READ,\n } satisfies InputToProto<NotificationReadState, Proto.ReadState>,\n} as const;\n\nexport const TelegramApprovalActionCodec = {\n protoToOutput: {\n [Proto.TelegramApprovalAction.ACTION_UNSPECIFIED]: \"unspecified\",\n [Proto.TelegramApprovalAction.PLACE_ORDER]: \"place_order\",\n [Proto.TelegramApprovalAction.PLACE_ORDERS]: \"place_orders\",\n [Proto.TelegramApprovalAction.MODIFY_ORDERS]: \"modify_orders\",\n [Proto.TelegramApprovalAction.CANCEL_ORDER]: \"cancel_order\",\n [Proto.TelegramApprovalAction.CANCEL_ALL_ORDERS]: \"cancel_all_orders\",\n [Proto.TelegramApprovalAction.MODIFY_TRIGGER]: \"modify_trigger\",\n [Proto.TelegramApprovalAction.PAUSE_TRIGGER]: \"pause_trigger\",\n [Proto.TelegramApprovalAction.RESUME_TRIGGER]: \"resume_trigger\",\n [Proto.TelegramApprovalAction.SWAP]: \"swap\",\n } satisfies ProtoToOutput<Proto.TelegramApprovalAction, TelegramApprovalAction>,\n} as const;\n\nexport const BrokerAllowlistEventCodec = {\n protoToOutput: {\n [Proto.BrokerAllowlistEvent.BROKER_ALLOWLIST_EVENT_UNSPECIFIED]: \"unspecified\",\n [Proto.BrokerAllowlistEvent.CHANGE_REQUESTED]: \"change_requested\",\n [Proto.BrokerAllowlistEvent.CHANGE_APPLIED]: \"change_applied\",\n [Proto.BrokerAllowlistEvent.CHANGE_NOT_APPLIED]: \"change_not_applied\",\n } satisfies ProtoToOutput<Proto.BrokerAllowlistEvent, BrokerAllowlistEvent>,\n} as const;\n\nexport const BrokerAllowlistActionCodec = {\n protoToOutput: {\n [Proto.BrokerAllowlistAction.BROKER_ALLOWLIST_ACTION_UNSPECIFIED]: \"unspecified\",\n [Proto.BrokerAllowlistAction.ADD_DESTINATION]: \"add_destination\",\n [Proto.BrokerAllowlistAction.REMOVE_DESTINATION]: \"remove_destination\",\n } satisfies ProtoToOutput<Proto.BrokerAllowlistAction, BrokerAllowlistAction>,\n} as const;\n"],"mappings":";;AAWA,MAAa,+BAA+B,CAAC,UAAU,UAAU;AAIjE,MAAa,iCAAiC,CAAC,UAAU,MAAM;AA6B/D,MAAa,wBAAwB,EACjC,eAAe;EACgC,IAAA;EACL,IAAA;EACM,IAAA;EACM,IAAA;AACtD,EACJ;AAEA,MAAa,4BAA4B;CACrC,cAAc;EACV,QAAA;EACA,UAAA;CACJ;CACA,eAAe;GACwC,IAAA;GACd,IAAA;GACE,IAAA;CAC3C;AACJ;AAEA,MAAa,6BAA6B,EACtC,cAAc;CACV,QAAA;CACA,MAAA;AACJ,EACJ;AAEA,MAAa,8BAA8B,EACvC,eAAe;EACwC,IAAA;EACP,IAAA;EACC,IAAA;EACC,IAAA;EACD,IAAA;EACK,IAAA;EACH,IAAA;EACD,IAAA;EACC,IAAA;EACV,IAAA;AACzC,EACJ;AAEA,MAAa,4BAA4B,EACrC,eAAe;EACsD,IAAA;EAClB,IAAA;EACF,IAAA;EACI,IAAA;AACrD,EACJ;AAEA,MAAa,6BAA6B,EACtC,eAAe;EACwD,IAAA;EACpB,IAAA;EACG,IAAA;AACtD,EACJ"}
|
|
@@ -56,7 +56,7 @@ declare const MarkAllNotificationsReadInputSchema: v.StrictObjectSchema<{
|
|
|
56
56
|
type MarkAllNotificationsReadInput = v.InferInput<typeof MarkAllNotificationsReadInputSchema>;
|
|
57
57
|
declare function formatNotification(notification: Notification): {
|
|
58
58
|
notificationId: string;
|
|
59
|
-
type: "unspecified" | "price_alert" | "telegram_approval";
|
|
59
|
+
type: "unspecified" | "price_alert" | "telegram_approval" | "broker_allowlist_change";
|
|
60
60
|
category: "unspecified" | "alerts" | "security";
|
|
61
61
|
/** Plain-text title, the same for every notification of a type. */
|
|
62
62
|
title: string;
|
|
@@ -86,6 +86,23 @@ declare function formatNotification(notification: Notification): {
|
|
|
86
86
|
/** Key parameters in display order, such as market, side and quantity. */
|
|
87
87
|
parameters?: undefined;
|
|
88
88
|
approvedAt?: undefined;
|
|
89
|
+
broker?: undefined;
|
|
90
|
+
/** Sub-account ID of the broker vault. */
|
|
91
|
+
vaultAccountId?: undefined;
|
|
92
|
+
/** The change's ID; key the broker's vault allowlist view on it. */
|
|
93
|
+
changeId?: undefined;
|
|
94
|
+
event?: undefined;
|
|
95
|
+
/** Destination chain ID, as a decimal string. */
|
|
96
|
+
destinationChainId?: undefined;
|
|
97
|
+
destinationAddress?: undefined;
|
|
98
|
+
/** The requesting member's name for an added address; empty when none. */
|
|
99
|
+
label?: undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Account ID of the member who requested the change. Show a `change_requested`
|
|
102
|
+
* the caller did not make prominently: an added address becomes payable 24 hours
|
|
103
|
+
* after it is listed.
|
|
104
|
+
*/
|
|
105
|
+
requestedByAccountId?: undefined;
|
|
89
106
|
} | {
|
|
90
107
|
type: "telegram_approval";
|
|
91
108
|
/** The approval's ID in `client.assistant`. */
|
|
@@ -110,6 +127,61 @@ declare function formatNotification(notification: Notification): {
|
|
|
110
127
|
/** Price that fired the alert, as a decimal string. */
|
|
111
128
|
triggeredPrice?: undefined;
|
|
112
129
|
triggeredAt?: undefined;
|
|
130
|
+
broker?: undefined;
|
|
131
|
+
/** Sub-account ID of the broker vault. */
|
|
132
|
+
vaultAccountId?: undefined;
|
|
133
|
+
/** The change's ID; key the broker's vault allowlist view on it. */
|
|
134
|
+
changeId?: undefined;
|
|
135
|
+
event?: undefined;
|
|
136
|
+
/** Destination chain ID, as a decimal string. */
|
|
137
|
+
destinationChainId?: undefined;
|
|
138
|
+
destinationAddress?: undefined;
|
|
139
|
+
/** The requesting member's name for an added address; empty when none. */
|
|
140
|
+
label?: undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Account ID of the member who requested the change. Show a `change_requested`
|
|
143
|
+
* the caller did not make prominently: an added address becomes payable 24 hours
|
|
144
|
+
* after it is listed.
|
|
145
|
+
*/
|
|
146
|
+
requestedByAccountId?: undefined;
|
|
147
|
+
} | {
|
|
148
|
+
type: "broker_allowlist_change";
|
|
149
|
+
broker: string;
|
|
150
|
+
/** Sub-account ID of the broker vault. */
|
|
151
|
+
vaultAccountId: string;
|
|
152
|
+
/** The change's ID; key the broker's vault allowlist view on it. */
|
|
153
|
+
changeId: string;
|
|
154
|
+
event: "unspecified" | "change_requested" | "change_applied" | "change_not_applied";
|
|
155
|
+
action: "unspecified" | "add_destination" | "remove_destination";
|
|
156
|
+
/** Destination chain ID, as a decimal string. */
|
|
157
|
+
destinationChainId: string;
|
|
158
|
+
destinationAddress: string;
|
|
159
|
+
/** The requesting member's name for an added address; empty when none. */
|
|
160
|
+
label: string;
|
|
161
|
+
/**
|
|
162
|
+
* Account ID of the member who requested the change. Show a `change_requested`
|
|
163
|
+
* the caller did not make prominently: an added address becomes payable 24 hours
|
|
164
|
+
* after it is listed.
|
|
165
|
+
*/
|
|
166
|
+
requestedByAccountId: string;
|
|
167
|
+
/** The alert's ID in `client.priceAlerts`. */
|
|
168
|
+
alertId?: undefined;
|
|
169
|
+
symbolId?: undefined;
|
|
170
|
+
direction?: undefined;
|
|
171
|
+
priceSource?: undefined;
|
|
172
|
+
/** Alert price, as a decimal string. */
|
|
173
|
+
price?: undefined;
|
|
174
|
+
/** Price that fired the alert, as a decimal string. */
|
|
175
|
+
triggeredPrice?: undefined;
|
|
176
|
+
triggeredAt?: undefined;
|
|
177
|
+
/** The approval's ID in `client.assistant`. */
|
|
178
|
+
approvalId?: undefined;
|
|
179
|
+
/** Trading account (subaccount) the action acted on. */
|
|
180
|
+
accountId?: undefined;
|
|
181
|
+
summary?: undefined;
|
|
182
|
+
/** Key parameters in display order, such as market, side and quantity. */
|
|
183
|
+
parameters?: undefined;
|
|
184
|
+
approvedAt?: undefined;
|
|
113
185
|
} | {
|
|
114
186
|
type: "unspecified";
|
|
115
187
|
/** The alert's ID in `client.priceAlerts`. */
|
|
@@ -131,6 +203,23 @@ declare function formatNotification(notification: Notification): {
|
|
|
131
203
|
/** Key parameters in display order, such as market, side and quantity. */
|
|
132
204
|
parameters?: undefined;
|
|
133
205
|
approvedAt?: undefined;
|
|
206
|
+
broker?: undefined;
|
|
207
|
+
/** Sub-account ID of the broker vault. */
|
|
208
|
+
vaultAccountId?: undefined;
|
|
209
|
+
/** The change's ID; key the broker's vault allowlist view on it. */
|
|
210
|
+
changeId?: undefined;
|
|
211
|
+
event?: undefined;
|
|
212
|
+
/** Destination chain ID, as a decimal string. */
|
|
213
|
+
destinationChainId?: undefined;
|
|
214
|
+
destinationAddress?: undefined;
|
|
215
|
+
/** The requesting member's name for an added address; empty when none. */
|
|
216
|
+
label?: undefined;
|
|
217
|
+
/**
|
|
218
|
+
* Account ID of the member who requested the change. Show a `change_requested`
|
|
219
|
+
* the caller did not make prominently: an added address becomes payable 24 hours
|
|
220
|
+
* after it is listed.
|
|
221
|
+
*/
|
|
222
|
+
requestedByAccountId?: undefined;
|
|
134
223
|
};
|
|
135
224
|
};
|
|
136
225
|
/**
|
|
@@ -149,7 +238,7 @@ declare function formatNotificationCounts(counts: GetNotificationCountsResponse)
|
|
|
149
238
|
unread: number;
|
|
150
239
|
/** Every type in ascending enum order, including types with no notification. */
|
|
151
240
|
types: {
|
|
152
|
-
type: "unspecified" | "price_alert" | "telegram_approval";
|
|
241
|
+
type: "unspecified" | "price_alert" | "telegram_approval" | "broker_allowlist_change";
|
|
153
242
|
category: "unspecified" | "alerts" | "security";
|
|
154
243
|
total: number;
|
|
155
244
|
unread: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.schemas.d.ts","names":[],"sources":["../../../src/services/notifications/notifications.schemas.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"notifications.schemas.d.ts","names":[],"sources":["../../../src/services/notifications/notifications.schemas.ts"],"mappings":";;;cA2Ca,8BAA4B,EAAA,yBAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2B7B,yBAAyB,EAAE,kBAAkB;cAE5C,4BAA0B,EAAA;;;KAI3B,uBAAuB,EAAE,kBAAkB;cAE1C,8BAA4B,EAAA;;;;KAU7B,yBAAyB,EAAE,kBAAkB;cAE5C,qCAAmC,EAAA;;;;;;;;KASpC,gCAAgC,EAAE,kBACnC;iBA4EK,mBAAmB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoBrC,sBAAsB,kBAAkB;KAExC,4BAA4B;;KAG5B;EACR,eAAe;EACf;;iBAGY,yBAAyB,QAAQ;;;;;;;;;;;;KAerC,qBAAqB,kBAAkB"}
|
|
@@ -5,7 +5,7 @@ import { enumLabel } from "../../shared/proto-enum-codec.js";
|
|
|
5
5
|
import { scaledToDecimalOutput } from "../../shared/decimal-surface.js";
|
|
6
6
|
import { msToTimestamp } from "../../utils/timestamp.js";
|
|
7
7
|
import { PriceAlertDirectionCodec, PriceAlertPriceSourceCodec } from "../price-alerts/price-alerts.codecs.js";
|
|
8
|
-
import { NOTIFICATION_CATEGORY_VALUES, NOTIFICATION_READ_STATE_VALUES, NotificationCategoryCodec, NotificationReadStateCodec, NotificationTypeCodec, TelegramApprovalActionCodec } from "./notifications.codecs.js";
|
|
8
|
+
import { BrokerAllowlistActionCodec, BrokerAllowlistEventCodec, NOTIFICATION_CATEGORY_VALUES, NOTIFICATION_READ_STATE_VALUES, NotificationCategoryCodec, NotificationReadStateCodec, NotificationTypeCodec, TelegramApprovalActionCodec } from "./notifications.codecs.js";
|
|
9
9
|
import * as v from "valibot";
|
|
10
10
|
//#region src/services/notifications/notifications.schemas.ts
|
|
11
11
|
const NotificationIdInputSchema = idInputSchema("notificationId");
|
|
@@ -79,6 +79,30 @@ function formatDetail(detail) {
|
|
|
79
79
|
approvedAt: tsObjToMs(notice.approvedAt) ?? null
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
+
case "brokerAllowlist": {
|
|
83
|
+
const notice = detail.value;
|
|
84
|
+
return {
|
|
85
|
+
type: "broker_allowlist_change",
|
|
86
|
+
broker: notice.broker,
|
|
87
|
+
/** Sub-account ID of the broker vault. */
|
|
88
|
+
vaultAccountId: formatId(notice.vaultAccountId),
|
|
89
|
+
/** The change's ID; key the broker's vault allowlist view on it. */
|
|
90
|
+
changeId: formatId(notice.changeId),
|
|
91
|
+
event: enumLabel(BrokerAllowlistEventCodec.protoToOutput, notice.event),
|
|
92
|
+
action: enumLabel(BrokerAllowlistActionCodec.protoToOutput, notice.action),
|
|
93
|
+
/** Destination chain ID, as a decimal string. */
|
|
94
|
+
destinationChainId: notice.destinationChainId.toString(),
|
|
95
|
+
destinationAddress: notice.destinationAddress,
|
|
96
|
+
/** The requesting member's name for an added address; empty when none. */
|
|
97
|
+
label: notice.label,
|
|
98
|
+
/**
|
|
99
|
+
* Account ID of the member who requested the change. Show a `change_requested`
|
|
100
|
+
* the caller did not make prominently: an added address becomes payable 24 hours
|
|
101
|
+
* after it is listed.
|
|
102
|
+
*/
|
|
103
|
+
requestedByAccountId: formatId(notice.requestedByAccountId)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
82
106
|
default: return { type: "unspecified" };
|
|
83
107
|
}
|
|
84
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifications.schemas.js","names":[],"sources":["../../../src/services/notifications/notifications.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { PRICE_SCALE } from \"../../catalogs/readers.js\";\nimport type * as Proto from \"../../gen/notifications/v1/notifications_pb.js\";\nimport { scaledToDecimalOutput } from \"../../shared/decimal-surface.js\";\nimport { enumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { idInputSchema, optionalIdInputSchema } from \"../../shared/schemas.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { tsObjToMs } from \"../../utils/time.js\";\nimport { msToTimestamp } from \"../../utils/timestamp.js\";\nimport {\n PriceAlertDirectionCodec,\n PriceAlertPriceSourceCodec,\n} from \"../price-alerts/price-alerts.codecs.js\";\nimport {\n NOTIFICATION_CATEGORY_VALUES,\n NOTIFICATION_READ_STATE_VALUES,\n NotificationCategoryCodec,\n NotificationReadStateCodec,\n NotificationTypeCodec,\n TelegramApprovalActionCodec,\n} from \"./notifications.codecs.js\";\n\nconst NotificationIdInputSchema = idInputSchema(\"notificationId\");\n\n/** Omit or pass empty for every category. */\nconst CategoriesInputSchema = v.optional(\n v.pipe(\n v.array(v.picklist(NOTIFICATION_CATEGORY_VALUES)),\n v.transform((categories) =>\n categories.map((category) => NotificationCategoryCodec.inputToProto[category]),\n ),\n ),\n);\n\nconst TimestampMsInputSchema = v.pipe(\n v.number(),\n v.integer(),\n v.minValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n);\n\nexport const ListNotificationsInputSchema = v.pipe(\n v.strictObject({\n categories: CategoriesInputSchema,\n /** Only read or only unread notifications; omit for both. */\n readState: v.optional(v.picklist(NOTIFICATION_READ_STATE_VALUES)),\n /** Epoch ms, inclusive. */\n startTime: v.optional(TimestampMsInputSchema),\n /** Epoch ms, exclusive; after `startTime` when both are set. */\n endTime: v.optional(TimestampMsInputSchema),\n /** Page size: default 25, at most 100. */\n limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(100))),\n /** Previous `nextPageToken`; reuse only with the same filters. */\n pageToken: v.optional(v.pipe(v.string(), v.trim())),\n }),\n v.check(\n ({ startTime, endTime }) =>\n startTime === undefined || endTime === undefined || endTime > startTime,\n \"endTime: must be after startTime\",\n ),\n v.transform(({ readState, startTime, endTime, ...input }) => ({\n ...input,\n readState: readState && NotificationReadStateCodec.inputToProto[readState],\n startTime: startTime === undefined ? undefined : msToTimestamp(startTime),\n endTime: endTime === undefined ? undefined : msToTimestamp(endTime),\n })),\n);\n\nexport type ListNotificationsInput = v.InferInput<typeof ListNotificationsInputSchema>;\n\nexport const GetNotificationInputSchema = v.strictObject({\n notificationId: NotificationIdInputSchema,\n});\n\nexport type GetNotificationInput = v.InferInput<typeof GetNotificationInputSchema>;\n\nexport const MarkNotificationsInputSchema = v.strictObject({\n /** One to 100 distinct notification IDs. */\n notificationIds: v.pipe(\n v.array(NotificationIdInputSchema),\n v.minLength(1, \"At least one notification ID is required.\"),\n v.maxLength(100, \"At most 100 notification IDs are allowed.\"),\n v.check((ids) => new Set(ids).size === ids.length, \"Notification IDs must be distinct.\"),\n ),\n});\n\nexport type MarkNotificationsInput = v.InferInput<typeof MarkNotificationsInputSchema>;\n\nexport const MarkAllNotificationsReadInputSchema = v.strictObject({\n categories: CategoriesInputSchema,\n /**\n * Mark only this notification and older ones. Pass the newest one shown, so one that arrives\n * later stays unread; omit to mark every notification that exists when the call runs.\n */\n throughNotificationId: optionalIdInputSchema(\"throughNotificationId\"),\n});\n\nexport type MarkAllNotificationsReadInput = v.InferInput<\n typeof MarkAllNotificationsReadInputSchema\n>;\n\n/*\n * Outputs are formatted straight from the decoded messages, like the assistant's run events.\n * The `detail` oneof becomes a `type`-tagged union; a case this build does not know becomes\n * `{ type: \"unspecified\" }`, and the notification's `title` and `text` describe it.\n */\n\nconst price = (ticks: bigint) => scaledToDecimalOutput(ticks, PRICE_SCALE);\n\nfunction formatDetail(detail: Proto.Notification[\"detail\"]) {\n switch (detail.case) {\n case \"priceAlert\": {\n const notice = detail.value;\n return {\n type: \"price_alert\" as const,\n /** The alert's ID in `client.priceAlerts`. */\n alertId: formatId(notice.alertId),\n symbolId: notice.symbolId,\n direction: enumLabel(PriceAlertDirectionCodec.protoToOutput, notice.direction),\n priceSource: enumLabel(\n PriceAlertPriceSourceCodec.protoToOutput,\n notice.priceSource,\n ),\n /** Alert price, as a decimal string. */\n price: price(notice.priceTicks),\n /** Price that fired the alert, as a decimal string. */\n triggeredPrice: price(notice.triggeredPriceTicks),\n triggeredAt: tsObjToMs(notice.triggeredAt) ?? null,\n };\n }\n case \"telegramApproval\": {\n const notice = detail.value;\n return {\n type: \"telegram_approval\" as const,\n /** The approval's ID in `client.assistant`. */\n approvalId: formatId(notice.approvalId),\n action: enumLabel(TelegramApprovalActionCodec.protoToOutput, notice.action),\n /** Trading account (subaccount) the action acted on. */\n accountId: formatId(notice.accountId),\n summary: notice.summary,\n /** Key parameters in display order, such as market, side and quantity. */\n parameters: notice.parameters.map(({ label, value }) => ({ label, value })),\n approvedAt: tsObjToMs(notice.approvedAt) ?? null,\n };\n }\n default:\n return { type: \"unspecified\" as const };\n }\n}\n\nexport function formatNotification(notification: Proto.Notification) {\n return {\n notificationId: formatId(notification.notificationId),\n type: enumLabel(NotificationTypeCodec.protoToOutput, notification.type),\n category: enumLabel(NotificationCategoryCodec.protoToOutput, notification.category),\n /** Plain-text title, the same for every notification of a type. */\n title: notification.title,\n /** Plain-text summary; may span several lines. */\n text: notification.text,\n createdAt: tsObjToMs(notification.createdAt) ?? null,\n /** Null while unread. */\n readAt: tsObjToMs(notification.readAt) ?? null,\n detail: formatDetail(notification.detail),\n };\n}\n\n/**\n * One notification. When `detail.type` is `\"unspecified\"` (a type this SDK build does not\n * know), show `title` and `text` only.\n */\nexport type AccountNotification = ReturnType<typeof formatNotification>;\n\nexport type AccountNotificationDetail = AccountNotification[\"detail\"];\n\n/** One page of notifications, newest first; an empty `nextPageToken` means no more. */\nexport type ListNotificationsResult = {\n notifications: AccountNotification[];\n nextPageToken: string;\n};\n\nexport function formatNotificationCounts(counts: Proto.GetNotificationCountsResponse) {\n return {\n total: Number(counts.total),\n unread: Number(counts.unread),\n /** Every type in ascending enum order, including types with no notification. */\n types: counts.types.map((count) => ({\n type: enumLabel(NotificationTypeCodec.protoToOutput, count.type),\n category: enumLabel(NotificationCategoryCodec.protoToOutput, count.category),\n total: Number(count.total),\n unread: Number(count.unread),\n })),\n };\n}\n\n/** Exact counts of the caller's notifications, as of one moment. */\nexport type NotificationCounts = ReturnType<typeof formatNotificationCounts>;\n"],"mappings":";;;;;;;;;;AAsBA,MAAM,4BAA4B,cAAc,gBAAgB;;AAGhE,MAAM,wBAAwB,EAAE,SAC5B,EAAE,KACE,EAAE,MAAM,EAAE,SAAS,4BAA4B,CAAC,GAChD,EAAE,WAAW,eACT,WAAW,KAAK,aAAa,0BAA0B,aAAa,SAAS,CACjF,CACJ,CACJ;AAEA,MAAM,yBAAyB,EAAE,KAC7B,EAAE,OAAO,GACT,EAAE,QAAQ,GACV,EAAE,SAAS,CAAC,GACZ,EAAE,SAAS,OAAO,gBAAgB,CACtC;AAEA,MAAa,+BAA+B,EAAE,KAC1C,EAAE,aAAa;CACX,YAAY;;CAEZ,W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CACN;AACJ"}
|
|
1
|
+
{"version":3,"file":"notifications.schemas.js","names":[],"sources":["../../../src/services/notifications/notifications.schemas.ts"],"sourcesContent":["import * as v from \"valibot\";\nimport { PRICE_SCALE } from \"../../catalogs/readers.js\";\nimport type * as Proto from \"../../gen/notifications/v1/notifications_pb.js\";\nimport { scaledToDecimalOutput } from \"../../shared/decimal-surface.js\";\nimport { enumLabel } from \"../../shared/proto-enum-codec.js\";\nimport { idInputSchema, optionalIdInputSchema } from \"../../shared/schemas.js\";\nimport { formatId } from \"../../utils/base58-id.js\";\nimport { tsObjToMs } from \"../../utils/time.js\";\nimport { msToTimestamp } from \"../../utils/timestamp.js\";\nimport {\n PriceAlertDirectionCodec,\n PriceAlertPriceSourceCodec,\n} from \"../price-alerts/price-alerts.codecs.js\";\nimport {\n BrokerAllowlistActionCodec,\n BrokerAllowlistEventCodec,\n NOTIFICATION_CATEGORY_VALUES,\n NOTIFICATION_READ_STATE_VALUES,\n NotificationCategoryCodec,\n NotificationReadStateCodec,\n NotificationTypeCodec,\n TelegramApprovalActionCodec,\n} from \"./notifications.codecs.js\";\n\nconst NotificationIdInputSchema = idInputSchema(\"notificationId\");\n\n/** Omit or pass empty for every category. */\nconst CategoriesInputSchema = v.optional(\n v.pipe(\n v.array(v.picklist(NOTIFICATION_CATEGORY_VALUES)),\n v.transform((categories) =>\n categories.map((category) => NotificationCategoryCodec.inputToProto[category]),\n ),\n ),\n);\n\nconst TimestampMsInputSchema = v.pipe(\n v.number(),\n v.integer(),\n v.minValue(0),\n v.maxValue(Number.MAX_SAFE_INTEGER),\n);\n\nexport const ListNotificationsInputSchema = v.pipe(\n v.strictObject({\n categories: CategoriesInputSchema,\n /** Only read or only unread notifications; omit for both. */\n readState: v.optional(v.picklist(NOTIFICATION_READ_STATE_VALUES)),\n /** Epoch ms, inclusive. */\n startTime: v.optional(TimestampMsInputSchema),\n /** Epoch ms, exclusive; after `startTime` when both are set. */\n endTime: v.optional(TimestampMsInputSchema),\n /** Page size: default 25, at most 100. */\n limit: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(100))),\n /** Previous `nextPageToken`; reuse only with the same filters. */\n pageToken: v.optional(v.pipe(v.string(), v.trim())),\n }),\n v.check(\n ({ startTime, endTime }) =>\n startTime === undefined || endTime === undefined || endTime > startTime,\n \"endTime: must be after startTime\",\n ),\n v.transform(({ readState, startTime, endTime, ...input }) => ({\n ...input,\n readState: readState && NotificationReadStateCodec.inputToProto[readState],\n startTime: startTime === undefined ? undefined : msToTimestamp(startTime),\n endTime: endTime === undefined ? undefined : msToTimestamp(endTime),\n })),\n);\n\nexport type ListNotificationsInput = v.InferInput<typeof ListNotificationsInputSchema>;\n\nexport const GetNotificationInputSchema = v.strictObject({\n notificationId: NotificationIdInputSchema,\n});\n\nexport type GetNotificationInput = v.InferInput<typeof GetNotificationInputSchema>;\n\nexport const MarkNotificationsInputSchema = v.strictObject({\n /** One to 100 distinct notification IDs. */\n notificationIds: v.pipe(\n v.array(NotificationIdInputSchema),\n v.minLength(1, \"At least one notification ID is required.\"),\n v.maxLength(100, \"At most 100 notification IDs are allowed.\"),\n v.check((ids) => new Set(ids).size === ids.length, \"Notification IDs must be distinct.\"),\n ),\n});\n\nexport type MarkNotificationsInput = v.InferInput<typeof MarkNotificationsInputSchema>;\n\nexport const MarkAllNotificationsReadInputSchema = v.strictObject({\n categories: CategoriesInputSchema,\n /**\n * Mark only this notification and older ones. Pass the newest one shown, so one that arrives\n * later stays unread; omit to mark every notification that exists when the call runs.\n */\n throughNotificationId: optionalIdInputSchema(\"throughNotificationId\"),\n});\n\nexport type MarkAllNotificationsReadInput = v.InferInput<\n typeof MarkAllNotificationsReadInputSchema\n>;\n\n/*\n * Outputs are formatted straight from the decoded messages, like the assistant's run events.\n * The `detail` oneof becomes a `type`-tagged union; a case this build does not know becomes\n * `{ type: \"unspecified\" }`, and the notification's `title` and `text` describe it.\n */\n\nconst price = (ticks: bigint) => scaledToDecimalOutput(ticks, PRICE_SCALE);\n\nfunction formatDetail(detail: Proto.Notification[\"detail\"]) {\n switch (detail.case) {\n case \"priceAlert\": {\n const notice = detail.value;\n return {\n type: \"price_alert\" as const,\n /** The alert's ID in `client.priceAlerts`. */\n alertId: formatId(notice.alertId),\n symbolId: notice.symbolId,\n direction: enumLabel(PriceAlertDirectionCodec.protoToOutput, notice.direction),\n priceSource: enumLabel(\n PriceAlertPriceSourceCodec.protoToOutput,\n notice.priceSource,\n ),\n /** Alert price, as a decimal string. */\n price: price(notice.priceTicks),\n /** Price that fired the alert, as a decimal string. */\n triggeredPrice: price(notice.triggeredPriceTicks),\n triggeredAt: tsObjToMs(notice.triggeredAt) ?? null,\n };\n }\n case \"telegramApproval\": {\n const notice = detail.value;\n return {\n type: \"telegram_approval\" as const,\n /** The approval's ID in `client.assistant`. */\n approvalId: formatId(notice.approvalId),\n action: enumLabel(TelegramApprovalActionCodec.protoToOutput, notice.action),\n /** Trading account (subaccount) the action acted on. */\n accountId: formatId(notice.accountId),\n summary: notice.summary,\n /** Key parameters in display order, such as market, side and quantity. */\n parameters: notice.parameters.map(({ label, value }) => ({ label, value })),\n approvedAt: tsObjToMs(notice.approvedAt) ?? null,\n };\n }\n case \"brokerAllowlist\": {\n const notice = detail.value;\n return {\n type: \"broker_allowlist_change\" as const,\n broker: notice.broker,\n /** Sub-account ID of the broker vault. */\n vaultAccountId: formatId(notice.vaultAccountId),\n /** The change's ID; key the broker's vault allowlist view on it. */\n changeId: formatId(notice.changeId),\n event: enumLabel(BrokerAllowlistEventCodec.protoToOutput, notice.event),\n action: enumLabel(BrokerAllowlistActionCodec.protoToOutput, notice.action),\n /** Destination chain ID, as a decimal string. */\n destinationChainId: notice.destinationChainId.toString(),\n destinationAddress: notice.destinationAddress,\n /** The requesting member's name for an added address; empty when none. */\n label: notice.label,\n /**\n * Account ID of the member who requested the change. Show a `change_requested`\n * the caller did not make prominently: an added address becomes payable 24 hours\n * after it is listed.\n */\n requestedByAccountId: formatId(notice.requestedByAccountId),\n };\n }\n default:\n return { type: \"unspecified\" as const };\n }\n}\n\nexport function formatNotification(notification: Proto.Notification) {\n return {\n notificationId: formatId(notification.notificationId),\n type: enumLabel(NotificationTypeCodec.protoToOutput, notification.type),\n category: enumLabel(NotificationCategoryCodec.protoToOutput, notification.category),\n /** Plain-text title, the same for every notification of a type. */\n title: notification.title,\n /** Plain-text summary; may span several lines. */\n text: notification.text,\n createdAt: tsObjToMs(notification.createdAt) ?? null,\n /** Null while unread. */\n readAt: tsObjToMs(notification.readAt) ?? null,\n detail: formatDetail(notification.detail),\n };\n}\n\n/**\n * One notification. When `detail.type` is `\"unspecified\"` (a type this SDK build does not\n * know), show `title` and `text` only.\n */\nexport type AccountNotification = ReturnType<typeof formatNotification>;\n\nexport type AccountNotificationDetail = AccountNotification[\"detail\"];\n\n/** One page of notifications, newest first; an empty `nextPageToken` means no more. */\nexport type ListNotificationsResult = {\n notifications: AccountNotification[];\n nextPageToken: string;\n};\n\nexport function formatNotificationCounts(counts: Proto.GetNotificationCountsResponse) {\n return {\n total: Number(counts.total),\n unread: Number(counts.unread),\n /** Every type in ascending enum order, including types with no notification. */\n types: counts.types.map((count) => ({\n type: enumLabel(NotificationTypeCodec.protoToOutput, count.type),\n category: enumLabel(NotificationCategoryCodec.protoToOutput, count.category),\n total: Number(count.total),\n unread: Number(count.unread),\n })),\n };\n}\n\n/** Exact counts of the caller's notifications, as of one moment. */\nexport type NotificationCounts = ReturnType<typeof formatNotificationCounts>;\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,4BAA4B,cAAc,gBAAgB;;AAGhE,MAAM,wBAAwB,EAAE,SAC5B,EAAE,KACE,EAAE,MAAM,EAAE,SAAS,4BAA4B,CAAC,GAChD,EAAE,WAAW,eACT,WAAW,KAAK,aAAa,0BAA0B,aAAa,SAAS,CACjF,CACJ,CACJ;AAEA,MAAM,yBAAyB,EAAE,KAC7B,EAAE,OAAO,GACT,EAAE,QAAQ,GACV,EAAE,SAAS,CAAC,GACZ,EAAE,SA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,OAAO,aAAa;;EAEpB,MAAM,aAAa;EACnB,WAAW,UAAU,aAAa,SAAS,KAAK;;EAEhD,QAAQ,UAAU,aAAa,MAAM,KAAK;EAC1C,QAAQ,aAAa,aAAa,MAAM;CAC5C;AACJ;AAgBA,SAAgB,yBAAyB,QAA6C;CAClF,OAAO;EACH,OAAO,OAAO,OAAO,KAAK;EAC1B,QAAQ,OAAO,OAAO,MAAM;;EAE5B,OAAO,OAAO,MAAM,KAAK,WAAW;GAChC,MAAM,UAAU,sBAAsB,eAAe,MAAM,IAAI;GAC/D,UAAU,UAAU,0BAA0B,eAAe,MAAM,QAAQ;GAC3E,OAAO,OAAO,MAAM,KAAK;GACzB,QAAQ,OAAO,MAAM,MAAM;EAC/B,EAAE;CACN;AACJ"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AccountNotification, AccountNotificationDetail, GetNotificationInput, ListNotificationsInput, ListNotificationsResult, MarkAllNotificationsReadInput, MarkNotificationsInput, NotificationCounts } from "./notifications.schemas.js";
|
|
2
|
-
import { NotificationCategory, NotificationReadState, NotificationType, TelegramApprovalAction } from "./notifications.codecs.js";
|
|
3
|
-
export type { AccountNotification, AccountNotificationDetail, GetNotificationInput, ListNotificationsInput, ListNotificationsResult, MarkAllNotificationsReadInput, MarkNotificationsInput, NotificationCategory, NotificationCounts, NotificationReadState, NotificationType, TelegramApprovalAction };
|
|
2
|
+
import { BrokerAllowlistAction, BrokerAllowlistEvent, NotificationCategory, NotificationReadState, NotificationType, TelegramApprovalAction } from "./notifications.codecs.js";
|
|
3
|
+
export type { AccountNotification, AccountNotificationDetail, BrokerAllowlistAction, BrokerAllowlistEvent, GetNotificationInput, ListNotificationsInput, ListNotificationsResult, MarkAllNotificationsReadInput, MarkNotificationsInput, NotificationCategory, NotificationCounts, NotificationReadState, NotificationType, TelegramApprovalAction };
|
|
@@ -33,11 +33,11 @@ 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
|
|
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; 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.
|
|
37
37
|
*
|
|
38
38
|
* `depth` is clamped to [1, 500] and rides the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.
|
|
39
39
|
*
|
|
40
|
-
* Refetching is driven by
|
|
40
|
+
* 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.
|
|
41
41
|
*/
|
|
42
42
|
createSubscription(input: CreateOrderbookSubscriptionInput): OrderbookSubscription;
|
|
43
43
|
}
|
|
@@ -50,11 +50,11 @@ var OrderbookService = class {
|
|
|
50
50
|
return this.createSubscription(input).unsubscribe;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Creates a stateful order book subscription that first fetches a snapshot, buffers proto deltas from public:spot:orderbook:deltas:depth:{depth}:{symbolId}:proto, applies
|
|
53
|
+
* 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.
|
|
54
54
|
*
|
|
55
55
|
* `depth` is clamped to [1, 500] and rides the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.
|
|
56
56
|
*
|
|
57
|
-
* Refetching is driven by
|
|
57
|
+
* 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.
|
|
58
58
|
*/
|
|
59
59
|
createSubscription(input) {
|
|
60
60
|
const { symbolId } = parse(GetOrderbookInputSchema, {
|
|
@@ -69,6 +69,7 @@ var OrderbookService = class {
|
|
|
69
69
|
let bidsMap = /* @__PURE__ */ new Map();
|
|
70
70
|
let asksMap = /* @__PURE__ */ new Map();
|
|
71
71
|
let currentBookSeq = 0n;
|
|
72
|
+
let awaitingReset = false;
|
|
72
73
|
let bucketTicks = null;
|
|
73
74
|
let stream;
|
|
74
75
|
function levelsToMap(levels) {
|
|
@@ -153,22 +154,25 @@ var OrderbookService = class {
|
|
|
153
154
|
if (!isBookAvailable(res)) throw new ServiceUnavailableError(`Order book for symbol ${symbolId} is not available yet`);
|
|
154
155
|
return res;
|
|
155
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Applies a delta only when it chains onto the current book (`bookSeqStart` equals the
|
|
159
|
+
* last applied `bookSeqEnd`) or is a reset. A delta that does not chain leaves the book
|
|
160
|
+
* waiting for the next reset, which the server sends periodically and after a gap.
|
|
161
|
+
*/
|
|
156
162
|
function handleDelta(delta) {
|
|
157
|
-
if (delta.bookSeqEnd <= currentBookSeq) return
|
|
163
|
+
if (delta.bookSeqEnd <= currentBookSeq) return;
|
|
158
164
|
if (delta.reset) {
|
|
159
165
|
bidsMap.clear();
|
|
160
166
|
asksMap.clear();
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return false;
|
|
167
|
+
awaitingReset = false;
|
|
168
|
+
} else if (awaitingReset || delta.bookSeqStart !== currentBookSeq) {
|
|
169
|
+
awaitingReset = true;
|
|
170
|
+
return;
|
|
166
171
|
}
|
|
167
172
|
applySideDelta(bidsMap, delta.bids);
|
|
168
173
|
applySideDelta(asksMap, delta.asks);
|
|
169
|
-
currentBookSeq = delta.bookSeqEnd
|
|
174
|
+
currentBookSeq = delta.bookSeqEnd;
|
|
170
175
|
emit();
|
|
171
|
-
return true;
|
|
172
176
|
}
|
|
173
177
|
setBucket(input.bucket);
|
|
174
178
|
stream = snapshotThenStream({
|
|
@@ -187,16 +191,17 @@ var OrderbookService = class {
|
|
|
187
191
|
bidsMap = levelsToMap(snapshot.bids);
|
|
188
192
|
asksMap = levelsToMap(snapshot.asks);
|
|
189
193
|
currentBookSeq = snapshot.bookSeq;
|
|
194
|
+
awaitingReset = false;
|
|
190
195
|
emit();
|
|
191
196
|
for (const delta of bufferedDeltas) {
|
|
192
197
|
if (stream?.isDisposed()) return;
|
|
193
|
-
|
|
198
|
+
handleDelta(delta);
|
|
194
199
|
}
|
|
195
200
|
},
|
|
196
201
|
applyLivePublications: (deltas) => {
|
|
197
202
|
for (const delta of deltas) {
|
|
198
203
|
if (stream?.isDisposed()) return;
|
|
199
|
-
|
|
204
|
+
handleDelta(delta);
|
|
200
205
|
}
|
|
201
206
|
},
|
|
202
207
|
onOpen: input.onOpen,
|
|
@@ -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 { isResourceNotFoundError } from \"../../utils/errors.js\";\nimport { ServiceUnavailableError } 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 requested depth, 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: validated.protoDepth },\n toConnectCallOptions(options),\n );\n return parse(createOrderbookDataSchema(this.#scales, validated.symbolId), {\n symbolId: res.symbolId,\n depth: validated.depth,\n bookSeq: res.bookSeq,\n available: isBookAvailable(res),\n bids: res.bids,\n asks: res.asks,\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 sequence-checked updates, and refetches on observed sequence gaps or reconnects. 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` is clamped to [1, 500] and rides the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.\n *\n * Refetching is driven by observed sequence gaps and 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 } = parse(GetOrderbookInputSchema, {\n symbolId: input.symbolId,\n depth: input.depth,\n });\n const requestedDepth = Math.min(500, Math.max(1, Math.trunc(input.depth ?? 50)));\n const channelDepth = orderbookWsChannelDepth(requestedDepth);\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 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: requestedDepth,\n bookSeq: currentBookSeq.toString(),\n available: true,\n bids: sideToUIBucketed(bidsMap, \"bids\", requestedDepth, bucketTicks),\n asks: sideToUIBucketed(asksMap, \"asks\", requestedDepth, 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 const validated = parse(GetOrderbookInputSchema, {\n symbolId,\n depth: channelDepth,\n });\n let res: Proto.GetOrderBookResponse;\n try {\n res = await client.getOrderBook({\n symbolId: validated.symbolId,\n depth: validated.protoDepth,\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 return res;\n }\n\n function handleDelta(delta: Proto.OrderBookDelta): boolean {\n if (delta.bookSeqEnd <= currentBookSeq) return true;\n\n if (delta.reset) {\n bidsMap.clear();\n asksMap.clear();\n currentBookSeq = 0n;\n }\n\n if (currentBookSeq !== 0n && delta.bookSeqStart > currentBookSeq + 1n) {\n stream?.refreshSnapshot();\n return false;\n }\n\n applySideDelta(bidsMap, delta.bids);\n applySideDelta(asksMap, delta.asks);\n\n currentBookSeq = delta.bookSeqEnd > currentBookSeq ? delta.bookSeqEnd : currentBookSeq;\n emit();\n return true;\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 snapshotRetry: { maxAttempts: 3, delayMs: 1_000 },\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 emit();\n for (const delta of bufferedDeltas) {\n if (stream?.isDisposed()) return;\n if (!handleDelta(delta)) return;\n }\n },\n applyLivePublications: (deltas) => {\n for (const delta of deltas) {\n if (stream?.isDisposed()) return;\n if (!handleDelta(delta)) return;\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":";;;;;;;;;;;;;;;;AAoDA,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,UAAU;EAAW,GAC5D,qBAAqB,OAAO,CAChC;EACA,OAAO,MAAM,0BAA0B,KAAKG,SAAS,UAAU,QAAQ,GAAG;GACtE,UAAU,IAAI;GACd,OAAO,UAAU;GACjB,SAAS,IAAI;GACb,WAAW,gBAAgB,GAAG;GAC9B,MAAM,IAAI;GACV,MAAM,IAAI;EACd,CAA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AAa;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 { isResourceNotFoundError } from \"../../utils/errors.js\";\nimport { ServiceUnavailableError } 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 requested depth, 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: validated.protoDepth },\n toConnectCallOptions(options),\n );\n return parse(createOrderbookDataSchema(this.#scales, validated.symbolId), {\n symbolId: res.symbolId,\n depth: validated.depth,\n bookSeq: res.bookSeq,\n available: isBookAvailable(res),\n bids: res.bids,\n asks: res.asks,\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` is clamped to [1, 500] and rides the smallest published channel depth that covers it (see ORDERBOOK_WS_DEPTHS); levels are sliced back to the requested depth locally.\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 } = parse(GetOrderbookInputSchema, {\n symbolId: input.symbolId,\n depth: input.depth,\n });\n const requestedDepth = Math.min(500, Math.max(1, Math.trunc(input.depth ?? 50)));\n const channelDepth = orderbookWsChannelDepth(requestedDepth);\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 // 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: requestedDepth,\n bookSeq: currentBookSeq.toString(),\n available: true,\n bids: sideToUIBucketed(bidsMap, \"bids\", requestedDepth, bucketTicks),\n asks: sideToUIBucketed(asksMap, \"asks\", requestedDepth, 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 const validated = parse(GetOrderbookInputSchema, {\n symbolId,\n depth: channelDepth,\n });\n let res: Proto.GetOrderBookResponse;\n try {\n res = await client.getOrderBook({\n symbolId: validated.symbolId,\n depth: validated.protoDepth,\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 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 snapshotRetry: { maxAttempts: 3, delayMs: 1_000 },\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 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":";;;;;;;;;;;;;;;;AAoDA,IAAa,mBAAb,MAA8B;CAC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AK;GAClC,gBAAgB,UAAU,mBAAmB;IACzC,UAAU,YAAY,SAAS,IAAI;IACnC,UAAU,YAAY,SAAS,IAAI;IACnC,iBAAiB,SAAS;IAC1B,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 GetOrderbookInputSchema: v.SchemaWithPipe<readonly [v.ObjectSchema
|
|
|
10
10
|
depth: number;
|
|
11
11
|
}, {
|
|
12
12
|
symbolId: number;
|
|
13
|
-
depth: 1 |
|
|
13
|
+
depth: 1 | 5 | 10 | 20 | 100 | 200 | 500 | 1000 | 50;
|
|
14
14
|
protoDepth: Depth;
|
|
15
15
|
}>]>;
|
|
16
16
|
type GetOrderbookInput = v.InferInput<typeof GetOrderbookInputSchema>;
|