@polyester/sdk 0.36.0-devnet-20261120015159 → 0.36.0-devnet-20261121035512

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.
Files changed (209) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/client.d.ts +2 -0
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +2 -0
  5. package/dist/client.js.map +1 -1
  6. package/dist/gen/ai/v1/assistant_pb.d.ts +1 -1
  7. package/dist/gen/ai/v1/assistant_pb.js +1 -1
  8. package/dist/gen/alerts/v1/price_alerts_pb.d.ts +1 -1
  9. package/dist/gen/auth/v1/activity_pb.d.ts +1 -1
  10. package/dist/gen/auth/v1/address_book_pb.d.ts +1 -1
  11. package/dist/gen/auth/v1/address_book_pb.js +1 -1
  12. package/dist/gen/auth/v1/api_keys_pb.d.ts +1 -1
  13. package/dist/gen/auth/v1/auth_pb.d.ts +1 -1
  14. package/dist/gen/auth/v1/auth_pb.js +1 -1
  15. package/dist/gen/auth/v1/connected_apps_pb.d.ts +1 -1
  16. package/dist/gen/auth/v1/mfa_pb.d.ts +1 -1
  17. package/dist/gen/auth/v1/policies_pb.d.ts +1 -1
  18. package/dist/gen/auth/v1/profile_pb.d.ts +1 -1
  19. package/dist/gen/auth/v1/resolve_pb.d.ts +1 -1
  20. package/dist/gen/auth/v1/social_verification_pb.d.ts +1 -1
  21. package/dist/gen/auth/v1/subaccounts_pb.d.ts +1 -1
  22. package/dist/gen/auth/v1/subaccounts_pb.js +1 -1
  23. package/dist/gen/chain/analytics/v1/analytics_read_pb.d.ts +1 -1
  24. package/dist/gen/chain/deposit/v1/deposit_pb.d.ts +1 -1
  25. package/dist/gen/chain/guard/v1/guard_signer_pb.d.ts +1 -1
  26. package/dist/gen/chain/lifecycle/v1/lifecycle_read_pb.d.ts +1 -1
  27. package/dist/gen/chain/lifecycle/v1/types_pb.d.ts +1 -1
  28. package/dist/gen/chain/withdraw/v1/auto_withdraw_pb.d.ts +1 -1
  29. package/dist/gen/chain/withdraw/v1/withdraw_pb.d.ts +1 -1
  30. package/dist/gen/chain/zipper/v1/reason_pb.d.ts +1 -1
  31. package/dist/gen/chain/zipper/v1/zipper_pb.d.ts +1 -1
  32. package/dist/gen/changelog/v1/changelog_pb.d.ts +1 -1
  33. package/dist/gen/checkpoints/v1/checkpoints_pb.d.ts +1 -1
  34. package/dist/gen/claims/v1/claims_pb.d.ts +1 -1
  35. package/dist/gen/fees/v1/fees_pb.d.ts +1 -1
  36. package/dist/gen/index.d.ts +1 -1
  37. package/dist/gen/index.js +27 -27
  38. package/dist/gen/ledger/read/v1/ledger_read_pb.d.ts +1 -1
  39. package/dist/gen/ledger/read/v1/statement_export_pb.d.ts +1 -1
  40. package/dist/gen/marketdata/v1/asset_info_pb.d.ts +1 -1
  41. package/dist/gen/marketdata/v1/heatmap_pb.d.ts +1 -1
  42. package/dist/gen/marketdata/v1/marketdata_pb.d.ts +1 -1
  43. package/dist/gen/marketoverview/v1/marketoverview_pb.d.ts +1 -1
  44. package/dist/gen/notifications/v1/notifications_pb.d.ts +1 -1
  45. package/dist/gen/orderbook/v1/orderbook_pb.d.ts +1 -1
  46. package/dist/gen/orders/v1/orders_pb.d.ts +1 -1
  47. package/dist/gen/orders/v1/orders_read_pb.d.ts +1 -1
  48. package/dist/gen/polyester/api/v1/request_error_pb.d.ts +1 -1
  49. package/dist/gen/polyester/ratelimit/v1/types_pb.d.ts +1 -1
  50. package/dist/gen/polyester/type/v1/u128_pb.d.ts +1 -1
  51. package/dist/gen/privatews/v1/private_ws_pb.d.ts +1 -1
  52. package/dist/gen/ratelimit/v1/ratelimit_pb.d.ts +1 -1
  53. package/dist/gen/rewards/v1/rewards_pb.d.ts +1 -1
  54. package/dist/gen/strategies/v1/strategies_pb.d.ts +1 -1
  55. package/dist/gen/swap/quickswap/v1/quickswap_broker_pb.d.ts +1 -1
  56. package/dist/gen/swap/quickswap/v1/quickswap_explorer_pb.d.ts +1 -1
  57. package/dist/gen/swap/quickswap/v1/quickswap_pb.d.ts +1 -1
  58. package/dist/gen/swap/quickswap/v1/quickswap_referral_pb.d.ts +1 -1
  59. package/dist/gen/swap/v1/swap_pb.d.ts +1 -1
  60. package/dist/gen/system/v1/system_pb.d.ts +1 -1
  61. package/dist/gen/tradews/v1/trade_ws_pb.d.ts +1 -1
  62. package/dist/gen/transfer/v1/dust_conversion_pb.d.ts +1 -1
  63. package/dist/gen/transfer/v1/internal_transfer_pb.d.ts +1 -1
  64. package/dist/gen/triggers/v1/triggers_pb.d.ts +1 -1
  65. package/dist/gen/vip/v1/vip_pb.d.ts +1 -1
  66. package/dist/index.d.ts +4 -1
  67. package/dist/services/account-activity/account-activity.js +1 -1
  68. package/dist/services/account-activity/account-activity.schemas.d.ts +6 -6
  69. package/dist/services/accounts/accounts.js +1 -1
  70. package/dist/services/accounts/accounts.schemas.js +1 -1
  71. package/dist/services/address-book/address-book.js +1 -1
  72. package/dist/services/address-book/address-book.schemas.d.ts +2 -2
  73. package/dist/services/api-keys/api-keys.js +1 -1
  74. package/dist/services/api-keys/api-keys.schemas.d.ts +6 -6
  75. package/dist/services/assistant/assistant-events.schemas.d.ts +28 -28
  76. package/dist/services/assistant/assistant.js +1 -1
  77. package/dist/services/assistant/assistant.schemas.d.ts +1 -1
  78. package/dist/services/auth/profile/profile.js +1 -1
  79. package/dist/services/auto-withdraw/auto-withdraw.js +1 -1
  80. package/dist/services/auto-withdraw/auto-withdraw.schemas.d.ts.map +1 -1
  81. package/dist/services/auto-withdraw/auto-withdraw.schemas.js +5 -12
  82. package/dist/services/auto-withdraw/auto-withdraw.schemas.js.map +1 -1
  83. package/dist/services/balances/balances.js +1 -1
  84. package/dist/services/candles/candles.js +1 -1
  85. package/dist/services/candles/candles.schemas.d.ts +10 -10
  86. package/dist/services/chain-analytics/chain-analytics.js +1 -1
  87. package/dist/services/changelog/changelog.js +1 -1
  88. package/dist/services/changelog/changelog.schemas.d.ts +38 -38
  89. package/dist/services/checkpoints/checkpoints.js +1 -1
  90. package/dist/services/checkpoints/checkpoints.schemas.d.ts +1 -1
  91. package/dist/services/claims/claims.js +1 -1
  92. package/dist/services/claims/claims.schemas.d.ts +2 -2
  93. package/dist/services/claims/claims.schemas.js +1 -1
  94. package/dist/services/connected-apps/connected-apps.js +1 -1
  95. package/dist/services/deposit/deposit.js +1 -1
  96. package/dist/services/dust-conversion/dust-conversion.js +1 -1
  97. package/dist/services/dust-conversion/dust-conversion.schemas.d.ts +8 -8
  98. package/dist/services/dust-conversion/dust-conversion.schemas.js +1 -1
  99. package/dist/services/fees/fees.js +1 -1
  100. package/dist/services/guard-signer/guard-signer.js +1 -1
  101. package/dist/services/heatmap/heatmap.js +1 -1
  102. package/dist/services/heatmap/heatmap.schemas.d.ts +3 -3
  103. package/dist/services/internal-transfers/internal-transfers.js +1 -1
  104. package/dist/services/internal-transfers/internal-transfers.schemas.d.ts +6 -6
  105. package/dist/services/lifecycle/lifecycle.js +1 -1
  106. package/dist/services/lifecycle/lifecycle.schemas.d.ts +52 -52
  107. package/dist/services/lifecycle/lifecycle.schemas.js +2 -2
  108. package/dist/services/market-data/market-data.d.ts +20 -0
  109. package/dist/services/market-data/market-data.d.ts.map +1 -1
  110. package/dist/services/market-data/market-data.js +94 -2
  111. package/dist/services/market-data/market-data.js.map +1 -1
  112. package/dist/services/market-overview/market-overview.js +1 -1
  113. package/dist/services/market-overview/market-overview.schemas.js +1 -1
  114. package/dist/services/notifications/notifications.js +1 -1
  115. package/dist/services/notifications/notifications.schemas.d.ts +5 -25
  116. package/dist/services/notifications/notifications.schemas.d.ts.map +1 -1
  117. package/dist/services/orderbook/orderbook.js +1 -1
  118. package/dist/services/orders/order-errors.schemas.d.ts +9 -9
  119. package/dist/services/orders/order-errors.schemas.js +1 -1
  120. package/dist/services/orders/orders-batch.schemas.d.ts +95 -95
  121. package/dist/services/orders/orders-batch.schemas.js +1 -1
  122. package/dist/services/orders/orders-input.schemas.d.ts +15 -15
  123. package/dist/services/orders/orders-input.schemas.js +1 -1
  124. package/dist/services/orders/orders-modify.schemas.js +1 -1
  125. package/dist/services/orders/orders-output.schemas.d.ts +8 -8
  126. package/dist/services/orders/orders-risk.schemas.js +2 -2
  127. package/dist/services/orders/orders.js +2 -2
  128. package/dist/services/policies/api-key-policies/api-key-policies.js +1 -1
  129. package/dist/services/policies/shared.codecs.js +1 -1
  130. package/dist/services/policies/subaccount-policies/subaccount-policies.js +1 -1
  131. package/dist/services/price-alerts/price-alerts.js +1 -1
  132. package/dist/services/price-alerts/price-alerts.schemas.d.ts +10 -10
  133. package/dist/services/rate-limits/rate-limits.js +1 -1
  134. package/dist/services/rewards/rewards.js +1 -1
  135. package/dist/services/rewards/rewards.schemas.d.ts +4 -4
  136. package/dist/services/social-verification/social-verification.js +1 -1
  137. package/dist/services/social-verification/social-verification.schemas.js +1 -1
  138. package/dist/services/statement-exports/statement-exports.js +1 -1
  139. package/dist/services/statement-exports/statement-exports.schemas.d.ts +6 -6
  140. package/dist/services/strategies/strategies.js +1 -1
  141. package/dist/services/strategies/strategies.schemas.d.ts +5 -5
  142. package/dist/services/subaccounts/subaccounts.js +2 -2
  143. package/dist/services/subaccounts/subaccounts.schemas.d.ts +18 -18
  144. package/dist/services/swap/service.d.ts +8 -0
  145. package/dist/services/swap/service.d.ts.map +1 -0
  146. package/dist/services/swap/service.js +9 -0
  147. package/dist/services/swap/service.js.map +1 -0
  148. package/dist/services/swap/swap.codecs.d.ts +19 -0
  149. package/dist/services/swap/swap.codecs.d.ts.map +1 -0
  150. package/dist/services/swap/swap.codecs.js +39 -0
  151. package/dist/services/swap/swap.codecs.js.map +1 -0
  152. package/dist/services/swap/swap.d.ts +51 -0
  153. package/dist/services/swap/swap.d.ts.map +1 -0
  154. package/dist/services/swap/swap.js +71 -0
  155. package/dist/services/swap/swap.js.map +1 -0
  156. package/dist/services/swap/swap.schemas.d.ts +520 -0
  157. package/dist/services/swap/swap.schemas.d.ts.map +1 -0
  158. package/dist/services/swap/swap.schemas.js +213 -0
  159. package/dist/services/swap/swap.schemas.js.map +1 -0
  160. package/dist/services/swap/swap.types.d.ts +3 -0
  161. package/dist/services/system/system.js +1 -1
  162. package/dist/services/system/system.schemas.d.ts +13 -13
  163. package/dist/services/trades/trades.js +1 -1
  164. package/dist/services/trades/trades.schemas.d.ts +1 -1
  165. package/dist/services/trading-withdraws/trading-withdraws.js +1 -1
  166. package/dist/services/trading-withdraws/trading-withdraws.schemas.js +1 -1
  167. package/dist/services/trading-withdraws/wallet-message.js +1 -1
  168. package/dist/services/transfers/transfers.js +1 -1
  169. package/dist/services/triggers/trigger-child-order.schemas.js +2 -2
  170. package/dist/services/triggers/trigger-input.schemas.d.ts +2 -2
  171. package/dist/services/triggers/trigger-input.schemas.js +2 -2
  172. package/dist/services/triggers/triggers-output.schemas.d.ts +53 -53
  173. package/dist/services/triggers/triggers.js +1 -1
  174. package/dist/services/vip/vip.js +1 -1
  175. package/dist/services/vip/vip.schemas.d.ts +3 -3
  176. package/dist/services/vip/vip.schemas.js +1 -1
  177. package/dist/services/zipper/zipper.js +1 -1
  178. package/dist/services/zipper/zipper.schemas.js +1 -1
  179. package/dist/shared/connect-error-mapping.d.ts.map +1 -1
  180. package/dist/shared/connect-error-mapping.js +1 -0
  181. package/dist/shared/connect-error-mapping.js.map +1 -1
  182. package/dist/shared/decimal-surface.d.ts.map +1 -1
  183. package/dist/shared/decimal-surface.js +11 -1
  184. package/dist/shared/decimal-surface.js.map +1 -1
  185. package/dist/shared/error-detail.d.ts +16 -4
  186. package/dist/shared/error-detail.d.ts.map +1 -1
  187. package/dist/shared/error-detail.js +1 -0
  188. package/dist/shared/error-detail.js.map +1 -1
  189. package/dist/shared/error-details/alerts.js +1 -1
  190. package/dist/shared/error-details/assistant.js +1 -1
  191. package/dist/shared/error-details/auth.js +1 -1
  192. package/dist/shared/error-details/claims.js +1 -1
  193. package/dist/shared/error-details/internal-transfer.js +1 -1
  194. package/dist/shared/error-details/ledger.js +1 -1
  195. package/dist/shared/error-details/market-overview.js +1 -1
  196. package/dist/shared/error-details/notifications.js +1 -1
  197. package/dist/shared/error-details/orders.js +1 -1
  198. package/dist/shared/error-details/profile.js +1 -1
  199. package/dist/shared/error-details/rate-limit.js +1 -1
  200. package/dist/shared/error-details/strategies.js +1 -1
  201. package/dist/shared/error-details/swap.js +22 -0
  202. package/dist/shared/error-details/swap.js.map +1 -0
  203. package/dist/shared/error-details/withdraw.js +1 -1
  204. package/dist/shared/rate-limit.schemas.d.ts +1 -1
  205. package/dist/shared/rate-limit.schemas.js +1 -1
  206. package/dist/wired-services.d.ts.map +1 -1
  207. package/dist/wired-services.js +23 -21
  208. package/dist/wired-services.js.map +1 -1
  209. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
