@orangecharts/wrun-chart-host 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +3 -1
  2. package/dist/constants/feature-flags.constants.d.ts +9 -0
  3. package/dist/constants/feature-flags.constants.js +86 -16
  4. package/dist/constants/marketCapabilities.constants.d.ts +14 -9
  5. package/dist/constants/marketCapabilities.constants.js +36 -13
  6. package/dist/constants/opra-compliance.constants.d.ts +15 -0
  7. package/dist/constants/opra-compliance.constants.js +15 -0
  8. package/dist/constants/option-venues.constants.d.ts +11 -6
  9. package/dist/constants/option-venues.constants.js +5 -2
  10. package/dist/constants/scriptEditor/builtin-script-snippets.d.ts +26 -0
  11. package/dist/constants/scriptEditor/builtin-script-snippets.js +6 -0
  12. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.d.ts +15 -0
  13. package/dist/constants/scriptEditor/technicalIndicatorScriptKeys.constants.js +17 -0
  14. package/dist/constants/venue-presets.constants.d.ts +20 -20
  15. package/dist/constants/venue-presets.constants.js +24 -26
  16. package/dist/host-env.d.ts +39 -9
  17. package/dist/host-env.js +6 -0
  18. package/dist/host-ports.types.d.ts +108 -18
  19. package/dist/index.d.ts +14 -0
  20. package/dist/index.js +14 -0
  21. package/dist/interfaces/kscript-diagnostics.interface.d.ts +6 -0
  22. package/dist/interfaces/opra-realtime.interface.d.ts +13 -11
  23. package/dist/interfaces/opra-realtime.interface.js +10 -10
  24. package/dist/interfaces/replay.interface.d.ts +8 -0
  25. package/dist/interfaces/wrun-runtime.interface.d.ts +52 -15
  26. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +94 -14
  27. package/dist/kscript-data/controls/live-trades-merge.util.js +132 -22
  28. package/dist/kscript-data/controls/live-trades-order-gate.util.d.ts +56 -0
  29. package/dist/kscript-data/controls/live-trades-order-gate.util.js +107 -0
  30. package/dist/market-data/billing.interface.d.ts +227 -42
  31. package/dist/market-data/billing.interface.js +60 -12
  32. package/dist/market-data/venue.d.ts +88 -6
  33. package/dist/market-data/venues/cme.contract.copy.json +66 -0
  34. package/dist/market-data/venues/cme.d.ts +126 -0
  35. package/dist/market-data/venues/cme.js +133 -0
  36. package/dist/market-data/venues/index.d.ts +165 -8
  37. package/dist/market-data/venues/index.js +48 -6
  38. package/dist/market-data/venues/opra.contract.copy.json +5 -3
  39. package/dist/market-data/venues/opra.d.ts +3 -3
  40. package/dist/market-data/venues/opra.js +5 -4
  41. package/dist/replay/replayLadder.js +3 -1
  42. package/dist/settings-templates/index.js +7 -3
  43. package/dist/settings-templates/indicator-fields.d.ts +5 -4
  44. package/dist/settings-templates/indicator-fields.js +45 -6
  45. package/dist/settings-templates/tool-rules.d.ts +27 -17
  46. package/dist/settings-templates/tool-rules.js +27 -11
  47. package/dist/settings-templates/tool-tables.generated.js +91 -31
  48. package/dist/utility/chart/book-live-bucket.util.d.ts +15 -0
  49. package/dist/utility/chart/book-live-bucket.util.js +47 -0
  50. package/dist/utility/chart/crypto-index.leaf.d.ts +2 -2
  51. package/dist/utility/chart/crypto-index.leaf.js +2 -2
  52. package/dist/utility/chart/index-mode-admission.util.js +24 -3
  53. package/dist/utility/chart/index-mode.util.d.ts +5 -2
  54. package/dist/utility/chart/index-mode.util.js +23 -13
  55. package/dist/utility/chart/kscript-drawing-safe-area.util.d.ts +35 -11
  56. package/dist/utility/chart/kscript-drawing-safe-area.util.js +145 -35
  57. package/dist/utility/chart/kscript-live-coalesce.util.d.ts +7 -2
  58. package/dist/utility/chart/kscript-live-coalesce.util.js +9 -3
  59. package/dist/utility/chart/kscript-provenance-keys.util.js +6 -0
  60. package/dist/utility/chart/kscript-standin-identity.leaf.d.ts +3 -1
  61. package/dist/utility/chart/kscript-titancharts-render-keys.constants.d.ts +32 -2
  62. package/dist/utility/chart/kscript-titancharts-render-keys.constants.js +45 -0
  63. package/dist/utility/chart/kscript-venue-policy.util.d.ts +53 -27
  64. package/dist/utility/chart/kscript-venue-policy.util.js +74 -32
  65. package/dist/utility/chart/market-session-schedule.util.d.ts +10 -0
  66. package/dist/utility/chart/market-session-schedule.util.js +16 -0
  67. package/dist/utility/chart/marketKind.util.d.ts +12 -10
  68. package/dist/utility/chart/marketKind.util.js +17 -7
  69. package/dist/utility/chart/om-panel-push-style.util.d.ts +7 -7
  70. package/dist/utility/chart/om-panel-push-style.util.js +17 -15
  71. package/dist/utility/chart/om-panel.util.js +6 -6
  72. package/dist/utility/chart/opra-read-access.leaf.d.ts +5 -3
  73. package/dist/utility/chart/opra-read-access.leaf.js +5 -3
  74. package/dist/utility/chart/profile-block-size.util.d.ts +16 -0
  75. package/dist/utility/chart/profile-block-size.util.js +7 -0
  76. package/dist/utility/chart/quote-perp.leaf.d.ts +17 -0
  77. package/dist/utility/chart/quote-perp.leaf.js +20 -0
  78. package/dist/utility/chart/rth-session.util.d.ts +3 -2
  79. package/dist/utility/chart/rth-session.util.js +2 -1
  80. package/dist/utility/chart/window-geometry.leaf.d.ts +8 -0
  81. package/dist/utility/chart/window-geometry.leaf.js +22 -6
  82. package/dist/utility/chart/wrun-run-result.util.d.ts +17 -0
  83. package/dist/utility/chart/wrun-run-result.util.js +145 -7
  84. package/dist/utility/common/transformations.util.d.ts +7 -0
  85. package/dist/utility/common/transformations.util.js +11 -0
  86. package/dist/utility/options/option-bar-anchor.util.d.ts +145 -0
  87. package/dist/utility/options/option-bar-anchor.util.js +340 -0
  88. package/dist/utility/options/option-venue.util.d.ts +21 -3
  89. package/dist/utility/options/option-venue.util.js +30 -3
  90. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +2 -0
  91. package/dist/utility/wrun/derived-roots.util.d.ts +213 -0
  92. package/dist/utility/wrun/derived-roots.util.js +471 -0
  93. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.d.ts +41 -6
  94. package/dist/utility/wrun/run-schedule/wrun-chart-gate-reader.util.js +89 -19
  95. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.d.ts +9 -4
  96. package/dist/utility/wrun/run-schedule/wrun-gate-reader-warm.util.js +47 -6
  97. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.d.ts +5 -3
  98. package/dist/utility/wrun/run-schedule/wrun-late-reads.util.js +6 -4
  99. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.d.ts +2 -2
  100. package/dist/utility/wrun/run-schedule/wrun-prefix-feeds.util.js +5 -1
  101. package/dist/utility/wrun/sources/lanes/option_daily.js +5 -2
  102. package/dist/utility/wrun/sources/lanes/options_flow.js +5 -2
  103. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +64 -19
  104. package/dist/utility/wrun/sources/opra-option-lanes.util.js +105 -35
  105. package/dist/utility/wrun/sources/row-lane-registry.js +3 -2
  106. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +2 -1
  107. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +9 -3
  108. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +15 -6
  109. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +14 -0
  110. package/dist/utility/wrun/sources/row-lanes/option_prints.js +82 -13
  111. package/dist/utility/wrun/sources/row-lanes/option_strike_flow.js +17 -4
  112. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +55 -8
  113. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +95 -14
  114. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +5 -2
  115. package/dist/utility/wrun/sources/row-lanes/option_surface.js +7 -3
  116. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +19 -0
  117. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +35 -14
  118. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +70 -20
  119. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.d.ts +64 -0
  120. package/dist/utility/wrun/sources/wrun-row-lane-add-memo.util.js +89 -0
  121. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.d.ts +45 -1
  122. package/dist/utility/wrun/sources/wrun-row-lane-first-paint.util.js +114 -6
  123. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +56 -5
  124. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +224 -26
  125. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +822 -58
  126. package/dist/utility/wrun/wrun-batched-marks.util.d.ts +16 -3
  127. package/dist/utility/wrun/wrun-batched-marks.util.js +30 -19
  128. package/dist/utility/wrun/wrun-batched-readout.util.d.ts +37 -9
  129. package/dist/utility/wrun/wrun-batched-readout.util.js +61 -15
  130. package/dist/utility/wrun/wrun-builtin-twin.util.d.ts +12 -0
  131. package/dist/utility/wrun/wrun-builtin-twin.util.js +21 -0
  132. package/dist/utility/wrun/wrun-canvas-readout.util.d.ts +4 -0
  133. package/dist/utility/wrun/wrun-cell-capacity.leaf.d.ts +66 -0
  134. package/dist/utility/wrun/wrun-cell-capacity.leaf.js +86 -0
  135. package/dist/utility/wrun/wrun-chart-market-facts.util.d.ts +192 -13
  136. package/dist/utility/wrun/wrun-chart-market-facts.util.js +437 -55
  137. package/dist/utility/wrun/wrun-color-facts.util.d.ts +19 -9
  138. package/dist/utility/wrun/wrun-color-facts.util.js +24 -14
  139. package/dist/utility/wrun/wrun-color-settings.util.d.ts +15 -4
  140. package/dist/utility/wrun/wrun-color-settings.util.js +31 -12
  141. package/dist/utility/wrun/wrun-dollar-unit-port.leaf.d.ts +17 -0
  142. package/dist/utility/wrun/wrun-dollar-unit-port.leaf.js +9 -0
  143. package/dist/utility/wrun/wrun-download-meter.util.d.ts +107 -0
  144. package/dist/utility/wrun/wrun-download-meter.util.js +134 -0
  145. package/dist/utility/wrun/wrun-download-plan.util.d.ts +99 -0
  146. package/dist/utility/wrun/wrun-download-plan.util.js +118 -0
  147. package/dist/utility/wrun/wrun-draft-legend-note.util.d.ts +11 -3
  148. package/dist/utility/wrun/wrun-draft-legend-note.util.js +26 -4
  149. package/dist/utility/wrun/wrun-draft-overlay.util.d.ts +6 -1
  150. package/dist/utility/wrun/wrun-draft-overlay.util.js +23 -3
  151. package/dist/utility/wrun/wrun-frames.d.ts +27 -6
  152. package/dist/utility/wrun/wrun-frames.js +78 -15
  153. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +2 -2
  154. package/dist/utility/wrun/wrun-hosted-wire-caps.js +7 -0
  155. package/dist/utility/wrun/wrun-hosted-wire.util.d.ts +7 -1
  156. package/dist/utility/wrun/wrun-hosted-wire.util.js +12 -2
  157. package/dist/utility/wrun/wrun-hud-looks.util.d.ts +51 -21
  158. package/dist/utility/wrun/wrun-hud-looks.util.js +74 -28
  159. package/dist/utility/wrun/wrun-latest-snapshot.d.ts +11 -0
  160. package/dist/utility/wrun/wrun-lifecycle-runtime.util.d.ts +8 -6
  161. package/dist/utility/wrun/wrun-lifecycle-runtime.util.js +8 -6
  162. package/dist/utility/wrun/wrun-lifecycle.contract.d.ts +4 -2
  163. package/dist/utility/wrun/wrun-live-intake.util.d.ts +19 -9
  164. package/dist/utility/wrun/wrun-live-intake.util.js +213 -45
  165. package/dist/utility/wrun/wrun-live-tick.util.d.ts +4 -0
  166. package/dist/utility/wrun/wrun-live-tick.util.js +246 -49
  167. package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.d.ts +53 -0
  168. package/dist/utility/wrun/wrun-market-size-contract-carry.leaf.js +162 -0
  169. package/dist/utility/wrun/wrun-market-size-defaults.leaf.d.ts +205 -48
  170. package/dist/utility/wrun/wrun-market-size-defaults.leaf.js +277 -34
  171. package/dist/utility/wrun/wrun-market-size-defaults.util.d.ts +51 -7
  172. package/dist/utility/wrun/wrun-market-size-defaults.util.js +340 -56
  173. package/dist/utility/wrun/wrun-opra-lane.util.d.ts +17 -4
  174. package/dist/utility/wrun/wrun-opra-lane.util.js +6 -4
  175. package/dist/utility/wrun/wrun-option-prints.util.d.ts +41 -2
  176. package/dist/utility/wrun/wrun-option-prints.util.js +80 -13
  177. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.d.ts +31 -0
  178. package/dist/utility/wrun/wrun-option-strike-flow-forecast.util.js +119 -0
  179. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.d.ts +26 -6
  180. package/dist/utility/wrun/wrun-option-strike-flow-lane.util.js +50 -11
  181. package/dist/utility/wrun/wrun-option-strike-flow.util.d.ts +109 -19
  182. package/dist/utility/wrun/wrun-option-strike-flow.util.js +222 -61
  183. package/dist/utility/wrun/wrun-option-views.util.d.ts +96 -18
  184. package/dist/utility/wrun/wrun-option-views.util.js +246 -51
  185. package/dist/utility/wrun/wrun-options-stop.util.d.ts +2 -1
  186. package/dist/utility/wrun/wrun-options-stop.util.js +3 -2
  187. package/dist/utility/wrun/wrun-output-style.util.d.ts +6 -2
  188. package/dist/utility/wrun/wrun-output-style.util.js +20 -2
  189. package/dist/utility/wrun/wrun-overlay-drivers.util.d.ts +20 -0
  190. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.d.ts +31 -14
  191. package/dist/utility/wrun/wrun-overlay-lifecycle.lazy.js +22 -0
  192. package/dist/utility/wrun/wrun-overlay-lifecycle.util.d.ts +10 -1
  193. package/dist/utility/wrun/wrun-overlay-lifecycle.util.js +52 -4
  194. package/dist/utility/wrun/wrun-overlay-recovery.util.d.ts +7 -0
  195. package/dist/utility/wrun/wrun-overlay-recovery.util.js +25 -1
  196. package/dist/utility/wrun/wrun-overlay-result.util.d.ts +7 -1
  197. package/dist/utility/wrun/wrun-overlay-result.util.js +2 -0
  198. package/dist/utility/wrun/wrun-overlay-run.util.d.ts +134 -37
  199. package/dist/utility/wrun/wrun-overlay-run.util.js +1118 -254
  200. package/dist/utility/wrun/wrun-pack-widths.leaf.d.ts +4 -4
  201. package/dist/utility/wrun/wrun-pack-widths.leaf.js +4 -4
  202. package/dist/utility/wrun/wrun-pack.util.d.ts +7 -3
  203. package/dist/utility/wrun/wrun-pack.util.js +20 -9
  204. package/dist/utility/wrun/wrun-pane-format.util.d.ts +2 -1
  205. package/dist/utility/wrun/wrun-pane-format.util.js +7 -3
  206. package/dist/utility/wrun/wrun-panel-mount.util.d.ts +9 -0
  207. package/dist/utility/wrun/wrun-panel-mount.util.js +63 -13
  208. package/dist/utility/wrun/wrun-panel-style.util.d.ts +37 -24
  209. package/dist/utility/wrun/wrun-panel-style.util.js +100 -29
  210. package/dist/utility/wrun/wrun-param-map.util.d.ts +15 -11
  211. package/dist/utility/wrun/wrun-param-map.util.js +13 -5
  212. package/dist/utility/wrun/wrun-param-values.util.d.ts +21 -3
  213. package/dist/utility/wrun/wrun-param-values.util.js +6 -0
  214. package/dist/utility/wrun/wrun-pin-spelling.util.js +12 -11
  215. package/dist/utility/wrun/wrun-prefix-lanes.util.js +2 -2
  216. package/dist/utility/wrun/wrun-refusal-surface.util.d.ts +50 -0
  217. package/dist/utility/wrun/wrun-refusal-surface.util.js +68 -0
  218. package/dist/utility/wrun/wrun-refusal.util.js +10 -1
  219. package/dist/utility/wrun/wrun-refused-latest.util.d.ts +10 -0
  220. package/dist/utility/wrun/wrun-refused-latest.util.js +12 -0
  221. package/dist/utility/wrun/wrun-row-source.d.ts +11 -0
  222. package/dist/utility/wrun/wrun-run-interval.util.d.ts +4 -2
  223. package/dist/utility/wrun/wrun-run-interval.util.js +9 -6
  224. package/dist/utility/wrun/wrun-script-inputs.util.d.ts +52 -1
  225. package/dist/utility/wrun/wrun-script-inputs.util.js +112 -4
  226. package/dist/utility/wrun/wrun-setting-words.util.d.ts +7 -3
  227. package/dist/utility/wrun/wrun-setting-words.util.js +13 -5
  228. package/dist/utility/wrun/wrun-socket-row-source.d.ts +27 -2
  229. package/dist/utility/wrun/wrun-socket-row-source.js +113 -8
  230. package/dist/utility/wrun/wrun-source-rows.util.d.ts +9 -1
  231. package/dist/utility/wrun/wrun-source-rows.util.js +108 -43
  232. package/dist/utility/wrun/wrun-style-words.util.js +6 -4
  233. package/dist/utility/wrun/wrun-table-chrome.util.d.ts +3 -2
  234. package/dist/utility/wrun/wrun-table-chrome.util.js +19 -11
  235. package/dist/utility/wrun/wrun-tape-per-order.util.d.ts +2 -0
  236. package/dist/utility/wrun/wrun-tape-per-order.util.js +26 -0
  237. package/dist/utility/wrun/wrun-tape-source.util.d.ts +126 -50
  238. package/dist/utility/wrun/wrun-tape-source.util.js +193 -68
  239. package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +7 -5
  240. package/dist/utility/wrun/wrun-volume-profile-lane.util.js +8 -6
  241. package/dist/utils/replay/replay-buffer-math.d.ts +53 -2
  242. package/dist/utils/replay/replay-buffer-math.js +227 -20
  243. package/dist/workers/utils/volume-profile.worker.util.d.ts +4 -1
  244. package/dist/workers/utils/volume-profile.worker.util.js +5 -2
  245. package/dist/workers/wrun/wrun-abi-host.js +3 -2
  246. package/package.json +5 -5
