@orangecharts/wrun-chart-host 0.2.0 → 0.3.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 (320) hide show
  1. package/README.md +14 -6
  2. package/dist/constants/common.constants.d.ts +15 -0
  3. package/dist/constants/common.constants.js +23 -0
  4. package/dist/constants/data-source.constants.d.ts +1 -0
  5. package/dist/constants/data-source.constants.js +1 -0
  6. package/dist/constants/economic.constants.d.ts +39 -0
  7. package/dist/constants/economic.constants.js +77 -0
  8. package/dist/constants/etf-covered-coins.constants.d.ts +1 -0
  9. package/dist/constants/etf-covered-coins.constants.js +9 -0
  10. package/dist/constants/feature-flags.constants.d.ts +60 -0
  11. package/dist/constants/feature-flags.constants.js +308 -0
  12. package/dist/constants/feature-limits.constants.d.ts +134 -0
  13. package/dist/constants/feature-limits.constants.js +155 -0
  14. package/dist/constants/marketCapabilities.constants.d.ts +87 -0
  15. package/dist/constants/marketCapabilities.constants.js +213 -0
  16. package/dist/constants/option-venues.constants.d.ts +100 -0
  17. package/dist/constants/option-venues.constants.js +167 -0
  18. package/dist/constants/overlay-data.constants.d.ts +53 -0
  19. package/dist/constants/overlay-data.constants.js +80 -0
  20. package/dist/constants/pane-grid.constants.d.ts +15 -0
  21. package/dist/constants/pane-grid.constants.js +17 -0
  22. package/dist/constants/venue-presets.constants.d.ts +10 -0
  23. package/dist/constants/venue-presets.constants.js +22 -0
  24. package/dist/enums/chart.enum.d.ts +68 -0
  25. package/dist/enums/chart.enum.js +70 -0
  26. package/dist/helpers/data.helpers.d.ts +2 -0
  27. package/dist/helpers/data.helpers.js +14 -0
  28. package/dist/host-env.d.ts +161 -5
  29. package/dist/host-ports.types.d.ts +446 -0
  30. package/dist/host-ports.types.js +1 -0
  31. package/dist/index.d.ts +128 -0
  32. package/dist/index.js +128 -0
  33. package/dist/indicators/controls/technical-script/technical-script-input-rendering.d.ts +86 -0
  34. package/dist/indicators/controls/technical-script/technical-script-input-rendering.js +179 -0
  35. package/dist/interfaces/asset-venue.interface.d.ts +91 -0
  36. package/dist/interfaces/asset-venue.interface.js +1 -0
  37. package/dist/interfaces/cancel-reason.interface.d.ts +24 -0
  38. package/dist/interfaces/cancel-reason.interface.js +2 -0
  39. package/dist/interfaces/catalog-display.interface.d.ts +3 -0
  40. package/dist/interfaces/catalog-display.interface.js +1 -0
  41. package/dist/interfaces/cme-realtime.interface.d.ts +251 -0
  42. package/dist/interfaces/cme-realtime.interface.js +46 -0
  43. package/dist/interfaces/feed.interface.d.ts +80 -0
  44. package/dist/interfaces/feed.interface.js +7 -0
  45. package/dist/interfaces/market-kind.interface.d.ts +8 -0
  46. package/dist/interfaces/market-kind.interface.js +1 -0
  47. package/dist/interfaces/opra-realtime.interface.d.ts +224 -0
  48. package/dist/interfaces/opra-realtime.interface.js +105 -0
  49. package/dist/interfaces/option-instrument.interface.d.ts +32 -0
  50. package/dist/interfaces/option-instrument.interface.js +1 -0
  51. package/dist/interfaces/options-chain-scope.interface.d.ts +29 -0
  52. package/dist/interfaces/options-chain-scope.interface.js +7 -0
  53. package/dist/interfaces/prediction-market.interface.d.ts +88 -0
  54. package/dist/interfaces/prediction-market.interface.js +8 -0
  55. package/dist/interfaces/wrun-runtime.interface.d.ts +5 -0
  56. package/dist/kscript-data/controls/live-trades-merge.util.d.ts +185 -0
  57. package/dist/kscript-data/controls/live-trades-merge.util.js +357 -0
  58. package/dist/settings-templates/frvp-fields.d.ts +27 -0
  59. package/dist/settings-templates/frvp-fields.js +108 -0
  60. package/dist/settings-templates/index.d.ts +119 -0
  61. package/dist/settings-templates/index.js +442 -0
  62. package/dist/settings-templates/indicator-fields.d.ts +56 -0
  63. package/dist/settings-templates/indicator-fields.js +793 -0
  64. package/dist/settings-templates/tool-rules.d.ts +59 -0
  65. package/dist/settings-templates/tool-rules.js +49 -0
  66. package/dist/settings-templates/tool-tables.generated.d.ts +2 -0
  67. package/dist/settings-templates/tool-tables.generated.js +1668 -0
  68. package/dist/utility/blk-market.util.d.ts +5 -0
  69. package/dist/utility/blk-market.util.js +12 -0
  70. package/dist/utility/chart/chart-load-phase.util.d.ts +32 -0
  71. package/dist/utility/chart/chart-load-phase.util.js +78 -0
  72. package/dist/utility/chart/cme-cache-context.util.d.ts +108 -0
  73. package/dist/utility/chart/cme-cache-context.util.js +166 -0
  74. package/dist/utility/chart/cme-session-bucket.util.d.ts +82 -0
  75. package/dist/utility/chart/cme-session-bucket.util.js +343 -0
  76. package/dist/utility/chart/cme-trade-calendar.util.d.ts +26 -0
  77. package/dist/utility/chart/cme-trade-calendar.util.js +147 -0
  78. package/dist/utility/chart/continuous-contracts.util.d.ts +138 -0
  79. package/dist/utility/chart/continuous-contracts.util.js +374 -0
  80. package/dist/utility/chart/feed-interval.util.d.ts +119 -0
  81. package/dist/utility/chart/feed-interval.util.js +321 -0
  82. package/dist/utility/chart/fetch-dedupe-policy.util.d.ts +110 -0
  83. package/dist/utility/chart/fetch-dedupe-policy.util.js +407 -0
  84. package/dist/utility/chart/footprint-band.util.d.ts +76 -0
  85. package/dist/utility/chart/footprint-band.util.js +205 -0
  86. package/dist/utility/chart/footprint-cell-identity.util.d.ts +82 -0
  87. package/dist/utility/chart/footprint-cell-identity.util.js +346 -0
  88. package/dist/utility/chart/formula-calendar.util.d.ts +27 -0
  89. package/dist/utility/chart/formula-calendar.util.js +59 -0
  90. package/dist/utility/chart/history-wall.util.d.ts +67 -0
  91. package/dist/utility/chart/history-wall.util.js +87 -0
  92. package/dist/utility/chart/index-mode.util.d.ts +66 -0
  93. package/dist/utility/chart/index-mode.util.js +360 -0
  94. package/dist/utility/chart/indicator-coverage-planner.util.d.ts +217 -0
  95. package/dist/utility/chart/indicator-coverage-planner.util.js +443 -0
  96. package/dist/utility/chart/indicator-coverage-state.util.d.ts +33 -0
  97. package/dist/utility/chart/indicator-coverage-state.util.js +110 -0
  98. package/dist/utility/chart/indicator-gap-detector.util.d.ts +127 -0
  99. package/dist/utility/chart/indicator-gap-detector.util.js +260 -0
  100. package/dist/utility/chart/indicator-gap-repair.util.d.ts +88 -0
  101. package/dist/utility/chart/indicator-gap-repair.util.js +177 -0
  102. package/dist/utility/chart/indicator-inflight-registry.util.d.ts +26 -0
  103. package/dist/utility/chart/indicator-inflight-registry.util.js +254 -0
  104. package/dist/utility/chart/interval-registry.util.d.ts +23 -0
  105. package/dist/utility/chart/interval-registry.util.js +83 -0
  106. package/dist/utility/chart/kscript-main-grid-stages.util.d.ts +21 -0
  107. package/dist/utility/chart/kscript-main-grid-stages.util.js +332 -0
  108. package/dist/utility/chart/legacy-exchange.leaf.d.ts +11 -0
  109. package/dist/utility/chart/legacy-exchange.leaf.js +43 -0
  110. package/dist/utility/chart/live-bucket.util.d.ts +66 -0
  111. package/dist/utility/chart/live-bucket.util.js +165 -0
  112. package/dist/utility/chart/market-session-schedule.util.d.ts +91 -0
  113. package/dist/utility/chart/market-session-schedule.util.js +337 -0
  114. package/dist/utility/chart/marketKind.util.d.ts +181 -0
  115. package/dist/utility/chart/marketKind.util.js +371 -0
  116. package/dist/utility/chart/opra-read-access.leaf.d.ts +26 -0
  117. package/dist/utility/chart/opra-read-access.leaf.js +25 -0
  118. package/dist/utility/chart/prediction-identity.util.d.ts +159 -0
  119. package/dist/utility/chart/prediction-identity.util.js +236 -0
  120. package/dist/utility/chart/rth-session.util.d.ts +352 -0
  121. package/dist/utility/chart/rth-session.util.js +926 -0
  122. package/dist/utility/chart/titan-constants.pin.d.ts +43 -0
  123. package/dist/utility/chart/titan-constants.pin.js +50 -0
  124. package/dist/utility/chart/us-equities-session.util.d.ts +127 -0
  125. package/dist/utility/chart/us-equities-session.util.js +251 -0
  126. package/dist/utility/chart/wrun-bar-session-facts.util.d.ts +100 -0
  127. package/dist/utility/chart/wrun-bar-session-facts.util.js +354 -0
  128. package/dist/utility/chart/wrun-wire-ref.util.d.ts +23 -0
  129. package/dist/utility/chart/wrun-wire-ref.util.js +16 -0
  130. package/dist/utility/common/safe-math-eval.d.ts +18 -0
  131. package/dist/utility/common/safe-math-eval.js +160 -0
  132. package/dist/utility/common/time.util.d.ts +134 -0
  133. package/dist/utility/common/time.util.js +428 -0
  134. package/dist/utility/common/transformations.util.d.ts +126 -0
  135. package/dist/utility/common/transformations.util.js +711 -0
  136. package/dist/utility/common/visible-timeout.util.d.ts +17 -0
  137. package/dist/utility/common/visible-timeout.util.js +75 -0
  138. package/dist/utility/exchange-normalization.util.d.ts +8 -0
  139. package/dist/utility/exchange-normalization.util.js +32 -0
  140. package/dist/utility/intl-locale.util.d.ts +2 -0
  141. package/dist/utility/intl-locale.util.js +28 -0
  142. package/dist/utility/number-format.util.d.ts +14 -1
  143. package/dist/utility/number-format.util.js +50 -19
  144. package/dist/utility/options/option-symbol.util.d.ts +28 -0
  145. package/dist/utility/options/option-symbol.util.js +176 -0
  146. package/dist/utility/options/option-trade-units.util.d.ts +190 -0
  147. package/dist/utility/options/option-trade-units.util.js +283 -0
  148. package/dist/utility/options/option-venue.util.d.ts +75 -0
  149. package/dist/utility/options/option-venue.util.js +85 -0
  150. package/dist/utility/pool-symbol.leaf.d.ts +34 -0
  151. package/dist/utility/pool-symbol.leaf.js +95 -0
  152. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.d.ts +109 -0
  153. package/dist/utility/scriptEditor/wrun-runtime-diagnostics.leaf.js +302 -0
  154. package/dist/utility/symbol-selection/contract-expiry.util.d.ts +39 -0
  155. package/dist/utility/symbol-selection/contract-expiry.util.js +111 -0
  156. package/dist/utility/v2/gate-plane.util.d.ts +58 -0
  157. package/dist/utility/v2/gate-plane.util.js +99 -0
  158. package/dist/utility/v2/gate-session-latch.util.d.ts +22 -0
  159. package/dist/utility/v2/gate-session-latch.util.js +34 -0
  160. package/dist/utility/watchlist/import/tradingview-symbols.leaf.d.ts +76 -0
  161. package/dist/utility/watchlist/import/tradingview-symbols.leaf.js +221 -0
  162. package/dist/utility/wrun/sources/host-grid-landing.d.ts +15 -0
  163. package/dist/utility/wrun/sources/host-grid-landing.js +26 -0
  164. package/dist/utility/wrun/sources/lanes/bitfinex_funding.d.ts +27 -0
  165. package/dist/utility/wrun/sources/lanes/bitfinex_funding.js +85 -0
  166. package/dist/utility/wrun/sources/lanes/economic.d.ts +27 -0
  167. package/dist/utility/wrun/sources/lanes/economic.js +79 -0
  168. package/dist/utility/wrun/sources/lanes/etf_holdings.d.ts +35 -0
  169. package/dist/utility/wrun/sources/lanes/etf_holdings.js +165 -0
  170. package/dist/utility/wrun/sources/lanes/etf_premium.d.ts +19 -0
  171. package/dist/utility/wrun/sources/lanes/etf_premium.js +114 -0
  172. package/dist/utility/wrun/sources/lanes/ethena_positions.d.ts +30 -0
  173. package/dist/utility/wrun/sources/lanes/ethena_positions.js +51 -0
  174. package/dist/utility/wrun/sources/lanes/index.d.ts +2 -0
  175. package/dist/utility/wrun/sources/lanes/index.js +32 -0
  176. package/dist/utility/wrun/sources/lanes/long_short_ratio.d.ts +17 -0
  177. package/dist/utility/wrun/sources/lanes/long_short_ratio.js +47 -0
  178. package/dist/utility/wrun/sources/lanes/option_daily.d.ts +30 -0
  179. package/dist/utility/wrun/sources/lanes/option_daily.js +53 -0
  180. package/dist/utility/wrun/sources/lanes/option_stats_10m.d.ts +23 -0
  181. package/dist/utility/wrun/sources/lanes/option_stats_10m.js +20 -0
  182. package/dist/utility/wrun/sources/lanes/options_flow.d.ts +50 -0
  183. package/dist/utility/wrun/sources/lanes/options_flow.js +155 -0
  184. package/dist/utility/wrun/sources/lanes/options_oi.d.ts +29 -0
  185. package/dist/utility/wrun/sources/lanes/options_oi.js +59 -0
  186. package/dist/utility/wrun/sources/lanes/options_volume.d.ts +38 -0
  187. package/dist/utility/wrun/sources/lanes/options_volume.js +63 -0
  188. package/dist/utility/wrun/sources/lanes/series.d.ts +67 -0
  189. package/dist/utility/wrun/sources/lanes/series.js +321 -0
  190. package/dist/utility/wrun/sources/lanes/token_supply.d.ts +30 -0
  191. package/dist/utility/wrun/sources/lanes/token_supply.js +145 -0
  192. package/dist/utility/wrun/sources/lanes/treasury_balance.d.ts +25 -0
  193. package/dist/utility/wrun/sources/lanes/treasury_balance.js +47 -0
  194. package/dist/utility/wrun/sources/lanes/volatility_index.d.ts +21 -0
  195. package/dist/utility/wrun/sources/lanes/volatility_index.js +11 -0
  196. package/dist/utility/wrun/sources/opra-option-lanes.util.d.ts +196 -0
  197. package/dist/utility/wrun/sources/opra-option-lanes.util.js +446 -0
  198. package/dist/utility/wrun/sources/registry.d.ts +21 -0
  199. package/dist/utility/wrun/sources/registry.js +207 -0
  200. package/dist/utility/wrun/sources/row-lane-registry.d.ts +28 -0
  201. package/dist/utility/wrun/sources/row-lane-registry.js +230 -0
  202. package/dist/utility/wrun/sources/row-lanes/index.d.ts +2 -0
  203. package/dist/utility/wrun/sources/row-lanes/index.js +12 -0
  204. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.d.ts +2 -0
  205. package/dist/utility/wrun/sources/row-lanes/option_contract_flow.js +38 -0
  206. package/dist/utility/wrun/sources/row-lanes/option_contract_state.d.ts +6 -0
  207. package/dist/utility/wrun/sources/row-lanes/option_contract_state.js +70 -0
  208. package/dist/utility/wrun/sources/row-lanes/option_prints.d.ts +4 -0
  209. package/dist/utility/wrun/sources/row-lanes/option_prints.js +191 -0
  210. package/dist/utility/wrun/sources/row-lanes/option_strikes.d.ts +13 -0
  211. package/dist/utility/wrun/sources/row-lanes/option_strikes.js +137 -0
  212. package/dist/utility/wrun/sources/row-lanes/option_surface.d.ts +38 -0
  213. package/dist/utility/wrun/sources/row-lanes/option_surface.js +150 -0
  214. package/dist/utility/wrun/sources/wrun-poll-lane.types.d.ts +275 -0
  215. package/dist/utility/wrun/sources/wrun-poll-lane.types.js +26 -0
  216. package/dist/utility/wrun/sources/wrun-poll-lanes.util.d.ts +224 -0
  217. package/dist/utility/wrun/sources/wrun-poll-lanes.util.js +394 -0
  218. package/dist/utility/wrun/sources/wrun-row-lane.types.d.ts +283 -0
  219. package/dist/utility/wrun/sources/wrun-row-lane.types.js +16 -0
  220. package/dist/utility/wrun/sources/wrun-row-lanes.util.d.ts +205 -0
  221. package/dist/utility/wrun/sources/wrun-row-lanes.util.js +469 -0
  222. package/dist/utility/wrun/wrun-browser-sources.leaf.d.ts +28 -0
  223. package/dist/utility/wrun/wrun-browser-sources.leaf.js +66 -0
  224. package/dist/utility/wrun/wrun-cloud-record.util.d.ts +65 -0
  225. package/dist/utility/wrun/wrun-cloud-record.util.js +121 -0
  226. package/dist/utility/wrun/wrun-daily-lane.util.d.ts +95 -0
  227. package/dist/utility/wrun/wrun-daily-lane.util.js +297 -0
  228. package/dist/utility/wrun/wrun-deadline.util.d.ts +52 -0
  229. package/dist/utility/wrun/wrun-deadline.util.js +82 -0
  230. package/dist/utility/wrun/wrun-etf-flow-lane.util.d.ts +94 -0
  231. package/dist/utility/wrun/wrun-etf-flow-lane.util.js +224 -0
  232. package/dist/utility/wrun/wrun-etf-funds.util.d.ts +82 -0
  233. package/dist/utility/wrun/wrun-etf-funds.util.js +242 -0
  234. package/dist/utility/wrun/wrun-frames.d.ts +20 -1
  235. package/dist/utility/wrun/wrun-frames.js +103 -49
  236. package/dist/utility/wrun/wrun-hosted-wire-caps.d.ts +2 -2
  237. package/dist/utility/wrun/wrun-hosted-wire-caps.js +27 -0
  238. package/dist/utility/wrun/wrun-lane-refusal.leaf.d.ts +22 -0
  239. package/dist/utility/wrun/wrun-lane-refusal.leaf.js +32 -0
  240. package/dist/utility/wrun/wrun-lane-warmup.util.d.ts +18 -0
  241. package/dist/utility/wrun/wrun-lane-warmup.util.js +112 -0
  242. package/dist/utility/wrun/wrun-leg-close.util.d.ts +57 -0
  243. package/dist/utility/wrun/wrun-leg-close.util.js +187 -0
  244. package/dist/utility/wrun/wrun-leg-fetch.util.d.ts +144 -0
  245. package/dist/utility/wrun/wrun-leg-fetch.util.js +212 -0
  246. package/dist/utility/wrun/wrun-leg-stream-classes.d.ts +73 -0
  247. package/dist/utility/wrun/wrun-leg-stream-classes.js +86 -0
  248. package/dist/utility/wrun/wrun-levels-child.util.d.ts +101 -6
  249. package/dist/utility/wrun/wrun-levels-child.util.js +335 -157
  250. package/dist/utility/wrun/wrun-memory-clamp.util.d.ts +33 -0
  251. package/dist/utility/wrun/wrun-memory-clamp.util.js +146 -0
  252. package/dist/utility/wrun/wrun-odds-template-market.util.d.ts +51 -0
  253. package/dist/utility/wrun/wrun-odds-template-market.util.js +251 -0
  254. package/dist/utility/wrun/wrun-opra-flow.leaf.d.ts +65 -0
  255. package/dist/utility/wrun/wrun-opra-flow.leaf.js +94 -0
  256. package/dist/utility/wrun/wrun-opra-lane.util.d.ts +47 -0
  257. package/dist/utility/wrun/wrun-opra-lane.util.js +58 -0
  258. package/dist/utility/wrun/wrun-opra-stats.leaf.d.ts +30 -0
  259. package/dist/utility/wrun/wrun-opra-stats.leaf.js +96 -0
  260. package/dist/utility/wrun/wrun-opra-underlying.util.d.ts +12 -0
  261. package/dist/utility/wrun/wrun-opra-underlying.util.js +1 -0
  262. package/dist/utility/wrun/wrun-option-contract-flow.util.d.ts +142 -0
  263. package/dist/utility/wrun/wrun-option-contract-flow.util.js +451 -0
  264. package/dist/utility/wrun/wrun-option-knobs.util.d.ts +43 -0
  265. package/dist/utility/wrun/wrun-option-knobs.util.js +81 -0
  266. package/dist/utility/wrun/wrun-option-prints.util.d.ts +144 -0
  267. package/dist/utility/wrun/wrun-option-prints.util.js +356 -0
  268. package/dist/utility/wrun/wrun-option-summary-lane.util.d.ts +102 -0
  269. package/dist/utility/wrun/wrun-option-summary-lane.util.js +143 -0
  270. package/dist/utility/wrun/wrun-options-chain.util.d.ts +308 -0
  271. package/dist/utility/wrun/wrun-options-chain.util.js +502 -0
  272. package/dist/utility/wrun/wrun-overlay-identity.util.d.ts +9 -4
  273. package/dist/utility/wrun/wrun-overlay-identity.util.js +16 -6
  274. package/dist/utility/wrun/wrun-param-map.util.d.ts +298 -0
  275. package/dist/utility/wrun/wrun-param-map.util.js +581 -0
  276. package/dist/utility/wrun/wrun-pin-spelling.util.d.ts +149 -0
  277. package/dist/utility/wrun/wrun-pin-spelling.util.js +523 -0
  278. package/dist/utility/wrun/wrun-pin-venues.util.d.ts +116 -0
  279. package/dist/utility/wrun/wrun-pin-venues.util.js +320 -0
  280. package/dist/utility/wrun/wrun-pinned-interval.util.d.ts +20 -0
  281. package/dist/utility/wrun/wrun-pinned-interval.util.js +47 -0
  282. package/dist/utility/wrun/wrun-present-bits.util.d.ts +37 -0
  283. package/dist/utility/wrun/wrun-present-bits.util.js +73 -0
  284. package/dist/utility/wrun/wrun-protocol-pending.util.d.ts +33 -0
  285. package/dist/utility/wrun/wrun-protocol-pending.util.js +57 -0
  286. package/dist/utility/wrun/wrun-refusal.util.d.ts +41 -1
  287. package/dist/utility/wrun/wrun-refusal.util.js +69 -2
  288. package/dist/utility/wrun/wrun-registry-errors.util.d.ts +1 -14
  289. package/dist/utility/wrun/wrun-registry-errors.util.js +0 -16
  290. package/dist/utility/wrun/wrun-row-source.d.ts +158 -0
  291. package/dist/utility/wrun/wrun-row-source.js +75 -0
  292. package/dist/utility/wrun/wrun-run-health.util.d.ts +155 -0
  293. package/dist/utility/wrun/wrun-run-health.util.js +273 -0
  294. package/dist/utility/wrun/wrun-socket-row-source.d.ts +439 -0
  295. package/dist/utility/wrun/wrun-socket-row-source.js +1689 -0
  296. package/dist/utility/wrun/wrun-socket-session-losses.util.d.ts +18 -0
  297. package/dist/utility/wrun/wrun-socket-session-losses.util.js +25 -0
  298. package/dist/utility/wrun/wrun-source-rows.util.d.ts +911 -0
  299. package/dist/utility/wrun/wrun-source-rows.util.js +2597 -0
  300. package/dist/utility/wrun/wrun-tape-source.util.d.ts +82 -0
  301. package/dist/utility/wrun/wrun-tape-source.util.js +151 -0
  302. package/dist/utility/wrun/wrun-tier-grid.util.d.ts +137 -0
  303. package/dist/utility/wrun/wrun-tier-grid.util.js +279 -0
  304. package/dist/utility/wrun/wrun-trades-lane.util.d.ts +52 -0
  305. package/dist/utility/wrun/wrun-trades-lane.util.js +58 -0
  306. package/dist/utility/wrun/wrun-volume-profile-lane.util.d.ts +41 -0
  307. package/dist/utility/wrun/wrun-volume-profile-lane.util.js +66 -0
  308. package/dist/utility/wrun-display-name.util.d.ts +33 -0
  309. package/dist/utility/wrun-display-name.util.js +64 -0
  310. package/dist/workers/constants/kscript-transport-codes.d.ts +15 -0
  311. package/dist/workers/constants/kscript-transport-codes.js +15 -0
  312. package/dist/workers/constants/socket-slots.d.ts +574 -0
  313. package/dist/workers/constants/socket-slots.js +539 -0
  314. package/dist/workers/utils/number.worker.util.d.ts +5 -0
  315. package/dist/workers/utils/number.worker.util.js +10 -0
  316. package/dist/workers/utils/time.worker.util.d.ts +12 -0
  317. package/dist/workers/utils/time.worker.util.js +24 -0
  318. package/dist/workers/utils/volume-profile.worker.util.d.ts +200 -0
  319. package/dist/workers/utils/volume-profile.worker.util.js +631 -0
  320. package/package.json +10 -4
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Option trade units: the ONE place an option trade's price and amount become a coin size, a premium, a USD value
3
+ * and a per-coin price (OPTIONS-PORT recon P3b, section 5.2). The venue conventions ride two registry fields, so no
4
+ * venue rule lives in code:
5
+ * - `contractMultiplier` (cm): coin per one unit of the stored trade amount (Binance the listing `unit`,
6
+ * 1, 100 or 1000; OKX ctVal x ctMult; 1 on Deribit, Bybit, Bullish and Derive). It scales sizes only,
7
+ * never a price. Absent means unknown: a stored size cannot be read, never 1.
8
+ * - `pointValue` (pv): USD per 1.0 of the stored price per unit of stored amount (1 on USD books, ctVal x
9
+ * ctMult on OKX USD-margined books). Absent on a coin book, whose premium is in coin.
10
+ *
11
+ * Every source of an option trade and the units it carries. Each reader names its source; the two rule sets
12
+ * below are never mixed:
13
+ * 1. Gateway raw TRADE rows (a TRADES read with no interval and no normalize transform: the K_TRADES history and
14
+ * its TRADE_LARGE table, the market replay's K_TRADES trade windows): STORED units, the venue's own amount and
15
+ * price (tsdb-gateway trade.go). Read them with the stored-row rules (`resolveStoredOptionTrade`, the
16
+ * `storedOptionTrade*` helpers); amount x cm applies to these rows only.
17
+ * 2. Live-feed prints on the COIN arm (TRADE, TRADE_AGG, LIQUIDATION and VOLUME_PROFILE_AGG subscribed with no quote,
18
+ * COIN or DEFAULT: the tape and its worker classifier, the tape bubbles, the K_TRADES live fold, the wrun tape
19
+ * intake, Volume Delta's live merge): COIN on arrival. Live-feed already applied amount x cm (a NULL cm read as 1)
20
+ * and never divides an option amount by its price. Read them with the live-print rules
21
+ * (`resolveLiveOptionPrint`, the `liveOptionPrint*` helpers): the delivered amount IS the coin size, never
22
+ * multiplied by cm again, and the premium divides the multiplier live-feed applied back out.
23
+ * 3. Live-feed prints on the USD arm (quote USD: the Trades and Liquidations widget): the USD premium (price x
24
+ * stored amount x pv) on a USD book, 0 on a coin book ("cannot denominate"). Already USD: read as served
25
+ * (`servedTradeVolume`, cme-units.util), never through these rules.
26
+ * 4. Gateway served aggregates (TRADE_AGG candles and their sided split, OHLCV, volume profile, footprint, TPO,
27
+ * liquidations): coin as amount x cm and USD as price x amount x pv, 0 on a coin book. Read as served
28
+ * (`servedTradeVolume`), never through a multiplier again.
29
+ * 5. OPTION_SUMMARY (OI, bid and ask sizes): coin already (the collector converts them); never through cm.
30
+ * CME Group and OPRA option rows keep their contract-priced chain and never reach these rules
31
+ * (`isPlainOptionContract`).
32
+ *
33
+ * Stored-row rules, per row:
34
+ * 1. Coin size = amount x cm.
35
+ * 2. Premium in the book's own currency: price x amount x pv on a USD book (USD), price x amount x cm on
36
+ * a coin book (coin).
37
+ * 3. USD premium = price x amount x pv; on a coin book price x amount x cm x the index at the print when
38
+ * the reader has one, else null ("cannot denominate").
39
+ * 4. USD notional = coin size x the index at the print.
40
+ * 5. Per-coin price (the OPTION_SUMMARY basis): price x pv / cm on a USD book, the price itself (in coin)
41
+ * on a coin book.
42
+ * Live-print rules, per print (`coin` the delivered amount, cm' the multiplier live-feed applied: cm, or 1 when
43
+ * the registry has none):
44
+ * 1. Coin size = coin.
45
+ * 2. Premium in the book's own currency: price x coin x pv / cm' on a USD book (price x contracts x pv), price x
46
+ * coin on a coin book.
47
+ * 3. USD premium: that premium on a USD book; on a coin book price x coin x the index at the print, else null.
48
+ * 4. USD notional = coin x the index at the print.
49
+ * 5. Per-coin price: as for a stored row (live-feed leaves the price as stored).
50
+ * The registry `inverse` flag is never read: on an option row it names the settlement currency, not a
51
+ * USD-sized contract, so an option amount is never divided by its price.
52
+ *
53
+ * A book is a coin-premium book only by its ANSWERED units (`optionPremiumIsCoin`: a multiplier and no point value).
54
+ * Units with neither field (`OPTION_TRADE_UNITS_UNKNOWN` while a read runs, or a record the registry never filled)
55
+ * are no answer, so no reader takes a book as coin-premium before its units say so.
56
+ * The read is fresh (`{ fresh: true }`): a cached registry record can predate the point value fill, and kept for the
57
+ * session it would read a USD book as a coin book until reload.
58
+ *
59
+ * Worked rows (pinned by tests/utility/options/option-trade-units.util.spec.ts):
60
+ * - Binance DOGE, 3 contracts at 2.65 USDT each, cm 1000, pv 1, index 0.0792: size 3,000 DOGE, premium
61
+ * 7.95 USD, notional 237.60 USD, per-coin price 0.00265. Stored row: amount 3; live print: 3,000.
62
+ * - OKX coin book BTC-USD-261106-83000-C, 1 contract at 0.0285 BTC, cm 0.01, pv absent, index 82,065.7:
63
+ * size 0.01 BTC, premium 0.000285 BTC (23.39 USD), notional 820.66 USD, per-coin price 0.0285 BTC. Stored row:
64
+ * amount 1; live print: 0.01.
65
+ *
66
+ * Pure and worker-safe.
67
+ */
68
+ /** One option book's registry units; null is unknown (cm) or a coin-premium book (pv). */
69
+ export interface OptionTradeUnits {
70
+ contractMultiplier: number | null;
71
+ pointValue: number | null;
72
+ }
73
+ /** The currency an option book's premium is quoted in: USD on a point-valued book, the coin otherwise. */
74
+ export type OptionPremiumCurrency = 'USD' | 'COIN';
75
+ /** Every value one option print resolves to; null where the units cannot say. */
76
+ export interface OptionTradeValues {
77
+ /** Coin units traded. */
78
+ coinSize: number | null;
79
+ /** The premium in the book's own currency (`premiumCurrency`). */
80
+ premium: number | null;
81
+ premiumCurrency: OptionPremiumCurrency;
82
+ /** The premium in USD; null on a coin book without an index. */
83
+ usdPremium: number | null;
84
+ /** Coin size x the index; null without an index. */
85
+ usdNotional: number | null;
86
+ /** Price per coin of underlying: USD on a USD book, coin on a coin book. */
87
+ perCoinPrice: number | null;
88
+ }
89
+ /**
90
+ * The trade units of one registry row (`SymbolMetadataRecord`, a raw `registryMetadatas` row), or null for a
91
+ * row that is not an option: only option rows carry these meanings. An absent, zero, negative or non-finite
92
+ * field reads null.
93
+ */
94
+ export declare function optionTradeUnitsOf(row: {
95
+ category?: unknown;
96
+ contractMultiplier?: unknown;
97
+ pointValue?: unknown;
98
+ } | null | undefined): OptionTradeUnits | null;
99
+ /**
100
+ * True for an option contract on a plain (crypto) option venue: an option venue row of the venue table whose
101
+ * symbol grammar parses the raw symbol. The cheap gate before a registry read, so a perpetual or a spot
102
+ * market on the same venue never costs one.
103
+ */
104
+ export declare function isPlainOptionContract(exchange: string, symbol: string): boolean;
105
+ /** How the units are read: always fresh, past the metadata service's memory and disk copies. */
106
+ export interface OptionRegistryReadOptions {
107
+ fresh: true;
108
+ }
109
+ /**
110
+ * The caller's registry read: the metadata service's `getSymbolMetadata` on the main thread. It is handed
111
+ * `{ fresh: true }` and must pass it on (a wrapper that drops it can answer a record from before the registry fill).
112
+ */
113
+ export type OptionRegistryRead = (exchange: string, symbol: string, options: OptionRegistryReadOptions) => Promise<Record<string, unknown> | null>;
114
+ /**
115
+ * The units of an option contract whose read has not answered yet: no multiplier and no point value, so nothing
116
+ * sizes or prices a raw print in USD until it answers (a print shows no USD rather than a guess). It is no answer:
117
+ * it never makes a book coin-premium (`optionPremiumIsCoin`), so a served aggregate reads as served and a Unit
118
+ * setting keeps its USD default meanwhile.
119
+ */
120
+ export declare const OPTION_TRADE_UNITS_UNKNOWN: OptionTradeUnits;
121
+ /**
122
+ * The registry trade units of one option contract on a plain option venue, read once through `read` (a fresh
123
+ * registry read: `{ fresh: true }`) and kept for the realm; null without a read for any other market, and null for a
124
+ * record that is not an option or a failed read.
125
+ */
126
+ export declare function loadOptionTradeUnits(market: {
127
+ exchange: string;
128
+ symbol: string;
129
+ }, read: OptionRegistryRead): Promise<OptionTradeUnits | null>;
130
+ /**
131
+ * A market's trade units for a synchronous reader: the answered units, null for a market that is not an option
132
+ * contract on a plain venue, and `OPTION_TRADE_UNITS_UNKNOWN` while its read has not answered (the read is
133
+ * started here; `loadOptionTradeUnits` answers it).
134
+ */
135
+ export declare function optionTradeUnitsNow(market: {
136
+ exchange: string;
137
+ symbol: string;
138
+ }, read: OptionRegistryRead): OptionTradeUnits | null;
139
+ /**
140
+ * A market's answered trade units for a reader that may not start a read (a store-free module): the answered units,
141
+ * null for a market that is not an option contract on a plain venue, `OPTION_TRADE_UNITS_UNKNOWN` until a read
142
+ * started elsewhere (`loadOptionTradeUnits`, `optionTradeUnitsNow`) answers.
143
+ */
144
+ export declare function peekOptionTradeUnits(market: {
145
+ exchange: string;
146
+ symbol: string;
147
+ }): OptionTradeUnits | null;
148
+ /** Forgets every answered read (specs only). */
149
+ export declare function __resetOptionTradeUnitsForTests(): void;
150
+ /**
151
+ * True for a book whose premium is in coin: answered units with a multiplier and no point value (every option book's
152
+ * multiplier is written explicitly, so one without a multiplier is no answer). Its USD reads need the index at the
153
+ * print. Units with neither field (`OPTION_TRADE_UNITS_UNKNOWN` while a read runs) are no answer and read false.
154
+ */
155
+ export declare function optionPremiumIsCoin(units: OptionTradeUnits | null | undefined): boolean;
156
+ /** Price per coin of underlying, to compare with OPTION_SUMMARY: price x pv / cm on a USD book, price on a coin book. */
157
+ export declare function optionTradePerCoinPrice(price: number, units: OptionTradeUnits | null | undefined): number | null;
158
+ /** A stored row's coin units traded: amount x cm; null when the multiplier is unknown. */
159
+ export declare function storedOptionTradeCoinSize(amount: number, units: OptionTradeUnits | null | undefined): number | null;
160
+ /** A stored row's premium in the book's own currency (USD on a point-valued book, coin otherwise); null when unknown. */
161
+ export declare function storedOptionTradePremium(price: number, amount: number, units: OptionTradeUnits | null | undefined): number | null;
162
+ /** A stored row's premium in USD: on a coin book through the index at the print, else null ("cannot denominate"). */
163
+ export declare function storedOptionTradeUsdPremium(price: number, amount: number, units: OptionTradeUnits | null | undefined, indexPrice?: number): number | null;
164
+ /** A stored row's coin size x the index at the print; null without either. */
165
+ export declare function storedOptionTradeUsdNotional(amount: number, units: OptionTradeUnits | null | undefined, indexPrice?: number): number | null;
166
+ /** Every value one stored row resolves to, by the stored-row rules. */
167
+ export declare function resolveStoredOptionTrade(trade: {
168
+ price: number;
169
+ amount: number;
170
+ }, units: OptionTradeUnits | null | undefined, indexPrice?: number): OptionTradeValues;
171
+ /**
172
+ * A live print's premium in the book's own currency: price x coin x pv / cm' on a USD book (cm' the multiplier
173
+ * live-feed sized the print with, 1 when the registry has none), price x coin on a coin book; null while the units
174
+ * are unknown.
175
+ */
176
+ export declare function liveOptionPrintPremium(price: number, coin: number, units: OptionTradeUnits | null | undefined): number | null;
177
+ /** A live print's premium in USD: on a coin book through the index at the print, else null ("cannot denominate"). */
178
+ export declare function liveOptionPrintUsdPremium(price: number, coin: number, units: OptionTradeUnits | null | undefined, indexPrice?: number): number | null;
179
+ /**
180
+ * The USD of an amount live-feed delivered on its COIN arm, on any market: on an option contract (`units` its trade
181
+ * units, answered or `OPTION_TRADE_UNITS_UNKNOWN`) the premium by the live-print rule, null while the units are
182
+ * unknown and on a coin-premium book; on every other market (`units` null) price x amount, exactly as a live merge
183
+ * computes it today. The one conversion a live merge needs to show a coin-arm amount in USD.
184
+ */
185
+ export declare function liveAmountUsd(price: number, amount: number, units: OptionTradeUnits | null | undefined): number | null;
186
+ /** Every value one live print resolves to, by the live-print rules: its delivered amount is the coin size. */
187
+ export declare function resolveLiveOptionPrint(print: {
188
+ price: number;
189
+ coin: number;
190
+ }, units: OptionTradeUnits | null | undefined, indexPrice?: number): OptionTradeValues;
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Option trade units: the ONE place an option trade's price and amount become a coin size, a premium, a USD value
3
+ * and a per-coin price (OPTIONS-PORT recon P3b, section 5.2). The venue conventions ride two registry fields, so no
4
+ * venue rule lives in code:
5
+ * - `contractMultiplier` (cm): coin per one unit of the stored trade amount (Binance the listing `unit`,
6
+ * 1, 100 or 1000; OKX ctVal x ctMult; 1 on Deribit, Bybit, Bullish and Derive). It scales sizes only,
7
+ * never a price. Absent means unknown: a stored size cannot be read, never 1.
8
+ * - `pointValue` (pv): USD per 1.0 of the stored price per unit of stored amount (1 on USD books, ctVal x
9
+ * ctMult on OKX USD-margined books). Absent on a coin book, whose premium is in coin.
10
+ *
11
+ * Every source of an option trade and the units it carries. Each reader names its source; the two rule sets
12
+ * below are never mixed:
13
+ * 1. Gateway raw TRADE rows (a TRADES read with no interval and no normalize transform: the K_TRADES history and
14
+ * its TRADE_LARGE table, the market replay's K_TRADES trade windows): STORED units, the venue's own amount and
15
+ * price (tsdb-gateway trade.go). Read them with the stored-row rules (`resolveStoredOptionTrade`, the
16
+ * `storedOptionTrade*` helpers); amount x cm applies to these rows only.
17
+ * 2. Live-feed prints on the COIN arm (TRADE, TRADE_AGG, LIQUIDATION and VOLUME_PROFILE_AGG subscribed with no quote,
18
+ * COIN or DEFAULT: the tape and its worker classifier, the tape bubbles, the K_TRADES live fold, the wrun tape
19
+ * intake, Volume Delta's live merge): COIN on arrival. Live-feed already applied amount x cm (a NULL cm read as 1)
20
+ * and never divides an option amount by its price. Read them with the live-print rules
21
+ * (`resolveLiveOptionPrint`, the `liveOptionPrint*` helpers): the delivered amount IS the coin size, never
22
+ * multiplied by cm again, and the premium divides the multiplier live-feed applied back out.
23
+ * 3. Live-feed prints on the USD arm (quote USD: the Trades and Liquidations widget): the USD premium (price x
24
+ * stored amount x pv) on a USD book, 0 on a coin book ("cannot denominate"). Already USD: read as served
25
+ * (`servedTradeVolume`, cme-units.util), never through these rules.
26
+ * 4. Gateway served aggregates (TRADE_AGG candles and their sided split, OHLCV, volume profile, footprint, TPO,
27
+ * liquidations): coin as amount x cm and USD as price x amount x pv, 0 on a coin book. Read as served
28
+ * (`servedTradeVolume`), never through a multiplier again.
29
+ * 5. OPTION_SUMMARY (OI, bid and ask sizes): coin already (the collector converts them); never through cm.
30
+ * CME Group and OPRA option rows keep their contract-priced chain and never reach these rules
31
+ * (`isPlainOptionContract`).
32
+ *
33
+ * Stored-row rules, per row:
34
+ * 1. Coin size = amount x cm.
35
+ * 2. Premium in the book's own currency: price x amount x pv on a USD book (USD), price x amount x cm on
36
+ * a coin book (coin).
37
+ * 3. USD premium = price x amount x pv; on a coin book price x amount x cm x the index at the print when
38
+ * the reader has one, else null ("cannot denominate").
39
+ * 4. USD notional = coin size x the index at the print.
40
+ * 5. Per-coin price (the OPTION_SUMMARY basis): price x pv / cm on a USD book, the price itself (in coin)
41
+ * on a coin book.
42
+ * Live-print rules, per print (`coin` the delivered amount, cm' the multiplier live-feed applied: cm, or 1 when
43
+ * the registry has none):
44
+ * 1. Coin size = coin.
45
+ * 2. Premium in the book's own currency: price x coin x pv / cm' on a USD book (price x contracts x pv), price x
46
+ * coin on a coin book.
47
+ * 3. USD premium: that premium on a USD book; on a coin book price x coin x the index at the print, else null.
48
+ * 4. USD notional = coin x the index at the print.
49
+ * 5. Per-coin price: as for a stored row (live-feed leaves the price as stored).
50
+ * The registry `inverse` flag is never read: on an option row it names the settlement currency, not a
51
+ * USD-sized contract, so an option amount is never divided by its price.
52
+ *
53
+ * A book is a coin-premium book only by its ANSWERED units (`optionPremiumIsCoin`: a multiplier and no point value).
54
+ * Units with neither field (`OPTION_TRADE_UNITS_UNKNOWN` while a read runs, or a record the registry never filled)
55
+ * are no answer, so no reader takes a book as coin-premium before its units say so.
56
+ * The read is fresh (`{ fresh: true }`): a cached registry record can predate the point value fill, and kept for the
57
+ * session it would read a USD book as a coin book until reload.
58
+ *
59
+ * Worked rows (pinned by tests/utility/options/option-trade-units.util.spec.ts):
60
+ * - Binance DOGE, 3 contracts at 2.65 USDT each, cm 1000, pv 1, index 0.0792: size 3,000 DOGE, premium
61
+ * 7.95 USD, notional 237.60 USD, per-coin price 0.00265. Stored row: amount 3; live print: 3,000.
62
+ * - OKX coin book BTC-USD-261106-83000-C, 1 contract at 0.0285 BTC, cm 0.01, pv absent, index 82,065.7:
63
+ * size 0.01 BTC, premium 0.000285 BTC (23.39 USD), notional 820.66 USD, per-coin price 0.0285 BTC. Stored row:
64
+ * amount 1; live print: 0.01.
65
+ *
66
+ * Pure and worker-safe.
67
+ */
68
+ import { Category } from '@orangecharts/orange-v2-pb-common';
69
+ import { parseOptionSymbol } from './option-symbol.util.js';
70
+ import { optionVenueForExchange } from './option-venue.util.js';
71
+ const positiveOrNull = (value) => {
72
+ const number = typeof value === 'number' ? value : typeof value === 'string' ? Number(value) : Number.NaN;
73
+ return Number.isFinite(number) && number > 0 ? number : null;
74
+ };
75
+ const finiteOrNull = (value) => (Number.isFinite(value) ? value : null);
76
+ /** True for a registry or chart category naming an option: the enum NAME a decoded frame carries, or its number. */
77
+ function isOptionCategory(category) {
78
+ if (typeof category === 'number')
79
+ return category === Category.OPTION;
80
+ return typeof category === 'string' && category.toUpperCase() === Category[Category.OPTION];
81
+ }
82
+ /**
83
+ * The trade units of one registry row (`SymbolMetadataRecord`, a raw `registryMetadatas` row), or null for a
84
+ * row that is not an option: only option rows carry these meanings. An absent, zero, negative or non-finite
85
+ * field reads null.
86
+ */
87
+ export function optionTradeUnitsOf(row) {
88
+ if (!row || !isOptionCategory(row.category))
89
+ return null;
90
+ return {
91
+ contractMultiplier: positiveOrNull(row.contractMultiplier),
92
+ pointValue: positiveOrNull(row.pointValue),
93
+ };
94
+ }
95
+ /**
96
+ * True for an option contract on a plain (crypto) option venue: an option venue row of the venue table whose
97
+ * symbol grammar parses the raw symbol. The cheap gate before a registry read, so a perpetual or a spot
98
+ * market on the same venue never costs one.
99
+ */
100
+ export function isPlainOptionContract(exchange, symbol) {
101
+ const venue = optionVenueForExchange(exchange);
102
+ return venue?.lane === 'plain' && parseOptionSymbol(venue.id, symbol) !== null;
103
+ }
104
+ const OPTION_REGISTRY_FRESH = Object.freeze({ fresh: true });
105
+ /**
106
+ * The units of an option contract whose read has not answered yet: no multiplier and no point value, so nothing
107
+ * sizes or prices a raw print in USD until it answers (a print shows no USD rather than a guess). It is no answer:
108
+ * it never makes a book coin-premium (`optionPremiumIsCoin`), so a served aggregate reads as served and a Unit
109
+ * setting keeps its USD default meanwhile.
110
+ */
111
+ export const OPTION_TRADE_UNITS_UNKNOWN = Object.freeze({
112
+ contractMultiplier: null,
113
+ pointValue: null,
114
+ });
115
+ // Answered reads by market (`EXCHANGE|SYMBOL`), one memo per realm, so every surface of one market reads the units
116
+ // the first read answered; a failed read is not kept, the next load asks again.
117
+ const answeredUnits = new Map();
118
+ const readingUnits = new Map();
119
+ const unitsKey = (exchange, symbol) => `${exchange}|${symbol}`;
120
+ /**
121
+ * The registry trade units of one option contract on a plain option venue, read once through `read` (a fresh
122
+ * registry read: `{ fresh: true }`) and kept for the realm; null without a read for any other market, and null for a
123
+ * record that is not an option or a failed read.
124
+ */
125
+ export function loadOptionTradeUnits(market, read) {
126
+ if (!isPlainOptionContract(market.exchange, market.symbol))
127
+ return Promise.resolve(null);
128
+ const key = unitsKey(market.exchange, market.symbol);
129
+ if (answeredUnits.has(key))
130
+ return Promise.resolve(answeredUnits.get(key) ?? null);
131
+ const inFlight = readingUnits.get(key);
132
+ if (inFlight)
133
+ return inFlight;
134
+ const reading = (async () => {
135
+ try {
136
+ const units = optionTradeUnitsOf(await read(market.exchange, market.symbol, OPTION_REGISTRY_FRESH));
137
+ answeredUnits.set(key, units);
138
+ return units;
139
+ }
140
+ catch {
141
+ return null;
142
+ }
143
+ finally {
144
+ readingUnits.delete(key);
145
+ }
146
+ })();
147
+ readingUnits.set(key, reading);
148
+ return reading;
149
+ }
150
+ /**
151
+ * A market's trade units for a synchronous reader: the answered units, null for a market that is not an option
152
+ * contract on a plain venue, and `OPTION_TRADE_UNITS_UNKNOWN` while its read has not answered (the read is
153
+ * started here; `loadOptionTradeUnits` answers it).
154
+ */
155
+ export function optionTradeUnitsNow(market, read) {
156
+ if (!isPlainOptionContract(market.exchange, market.symbol))
157
+ return null;
158
+ const key = unitsKey(market.exchange, market.symbol);
159
+ if (answeredUnits.has(key))
160
+ return answeredUnits.get(key) ?? null;
161
+ void loadOptionTradeUnits(market, read);
162
+ return OPTION_TRADE_UNITS_UNKNOWN;
163
+ }
164
+ /**
165
+ * A market's answered trade units for a reader that may not start a read (a store-free module): the answered units,
166
+ * null for a market that is not an option contract on a plain venue, `OPTION_TRADE_UNITS_UNKNOWN` until a read
167
+ * started elsewhere (`loadOptionTradeUnits`, `optionTradeUnitsNow`) answers.
168
+ */
169
+ export function peekOptionTradeUnits(market) {
170
+ if (!isPlainOptionContract(market.exchange, market.symbol))
171
+ return null;
172
+ const key = unitsKey(market.exchange, market.symbol);
173
+ return answeredUnits.has(key) ? (answeredUnits.get(key) ?? null) : OPTION_TRADE_UNITS_UNKNOWN;
174
+ }
175
+ /** Forgets every answered read (specs only). */
176
+ export function __resetOptionTradeUnitsForTests() {
177
+ answeredUnits.clear();
178
+ readingUnits.clear();
179
+ }
180
+ /**
181
+ * True for a book whose premium is in coin: answered units with a multiplier and no point value (every option book's
182
+ * multiplier is written explicitly, so one without a multiplier is no answer). Its USD reads need the index at the
183
+ * print. Units with neither field (`OPTION_TRADE_UNITS_UNKNOWN` while a read runs) are no answer and read false.
184
+ */
185
+ export function optionPremiumIsCoin(units) {
186
+ return !!units && units.pointValue === null && units.contractMultiplier !== null;
187
+ }
188
+ /** Price per coin of underlying, to compare with OPTION_SUMMARY: price x pv / cm on a USD book, price on a coin book. */
189
+ export function optionTradePerCoinPrice(price, units) {
190
+ if (!units || !Number.isFinite(price))
191
+ return null;
192
+ if (units.pointValue === null)
193
+ return optionPremiumIsCoin(units) ? price : null;
194
+ return units.contractMultiplier === null ? null : finiteOrNull((price * units.pointValue) / units.contractMultiplier);
195
+ }
196
+ // ── Stored rows (source 1: gateway raw TRADE rows, the venue's own units) ──────────────────────────────────────────
197
+ /** A stored row's coin units traded: amount x cm; null when the multiplier is unknown. */
198
+ export function storedOptionTradeCoinSize(amount, units) {
199
+ const multiplier = units?.contractMultiplier ?? null;
200
+ if (multiplier === null || !Number.isFinite(amount))
201
+ return null;
202
+ return finiteOrNull(amount * multiplier);
203
+ }
204
+ /** A stored row's premium in the book's own currency (USD on a point-valued book, coin otherwise); null when unknown. */
205
+ export function storedOptionTradePremium(price, amount, units) {
206
+ if (!units || !Number.isFinite(price) || !Number.isFinite(amount))
207
+ return null;
208
+ const scale = units.pointValue ?? units.contractMultiplier;
209
+ return scale === null ? null : finiteOrNull(price * amount * scale);
210
+ }
211
+ /** A stored row's premium in USD: on a coin book through the index at the print, else null ("cannot denominate"). */
212
+ export function storedOptionTradeUsdPremium(price, amount, units, indexPrice) {
213
+ const premium = storedOptionTradePremium(price, amount, units);
214
+ if (premium === null || !units)
215
+ return null;
216
+ if (units.pointValue !== null)
217
+ return premium;
218
+ const index = positiveOrNull(indexPrice);
219
+ return index === null ? null : finiteOrNull(premium * index);
220
+ }
221
+ /** A stored row's coin size x the index at the print; null without either. */
222
+ export function storedOptionTradeUsdNotional(amount, units, indexPrice) {
223
+ const size = storedOptionTradeCoinSize(amount, units);
224
+ const index = positiveOrNull(indexPrice);
225
+ return size === null || index === null ? null : finiteOrNull(size * index);
226
+ }
227
+ /** Every value one stored row resolves to, by the stored-row rules. */
228
+ export function resolveStoredOptionTrade(trade, units, indexPrice) {
229
+ return {
230
+ coinSize: storedOptionTradeCoinSize(trade.amount, units),
231
+ premium: storedOptionTradePremium(trade.price, trade.amount, units),
232
+ premiumCurrency: optionPremiumIsCoin(units) ? 'COIN' : 'USD',
233
+ usdPremium: storedOptionTradeUsdPremium(trade.price, trade.amount, units, indexPrice),
234
+ usdNotional: storedOptionTradeUsdNotional(trade.amount, units, indexPrice),
235
+ perCoinPrice: optionTradePerCoinPrice(trade.price, units),
236
+ };
237
+ }
238
+ // ── Live prints (source 2: live-feed's COIN arm, coin on arrival) ─────────────────────────────────────────────────
239
+ /**
240
+ * A live print's premium in the book's own currency: price x coin x pv / cm' on a USD book (cm' the multiplier
241
+ * live-feed sized the print with, 1 when the registry has none), price x coin on a coin book; null while the units
242
+ * are unknown.
243
+ */
244
+ export function liveOptionPrintPremium(price, coin, units) {
245
+ if (!units || !Number.isFinite(price) || !Number.isFinite(coin))
246
+ return null;
247
+ if (units.pointValue !== null) {
248
+ return finiteOrNull((price * coin * units.pointValue) / (units.contractMultiplier ?? 1));
249
+ }
250
+ return optionPremiumIsCoin(units) ? finiteOrNull(price * coin) : null;
251
+ }
252
+ /** A live print's premium in USD: on a coin book through the index at the print, else null ("cannot denominate"). */
253
+ export function liveOptionPrintUsdPremium(price, coin, units, indexPrice) {
254
+ const premium = liveOptionPrintPremium(price, coin, units);
255
+ if (premium === null || !units)
256
+ return null;
257
+ if (units.pointValue !== null)
258
+ return premium;
259
+ const index = positiveOrNull(indexPrice);
260
+ return index === null ? null : finiteOrNull(premium * index);
261
+ }
262
+ /**
263
+ * The USD of an amount live-feed delivered on its COIN arm, on any market: on an option contract (`units` its trade
264
+ * units, answered or `OPTION_TRADE_UNITS_UNKNOWN`) the premium by the live-print rule, null while the units are
265
+ * unknown and on a coin-premium book; on every other market (`units` null) price x amount, exactly as a live merge
266
+ * computes it today. The one conversion a live merge needs to show a coin-arm amount in USD.
267
+ */
268
+ export function liveAmountUsd(price, amount, units) {
269
+ return units ? liveOptionPrintUsdPremium(price, amount, units) : price * amount;
270
+ }
271
+ /** Every value one live print resolves to, by the live-print rules: its delivered amount is the coin size. */
272
+ export function resolveLiveOptionPrint(print, units, indexPrice) {
273
+ const coinSize = Number.isFinite(print.coin) ? print.coin : null;
274
+ const index = positiveOrNull(indexPrice);
275
+ return {
276
+ coinSize,
277
+ premium: liveOptionPrintPremium(print.price, print.coin, units),
278
+ premiumCurrency: optionPremiumIsCoin(units) ? 'COIN' : 'USD',
279
+ usdPremium: liveOptionPrintUsdPremium(print.price, print.coin, units, indexPrice),
280
+ usdNotional: coinSize === null || index === null ? null : finiteOrNull(coinSize * index),
281
+ perCoinPrice: optionTradePerCoinPrice(print.price, units),
282
+ };
283
+ }
@@ -0,0 +1,75 @@
1
+ import { Category, Exchange } from '@orangecharts/orange-v2-pb-common';
2
+ import { type OptionVenue } from '../../constants/option-venues.constants.js';
3
+ import type { GateProvider } from '../../workers/constants/socket-slots.js';
4
+ /**
5
+ * Whether a gate plane's chain stamps true expiry instants (OptionVenue.expiryInstants: OPRA yes, CME no
6
+ * while its registry stamps bare UTC-midnight dates): what an option metric that reads time to expiry
7
+ * needs before it is offered on that plane.
8
+ */
9
+ export declare function planeServesExpiryInstants(plane: GateProvider): boolean;
10
+ /**
11
+ * Runtime flags read by the caller (`cryptoOptionsEnabled()`) and passed in, so these utils stay
12
+ * store-free. Omitted or `false` is the dark default, matching `WireGates` in scope-request.util.
13
+ */
14
+ export interface OptionVenueGates {
15
+ cryptoOptions?: boolean;
16
+ /** The `opra` flag: lights the OPRA row (US equity and index options). */
17
+ opra?: boolean;
18
+ }
19
+ /**
20
+ * Deliberately separate from `isCmeGoverned`: that predicate also drives billing, delayed-data
21
+ * badges and data terms, none of which apply to crypto providers.
22
+ */
23
+ export declare function optionVenueForExchange(exchange: Exchange | string): OptionVenue | null;
24
+ export declare function isOptionVenueExchange(exchange: Exchange | string): boolean;
25
+ /**
26
+ * An option contract chart on a plain crypto venue: the options suite reads that venue, not the
27
+ * Deribit coin set. The flag is read lazily so ordinary charts never touch the flag store.
28
+ */
29
+ export declare function isCryptoOptionChart(metadata: {
30
+ exchange?: string | null;
31
+ category?: Category | null;
32
+ } | null | undefined, cryptoOptionsOn: () => boolean): boolean;
33
+ export declare function visibleOptionVenues(gates?: OptionVenueGates): OptionVenue[];
34
+ /** The gate a gated row reads: `opra` for the OPRA row, `cryptoOptions` for every crypto provider. */
35
+ export declare function optionVenueGateKey(venue: OptionVenue): keyof OptionVenueGates;
36
+ /** True when the row is visible under the gates passed in (the same rule as `visibleOptionVenues`). */
37
+ export declare function isOptionVenueVisible(venue: OptionVenue, gates?: OptionVenueGates): boolean;
38
+ /**
39
+ * The provider whose options attach to a chart of this UNDERLYING exchange (a US stock chart on
40
+ * US_STOCKS, POLYGON or a listing venue resolves to OPRA). Null when no provider lists the exchange
41
+ * as an underlying venue; the CME bundle resolves through `optionVenueForExchange` instead because
42
+ * futures and their options share exchange codes.
43
+ */
44
+ export declare function optionVenueForUnderlyingExchange(exchange: Exchange | string): OptionVenue | null;
45
+ /**
46
+ * The underlying key a venue's chain RPC expects for a parsed contract: the base asset for most
47
+ * venues, the catalog ticker (base plus quote, `BTCUSDT`) where the venue keys by it.
48
+ */
49
+ export declare function venueUnderlying(venue: OptionVenue, parsed: {
50
+ root: string;
51
+ quoteAsset?: string;
52
+ }): string;
53
+ /**
54
+ * Where a crypto options indicator reads. `exchange` is the pb-common `Exchange` member name.
55
+ * Summaries are filed under the root `coin`; trades under `tradeCoin`, which differs on venues
56
+ * that key trades by the catalog ticker (Binance Options: `BTCUSDT`).
57
+ */
58
+ export interface OptionSource {
59
+ exchange: string;
60
+ coin: string;
61
+ tradeCoin: string;
62
+ }
63
+ /**
64
+ * Where an ordinary chart's coin reads its chain on a plain crypto venue (one the metadata listing
65
+ * names for the coin): the venue's exchange, the root coin, and the trade key the venue files trades
66
+ * under, derived from the venue's first settlement family the way a parsed contract's would be.
67
+ */
68
+ export declare function optionSourceForVenue(venue: OptionVenue, coin: string): OptionSource;
69
+ /** Deribit keeps the bare coin so stored chain, surface and heatmap-day keys stay valid. */
70
+ export declare function optionSourceKey(source: OptionSource): string;
71
+ /** `chartCoin` arrives normalized by the caller; null for any venue off the plain crypto lane. */
72
+ export declare function optionSourceFromTerminalIdentity(identity: {
73
+ exchange: Exchange;
74
+ underlying: string;
75
+ }, chartCoin: string): OptionSource | null;
@@ -0,0 +1,85 @@
1
+ import { Category, Exchange } from '@orangecharts/orange-v2-pb-common';
2
+ import { OPTION_VENUES } from '../../constants/option-venues.constants.js';
3
+ /**
4
+ * Whether a gate plane's chain stamps true expiry instants (OptionVenue.expiryInstants: OPRA yes, CME no
5
+ * while its registry stamps bare UTC-midnight dates): what an option metric that reads time to expiry
6
+ * needs before it is offered on that plane.
7
+ */
8
+ export function planeServesExpiryInstants(plane) {
9
+ return OPTION_VENUES.some((venue) => venue.plane === plane && venue.expiryInstants === true);
10
+ }
11
+ /**
12
+ * Deliberately separate from `isCmeGoverned`: that predicate also drives billing, delayed-data
13
+ * badges and data terms, none of which apply to crypto providers.
14
+ */
15
+ export function optionVenueForExchange(exchange) {
16
+ const name = typeof exchange === 'string' ? exchange.toUpperCase() : Exchange[exchange];
17
+ if (!name)
18
+ return null;
19
+ return OPTION_VENUES.find((venue) => venue.exchanges.includes(name)) ?? null;
20
+ }
21
+ export function isOptionVenueExchange(exchange) {
22
+ return optionVenueForExchange(exchange) !== null;
23
+ }
24
+ /**
25
+ * An option contract chart on a plain crypto venue: the options suite reads that venue, not the
26
+ * Deribit coin set. The flag is read lazily so ordinary charts never touch the flag store.
27
+ */
28
+ export function isCryptoOptionChart(metadata, cryptoOptionsOn) {
29
+ if (metadata?.category !== Category.OPTION || !metadata.exchange)
30
+ return false;
31
+ const venue = optionVenueForExchange(metadata.exchange);
32
+ return venue?.lane === 'plain' && (!venue.gated || cryptoOptionsOn());
33
+ }
34
+ export function visibleOptionVenues(gates = {}) {
35
+ return OPTION_VENUES.filter((venue) => !venue.gated || gates[optionVenueGateKey(venue)] === true);
36
+ }
37
+ /** The gate a gated row reads: `opra` for the OPRA row, `cryptoOptions` for every crypto provider. */
38
+ export function optionVenueGateKey(venue) {
39
+ return venue.gate === 'opra' ? 'opra' : 'cryptoOptions';
40
+ }
41
+ /** True when the row is visible under the gates passed in (the same rule as `visibleOptionVenues`). */
42
+ export function isOptionVenueVisible(venue, gates = {}) {
43
+ return !venue.gated || gates[optionVenueGateKey(venue)] === true;
44
+ }
45
+ /**
46
+ * The provider whose options attach to a chart of this UNDERLYING exchange (a US stock chart on
47
+ * US_STOCKS, POLYGON or a listing venue resolves to OPRA). Null when no provider lists the exchange
48
+ * as an underlying venue; the CME bundle resolves through `optionVenueForExchange` instead because
49
+ * futures and their options share exchange codes.
50
+ */
51
+ export function optionVenueForUnderlyingExchange(exchange) {
52
+ const name = typeof exchange === 'string' ? exchange.toUpperCase() : Exchange[exchange];
53
+ if (!name)
54
+ return null;
55
+ return OPTION_VENUES.find((venue) => venue.underlyingExchanges?.includes(name)) ?? null;
56
+ }
57
+ /**
58
+ * The underlying key a venue's chain RPC expects for a parsed contract: the base asset for most
59
+ * venues, the catalog ticker (base plus quote, `BTCUSDT`) where the venue keys by it.
60
+ */
61
+ export function venueUnderlying(venue, parsed) {
62
+ return venue.underlyingKey === 'assetTicker' ? `${parsed.root}${parsed.quoteAsset ?? ''}` : parsed.root;
63
+ }
64
+ /**
65
+ * Where an ordinary chart's coin reads its chain on a plain crypto venue (one the metadata listing
66
+ * names for the coin): the venue's exchange, the root coin, and the trade key the venue files trades
67
+ * under, derived from the venue's first settlement family the way a parsed contract's would be.
68
+ */
69
+ export function optionSourceForVenue(venue, coin) {
70
+ return {
71
+ exchange: venue.exchanges[0],
72
+ coin,
73
+ tradeCoin: venueUnderlying(venue, { root: coin, quoteAsset: venue.families?.[0]?.quoteAsset }),
74
+ };
75
+ }
76
+ /** Deribit keeps the bare coin so stored chain, surface and heatmap-day keys stay valid. */
77
+ export function optionSourceKey(source) {
78
+ return source.exchange === 'DERIBIT' ? source.coin : `${source.exchange}:${source.coin}`;
79
+ }
80
+ /** `chartCoin` arrives normalized by the caller; null for any venue off the plain crypto lane. */
81
+ export function optionSourceFromTerminalIdentity(identity, chartCoin) {
82
+ if (optionVenueForExchange(identity.exchange)?.lane !== 'plain')
83
+ return null;
84
+ return { exchange: Exchange[identity.exchange], coin: chartCoin, tradeCoin: identity.underlying };
85
+ }