+ import "../../gen/chain/lifecycle/v1/types_pb.js";
2
+ import "../../gen/chain/lifecycle/v1/lifecycle_read_pb.js";
1
3
  import { enumLabelSchema } from "../../shared/proto-enum-codec.js";
2
4
  import { fromU128 } from "../../utils/u128.js";
3
5
  import { scaledToDecimalOutput } from "../../shared/decimal-surface.js";
4
6
  import { AccountScopeInputEntries, accountScopeToSubaccountId } from "../../shared/account-scope.js";
5
- import "../../gen/chain/lifecycle/v1/types_pb.js";
6
- import "../../gen/chain/lifecycle/v1/lifecycle_read_pb.js";
7
7
  import { LIFECYCLE_FLOW_KIND_VALUES, LIFECYCLE_FLOW_PARTICIPATION_VALUES, LIFECYCLE_FLOW_STATE_VALUES, LIFECYCLE_LIST_ORDER_BY_VALUES, LIFECYCLE_LIST_SCOPE_VALUES, LIFECYCLE_SORT_VALUES, LIFECYCLE_TX_LOOKUP_KIND_VALUES, LifecycleFlowDomainCodec, LifecycleFlowKindCodec, LifecycleFlowParticipationCodec, LifecycleFlowStateCodec, LifecycleFlowStepActivityKindCodec, LifecycleFlowStepCodec, LifecycleFlowTimelineStatusCodec, LifecycleListOrderByCodec, LifecycleListScopeCodec, LifecycleRequestFeeStatusCodec, LifecycleSortCodec, LifecycleSourceCodec, LifecycleTxLookupKindCodec, lifecycleReasonFromCode, zipperReasonFromCode } from "./lifecycle.codecs.js";