@@ -6,13 +6,21 @@
6
6
  * place (src/services/market-data.service.ts). Nothing here names a venue. Worker-safe: types, one error class and pure
7
7
  * helpers.
8
8
  *
9
- * Differences from CME are deliberate: one product per venue, no depth, a professional declaration refused (recorded,
10
- * never re-priced), an EXPLICIT agreement acceptance (never inferred from a grant or a subscription), and pay first:
11
- * the declaration and the agreement bind real-time ACCESS, not the payment, so checkout needs neither and the server
12
- * serves real-time only once the account is both paid and qualified (delayed otherwise).
9
+ * OPRA's card is the base shape: one product per venue, no depth, a professional declaration refused (recorded, never
10
+ * re-priced), an EXPLICIT agreement acceptance (never inferred from a grant or a subscription), and pay first: the
11
+ * declaration and the agreement bind real-time ACCESS, not the payment, so checkout needs neither and the server
12
+ * serves real-time only once the account is both paid and qualified (delayed otherwise). A card may ask for CME's
13
+ * policies instead (docs/features/market-data/plane.md, "CME on the plane"): several products in level order, a
14
+ * checkout and an in-place plan change that name the product (`level`), professionals sold, the declaration first,
15
+ * and the data terms recorded as the registration the venue's wall makes; the wire additions below are optional, and a
16
+ * server that sends none of them reads exactly as before.
17
+ *
18
+ * The agreement itself is the server's (contracts K1 and K2 of the OPRA compliance round): `GET <basePath>/agreement`
19
+ * serves the complete populated text with its version and hash, the acceptance names that version and both hashes,
20
+ * and an acceptance counts only for the version the server presents now, never for a version a build carries.
13
21
  */