8
8
  import * as v from "valibot";
9
9
  //#region src/services/lifecycle/lifecycle.schemas.ts
@@ -9,6 +9,9 @@ import { AssetInfo, GetMarketTradesInput, GetPriceBandInput, ListAssetInfoInput,
9
9
  interface SubscribeTradesInput extends BaseSubscribeInput<MarketTrade> {
10
10
  symbolId: number;
11
11
  }
12
+ interface SubscribePriceBandInput extends BaseSubscribeInput<LivePriceBand> {
13
+ symbolId: number;
14
+ }
12
15
  /**
13
16
  * Exposes public spot trades, spot configuration, and live trade streams.
14
17
  */
@@ -52,6 +55,23 @@ declare class MarketDataService {
52
55
  * throws `ResourceNotFoundError`.
53
56
  */
54
57
  getPriceBand(input: GetPriceBandInput, options?: PolyesterRequestOptions): Promise<LivePriceBand>;
58
+ /**
59
+ * Streams one pair's live price band from public:spot:market:price_band:{symbolId}:proto,
60
+ * emitting the same `LivePriceBand` as `getPriceBand`. Each connection is seeded with
61
+ * `getPriceBand`; the stream sends a changed band at once and re-sends a current one about
62
+ * every 2 seconds.
63
+ *
64
+ * Only a newer band is emitted (greater `epoch`, then `updateId`, then `asOfTsNs`); repeated,
65
+ * late and replayed messages, and a seed the stream already passed, are dropped.
66
+ *
67
+ * Unknown bands arrive as `state: "unknown"` with null prices, never as `onError`: when the
68
+ * seed is refused `PRICE_BAND_STALE` / `PRICE_BAND_UNKNOWN`, when the stream says so, and
69
+ * when `validUntilMs` passes (by the local clock) with no newer message. An emitted band
70
+ * other than `unknown` is current until the next emission, so callers need no
71
+ * `validUntilMs` timer of their own. A seed that fails otherwise (network, unknown
72
+ * `symbolId`) goes to `onError` as `type: "snapshot"`, and the stream still delivers.
73
+ */
74
+ subscribePriceBand(input: SubscribePriceBandInput): () => void;
55
75
  /**
56
76
  * Subscribes to public trade prints on public:spot:market:trades:{symbolId}:proto for the requested symbol and emits parsed market trades.
57
77
  * Each publication batches trades, emitted one at a time in execution order; a trade
@@ -1 +1 @@
1
- {"version":3,"file":"market-data.d.ts","names":[],"sources":["../../../src/services/market-data/market-data.ts"],"mappings":";;;;;;;;UAsCU,6BAA6B,mBAAmB;EACtD;;;;;cAMS;;EAKG,YAAA,YAAY,qBAAqB,UAAU,mBAAmB,QAAQ;;;;;;;;;;EAe5E,WACF,OAAO,sBACP,UAAU,0BACX;IAAU,QAAQ;IAAe;IAAuB,WAAW;;;;;;;;;EAsBhE,cAAc,UAAU,0BAA0B,QAAQ;;;;;;;EAW1D,cACF,QAAO,oBACP,UAAU,0BACX,QAAQ;;;;;;;;EAaL,aACF,OAAO,mBACP,UAAU,0BACX,QAAQ;;;;;;EAYX,gBAAgB,OAAO"}
1
+ {"version":3,"file":"market-data.d.ts","names":[],"sources":["../../../src/services/market-data/market-data.ts"],"mappings":";;;;;;;;UA0CU,6BAA6B,mBAAmB;EACtD;;UAGM,gCAAgC,mBAAmB;EACzD;;;;;cAuBS;;EAKG,YAAA,YAAY,qBAAqB,UAAU,mBAAmB,QAAQ;;;;;;;;;;EAe5E,WACF,OAAO,sBACP,UAAU,0BACX;IAAU,QAAQ;IAAe;IAAuB,WAAW;;;;;;;;;EAsBhE,cAAc,UAAU,0BAA0B,QAAQ;;;;;;;EAW1D,cACF,QAAO,oBACP,UAAU,0BACX,QAAQ;;;;;;;;EAaL,aACF,OAAO,mBACP,UAAU,0BACX,QAAQ;;;;;;;;;;;;;;;;;EAuBX,mBAAmB,OAAO;;;;;;EA4E1B,gBAAgB,OAAO"}
@@ -1,14 +1,33 @@
1
+ import { GetPriceBandResponseSchema, LivePriceBandSchema, MarketDataService as MarketDataService$1, MarketTradeBatchSchema } from "../../gen/marketdata/v1/marketdata_pb.js";
2
+ import { ServiceUnavailableError } from "../../shared/errors.js";
1
3
  import { parse } from "../../shared/validation.js";
2
4
  import { toConnectCallOptions } from "../../shared/request-options.js";
3
- import { deliverBatch } from "../../shared/subscription-errors.js";
5
+ import { deliverBatch, publicationHandlerErrorContext } from "../../shared/subscription-errors.js";
4
6
  import { SymbolIdInputSchema } from "../shared.js";
5
- import { MarketDataService as MarketDataService$1, MarketTradeBatchSchema } from "../../gen/marketdata/v1/marketdata_pb.js";
6
7
  import { connectReadyGatedProtoChannel } from "../../realtime/ready-gated-subscription.js";
7
8
  import { isDev } from "../../utils/is-dev.js";
9
+ import { snapshotThenStream } from "../../realtime/snapshot-then-stream.js";
8
10
  import { AssetInfoSchema, GetMarketTradesInputSchema, GetPriceBandInputSchema, ListAssetInfoInputSchema, SpotConfigSchema, TradeBackfillSchema, formatLivePriceBand, formatMarketTrade } from "./market-data.schemas.js";
11
+ import { create } from "@bufbuild/protobuf";
9
12
  import { createClient } from "@connectrpc/connect";
10
13
  import * as v from "valibot";
11
14
  //#region src/services/market-data/market-data.ts
15
+ /** Newer by `epoch`, then `updateId`, then `asOfTsNs`; at an equal one, `unknown` replaces a band. */
16
+ function isNewerBand(band, than) {
17
+ for (const key of [
18
+ "epoch",
19
+ "updateId",
20
+ "asOfTsNs"
21
+ ]) {
22
+ const d = BigInt(band[key]) - BigInt(than[key]);
23
+ if (d !== 0n) return d > 0n;
24
+ }
25
+ return band.state === "unknown" && than.state !== "unknown";
26
+ }
27
+ /** True for `getPriceBand`'s refusal of a band not confirmed in the last 5 seconds. */
28
+ function isPriceBandUnknownError(error) {
29
+ return error instanceof ServiceUnavailableError && /^PRICE_BAND_(STALE|UNKNOWN)$/.test(error.message);
30
+ }
12
31
  /**
13
32
  * Exposes public spot trades, spot configuration, and live trade streams.
14
33
  */
@@ -81,6 +100,79 @@ var MarketDataService = class {
81
100
  return formatLivePriceBand(this.#scales, res.band);
82
101
  }
83
102
  /**
103
+ * Streams one pair's live price band from public:spot:market:price_band:{symbolId}:proto,
104
+ * emitting the same `LivePriceBand` as `getPriceBand`. Each connection is seeded with
105
+ * `getPriceBand`; the stream sends a changed band at once and re-sends a current one about
106
+ * every 2 seconds.
107
+ *
108
+ * Only a newer band is emitted (greater `epoch`, then `updateId`, then `asOfTsNs`); repeated,
109
+ * late and replayed messages, and a seed the stream already passed, are dropped.
110
+ *
111
+ * Unknown bands arrive as `state: "unknown"` with null prices, never as `onError`: when the
112
+ * seed is refused `PRICE_BAND_STALE` / `PRICE_BAND_UNKNOWN`, when the stream says so, and
113
+ * when `validUntilMs` passes (by the local clock) with no newer message. An emitted band
114
+ * other than `unknown` is current until the next emission, so callers need no
115
+ * `validUntilMs` timer of their own. A seed that fails otherwise (network, unknown
116
+ * `symbolId`) goes to `onError` as `type: "snapshot"`, and the stream still delivers.
117
+ */
118
+ subscribePriceBand(input) {
119
+ const symbolId = parse(SymbolIdInputSchema, input.symbolId);
120
+ const channel = `public:spot:market:price_band:${symbolId}:proto`;
121
+ const scales = this.#scales;
122
+ let current;
123
+ let lapseTimer;
124
+ const unknownBand = (from) => {
125
+ const asOfTsNs = BigInt(from?.asOfTsNs ?? 0);
126
+ return formatLivePriceBand(scales, create(LivePriceBandSchema, {
127
+ symbolId,
128
+ state: 4,
129
+ epoch: BigInt(from?.epoch ?? 0),
130
+ updateId: BigInt(from?.updateId ?? 0),
131
+ asOfTsNs,
132
+ updatedTsNs: asOfTsNs,
133
+ validUntilTsNs: asOfTsNs
134
+ }));
135
+ };
136
+ const apply = (...bands) => {
137
+ const band = bands.reduce((a, b) => isNewerBand(b, a) ? b : a);
138
+ if (current && !isNewerBand(band, current)) return;
139
+ clearTimeout(lapseTimer);
140
+ current = band.state !== "unknown" && band.validUntilMs <= Date.now() ? unknownBand(band) : band;
141
+ if (current.state !== "unknown") {
142
+ const live = current;
143
+ lapseTimer = setTimeout(() => {
144
+ try {
145
+ apply(unknownBand(live));
146
+ } catch (error) {
147
+ input.onError?.(publicationHandlerErrorContext(channel, error));
148
+ }
149
+ }, live.validUntilMs - Date.now());
150
+ }
151
+ input.onEvent(current);
152
+ };
153
+ const stream = snapshotThenStream({
154
+ realtime: this.#realtime,
155
+ channel,
156
+ schema: GetPriceBandResponseSchema,
157
+ snapshotErrorLog: "Failed to fetch price band",
158
+ snapshotFailureMode: "live",
159
+ fetchSnapshot: () => this.getPriceBand({ symbolId }).catch((error) => {
160
+ if (isPriceBandUnknownError(error)) return unknownBand();
161
+ throw error;
162
+ }),
163
+ readPublication: (res) => res.band ? [res.band] : [],
164
+ applySnapshot: (seed, buffered) => apply(seed, ...buffered.map((band) => formatLivePriceBand(scales, band))),
165
+ applyLivePublications: (bands) => apply(...bands.map((band) => formatLivePriceBand(scales, band))),
166
+ onOpen: input.onOpen,
167
+ onClose: input.onClose,
168
+ onError: input.onError
169
+ });
170
+ return () => {
171
+ clearTimeout(lapseTimer);
172
+ stream.unsubscribe();
173
+ };
174
+ }
175
+ /**
84
176
  * Subscribes to public trade prints on public:spot:market:trades:{symbolId}:proto for the requested symbol and emits parsed market trades.
85
177
  * Each publication batches trades, emitted one at a time in execution order; a trade
86
178
  * whose `matchId` was already emitted replaces the earlier copy.
@@ -1 +1 @@
1
- {"version":3,"file":"market-data.js","names":["#client","Proto.MarketDataService","#realtime","#scales","Proto.MarketTradeBatchSchema"],"sources":["../../../src/services/market-data/market-data.ts"],"sourcesContent":["import * as Proto from \"../../gen/marketdata/v1/marketdata_pb.js\";\nimport { SymbolIdInputSchema } from \"../shared.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport {\n deliverBatch,\n type SdkSubscriptionErrorContext,\n} from \"../../shared/subscription-errors.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport { connectReadyGatedProtoChannel } from \"../../realtime/ready-gated-subscription.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 * as v from \"valibot\";\nimport {\n AssetInfoSchema,\n GetMarketTradesInputSchema,\n GetPriceBandInputSchema,\n formatLivePriceBand,\n type GetPriceBandInput,\n type LivePriceBand,\n ListAssetInfoInputSchema,\n type AssetInfo,\n type ListAssetInfoInput,\n formatMarketTrade,\n type GetMarketTradesInput,\n type SpotConfig,\n SpotConfigSchema,\n type MarketTrade,\n TradeBackfillSchema,\n type TradeBackfill,\n} from \"./market-data.schemas.js\";\nimport { isDev } from \"../../utils/is-dev.js\";\n\ninterface SubscribeTradesInput extends BaseSubscribeInput<MarketTrade> {\n symbolId: number;\n}\n\n/**\n * Exposes public spot trades, spot configuration, and live trade streams.\n */\nexport class MarketDataService {\n #client: Client<typeof Proto.MarketDataService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n\n constructor(transports: PublicApiTransports, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.MarketDataService, transports.publicApi);\n this.#realtime = realtime;\n this.#scales = scales;\n }\n\n /**\n * Returns recent public trades for one spot market, ordered newest-first by execution timestamp with match id as a tie-breaker. Supports limit, time bounds, side filtering, and match-id pagination.\n *\n * With `afterTradeId`, it instead walks the symbol's trades by `matchId`, oldest first and\n * gap-free, to backfill trades missed on a live stream, and the result carries `backfill`.\n * Start from `\"0\"`, then pass `backfill.nextAfterTradeId`; when it equals the `afterTradeId`\n * sent, nothing newer is available yet, so retry later with backoff. `afterTradeId` cannot\n * be combined with `side`, `startTsNs`, `endTsNs` or `pageToken`.\n */\n async listTrades(\n input: GetMarketTradesInput,\n options?: PolyesterRequestOptions,\n ): Promise<{ trades: MarketTrade[]; nextPageToken: string; backfill?: TradeBackfill }> {\n await this.#scales.ready();\n const validatedInput = parse(GetMarketTradesInputSchema, input);\n const res = await this.#client.getTrades(validatedInput, toConnectCallOptions(options));\n const trades = res.trades.map((trade) => formatMarketTrade(this.#scales, trade));\n if (validatedInput.afterTradeId === undefined) {\n return { trades, nextPageToken: res.nextPageToken };\n }\n return {\n trades,\n nextPageToken: res.nextPageToken,\n backfill: parse(TradeBackfillSchema, res),\n };\n }\n\n /**\n * Returns the cacheable spot reference-data snapshot, including asset metadata, pair trading constraints, display scales, statuses, and market slippage defaults.\n *\n * This is the catalog's own data source, so it must never wait on catalog\n * readiness (that would deadlock the initial catalog refresh) and carries\n * no decimal conversion.\n */\n async getSpotConfig(options?: PolyesterRequestOptions): Promise<SpotConfig> {\n const res = await this.#client.getSpotConfig({}, toConnectCallOptions(options));\n return parse(SpotConfigSchema, res);\n }\n\n /**\n * Returns team-maintained asset information (description, official links, launch date and\n * price) and market statistics (supplies, market caps and rank) for the requested ledger\n * asset IDs, or for every asset with either, ordered by `assetId`. Assets with neither are\n * omitted. Public and cacheable; no pagination.\n */\n async listAssetInfo(\n input: ListAssetInfoInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<AssetInfo[]> {\n const request = parse(ListAssetInfoInputSchema, input);\n const res = await this.#client.listAssetInfo(request, toConnectCallOptions(options));\n return parse(v.array(AssetInfoSchema), res.assetInfo);\n }\n\n /**\n * Returns a spot pair's live price band: its reference price and the limit prices the pair\n * admits now. Advisory: the pair checks each order against its own band on arrival. Never\n * cached. A band not confirmed in the last 5 seconds throws `ServiceUnavailableError`\n * (`PRICE_BAND_STALE` or `PRICE_BAND_UNKNOWN`); retry after a second. An unknown `symbolId`\n * throws `ResourceNotFoundError`.\n */\n async getPriceBand(\n input: GetPriceBandInput,\n options?: PolyesterRequestOptions,\n ): Promise<LivePriceBand> {\n const request = parse(GetPriceBandInputSchema, input);\n const res = await this.#client.getPriceBand(request, toConnectCallOptions(options));\n if (!res.band) throw new Error(\"GetPriceBand response is missing its band\");\n return formatLivePriceBand(this.#scales, res.band);\n }\n\n /**\n * Subscribes to public trade prints on public:spot:market:trades:{symbolId}:proto for the requested symbol and emits parsed market trades.\n * Each publication batches trades, emitted one at a time in execution order; a trade\n * whose `matchId` was already emitted replaces the earlier copy.\n */\n subscribeTrades(input: SubscribeTradesInput): () => void {\n const symbolId = parse(SymbolIdInputSchema, input.symbolId);\n const channel = `public:spot:market:trades:${symbolId}:proto`;\n const notifyError = (error: SdkSubscriptionErrorContext) => {\n if (isDev()) {\n console.error(\"Market trades subscription error\", error);\n }\n input.onError?.(error);\n };\n return connectReadyGatedProtoChannel(this.#realtime, {\n channel,\n schema: Proto.MarketTradeBatchSchema,\n ready: () => this.#scales.ready(),\n onPublication: (batch) =>\n deliverBatch(\n channel,\n batch.events,\n (trade) => input.onEvent(formatMarketTrade(this.#scales, trade)),\n notifyError,\n ),\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: notifyError,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,IAAa,oBAAb,MAA+B;CAC3B;CACA;CACA;CAEA,YAAY,YAAiC,UAA6B,QAAmB;EACzF,KAAKA,UAAU,aAAaC,qBAAyB,WAAW,SAAS;EACzE,KAAKC,YAAY;EACjB,KAAKC,UAAU;CACnB;;;;;;;;;;CAWA,MAAM,WACF,OACA,SACmF;EACnF,MAAM,KAAKA,QAAQ,MAAM;EACzB,MAAM,iBAAiB,MAAM,4BAA4B,KAAK;EAC9D,MAAM,MAAM,MAAM,KAAKH,QAAQ,UAAU,gBAAgB,qBAAqB,OAAO,CAAC;EACtF,MAAM,SAAS,IAAI,OAAO,KAAK,UAAU,kBAAkB,KAAKG,SAAS,KAAK,CAAC;EAC/E,IAAI,eAAe,iBAAiB,KAAA,GAChC,OAAO;GAAE;GAAQ,eAAe,IAAI;EAAc;EAEtD,OAAO;GACH;GACA,eAAe,IAAI;GACnB,UAAU,MAAM,qBAAqB,GAAG;EAC5C;CACJ;;;;;;;;CASA,MAAM,cAAc,SAAwD;EACxE,MAAM,MAAM,MAAM,KAAKH,QAAQ,cAAc,CAAC,GAAG,qBAAqB,OAAO,CAAC;EAC9E,OAAO,MAAM,kBAAkB,GAAG;CACtC;;;;;;;CAQA,MAAM,cACF,QAA4B,CAAC,GAC7B,SACoB;EACpB,MAAM,UAAU,MAAM,0BAA0B,KAAK;EACrD,MAAM,MAAM,MAAM,KAAKA,QAAQ,cAAc,SAAS,qBAAqB,OAAO,CAAC;EACnF,OAAO,MAAM,EAAE,MAAM,eAAe,GAAG,IAAI,SAAS;CACxD;;;;;;;;CASA,MAAM,aACF,OACA,SACsB;EACtB,MAAM,UAAU,MAAM,yBAAyB,KAAK;EACpD,MAAM,MAAM,MAAM,KAAKA,QAAQ,aAAa,SAAS,qBAAqB,OAAO,CAAC;EAClF,IAAI,CAAC,IAAI,MAAM,MAAM,IAAI,MAAM,2CAA2C;EAC1E,OAAO,oBAAoB,KAAKG,SAAS,IAAI,IAAI;CACrD;;;;;;CAOA,gBAAgB,OAAyC;EAErD,MAAM,UAAU,6BADC,MAAM,qBAAqB,MAAM,QACE,EAAE;EACtD,MAAM,eAAe,UAAuC;GACxD,IAAI,MAAM,GACN,QAAQ,MAAM,oCAAoC,KAAK;GAE3D,MAAM,UAAU,KAAK;EACzB;EACA,OAAO,8BAA8B,KAAKD,WAAW;GACjD;GACA,QAAQE;GACR,aAAa,KAAKD,QAAQ,MAAM;GAChC,gBAAgB,UACZ,aACI,SACA,MAAM,SACL,UAAU,MAAM,QAAQ,kBAAkB,KAAKA,SAAS,KAAK,CAAC,GAC/D,WACJ;GACJ,mBAAmB,MAAM,SAAS;GAClC,sBAAsB,MAAM,UAAU;GACtC,SAAS;EACb,CAAC;CACL;AACJ"}
1
+ {"version":3,"file":"market-data.js","names":["#client","Proto.MarketDataService","#realtime","#scales","Proto.LivePriceBandSchema","Proto.GetPriceBandResponseSchema","Proto.MarketTradeBatchSchema"],"sources":["../../../src/services/market-data/market-data.ts"],"sourcesContent":["import * as Proto from \"../../gen/marketdata/v1/marketdata_pb.js\";\nimport { SymbolIdInputSchema } from \"../shared.js\";\nimport type { PolyesterRealtime } from \"../../realtime/types.js\";\nimport { create } from \"@bufbuild/protobuf\";\nimport { createClient, type Client } from \"@connectrpc/connect\";\nimport {\n deliverBatch,\n publicationHandlerErrorContext,\n type SdkSubscriptionErrorContext,\n} from \"../../shared/subscription-errors.js\";\nimport { parse } from \"../../shared/validation.js\";\nimport type { BaseSubscribeInput } from \"../../shared/types.js\";\nimport { connectReadyGatedProtoChannel } from \"../../realtime/ready-gated-subscription.js\";\nimport { snapshotThenStream } from \"../../realtime/snapshot-then-stream.js\";\nimport { ServiceUnavailableError } from \"../../shared/errors.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 * as v from \"valibot\";\nimport {\n AssetInfoSchema,\n GetMarketTradesInputSchema,\n GetPriceBandInputSchema,\n formatLivePriceBand,\n type GetPriceBandInput,\n type LivePriceBand,\n ListAssetInfoInputSchema,\n type AssetInfo,\n type ListAssetInfoInput,\n formatMarketTrade,\n type GetMarketTradesInput,\n type SpotConfig,\n SpotConfigSchema,\n type MarketTrade,\n TradeBackfillSchema,\n type TradeBackfill,\n} from \"./market-data.schemas.js\";\nimport { isDev } from \"../../utils/is-dev.js\";\n\ninterface SubscribeTradesInput extends BaseSubscribeInput<MarketTrade> {\n symbolId: number;\n}\n\ninterface SubscribePriceBandInput extends BaseSubscribeInput<LivePriceBand> {\n symbolId: number;\n}\n\n/** Newer by `epoch`, then `updateId`, then `asOfTsNs`; at an equal one, `unknown` replaces a band. */\nfunction isNewerBand(band: LivePriceBand, than: LivePriceBand): boolean {\n for (const key of [\"epoch\", \"updateId\", \"asOfTsNs\"] as const) {\n const d = BigInt(band[key]) - BigInt(than[key]);\n if (d !== 0n) return d > 0n;\n }\n return band.state === \"unknown\" && than.state !== \"unknown\";\n}\n\n/** True for `getPriceBand`'s refusal of a band not confirmed in the last 5 seconds. */\nfunction isPriceBandUnknownError(error: unknown): boolean {\n return (\n error instanceof ServiceUnavailableError &&\n /^PRICE_BAND_(STALE|UNKNOWN)$/.test(error.message)\n );\n}\n\n/**\n * Exposes public spot trades, spot configuration, and live trade streams.\n */\nexport class MarketDataService {\n #client: Client<typeof Proto.MarketDataService>;\n #realtime: PolyesterRealtime;\n #scales: SdkScales;\n\n constructor(transports: PublicApiTransports, realtime: PolyesterRealtime, scales: SdkScales) {\n this.#client = createClient(Proto.MarketDataService, transports.publicApi);\n this.#realtime = realtime;\n this.#scales = scales;\n }\n\n /**\n * Returns recent public trades for one spot market, ordered newest-first by execution timestamp with match id as a tie-breaker. Supports limit, time bounds, side filtering, and match-id pagination.\n *\n * With `afterTradeId`, it instead walks the symbol's trades by `matchId`, oldest first and\n * gap-free, to backfill trades missed on a live stream, and the result carries `backfill`.\n * Start from `\"0\"`, then pass `backfill.nextAfterTradeId`; when it equals the `afterTradeId`\n * sent, nothing newer is available yet, so retry later with backoff. `afterTradeId` cannot\n * be combined with `side`, `startTsNs`, `endTsNs` or `pageToken`.\n */\n async listTrades(\n input: GetMarketTradesInput,\n options?: PolyesterRequestOptions,\n ): Promise<{ trades: MarketTrade[]; nextPageToken: string; backfill?: TradeBackfill }> {\n await this.#scales.ready();\n const validatedInput = parse(GetMarketTradesInputSchema, input);\n const res = await this.#client.getTrades(validatedInput, toConnectCallOptions(options));\n const trades = res.trades.map((trade) => formatMarketTrade(this.#scales, trade));\n if (validatedInput.afterTradeId === undefined) {\n return { trades, nextPageToken: res.nextPageToken };\n }\n return {\n trades,\n nextPageToken: res.nextPageToken,\n backfill: parse(TradeBackfillSchema, res),\n };\n }\n\n /**\n * Returns the cacheable spot reference-data snapshot, including asset metadata, pair trading constraints, display scales, statuses, and market slippage defaults.\n *\n * This is the catalog's own data source, so it must never wait on catalog\n * readiness (that would deadlock the initial catalog refresh) and carries\n * no decimal conversion.\n */\n async getSpotConfig(options?: PolyesterRequestOptions): Promise<SpotConfig> {\n const res = await this.#client.getSpotConfig({}, toConnectCallOptions(options));\n return parse(SpotConfigSchema, res);\n }\n\n /**\n * Returns team-maintained asset information (description, official links, launch date and\n * price) and market statistics (supplies, market caps and rank) for the requested ledger\n * asset IDs, or for every asset with either, ordered by `assetId`. Assets with neither are\n * omitted. Public and cacheable; no pagination.\n */\n async listAssetInfo(\n input: ListAssetInfoInput = {},\n options?: PolyesterRequestOptions,\n ): Promise<AssetInfo[]> {\n const request = parse(ListAssetInfoInputSchema, input);\n const res = await this.#client.listAssetInfo(request, toConnectCallOptions(options));\n return parse(v.array(AssetInfoSchema), res.assetInfo);\n }\n\n /**\n * Returns a spot pair's live price band: its reference price and the limit prices the pair\n * admits now. Advisory: the pair checks each order against its own band on arrival. Never\n * cached. A band not confirmed in the last 5 seconds throws `ServiceUnavailableError`\n * (`PRICE_BAND_STALE` or `PRICE_BAND_UNKNOWN`); retry after a second. An unknown `symbolId`\n * throws `ResourceNotFoundError`.\n */\n async getPriceBand(\n input: GetPriceBandInput,\n options?: PolyesterRequestOptions,\n ): Promise<LivePriceBand> {\n const request = parse(GetPriceBandInputSchema, input);\n const res = await this.#client.getPriceBand(request, toConnectCallOptions(options));\n if (!res.band) throw new Error(\"GetPriceBand response is missing its band\");\n return formatLivePriceBand(this.#scales, res.band);\n }\n\n /**\n * Streams one pair's live price band from public:spot:market:price_band:{symbolId}:proto,\n * emitting the same `LivePriceBand` as `getPriceBand`. Each connection is seeded with\n * `getPriceBand`; the stream sends a changed band at once and re-sends a current one about\n * every 2 seconds.\n *\n * Only a newer band is emitted (greater `epoch`, then `updateId`, then `asOfTsNs`); repeated,\n * late and replayed messages, and a seed the stream already passed, are dropped.\n *\n * Unknown bands arrive as `state: \"unknown\"` with null prices, never as `onError`: when the\n * seed is refused `PRICE_BAND_STALE` / `PRICE_BAND_UNKNOWN`, when the stream says so, and\n * when `validUntilMs` passes (by the local clock) with no newer message. An emitted band\n * other than `unknown` is current until the next emission, so callers need no\n * `validUntilMs` timer of their own. A seed that fails otherwise (network, unknown\n * `symbolId`) goes to `onError` as `type: \"snapshot\"`, and the stream still delivers.\n */\n subscribePriceBand(input: SubscribePriceBandInput): () => void {\n const symbolId = parse(SymbolIdInputSchema, input.symbolId);\n const channel = `public:spot:market:price_band:${symbolId}:proto`;\n const scales = this.#scales;\n let current: LivePriceBand | undefined;\n let lapseTimer: ReturnType<typeof setTimeout> | undefined;\n\n // Shaped like the stream's UNKNOWN: the confirmation it replaces, 0 when none.\n const unknownBand = (from?: LivePriceBand): LivePriceBand => {\n const asOfTsNs = BigInt(from?.asOfTsNs ?? 0);\n return formatLivePriceBand(\n scales,\n create(Proto.LivePriceBandSchema, {\n symbolId,\n state: Proto.PriceBandState.UNKNOWN,\n epoch: BigInt(from?.epoch ?? 0),\n updateId: BigInt(from?.updateId ?? 0),\n asOfTsNs,\n updatedTsNs: asOfTsNs,\n validUntilTsNs: asOfTsNs,\n }),\n );\n };\n\n // Emits only the newest of `bands`, and only when it is newer than the current band.\n const apply = (...bands: LivePriceBand[]): void => {\n const band = bands.reduce((a, b) => (isNewerBand(b, a) ? b : a));\n if (current && !isNewerBand(band, current)) return;\n clearTimeout(lapseTimer);\n const lapsed = band.state !== \"unknown\" && band.validUntilMs <= Date.now();\n current = lapsed ? unknownBand(band) : band;\n if (current.state !== \"unknown\") {\n const live = current;\n lapseTimer = setTimeout(() => {\n try {\n apply(unknownBand(live));\n } catch (error) {\n input.onError?.(publicationHandlerErrorContext(channel, error));\n }\n }, live.validUntilMs - Date.now());\n }\n input.onEvent(current);\n };\n\n const stream = snapshotThenStream({\n realtime: this.#realtime,\n channel,\n schema: Proto.GetPriceBandResponseSchema,\n snapshotErrorLog: \"Failed to fetch price band\",\n snapshotFailureMode: \"live\",\n fetchSnapshot: () =>\n this.getPriceBand({ symbolId }).catch((error: unknown) => {\n if (isPriceBandUnknownError(error)) return unknownBand();\n throw error;\n }),\n readPublication: (res) => (res.band ? [res.band] : []),\n applySnapshot: (seed, buffered) =>\n apply(seed, ...buffered.map((band) => formatLivePriceBand(scales, band))),\n applyLivePublications: (bands) =>\n apply(...bands.map((band) => formatLivePriceBand(scales, band))),\n onOpen: input.onOpen,\n onClose: input.onClose,\n onError: input.onError,\n });\n\n return () => {\n clearTimeout(lapseTimer);\n stream.unsubscribe();\n };\n }\n\n /**\n * Subscribes to public trade prints on public:spot:market:trades:{symbolId}:proto for the requested symbol and emits parsed market trades.\n * Each publication batches trades, emitted one at a time in execution order; a trade\n * whose `matchId` was already emitted replaces the earlier copy.\n */\n subscribeTrades(input: SubscribeTradesInput): () => void {\n const symbolId = parse(SymbolIdInputSchema, input.symbolId);\n const channel = `public:spot:market:trades:${symbolId}:proto`;\n const notifyError = (error: SdkSubscriptionErrorContext) => {\n if (isDev()) {\n console.error(\"Market trades subscription error\", error);\n }\n input.onError?.(error);\n };\n return connectReadyGatedProtoChannel(this.#realtime, {\n channel,\n schema: Proto.MarketTradeBatchSchema,\n ready: () => this.#scales.ready(),\n onPublication: (batch) =>\n deliverBatch(\n channel,\n batch.events,\n (trade) => input.onEvent(formatMarketTrade(this.#scales, trade)),\n notifyError,\n ),\n onConnected: () => input.onOpen?.(),\n onDisconnected: () => input.onClose?.(),\n onError: notifyError,\n });\n }\n}\n"],"mappings":"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"}
@@ -1,8 +1,8 @@
1
+ import { MarketOverviewBatchSchema, MarketOverviewService as MarketOverviewService$1 } from "../../gen/marketoverview/v1/marketoverview_pb.js";
1
2
  import { parse } from "../../shared/validation.js";
2
3
  import { toConnectCallOptions } from "../../shared/request-options.js";
3
4
  import { CatalogLookupError } from "../../catalogs/types.js";
4
5
  import { isDev } from "../../utils/is-dev.js";
5
- import { MarketOverviewBatchSchema, MarketOverviewService as MarketOverviewService$1 } from "../../gen/marketoverview/v1/marketoverview_pb.js";
6
6
  import { snapshotThenStream } from "../../realtime/snapshot-then-stream.js";
7
7
  import { CurrencyConversionConfigSchema, CurrencyConversionRatesSchema, ListMarketOverviewInputSchema, SpotVolumeHistoryInputSchema, SpotVolumeHistoryResponseSchema, createMarketOverviewSchema } from "./market-overview.schemas.js";
8
8
  import { createClient } from "@connectrpc/connect";
@@ -1,8 +1,8 @@
1
+ import "../../gen/marketoverview/v1/marketoverview_pb.js";
1
2
  import { tsNsToMs } from "../../utils/time.js";
2
3
  import { enumLabelSchema } from "../../shared/proto-enum-codec.js";
3
4
  import { scaledToDecimalOutput } from "../../shared/decimal-surface.js";
4
5
  import { PositiveUint32InputSchema, SymbolIdInputSchema } from "../shared.js";
5
- import "../../gen/marketoverview/v1/marketoverview_pb.js";
6
6
  import { MARKET_OVERVIEW_ORDER_BY_VALUES, MARKET_OVERVIEW_SORT_VALUES, MarketOverviewOrderByCodec, MarketOverviewSortCodec, SPARKLINE_INTERVAL_VALUES, SparklineIntervalCodec } from "./market-overview.codecs.js";
7
7
  import * as v from "valibot";
8
8
  //#region src/services/market-overview/market-overview.schemas.ts
@@ -1,8 +1,8 @@
1
+ import { NotificationService } from "../../gen/notifications/v1/notifications_pb.js";
1
2
  import { InternalServerError } from "../../shared/errors.js";
2
3
  import { parse } from "../../shared/validation.js";
3
4
  import { removeUndefined } from "../../utils/remove-undefined.js";
4
5
  import { toConnectCallOptions } from "../../shared/request-options.js";
5
- import { NotificationService } from "../../gen/notifications/v1/notifications_pb.js";
6
6
  import { GetNotificationInputSchema, ListNotificationsInputSchema, MarkAllNotificationsReadInputSchema, MarkNotificationsInputSchema, formatNotification, formatNotificationCounts } from "./notifications.schemas.js";
7
7
  import { createClient } from "@connectrpc/connect";
8
8
  //#region src/services/notifications/notifications.ts
@@ -2,7 +2,7 @@ import { GetNotificationCountsResponse, Notification, NotificationCategory, Read
2
2
  import * as v from "valibot";
3
3
  //#region src/services/notifications/notifications.schemas.d.ts
4
4
  declare const ListNotificationsInputSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
5
- readonly categories: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["alerts", "security"], undefined>, undefined>, v.TransformAction<("security" | "alerts")[], (NotificationCategory.ALERTS | NotificationCategory.SECURITY)[]>]>, undefined>;
5
+ readonly categories: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["alerts", "security"], undefined>, undefined>, v.TransformAction<("alerts" | "security")[], (NotificationCategory.ALERTS | NotificationCategory.SECURITY)[]>]>, undefined>;
6
6
  /** Only read or only unread notifications; omit for both. */
7
7
  readonly readState: v.OptionalSchema<v.PicklistSchema<readonly ["unread", "read"], undefined>, undefined>;
8
8
  /** Epoch ms, inclusive. */
@@ -46,7 +46,7 @@ declare const MarkNotificationsInputSchema: v.StrictObjectSchema<{
46
46
  }, undefined>;
47
47
  type MarkNotificationsInput = v.InferInput<typeof MarkNotificationsInputSchema>;
48
48
  declare const MarkAllNotificationsReadInputSchema: v.StrictObjectSchema<{
49
- readonly categories: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["alerts", "security"], undefined>, undefined>, v.TransformAction<("security" | "alerts")[], (NotificationCategory.ALERTS | NotificationCategory.SECURITY)[]>]>, undefined>;
49
+ readonly categories: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["alerts", "security"], undefined>, undefined>, v.TransformAction<("alerts" | "security")[], (NotificationCategory.ALERTS | NotificationCategory.SECURITY)[]>]>, undefined>;
50
50
  /**
51
51
  * Mark only this notification and older ones. Pass the newest one shown, so one that arrives
52
52
  * later stays unread; omit to mark every notification that exists when the call runs.
@@ -57,7 +57,7 @@ type MarkAllNotificationsReadInput = v.InferInput<typeof MarkAllNotificationsRea
57
57
  declare function formatNotification(notification: Notification): {
58
58
  notificationId: string;
59
59
  type: "unspecified" | "price_alert" | "telegram_approval" | "broker_allowlist_change" | "telegram_linked" | "admin_key_action";
60
- category: "unspecified" | "security" | "alerts";
60
+ category: "unspecified" | "alerts" | "security";
61
61
  /** Plain-text title, the same for every notification of a type. */
62
62
  title: string;
63
63
  /** Plain-text summary; may span several lines. */
@@ -77,13 +77,10 @@ declare function formatNotification(notification: Notification): {
77
77
  /** Price that fired the alert, as a decimal string. */
78
78
  triggeredPrice: string;
79
79
  triggeredAt: number | null;
80
- /** The approval's ID in `client.assistant`. */
81
80
  approvalId?: undefined;
82
81
  action?: undefined;
83
- /** Trading account (subaccount) the action acted on. */
84
82
  accountId?: undefined;
85
83
  summary?: undefined;
86
- /** Key parameters in display order, such as market, side and quantity. */
87
84
  parameters?: undefined;
88
85
  approvedAt?: undefined;
89
86
  broker?: undefined;
@@ -117,7 +114,7 @@ declare function formatNotification(notification: Notification): {
117
114
  type: "telegram_approval";
118
115
  /** The approval's ID in `client.assistant`. */
119
116
  approvalId: string;
120
- action: "unspecified" | "place_order" | "place_orders" | "modify_orders" | "cancel_order" | "cancel_all_orders" | "modify_trigger" | "pause_trigger" | "resume_trigger" | "swap" | "convert_dust";
117
+ action: "unspecified" | "swap" | "place_orders" | "place_order" | "modify_orders" | "cancel_order" | "cancel_all_orders" | "modify_trigger" | "pause_trigger" | "resume_trigger" | "convert_dust";
121
118
  /** Trading account (subaccount) the action acted on. */
122
119
  accountId: string;
123
120
  summary: string;
@@ -132,7 +129,6 @@ declare function formatNotification(notification: Notification): {
132
129
  symbolId?: undefined;
133
130
  direction?: undefined;
134
131
  priceSource?: undefined;
135
- /** Alert price, as a decimal string. */
136
132
  price?: undefined;
137
133
  /** Price that fired the alert, as a decimal string. */
138
134
  triggeredPrice?: undefined;
@@ -189,17 +185,13 @@ declare function formatNotification(notification: Notification): {
189
185
  symbolId?: undefined;
190
186
  direction?: undefined;
191
187
  priceSource?: undefined;
192
- /** Alert price, as a decimal string. */
193
188
  price?: undefined;
194
189
  /** Price that fired the alert, as a decimal string. */
195
190
  triggeredPrice?: undefined;
196
191
  triggeredAt?: undefined;
197
- /** The approval's ID in `client.assistant`. */
198
192
  approvalId?: undefined;
199
- /** Trading account (subaccount) the action acted on. */
200
193
  accountId?: undefined;
201
194
  summary?: undefined;
202
- /** Key parameters in display order, such as market, side and quantity. */
203
195
  parameters?: undefined;
204
196
  approvedAt?: undefined;
205
197
  linkedAt?: undefined;
@@ -221,18 +213,14 @@ declare function formatNotification(notification: Notification): {
221
213
  symbolId?: undefined;
222
214
  direction?: undefined;
223
215
  priceSource?: undefined;
224
- /** Alert price, as a decimal string. */
225
216
  price?: undefined;
226
217
  /** Price that fired the alert, as a decimal string. */
227
218
  triggeredPrice?: undefined;
228
219
  triggeredAt?: undefined;
229
- /** The approval's ID in `client.assistant`. */
230
220
  approvalId?: undefined;
231
221
  action?: undefined;
232
- /** Trading account (subaccount) the action acted on. */
233
222
  accountId?: undefined;
234
223
  summary?: undefined;
235
- /** Key parameters in display order, such as market, side and quantity. */
236
224
  parameters?: undefined;
237
225
  approvedAt?: undefined;
238
226
  broker?: undefined;
@@ -279,17 +267,13 @@ declare function formatNotification(notification: Notification): {
279
267
  symbolId?: undefined;
280
268
  direction?: undefined;
281
269
  priceSource?: undefined;
282
- /** Alert price, as a decimal string. */
283
270
  price?: undefined;
284
271
  /** Price that fired the alert, as a decimal string. */
285
272
  triggeredPrice?: undefined;
286
273
  triggeredAt?: undefined;
287
- /** The approval's ID in `client.assistant`. */
288
274
  approvalId?: undefined;
289
- /** Trading account (subaccount) the action acted on. */
290
275
  accountId?: undefined;
291
276
  summary?: undefined;
292
- /** Key parameters in display order, such as market, side and quantity. */
293
277
  parameters?: undefined;
294
278
  approvedAt?: undefined;
295
279
  broker?: undefined;
@@ -317,18 +301,14 @@ declare function formatNotification(notification: Notification): {
317
301
  symbolId?: undefined;
318
302
  direction?: undefined;
319
303
  priceSource?: undefined;
320
- /** Alert price, as a decimal string. */
321
304
  price?: undefined;
322
305
  /** Price that fired the alert, as a decimal string. */
323
306
  triggeredPrice?: undefined;
324
307
  triggeredAt?: undefined;
325
- /** The approval's ID in `client.assistant`. */
326
308
  approvalId?: undefined;
327
309
  action?: undefined;
328
- /** Trading account (subaccount) the action acted on. */
329
310
  accountId?: undefined;
330
311
  summary?: undefined;
331
- /** Key parameters in display order, such as market, side and quantity. */
332
312
  parameters?: undefined;
333
313
  approvedAt?: undefined;
334
314
  broker?: undefined;
@@ -377,7 +357,7 @@ declare function formatNotificationCounts(counts: GetNotificationCountsResponse)
377
357
  /** Every type in ascending enum order, including types with no notification. */
378
358
  types: {
379
359
  type: "unspecified" | "price_alert" | "telegram_approval" | "broker_allowlist_change" | "telegram_linked" | "admin_key_action";
380
- category: "unspecified" | "security" | "alerts";
360
+ category: "unspecified" | "alerts" | "security";
381
361
  total: number;
382
362
  unread: number;
383
363
  }[];
@@ -1 +1 @@
1
- {"version":3,"file":"notifications.schemas.d.ts","names":[],"sources":["../../../src/services/notifications/notifications.schemas.ts"],"mappings":";;;cA4Ca,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;iBAmGK,mBAAmB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoBrC,sBAAsB,kBAAkB;KAExC,4BAA4B;;KAG5B;EACR,eAAe;EACf;;iBAGY,yBAAyB,QAAQ;;;;;;;;;;;;KAerC,qBAAqB,kBAAkB"}
1
+ {"version":3,"file":"notifications.schemas.d.ts","names":[],"sources":["../../../src/services/notifications/notifications.schemas.ts"],"mappings":";;;cA4Ca,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;iBAmGK,mBAAmB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoBrC,sBAAsB,kBAAkB;KAExC,4BAA4B;;KAG5B;EACR,eAAe;EACf;;iBAGY,yBAAyB,QAAQ;;;;;;;;;;;;KAerC,qBAAqB,kBAAkB"}
@@ -1,3 +1,4 @@
1
+ import { OrderBookDeltaSchema, OrderbookService as OrderbookService$1 } from "../../gen/orderbook/v1/orderbook_pb.js";
1
2
  import { PolyesterError, ServiceUnavailableError, ValidationError } from "../../shared/errors.js";
2
3
  import { parse } from "../../shared/validation.js";
3
4
  import { toConnectCallOptions } from "../../shared/request-options.js";
@@ -5,7 +6,6 @@ import { publicationHandlerErrorContext } from "../../shared/subscription-errors
5
6
  import { decimalInputToScaled } from "../../shared/decimal-surface.js";
6
7
  import { DepthTierCodec } from "../../shared/depth-tier.js";
7
8
  import { snapshotThenStream } from "../../realtime/snapshot-then-stream.js";
8
- import { OrderBookDeltaSchema, OrderbookService as OrderbookService$1 } from "../../gen/orderbook/v1/orderbook_pb.js";
9
9
  import { GetOrderbookInputSchema, createOrderbookDataSchema, formatOrderbookLevel } from "./orderbook.schemas.js";
10
10
  import { orderbookWsChannelDepth } from "./orderbook.codecs.js";
11
11
  import { createClient } from "@connectrpc/connect";