14
22
  import type { CancelFeedback } from '../interfaces/cancel-reason.interface.js';
15
- import type { MarketDataBillingInterval, MarketDataClassification, MarketDataVenue } from './venue.js';
23
+ import type { MarketDataBillingInterval, MarketDataClassification, MarketDataProduct, MarketDataVenue } from './venue.js';
16
24
  /**
17
25
  * POST <basePath>/attestation request body (201 for both classifications). The server derives the classification from
18
26
  * `answers` and refuses a body whose `classification` disagrees, so the client sends the one
@@ -38,8 +46,9 @@ export interface MarketDataAttestationRecordDto {
38
46
  attestedAt: string;
39
47
  formVersion: string;
40
48
  /**
41
- * ISO end of the declaration's validity (a year after it was made). Additive: a server that names none leaves the
42
- * record without a client-side expiry, and the checkout's refusal stays the authority.
49
+ * ISO end of the declaration's validity (a year after it was made). A non-professional record that names none reads
50
+ * lapsed (`isMarketDataAttestationLive`): status is reconfirmed every 12 months, and a record with no end can never be
51
+ * shown to be inside its year.
43
52
  */
44
53
  expiresAt?: string;
45
54
  }
@@ -47,27 +56,71 @@ export interface MarketDataAttestationRecordDto {
47
56
  export interface GetMarketDataAttestationResponseDto {
48
57
  attestation: MarketDataAttestationRecordDto | null;
49
58
  }
50
- /** POST <basePath>/checkout request body. */
59
+ /** POST <basePath>/checkout request body of a one-product venue (OPRA): the interval of its one plan. */
51
60
  export interface MarketDataCheckoutDto {
52
61
  interval: MarketDataBillingInterval;
53
62
  locale?: string;
54
63
  }
64
+ /**
65
+ * POST <basePath>/checkout request body of a venue that sells several products (CME, contract KB2): the product
66
+ * picked, by its key (`level`), and the Stripe page's language. The service adds the desktop app's `client` marker on
67
+ * the wire (the checkout then returns to the desktop return page).
68
+ */
69
+ export interface MarketDataProductCheckoutDto {
70
+ level: string;
71
+ /** The Stripe page's language; the service sends the app's when absent. */
72
+ locale?: string;
73
+ }
74
+ /** POST <basePath>/subscription/change-plan request body (contract KB2): the product the subscription moves to. */
75
+ export interface MarketDataChangePlanDto {
76
+ level: string;
77
+ }
55
78
  /**
56
79
  * POST <basePath>/checkout -> 200: a Stripe redirect, or a refusal. 'professional_unavailable' is terminal (the UI
57
- * shows "not available"). Pay first, the server no longer answers 'attestation_required' or 'agreement_required'; they
58
- * stay in the union and are handled defensively (the flow routes into that step).
80
+ * shows "not available"). 'review_held' and 'review_withdrawn': a review of the account's answers only an operator
81
+ * resolves, or one that withdrew real-time (the review card says which). Pay first, the server no longer answers
82
+ * 'attestation_required' or 'agreement_required'; they stay in the union and are handled defensively (the flow routes
83
+ * into that step).
59
84
  */
60
85
  export type MarketDataCheckoutResponseDto = {
61
86
  url: string;
62
87
  } | {
63
88
  refused: MarketDataPurchaseRefusalCode;
64
89
  };
65
- export type MarketDataPurchaseRefusalCode = 'professional_unavailable' | 'agreement_required' | 'attestation_required';
90
+ export type MarketDataPurchaseRefusalCode = 'professional_unavailable' | 'review_held' | 'review_withdrawn' | 'agreement_required' | 'attestation_required';
91
+ /**
92
+ * GET <basePath>/subscription `review`: the review of the account's answers that bears on real-time (Exhibit A Q19.2),
93
+ * or null. 'pending': an employer or occupation that suggests a financial firm or a registered person asks the
94
+ * subscriber to confirm the declaration before `deadline` (POST <basePath>/attestation/review/confirm); real-time runs
95
+ * until the deadline passes. 'held': an operator reviews the declaration and real-time waits. 'withdrawn': an operator
96
+ * withdrew real-time (`resolvedAt`); the way back is a new declaration.
97
+ */
98
+ export interface MarketDataReviewDto {
99
+ state: 'pending' | 'held' | 'withdrawn';
100
+ reason: string;
101
+ openedAt: string;
102
+ deadline: string | null;
103
+ resolvedAt: string | null;
104
+ }
105
+ /**
106
+ * POST <basePath>/attestation/review/confirm (no body) -> 200: the pending review confirmed; 409
107
+ * `<VENUE>_REVIEW_NOT_OPEN` when no review is pending (none, or one only an operator resolves).
108
+ */
109
+ export interface MarketDataReviewConfirmDto {
110
+ confirmed: boolean;
111
+ confirmedAt: string;
112
+ }
66
113
  /**
67
114
  * Why the server set a subscription to end at its period end on its own: 'unqualified', the account is paid but has
68
115
  * not completed the subscriber questions and the agreement.
69
116
  */
70
117
  export type MarketDataSubscriptionHold = 'unqualified';
118
+ /** A downgrade the subscription carries to its period end (contract KB2): the product it moves to, and when. */
119
+ export interface MarketDataPendingDowngrade {
120
+ level: string;
121
+ /** ISO timestamp the downgrade takes effect (the current period end). */
122
+ at: string;
123
+ }
71
124
  /** Subscription as served by GET <basePath>/subscription. */
72
125
  export interface MarketDataSubscriptionDto {
73
126
  interval: MarketDataBillingInterval;
@@ -82,9 +135,17 @@ export interface MarketDataSubscriptionDto {
82
135
  * subscriber's own cancel or none: completing the status never reverses that cancel.
83
136
  */
84
137
  hold: MarketDataSubscriptionHold | null;
138
+ /** The product held now (its key; still the higher one while a downgrade is pending). A multi-product venue only. */
139
+ level?: string;
140
+ /** A downgrade scheduled for the period end, or null. A multi-product venue only. */
141
+ pendingDowngrade?: MarketDataPendingDowngrade | null;
142
+ /** The Stripe payment method the subscription charges, or null. Additive (a multi-product venue's DTO names it). */
143
+ paymentMethodId?: string | null;
85
144
  }
86
145
  export interface GetMarketDataSubscriptionResponseDto {
87
146
  subscription: MarketDataSubscriptionDto | null;
147
+ /** Additive (a server from before the review answers none). */
148
+ review?: MarketDataReviewDto | null;
88
149
  }
89
150
  /**
90
151
  * GET <basePath>/data-terms -> 200; POST <basePath>/data-terms -> 201. Acceptance is an explicit record of the
@@ -100,65 +161,164 @@ export interface MarketDataAttestationWithdrawal {
100
161
  subscriptionCancelled: boolean;
101
162
  refunded: boolean;
102
163
  }
103
- /** POST <basePath>/attestation -> 201 body; `withdrawal` only for a professional declaration. */
164
+ /**
165
+ * POST <basePath>/attestation -> 201 body; `withdrawal` only for a professional declaration a refusing venue recorded.
166
+ * `offer` (a venue that sells professionals, plan 12.6 A11): the declaration changed a live subscriber from
167
+ * non-professional to professional, so the server cancelled the subscription at once (no refund of the period) and
168
+ * offers the product the new classification may hold, by its key (CME: `depth_pro`).
169
+ */
104
170
  export interface SubmitMarketDataAttestationResponseDto {
105
171
  attestationId: number;
106
172
  withdrawal?: MarketDataAttestationWithdrawal;
173
+ offer?: string;
107
174
  }
108
- /** The submit's answer in the domain: the record id, and what a professional declaration withdrew (else null). */
175
+ /**
176
+ * The submit's answer in the domain: the record id, what a professional declaration withdrew (else null), and the
177
+ * product a classification change offers (present only when the server named one).
178
+ */
109
179
  export interface MarketDataAttestationSubmitResult {
110
180
  attestationId: number;
111
181
  withdrawal: MarketDataAttestationWithdrawal | null;
182
+ offer?: string;
183
+ }
184
+ /**
185
+ * A postal address as a declaration records it inside its answers (`questionnaire.postalAddress.answerId`; CME's
186
+ * `postal_address`): the optional lines left out, never sent empty, and the ISO 3166-1 alpha-2 country.
187
+ */
188
+ export interface MarketDataPostalAddress {
189
+ line1: string;
190
+ line2?: string;
191
+ city: string;
192
+ region?: string;
193
+ postalCode: string;
194
+ country: string;
195
+ }
196
+ /**
197
+ * GET <basePath>/agreement -> 200 (signed in, any tier), contract K1: the subscriber agreement the server presents now.
198
+ * `text` is the complete populated agreement followed by its addendum (UTF-8, LF line ends, one blank line between
199
+ * paragraphs, no hard wraps): exactly the characters `sha256` hashes. `addendumOffset` is the character index where the
200
+ * addendum starts. The server is the single source of the text (the frontend never bundles a copy), and its `version`
201
+ * is the version an acceptance must name to count, never the version a build carries.
202
+ */
203
+ export interface MarketDataAgreementDocumentDto {
204
+ version: string;
205
+ sha256: string;
206
+ addendumVersion: string;
207
+ vendor: {
208
+ name: string;
209
+ address: string;
210
+ email: string;
211
+ };
212
+ text: string;
213
+ addendumOffset: number;
214
+ }
215
+ /**
216
+ * GET <basePath>/agreement/accepted -> 200, contract K1: the exact agreement text the caller accepted and how; 404
217
+ * `<VENUE>_AGREEMENT_NOT_ACCEPTED` when the caller accepted none.
218
+ */
219
+ export interface MarketDataAcceptedAgreementDto {
220
+ version: string;
221
+ sha256: string;
222
+ addendumVersion: string;
223
+ text: string;
224
+ acceptedAt: string;
225
+ manner: string;
226
+ attestationId: number | string | null;
227
+ }
228
+ /** The four addendum statements a subscriber confirms at assent: Addendum 1(a), 1(b), 1(c) and 2. */
229
+ export interface MarketDataAgreementRepresentations {
230
+ /** 1(a): a natural person or a qualifying trust, not an entity. */
231
+ naturalPerson: boolean;
232
+ /** 1(b): the data is used only for personal investment activities. */
233
+ personalUseOnly: boolean;
234
+ /** 1(c): not a Professional. */
235
+ notProfessional: boolean;
236
+ /** 2: notifies the vendor promptly when a statement of Section 1 stops being true. */
237
+ notifyOnChange: boolean;
112
238
  }
113
- /** POST <basePath>/data-terms request body: the agreement version the subscriber was shown and accepted. */
239
+ /** The manner of assent an acceptance records: the click on the agreement's own "I AGREE" button. */
240
+ export declare const MARKET_DATA_ASSENT_MANNER = "click:i-agree";
241
+ /**
242
+ * POST <basePath>/data-terms request body, contract K2: the agreement the subscriber was shown (the K1 version, hash and
243
+ * addendum version, and the browser's own SHA-256 of the exact text it displayed), the manner of assent and the four
244
+ * addendum representations. The server records it only when all four are true, both versions are the ones it serves
245
+ * and both hashes equal its hash (else 409 `<VENUE>_AGREEMENT_STALE`), the account holds a current non-professional
246
+ * declaration (else 409 `<VENUE>_ATTESTATION_REQUIRED`) and its email is verified (else 403 `<VENUE>_EMAIL_UNVERIFIED`).
247
+ */
114
248
  export interface AcceptMarketDataDataTermsDto {
115
249
  agreementVersion: string;
250
+ agreementSha256: string;
251
+ addendumVersion: string;
252
+ manner: typeof MARKET_DATA_ASSENT_MANNER;
253
+ displayedTextSha256: string;
254
+ representations: MarketDataAgreementRepresentations;
116
255
  }
117
256
  /** POST <basePath>/subscription/cancel and DELETE <basePath>/subscription/cancel -> 200 body. */
118
257
  export interface MarketDataCancelResponseDto {
119
258
  message?: string;
120
259
  }
121
- /**
122
- * POST <basePath>/register (no body) -> 201 body, sent only once the gate confirmed the free registration (delayed
123
- * data); 403 for a suspended account. Idempotent on the server.
124
- */
125
- export interface MarketDataRegisterResponseDto {
126
- registered: boolean;
127
- }
128
- /** The register's answer in the domain: it resolves only on the confirmed registration (anything else throws). */
129
- export interface MarketDataRegistration {
130
- registered: true;
131
- }
132
260
  export type MarketDataAttestation = MarketDataAttestationRecordDto;
133
261
  export type MarketDataSubscription = MarketDataSubscriptionDto;
262
+ /** The review of the account's answers, as served (`MarketDataReviewDto`). */
263
+ export type MarketDataReview = MarketDataReviewDto;
264
+ /** GET <basePath>/subscription in the domain: the subscription and the review its answer carries, each or none. */
265
+ export interface MarketDataSubscriptionAnswer {
266
+ subscription: MarketDataSubscription | null;
267
+ review: MarketDataReview | null;
268
+ }
134
269
  /** The explicit agreement record: accepted, for which version, and when. */
135
270
  export interface MarketDataAgreement {
136
271
  accepted: boolean;
137
272
  agreementVersion: string;
138
273
  acceptedAt: string | null;
139
274
  }
275
+ /** The agreement the server presents now (K1), as the store holds it: the text, its version, hash and addendum. */
276
+ export type MarketDataAgreementDocument = MarketDataAgreementDocumentDto;
277
+ /** The exact agreement the account accepted (K1), as the subscription page and the notice reopen it. */
278
+ export type MarketDataAcceptedAgreement = MarketDataAcceptedAgreementDto;
140
279
  /** A form's answers, keyed by the venue's question ids. A missing answer never qualifies. */
141
280
  export type MarketDataQualificationAnswers = Partial<Record<string, boolean>>;
142
281
  /** Every question of the venue's questionnaire answered with its qualifying answer. */
143
282
  export declare function isMarketDataNonProfessional(venue: MarketDataVenue, answers: MarketDataQualificationAnswers): boolean;
283
+ /** Whether a record's form version reads as the venue's current form (`acceptedFormVersions`, else the one version). */
284
+ export declare function isMarketDataFormVersionAccepted(venue: MarketDataVenue, formVersion: string): boolean;
285
+ /** The venue's products, in level order (a product without a level keeps its place in the card's list). */
286
+ export declare function marketDataProductsByLevel(venue: MarketDataVenue): readonly MarketDataProduct[];
287
+ /** The products a classification may hold, in level order (the plan picker's offer). */
288
+ export declare function marketDataProductsFor(venue: MarketDataVenue, classification: MarketDataClassification): readonly MarketDataProduct[];
289
+ /** The venue's product with this key (`level` on the wire), or null. */
290
+ export declare function marketDataProductByKey(venue: MarketDataVenue, key: string | null | undefined): MarketDataProduct | null;
291
+ /** The venue records its agreement as the registration its own wall makes (never a purchase step). */
292
+ export declare function isMarketDataRegistrationAgreement(venue: Pick<MarketDataVenue, 'agreement'>): boolean;
144
293
  /**
145
294
  * A declaration on the venue's current form (a new question set means a new declaration) whose validity has not ended
146
295
  * at `now`, either classification. The client owns expiry: `now` is the caller's clock (the store's last evaluation),
147
- * never an implied Date.now(). A record without `expiresAt` never expires here; one whose `expiresAt` does not parse
148
- * reads expired (ask again rather than trust it).
296
+ * never an implied Date.now(). A record without `expiresAt` reads lapsed, as does one whose `expiresAt` does not parse
297
+ * (ask again rather than trust it): status is reconfirmed every 12 months (Exhibit A Q19.3), and a record that names
298
+ * no end can never be shown to be inside its year.
149
299
  */
150
300
  export declare function isMarketDataAttestationLive(venue: MarketDataVenue, attestation: MarketDataAttestation | null | undefined, now: number): boolean;
151
301
  /** A non-professional declaration on the current form, still valid at `now`: the account may buy real-time. */
152
302
  export declare function isMarketDataAttestationCurrent(venue: MarketDataVenue, attestation: MarketDataAttestation | null | undefined, now: number): boolean;
153
- /** A professional declaration on the current form, still valid at `now`: real-time is not sold to the account. */
303
+ /**
304
+ * A professional declaration on the current form, still valid at `now`: real-time is not sold to the account. A
305
+ * professional record that names no expiry still refuses: a missing field never lifts a refusal (only a new
306
+ * non-professional declaration the server records does).
307
+ */
154
308
  export declare function isMarketDataProfessionalDeclaration(venue: MarketDataVenue, attestation: MarketDataAttestation | null | undefined, now: number): boolean;
155
309
  /**
156
- * The expiry (ISO, as served) a still-current non-professional declaration must be renewed by, once `now` is inside
157
- * the venue's renewal window before it; null otherwise (no expiry named, further off, or already lapsed).
310
+ * The expiry (ISO, as served) a declaration the venue sells to must be renewed by, once `now` is inside the venue's
311
+ * renewal window before it; null otherwise (no expiry named, further off, or already lapsed). A venue that refuses
312
+ * professionals sells to a non-professional declaration only; one that sells them (CME) to either classification, so
313
+ * a professional subscriber is told before its declaration lapses too.
158
314
  */
159
315
  export declare function marketDataAttestationRenewBy(venue: MarketDataVenue, attestation: MarketDataAttestation | null | undefined, now: number): string | null;
160
- /** An acceptance counts only for the agreement version the venue presents, never for an older text. */
161
- export declare function isMarketDataAgreementCurrent(venue: MarketDataVenue, agreement: MarketDataAgreement | null | undefined): boolean;
316
+ /**
317
+ * An acceptance counts only for the agreement version the SERVER presents now (`current`: its K1 answer), never for an
318
+ * older text and never for the version a build carries (the venue card's `agreement.version` is the contract export's
319
+ * pin, not the current text). With no current agreement read, nothing counts.
320
+ */
321
+ export declare function isMarketDataAgreementCurrent(current: Pick<MarketDataAgreementDocument, 'version'> | null | undefined, agreement: MarketDataAgreement | null | undefined): boolean;
162
322
  /**
163
323
  * Normalized checkout outcome. 'redirect' = leave for Stripe. 'refused' = the server declined (or the store answered a
164
324
  * professional account itself); 'professional_unavailable' ends the purchase until a later non-professional declaration,
@@ -175,11 +335,15 @@ export type MarketDataCheckoutResult = {
175
335
  kind: 'busy';
176
336
  };
177
337
  /**
178
- * Transport-free failure surface for the billing calls. Unlike CME, a 403 is NOT an attestation gate (refusals ride the
179
- * 200 checkout body), so it never routes back into the declaration: it is a route the account may not use (the
180
- * register's suspended account included). 'invoice_owed' is the tagged 409 while Stripe still collects an invoice.
338
+ * Transport-free failure surface for the billing calls. Unlike CME, a bare 403 is NOT an attestation gate (refusals ride
339
+ * the 200 checkout body), so it never routes back into the declaration: it is a route the account may not use.
340
+ * 'invoice_owed' is the tagged 409 while Stripe still collects an invoice. The agreement's typed refusals (K2), read
341
+ * from the body's tag: 'agreement_stale' (409 `<VENUE>_AGREEMENT_STALE`: the text changed, read it again),
342
+ * 'attestation_required' (409 `<VENUE>_ATTESTATION_REQUIRED`: declare first) and 'email_unverified' (403
343
+ * `<VENUE>_EMAIL_UNVERIFIED`: verify the email first); the review's 'review_not_open' (409 `<VENUE>_REVIEW_NOT_OPEN`:
344
+ * no pending review to confirm, read the records again).
181
345
  */
182
- export type MarketDataBillingErrorKind = 'conflict' | 'invoice_owed' | 'unauthorized' | 'forbidden' | 'network' | 'aborted' | 'server';
346
+ export type MarketDataBillingErrorKind = 'conflict' | 'invoice_owed' | 'agreement_stale' | 'attestation_required' | 'email_unverified' | 'review_not_open' | 'unauthorized' | 'forbidden' | 'network' | 'aborted' | 'server';
183
347
  export declare class MarketDataBillingError extends Error {
184
348
  readonly kind: MarketDataBillingErrorKind;
185
349
  readonly status: number | null;
@@ -197,14 +361,33 @@ export declare class MarketDataBillingError extends Error {
197
361
  export interface MarketDataBillingRepository {
198
362
  getAttestation(signal?: AbortSignal): Promise<MarketDataAttestation | null>;
199
363
  submitAttestation(body: MarketDataAttestationDto, signal?: AbortSignal): Promise<MarketDataAttestationSubmitResult>;
200
- getSubscription(signal?: AbortSignal): Promise<MarketDataSubscription | null>;
364
+ /** GET <basePath>/subscription: the subscription and the review of the account's answers, each or none. */
365
+ getSubscription(signal?: AbortSignal): Promise<MarketDataSubscriptionAnswer>;
366
+ /** POST <basePath>/attestation/review/confirm: the subscriber confirms a pending review (a typed refusal throws). */
367
+ confirmReview(signal?: AbortSignal): Promise<{
368
+ confirmedAt: string;
369
+ }>;
201
370
  /** Never resolves 'busy' (that is the store's own answer); a refusal resolves, a failure throws. */
202
- checkout(body: MarketDataCheckoutDto, options: {
371
+ checkout(body: MarketDataCheckoutDto | MarketDataProductCheckoutDto, options: {
203
372
  idempotencyId: string;
204
373
  signal?: AbortSignal;
205
374
  }): Promise<Exclude<MarketDataCheckoutResult, {
206
375
  kind: 'busy';
207
376
  }>>;
377
+ /**
378
+ * POST <basePath>/subscription/change-plan (a venue with `planChanges`): the subscription moved to the product, as
379
+ * the server answers it (an upgrade now, a downgrade pending to the period end); a typed refusal throws. A venue with
380
+ * one plan has no such route, so its repository may leave this out.
381
+ */
382
+ changePlan?(body: MarketDataChangePlanDto, options: {
383
+ idempotencyId: string;
384
+ signal?: AbortSignal;
385
+ }): Promise<MarketDataSubscription | null>;
386
+ /** POST <basePath>/subscription/restore (a venue with `planChanges`): a pending downgrade or period-end cancel cleared. */
387
+ restorePlan?(options: {
388
+ idempotencyId: string;
389
+ signal?: AbortSignal;
390
+ }): Promise<MarketDataSubscription | null>;
208
391
  /** Cancels at period end (one classification is sold, so there is no immediate switch-cancel), with the reason. */
209
392
  cancelSubscription(signal?: AbortSignal, feedback?: CancelFeedback): Promise<{
210
393
  message: string | null;
@@ -213,8 +396,10 @@ export interface MarketDataBillingRepository {
213
396
  message: string | null;
214
397
  }>;
215
398
  getDataTerms(signal?: AbortSignal): Promise<MarketDataAgreement>;
216
- acceptDataTerms(agreementVersion: string, signal?: AbortSignal): Promise<MarketDataAgreement>;
217
- /** The free registration: resolves only on the confirmed 201 `{ registered: true }`; a failure throws (a 403 is
218
- * 'forbidden'). */
219
- register(signal?: AbortSignal): Promise<MarketDataRegistration>;
399
+ /** GET <basePath>/agreement (K1): the agreement the server presents now; a body that is not one throws 'server'. */
400
+ getAgreement(signal?: AbortSignal): Promise<MarketDataAgreementDocument>;
401
+ /** GET <basePath>/agreement/accepted (K1): the exact text the account accepted, or null on the 404 (none). */
402
+ getAcceptedAgreement(signal?: AbortSignal): Promise<MarketDataAcceptedAgreement | null>;
403
+ /** POST <basePath>/data-terms (K2): the assent; a typed refusal throws its kind. */
404
+ acceptDataTerms(body: AcceptMarketDataDataTermsDto, signal?: AbortSignal): Promise<MarketDataAgreement>;
220
405
  }
@@ -1,19 +1,48 @@
1
+ /** The manner of assent an acceptance records: the click on the agreement's own "I AGREE" button. */
2
+ export const MARKET_DATA_ASSENT_MANNER = 'click:i-agree';
1
3
  const DAY_MS = 86_400_000;
2
4
  /** Every question of the venue's questionnaire answered with its qualifying answer. */
3
5
  export function isMarketDataNonProfessional(venue, answers) {
4
6
  return venue.questionnaire.questions.every((question) => answers[question.id] === question.qualifying);
5
7
  }
8
+ /** Whether a record's form version reads as the venue's current form (`acceptedFormVersions`, else the one version). */
9
+ export function isMarketDataFormVersionAccepted(venue, formVersion) {
10
+ const accepted = venue.questionnaire.acceptedFormVersions ?? [venue.questionnaire.formVersion];
11
+ return accepted.includes(formVersion);
12
+ }
13
+ /** The venue's products, in level order (a product without a level keeps its place in the card's list). */
14
+ export function marketDataProductsByLevel(venue) {
15
+ return venue.products
16
+ .map((product, index) => ({ product, index }))
17
+ .sort((a, b) => (a.product.level ?? a.index) - (b.product.level ?? b.index) || a.index - b.index)
18
+ .map(({ product }) => product);
19
+ }
20
+ /** The products a classification may hold, in level order (the plan picker's offer). */
21
+ export function marketDataProductsFor(venue, classification) {
22
+ return marketDataProductsByLevel(venue).filter((product) => product.classifications.includes(classification));
23
+ }
24
+ /** The venue's product with this key (`level` on the wire), or null. */
25
+ export function marketDataProductByKey(venue, key) {
26
+ if (!key)
27
+ return null;
28
+ return venue.products.find((product) => product.key === key) ?? null;
29
+ }
30
+ /** The venue records its agreement as the registration its own wall makes (never a purchase step). */
31
+ export function isMarketDataRegistrationAgreement(venue) {
32
+ return venue.agreement.recordedAs === 'registration';
33
+ }
6
34
  /**
7
35
  * A declaration on the venue's current form (a new question set means a new declaration) whose validity has not ended
8
36
  * at `now`, either classification. The client owns expiry: `now` is the caller's clock (the store's last evaluation),
9
- * never an implied Date.now(). A record without `expiresAt` never expires here; one whose `expiresAt` does not parse
10
- * reads expired (ask again rather than trust it).
37
+ * never an implied Date.now(). A record without `expiresAt` reads lapsed, as does one whose `expiresAt` does not parse
38
+ * (ask again rather than trust it): status is reconfirmed every 12 months (Exhibit A Q19.3), and a record that names
39
+ * no end can never be shown to be inside its year.
11
40
  */
12
41
  export function isMarketDataAttestationLive(venue, attestation, now) {
13
- if (!attestation || attestation.formVersion !== venue.questionnaire.formVersion)
42
+ if (!attestation || !isMarketDataFormVersionAccepted(venue, attestation.formVersion))
14
43
  return false;
15
44
  if (attestation.expiresAt === undefined)
16
- return true;
45
+ return false;
17
46
  const ends = Date.parse(attestation.expiresAt);
18
47
  return Number.isFinite(ends) && now < ends;
19
48
  }
@@ -21,24 +50,43 @@ export function isMarketDataAttestationLive(venue, attestation, now) {
21
50
  export function isMarketDataAttestationCurrent(venue, attestation, now) {
22
51
  return attestation?.classification === 'non_professional' && isMarketDataAttestationLive(venue, attestation, now);
23
52
  }
24
- /** A professional declaration on the current form, still valid at `now`: real-time is not sold to the account. */
53
+ /**
54
+ * A professional declaration on the current form, still valid at `now`: real-time is not sold to the account. A
55
+ * professional record that names no expiry still refuses: a missing field never lifts a refusal (only a new
56
+ * non-professional declaration the server records does).
57
+ */
25
58
  export function isMarketDataProfessionalDeclaration(venue, attestation, now) {
26
- return attestation?.classification === 'professional' && isMarketDataAttestationLive(venue, attestation, now);
59
+ if (attestation?.classification !== 'professional')
60
+ return false;
61
+ if (attestation.expiresAt === undefined)
62
+ return isMarketDataFormVersionAccepted(venue, attestation.formVersion);
63
+ return isMarketDataAttestationLive(venue, attestation, now);
27
64
  }
28
65
  /**
29
- * The expiry (ISO, as served) a still-current non-professional declaration must be renewed by, once `now` is inside
30
- * the venue's renewal window before it; null otherwise (no expiry named, further off, or already lapsed).
66
+ * The expiry (ISO, as served) a declaration the venue sells to must be renewed by, once `now` is inside the venue's
67
+ * renewal window before it; null otherwise (no expiry named, further off, or already lapsed). A venue that refuses
68
+ * professionals sells to a non-professional declaration only; one that sells them (CME) to either classification, so
69
+ * a professional subscriber is told before its declaration lapses too.
31
70
  */
32
71
  export function marketDataAttestationRenewBy(venue, attestation, now) {
33
- if (!isMarketDataAttestationCurrent(venue, attestation, now) || attestation?.expiresAt === undefined)
72
+ const sold = venue.professionalPolicy === 'sell'
73
+ ? isMarketDataAttestationLive(venue, attestation, now)
74
+ : isMarketDataAttestationCurrent(venue, attestation, now);
75
+ if (!sold || attestation?.expiresAt === undefined)
34
76
  return null;
35
77
  return Date.parse(attestation.expiresAt) - now <= venue.questionnaire.renewalWindowDays * DAY_MS
36
78
  ? attestation.expiresAt
37
79
  : null;
38
80
  }
39
- /** An acceptance counts only for the agreement version the venue presents, never for an older text. */
40
- export function isMarketDataAgreementCurrent(venue, agreement) {
41
- return agreement?.accepted === true && agreement.agreementVersion === venue.agreement.version;
81
+ /**
82
+ * An acceptance counts only for the agreement version the SERVER presents now (`current`: its K1 answer), never for an
83
+ * older text and never for the version a build carries (the venue card's `agreement.version` is the contract export's
84
+ * pin, not the current text). With no current agreement read, nothing counts.
85
+ */
86
+ export function isMarketDataAgreementCurrent(current, agreement) {
87
+ if (!current?.version)
88
+ return false;
89
+ return agreement?.accepted === true && agreement.agreementVersion === current.version;
42
90
  }
43
91
  export class MarketDataBillingError extends Error {
44
92
  kind;