@oanda/labs-crowd-view-widget 1.0.52 → 1.0.54

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 (312) hide show
  1. package/CHANGELOG.md +436 -0
  2. package/dist/main/CrowdViewWidget/Main.js +4 -6
  3. package/dist/main/CrowdViewWidget/Main.js.map +1 -1
  4. package/dist/main/CrowdViewWidget/components/Chart/Chart.js +18 -31
  5. package/dist/main/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
  6. package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js +7 -5
  7. package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
  8. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.js +18 -0
  9. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.js.map +1 -0
  10. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js +30 -0
  11. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js.map +1 -0
  12. package/dist/main/CrowdViewWidget/components/Chart/{utils → chartOptions}/getGridLines.js +5 -52
  13. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js.map +1 -0
  14. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.js +54 -0
  15. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.js.map +1 -0
  16. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.js +65 -0
  17. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.js.map +1 -0
  18. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.js +60 -0
  19. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.js.map +1 -0
  20. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js +53 -0
  21. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js.map +1 -0
  22. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getVisualMapConfig.js +31 -0
  23. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getVisualMapConfig.js.map +1 -0
  24. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js +42 -0
  25. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js.map +1 -0
  26. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js +75 -0
  27. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js.map +1 -0
  28. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/index.js +116 -0
  29. package/dist/main/CrowdViewWidget/components/Chart/chartOptions/index.js.map +1 -0
  30. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/formatXAxisLabel.js +18 -0
  31. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/formatXAxisLabel.js.map +1 -0
  32. package/dist/main/CrowdViewWidget/components/Chart/{utils → chartUtils}/getChartStyles.js +4 -4
  33. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getChartStyles.js.map +1 -0
  34. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getGradientColor.js +14 -0
  35. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getGradientColor.js.map +1 -0
  36. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getLabelData.js +42 -0
  37. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getLabelData.js.map +1 -0
  38. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getRectColor.js +14 -0
  39. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getRectColor.js.map +1 -0
  40. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js +108 -0
  41. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js.map +1 -0
  42. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/index.js +83 -0
  43. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/index.js.map +1 -0
  44. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/isDifferenceGreaterThanTwoWeeks.js +15 -0
  45. package/dist/main/CrowdViewWidget/components/Chart/chartUtils/isDifferenceGreaterThanTwoWeeks.js.map +1 -0
  46. package/dist/main/CrowdViewWidget/{utils/instrumentUtils.js → components/Chart/dataUtils/getInstrumentConfigForDivision.js} +3 -3
  47. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/getInstrumentConfigForDivision.js.map +1 -0
  48. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/getTimeSpanForGranularity.js +18 -0
  49. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/getTimeSpanForGranularity.js.map +1 -0
  50. package/dist/main/CrowdViewWidget/components/Chart/{utils → dataUtils}/index.js +8 -41
  51. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/index.js.map +1 -0
  52. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/processOrderPositionBooks.js +65 -0
  53. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/processOrderPositionBooks.js.map +1 -0
  54. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/processPriceCandles.js +65 -0
  55. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/processPriceCandles.js.map +1 -0
  56. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/processSentiments.js +43 -0
  57. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/processSentiments.js.map +1 -0
  58. package/dist/main/CrowdViewWidget/components/Chart/{utils → dataUtils}/validateData.js +8 -2
  59. package/dist/main/CrowdViewWidget/components/Chart/dataUtils/validateData.js.map +1 -0
  60. package/dist/main/CrowdViewWidget/components/Chart/getOption.js +103 -0
  61. package/dist/main/CrowdViewWidget/components/Chart/getOption.js.map +1 -0
  62. package/dist/main/CrowdViewWidget/components/Chart/index.js +11 -11
  63. package/dist/main/CrowdViewWidget/components/Chart/index.js.map +1 -1
  64. package/dist/main/CrowdViewWidget/components/Chart/types.js.map +1 -1
  65. package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js +53 -30
  66. package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
  67. package/dist/main/CrowdViewWidget/components/Legend/Legend.js +15 -13
  68. package/dist/main/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
  69. package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js +5 -16
  70. package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
  71. package/dist/main/CrowdViewWidget/constants.js +12 -18
  72. package/dist/main/CrowdViewWidget/constants.js.map +1 -1
  73. package/dist/main/gql/getOrderPositionBooks.js +1 -1
  74. package/dist/main/gql/getOrderPositionBooks.js.map +1 -1
  75. package/dist/main/gql/getPriceCandles.js +1 -1
  76. package/dist/main/gql/getPriceCandles.js.map +1 -1
  77. package/dist/main/gql/types/gql.js +2 -2
  78. package/dist/main/gql/types/gql.js.map +1 -1
  79. package/dist/main/gql/types/graphql.js +111 -18
  80. package/dist/main/gql/types/graphql.js.map +1 -1
  81. package/dist/main/translations/sources/en.json +2 -1
  82. package/dist/module/CrowdViewWidget/Main.js +3 -5
  83. package/dist/module/CrowdViewWidget/Main.js.map +1 -1
  84. package/dist/module/CrowdViewWidget/components/Chart/Chart.js +20 -33
  85. package/dist/module/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
  86. package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js +7 -5
  87. package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
  88. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.js +11 -0
  89. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.js.map +1 -0
  90. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js +23 -0
  91. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.js.map +1 -0
  92. package/dist/module/CrowdViewWidget/components/Chart/{utils → chartOptions}/getGridLines.js +5 -52
  93. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getGridLines.js.map +1 -0
  94. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.js +46 -0
  95. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.js.map +1 -0
  96. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.js +58 -0
  97. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.js.map +1 -0
  98. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.js +53 -0
  99. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.js.map +1 -0
  100. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js +46 -0
  101. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.js.map +1 -0
  102. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getVisualMapConfig.js +24 -0
  103. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getVisualMapConfig.js.map +1 -0
  104. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js +35 -0
  105. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.js.map +1 -0
  106. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js +68 -0
  107. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.js.map +1 -0
  108. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/index.js +11 -0
  109. package/dist/module/CrowdViewWidget/components/Chart/chartOptions/index.js.map +1 -0
  110. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/formatXAxisLabel.js +11 -0
  111. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/formatXAxisLabel.js.map +1 -0
  112. package/dist/module/CrowdViewWidget/components/Chart/{utils → chartUtils}/getChartStyles.js +4 -4
  113. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getChartStyles.js.map +1 -0
  114. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getGradientColor.js +6 -0
  115. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getGradientColor.js.map +1 -0
  116. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getLabelData.js +35 -0
  117. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getLabelData.js.map +1 -0
  118. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getRectColor.js +7 -0
  119. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getRectColor.js.map +1 -0
  120. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js +101 -0
  121. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.js.map +1 -0
  122. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/index.js +8 -0
  123. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/index.js.map +1 -0
  124. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/isDifferenceGreaterThanTwoWeeks.js +8 -0
  125. package/dist/module/CrowdViewWidget/components/Chart/chartUtils/isDifferenceGreaterThanTwoWeeks.js.map +1 -0
  126. package/dist/module/CrowdViewWidget/{utils/instrumentUtils.js → components/Chart/dataUtils/getInstrumentConfigForDivision.js} +3 -3
  127. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/getInstrumentConfigForDivision.js.map +1 -0
  128. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/getTimeSpanForGranularity.js +11 -0
  129. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/getTimeSpanForGranularity.js.map +1 -0
  130. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/index.js +7 -0
  131. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/index.js.map +1 -0
  132. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/processOrderPositionBooks.js +58 -0
  133. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/processOrderPositionBooks.js.map +1 -0
  134. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/processPriceCandles.js +58 -0
  135. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/processPriceCandles.js.map +1 -0
  136. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/processSentiments.js +36 -0
  137. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/processSentiments.js.map +1 -0
  138. package/dist/module/CrowdViewWidget/components/Chart/{utils → dataUtils}/validateData.js +8 -2
  139. package/dist/module/CrowdViewWidget/components/Chart/dataUtils/validateData.js.map +1 -0
  140. package/dist/module/CrowdViewWidget/components/Chart/getOption.js +96 -0
  141. package/dist/module/CrowdViewWidget/components/Chart/getOption.js.map +1 -0
  142. package/dist/module/CrowdViewWidget/components/Chart/index.js +1 -1
  143. package/dist/module/CrowdViewWidget/components/Chart/index.js.map +1 -1
  144. package/dist/module/CrowdViewWidget/components/Chart/types.js.map +1 -1
  145. package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js +50 -27
  146. package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
  147. package/dist/module/CrowdViewWidget/components/Legend/Legend.js +15 -13
  148. package/dist/module/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
  149. package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js +5 -16
  150. package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
  151. package/dist/module/CrowdViewWidget/constants.js +10 -17
  152. package/dist/module/CrowdViewWidget/constants.js.map +1 -1
  153. package/dist/module/gql/getOrderPositionBooks.js +1 -1
  154. package/dist/module/gql/getOrderPositionBooks.js.map +1 -1
  155. package/dist/module/gql/getPriceCandles.js +1 -1
  156. package/dist/module/gql/getPriceCandles.js.map +1 -1
  157. package/dist/module/gql/types/gql.js +2 -2
  158. package/dist/module/gql/types/gql.js.map +1 -1
  159. package/dist/module/gql/types/graphql.js +111 -18
  160. package/dist/module/gql/types/graphql.js.map +1 -1
  161. package/dist/module/translations/sources/en.json +2 -1
  162. package/dist/types/CrowdViewWidget/components/Chart/Chart.d.ts +1 -1
  163. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.d.ts +2 -0
  164. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.d.ts +6 -0
  165. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getGridLines.d.ts +6 -0
  166. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.d.ts +9 -0
  167. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.d.ts +11 -0
  168. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.d.ts +7 -0
  169. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.d.ts +16 -0
  170. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getVisualMapConfig.d.ts +7 -0
  171. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.d.ts +7 -0
  172. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.d.ts +9 -0
  173. package/dist/types/CrowdViewWidget/components/Chart/chartOptions/index.d.ts +10 -0
  174. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/formatXAxisLabel.d.ts +1 -0
  175. package/dist/types/CrowdViewWidget/components/Chart/{utils → chartUtils}/getChartStyles.d.ts +2 -2
  176. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/getGradientColor.d.ts +1 -0
  177. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/getLabelData.d.ts +17 -0
  178. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/getRectColor.d.ts +1 -0
  179. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.d.ts +10 -0
  180. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/index.d.ts +7 -0
  181. package/dist/types/CrowdViewWidget/components/Chart/chartUtils/isDifferenceGreaterThanTwoWeeks.d.ts +1 -0
  182. package/dist/types/CrowdViewWidget/{utils/instrumentUtils.d.ts → components/Chart/dataUtils/getInstrumentConfigForDivision.d.ts} +2 -2
  183. package/dist/types/CrowdViewWidget/components/Chart/dataUtils/getTimeSpanForGranularity.d.ts +2 -0
  184. package/dist/types/CrowdViewWidget/components/Chart/dataUtils/index.d.ts +6 -0
  185. package/dist/types/CrowdViewWidget/components/Chart/dataUtils/processOrderPositionBooks.d.ts +11 -0
  186. package/dist/types/CrowdViewWidget/components/Chart/dataUtils/processPriceCandles.d.ts +12 -0
  187. package/dist/types/CrowdViewWidget/components/Chart/dataUtils/processSentiments.d.ts +6 -0
  188. package/dist/types/CrowdViewWidget/components/Chart/{utils → dataUtils}/validateData.d.ts +1 -1
  189. package/dist/types/CrowdViewWidget/components/Chart/index.d.ts +1 -1
  190. package/dist/types/CrowdViewWidget/components/Chart/types.d.ts +28 -11
  191. package/dist/types/CrowdViewWidget/components/Legend/Legend.d.ts +1 -4
  192. package/dist/types/CrowdViewWidget/components/Legend/LegendBar.d.ts +1 -3
  193. package/dist/types/CrowdViewWidget/constants.d.ts +4 -12
  194. package/dist/types/gql/types/gql.d.ts +6 -4
  195. package/dist/types/gql/types/graphql.d.ts +30 -11
  196. package/package.json +3 -3
  197. package/src/CrowdViewWidget/Main.tsx +3 -4
  198. package/src/CrowdViewWidget/components/Chart/Chart.tsx +25 -40
  199. package/src/CrowdViewWidget/components/Chart/ChartWithData.tsx +8 -4
  200. package/src/CrowdViewWidget/components/Chart/chartOptions/getDataZoomConfig.ts +13 -0
  201. package/src/CrowdViewWidget/components/Chart/chartOptions/getGridConfig.ts +29 -0
  202. package/src/CrowdViewWidget/components/Chart/chartOptions/getGridLines.ts +84 -0
  203. package/src/CrowdViewWidget/components/Chart/chartOptions/getSeriesCandlestickConfig.ts +52 -0
  204. package/src/CrowdViewWidget/components/Chart/chartOptions/getSeriesHeatmapConfig.ts +82 -0
  205. package/src/CrowdViewWidget/components/Chart/chartOptions/getSeriesSentimentConfig.ts +63 -0
  206. package/src/CrowdViewWidget/components/Chart/chartOptions/getTooltipConfig.ts +63 -0
  207. package/src/CrowdViewWidget/components/Chart/chartOptions/getVisualMapConfig.ts +32 -0
  208. package/src/CrowdViewWidget/components/Chart/chartOptions/getXAxisConfig.ts +43 -0
  209. package/src/CrowdViewWidget/components/Chart/chartOptions/getYAxisConfig.ts +77 -0
  210. package/src/CrowdViewWidget/components/Chart/chartOptions/index.ts +10 -0
  211. package/src/CrowdViewWidget/components/Chart/chartUtils/formatXAxisLabel.ts +16 -0
  212. package/src/CrowdViewWidget/components/Chart/{utils → chartUtils}/getChartStyles.ts +9 -6
  213. package/src/CrowdViewWidget/components/Chart/chartUtils/getGradientColor.ts +16 -0
  214. package/src/CrowdViewWidget/components/Chart/chartUtils/getLabelData.ts +42 -0
  215. package/src/CrowdViewWidget/components/Chart/chartUtils/getRectColor.ts +27 -0
  216. package/src/CrowdViewWidget/components/Chart/chartUtils/getTooltipFormatter.ts +183 -0
  217. package/src/CrowdViewWidget/components/Chart/chartUtils/index.ts +7 -0
  218. package/src/CrowdViewWidget/components/Chart/chartUtils/isDifferenceGreaterThanTwoWeeks.ts +13 -0
  219. package/src/CrowdViewWidget/{utils/instrumentUtils.ts → components/Chart/dataUtils/getInstrumentConfigForDivision.ts} +2 -2
  220. package/src/CrowdViewWidget/components/Chart/dataUtils/getTimeSpanForGranularity.ts +14 -0
  221. package/src/CrowdViewWidget/components/Chart/dataUtils/index.ts +6 -0
  222. package/src/CrowdViewWidget/components/Chart/dataUtils/processOrderPositionBooks.ts +92 -0
  223. package/src/CrowdViewWidget/components/Chart/dataUtils/processPriceCandles.ts +67 -0
  224. package/src/CrowdViewWidget/components/Chart/dataUtils/processSentiments.ts +55 -0
  225. package/src/CrowdViewWidget/components/Chart/{utils → dataUtils}/validateData.ts +10 -2
  226. package/src/CrowdViewWidget/components/Chart/getOption.ts +114 -0
  227. package/src/CrowdViewWidget/components/Chart/index.ts +1 -1
  228. package/src/CrowdViewWidget/components/Chart/types.ts +30 -19
  229. package/src/CrowdViewWidget/components/Chart/useCrowdViewData.ts +84 -67
  230. package/src/CrowdViewWidget/components/Legend/Legend.tsx +24 -23
  231. package/src/CrowdViewWidget/components/Legend/LegendBar.tsx +13 -26
  232. package/src/CrowdViewWidget/constants.ts +21 -23
  233. package/src/gql/getOrderPositionBooks.ts +13 -5
  234. package/src/gql/getPriceCandles.ts +1 -0
  235. package/src/gql/types/gql.ts +6 -6
  236. package/src/gql/types/graphql.ts +98 -16
  237. package/src/translations/sources/en.json +2 -1
  238. package/test/components/Chart/utils/chartUtils.test.ts +39 -21
  239. package/test/components/Chart/utils/getChartStyles.test.ts +10 -10
  240. package/test/components/Chart/utils/processSentiments.test.ts +138 -30
  241. package/test/components/Legend.test.tsx +13 -21
  242. package/test/components/LegendBar.test.tsx +31 -51
  243. package/test/utils/instrumentUtils.test.ts +1 -1
  244. package/test/utils/processOrderPositionBooks.test.ts +201 -84
  245. package/test/utils/processPriceCandles.test.ts +93 -67
  246. package/test/utils/validateData.test.ts +136 -38
  247. package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js +0 -359
  248. package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js.map +0 -1
  249. package/dist/main/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js +0 -37
  250. package/dist/main/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js.map +0 -1
  251. package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js +0 -127
  252. package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +0 -1
  253. package/dist/main/CrowdViewWidget/components/Chart/utils/getChartStyles.js.map +0 -1
  254. package/dist/main/CrowdViewWidget/components/Chart/utils/getGridLines.js.map +0 -1
  255. package/dist/main/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js +0 -14
  256. package/dist/main/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js.map +0 -1
  257. package/dist/main/CrowdViewWidget/components/Chart/utils/index.js.map +0 -1
  258. package/dist/main/CrowdViewWidget/components/Chart/utils/processBuckets.js +0 -29
  259. package/dist/main/CrowdViewWidget/components/Chart/utils/processBuckets.js.map +0 -1
  260. package/dist/main/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js +0 -23
  261. package/dist/main/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js.map +0 -1
  262. package/dist/main/CrowdViewWidget/components/Chart/utils/processPriceCandles.js +0 -43
  263. package/dist/main/CrowdViewWidget/components/Chart/utils/processPriceCandles.js.map +0 -1
  264. package/dist/main/CrowdViewWidget/components/Chart/utils/processSentiments.js +0 -28
  265. package/dist/main/CrowdViewWidget/components/Chart/utils/processSentiments.js.map +0 -1
  266. package/dist/main/CrowdViewWidget/components/Chart/utils/validateData.js.map +0 -1
  267. package/dist/main/CrowdViewWidget/utils/instrumentUtils.js.map +0 -1
  268. package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js +0 -351
  269. package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js.map +0 -1
  270. package/dist/module/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js +0 -29
  271. package/dist/module/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js.map +0 -1
  272. package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js +0 -114
  273. package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +0 -1
  274. package/dist/module/CrowdViewWidget/components/Chart/utils/getChartStyles.js.map +0 -1
  275. package/dist/module/CrowdViewWidget/components/Chart/utils/getGridLines.js.map +0 -1
  276. package/dist/module/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js +0 -7
  277. package/dist/module/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js.map +0 -1
  278. package/dist/module/CrowdViewWidget/components/Chart/utils/index.js +0 -10
  279. package/dist/module/CrowdViewWidget/components/Chart/utils/index.js.map +0 -1
  280. package/dist/module/CrowdViewWidget/components/Chart/utils/processBuckets.js +0 -22
  281. package/dist/module/CrowdViewWidget/components/Chart/utils/processBuckets.js.map +0 -1
  282. package/dist/module/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js +0 -16
  283. package/dist/module/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js.map +0 -1
  284. package/dist/module/CrowdViewWidget/components/Chart/utils/processPriceCandles.js +0 -36
  285. package/dist/module/CrowdViewWidget/components/Chart/utils/processPriceCandles.js.map +0 -1
  286. package/dist/module/CrowdViewWidget/components/Chart/utils/processSentiments.js +0 -21
  287. package/dist/module/CrowdViewWidget/components/Chart/utils/processSentiments.js.map +0 -1
  288. package/dist/module/CrowdViewWidget/components/Chart/utils/validateData.js.map +0 -1
  289. package/dist/module/CrowdViewWidget/utils/instrumentUtils.js.map +0 -1
  290. package/dist/types/CrowdViewWidget/components/Chart/utils/aggregateBuckets.d.ts +0 -2
  291. package/dist/types/CrowdViewWidget/components/Chart/utils/chartUtils.d.ts +0 -31
  292. package/dist/types/CrowdViewWidget/components/Chart/utils/getGridLines.d.ts +0 -97
  293. package/dist/types/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.d.ts +0 -3
  294. package/dist/types/CrowdViewWidget/components/Chart/utils/index.d.ts +0 -9
  295. package/dist/types/CrowdViewWidget/components/Chart/utils/processBuckets.d.ts +0 -3
  296. package/dist/types/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.d.ts +0 -8
  297. package/dist/types/CrowdViewWidget/components/Chart/utils/processPriceCandles.d.ts +0 -27
  298. package/dist/types/CrowdViewWidget/components/Chart/utils/processSentiments.d.ts +0 -3
  299. package/src/CrowdViewWidget/components/Chart/chartOptions.ts +0 -401
  300. package/src/CrowdViewWidget/components/Chart/utils/aggregateBuckets.ts +0 -44
  301. package/src/CrowdViewWidget/components/Chart/utils/chartUtils.ts +0 -216
  302. package/src/CrowdViewWidget/components/Chart/utils/getGridLines.ts +0 -148
  303. package/src/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.ts +0 -13
  304. package/src/CrowdViewWidget/components/Chart/utils/index.ts +0 -9
  305. package/src/CrowdViewWidget/components/Chart/utils/processBuckets.ts +0 -43
  306. package/src/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.ts +0 -30
  307. package/src/CrowdViewWidget/components/Chart/utils/processPriceCandles.ts +0 -53
  308. package/src/CrowdViewWidget/components/Chart/utils/processSentiments.ts +0 -42
  309. package/test/utils/aggregateBuckets.test.ts +0 -82
  310. package/test/utils/getTargetBucketWidth.test.ts +0 -37
  311. package/test/utils/processBuckets.test.ts +0 -153
  312. /package/dist/types/CrowdViewWidget/components/Chart/{chartOptions.d.ts → getOption.d.ts} +0 -0
@@ -2,6 +2,7 @@
2
2
  * @jest-environment jsdom
3
3
  */
4
4
 
5
+ import { MockLayoutProvider } from '@oanda/labs-widget-common';
5
6
  import { render } from '@testing-library/react';
6
7
  import React from 'react';
7
8
 
@@ -13,27 +14,21 @@ describe('Crowd View Widget', () => {
13
14
  describe('components', () => {
14
15
  describe('<Legend />', () => {
15
16
  it('renders two LegendBar components', () => {
16
- const { getAllByText } = render(
17
- <Legend
18
- bookType={BookType.Position}
19
- isDark={false}
20
- longValues={[0.15, 0.55]}
21
- shortValues={[0.15, 0.55]}
22
- />
17
+ const { getAllByTestId } = render(
18
+ <MockLayoutProvider isDark={false}>
19
+ <Legend bookType={BookType.Position} />
20
+ </MockLayoutProvider>
23
21
  );
24
22
 
25
- expect(getAllByText(/long/)).toHaveLength(1);
26
- expect(getAllByText(/short/)).toHaveLength(1);
23
+ const segments = getAllByTestId('legend-bar-segment');
24
+ expect(segments.length).toBe(2);
27
25
  });
28
26
 
29
27
  it('passes isDark prop to LegendBar components in light mode', () => {
30
28
  const { getAllByTestId } = render(
31
- <Legend
32
- bookType={BookType.Position}
33
- isDark={false}
34
- longValues={[0.15, 0.55]}
35
- shortValues={[0.15, 0.55]}
36
- />
29
+ <MockLayoutProvider isDark={false}>
30
+ <Legend bookType={BookType.Position} />
31
+ </MockLayoutProvider>
37
32
  );
38
33
  const segments = getAllByTestId('legend-bar-segment');
39
34
  expect(segments.length).toBe(2);
@@ -49,12 +44,9 @@ describe('Crowd View Widget', () => {
49
44
 
50
45
  it('passes isDark prop to LegendBar components in dark mode', () => {
51
46
  const { getAllByTestId } = render(
52
- <Legend
53
- bookType={BookType.Position}
54
- isDark={true}
55
- longValues={[0.15, 0.55]}
56
- shortValues={[0.15, 0.55]}
57
- />
47
+ <MockLayoutProvider isDark={true}>
48
+ <Legend bookType={BookType.Position} />
49
+ </MockLayoutProvider>
58
50
  );
59
51
  const segments = getAllByTestId('legend-bar-segment');
60
52
  expect(segments.length).toBe(2);
@@ -11,44 +11,17 @@ import { COLOR_MAP } from '../../src/CrowdViewWidget/constants';
11
11
  describe('Crowd View Widget', () => {
12
12
  describe('components', () => {
13
13
  describe('<LegendBar />', () => {
14
- const mockValues = [0.15, 0.55];
15
-
16
- it('renders LegendBar with min and max values', () => {
17
- const { getByText } = render(
18
- <LegendBar
19
- isDark={false}
20
- label="long"
21
- type="long"
22
- values={mockValues}
23
- />
24
- );
25
-
26
- expect(getByText('long')).toBeInTheDocument();
27
- expect(getByText('0.15%')).toBeInTheDocument();
28
- expect(getByText('≤ 0.55%')).toBeInTheDocument();
29
- });
30
-
31
14
  it('renders exactly 1 segment', () => {
32
15
  const { getAllByTestId } = render(
33
- <LegendBar
34
- isDark={false}
35
- label="short"
36
- type="short"
37
- values={mockValues}
38
- />
16
+ <LegendBar isDark={false} type="short" />
39
17
  );
40
18
  const segments = getAllByTestId('legend-bar-segment');
41
19
  expect(segments.length).toBe(1);
42
20
  });
43
21
 
44
- it('uses light mode colors when isDark is false', () => {
22
+ it('uses light mode colors when isDark is false for long type', () => {
45
23
  const { getByTestId } = render(
46
- <LegendBar
47
- isDark={false}
48
- label="long"
49
- type="long"
50
- values={mockValues}
51
- />
24
+ <LegendBar isDark={false} type="long" />
52
25
  );
53
26
  const segment = getByTestId('legend-bar-segment');
54
27
  const style = segment.getAttribute('style');
@@ -56,15 +29,8 @@ describe('Crowd View Widget', () => {
56
29
  expect(style).toContain(COLOR_MAP.light.long[1]);
57
30
  });
58
31
 
59
- it('uses dark mode colors when isDark is true', () => {
60
- const { getByTestId } = render(
61
- <LegendBar
62
- isDark={true}
63
- label="long"
64
- type="long"
65
- values={mockValues}
66
- />
67
- );
32
+ it('uses dark mode colors when isDark is true for long type', () => {
33
+ const { getByTestId } = render(<LegendBar isDark={true} type="long" />);
68
34
  const segment = getByTestId('legend-bar-segment');
69
35
  const style = segment.getAttribute('style');
70
36
  expect(style).toContain(COLOR_MAP.dark.long[0]);
@@ -73,12 +39,7 @@ describe('Crowd View Widget', () => {
73
39
 
74
40
  it('uses light mode short colors when isDark is false', () => {
75
41
  const { getByTestId } = render(
76
- <LegendBar
77
- isDark={false}
78
- label="short"
79
- type="short"
80
- values={mockValues}
81
- />
42
+ <LegendBar isDark={false} type="short" />
82
43
  );
83
44
  const segment = getByTestId('legend-bar-segment');
84
45
  const style = segment.getAttribute('style');
@@ -88,18 +49,37 @@ describe('Crowd View Widget', () => {
88
49
 
89
50
  it('uses dark mode short colors when isDark is true', () => {
90
51
  const { getByTestId } = render(
91
- <LegendBar
92
- isDark={true}
93
- label="short"
94
- type="short"
95
- values={mockValues}
96
- />
52
+ <LegendBar isDark={true} type="short" />
97
53
  );
98
54
  const segment = getByTestId('legend-bar-segment');
99
55
  const style = segment.getAttribute('style');
100
56
  expect(style).toContain(COLOR_MAP.dark.short[0]);
101
57
  expect(style).toContain(COLOR_MAP.dark.short[1]);
102
58
  });
59
+
60
+ it('renders gradient with correct direction for long type', () => {
61
+ const { getByTestId } = render(
62
+ <LegendBar isDark={false} type="long" />
63
+ );
64
+ const segment = getByTestId('legend-bar-segment');
65
+ const style = segment.getAttribute('style');
66
+ // Long type should use long[1] as start and long[0] as end
67
+ expect(style).toMatch(/linear-gradient\(90deg/);
68
+ expect(style).toContain(COLOR_MAP.light.long[1]);
69
+ expect(style).toContain(COLOR_MAP.light.long[0]);
70
+ });
71
+
72
+ it('renders gradient with correct direction for short type', () => {
73
+ const { getByTestId } = render(
74
+ <LegendBar isDark={false} type="short" />
75
+ );
76
+ const segment = getByTestId('legend-bar-segment');
77
+ const style = segment.getAttribute('style');
78
+ // Short type should use short[0] as start and short[1] as end
79
+ expect(style).toMatch(/linear-gradient\(90deg/);
80
+ expect(style).toContain(COLOR_MAP.light.short[0]);
81
+ expect(style).toContain(COLOR_MAP.light.short[1]);
82
+ });
103
83
  });
104
84
  });
105
85
  });
@@ -2,7 +2,7 @@
2
2
  * @jest-environment jsdom
3
3
  */
4
4
 
5
- import { getInstrumentConfigForDivision } from '../../src/CrowdViewWidget/utils/instrumentUtils';
5
+ import { getInstrumentConfigForDivision } from '../../src/CrowdViewWidget/components/Chart/dataUtils/getInstrumentConfigForDivision';
6
6
  import { Division } from '../../src/gql/types/graphql';
7
7
 
8
8
  describe('instrumentUtils', () => {
@@ -3,125 +3,242 @@ import type { GetOrderPositionBooksQuery } from '../../src/gql/types/graphql';
3
3
 
4
4
  describe('processOrderPositionBooks', () => {
5
5
  const createMockOrderPositionBook = (time: string) => ({
6
- bucketWidth: 0.0005,
7
- price: 1.0,
8
6
  time,
9
- buckets: [{ price: 1.0, sentiment: 0.2 }],
7
+ price: 1.0,
8
+ buckets: [
9
+ { price: 1.0, sentiment: 0.2 },
10
+ { price: 1.0005, sentiment: -0.3 },
11
+ ],
10
12
  });
11
13
 
12
- it('should return empty array when orderPositionData is undefined', () => {
13
- const candleMap = new Map();
14
- expect(processOrderPositionBooks(undefined, candleMap)).toEqual([]);
14
+ it('should return empty arrays when orderPositionData is undefined', () => {
15
+ const result = processOrderPositionBooks(undefined, []);
16
+ expect(result).toEqual({
17
+ bookPrices: [],
18
+ bookIndexes: [],
19
+ buckets: [],
20
+ bucketWidth: 0,
21
+ sentimentThresholdMin: 0,
22
+ sentimentThresholdMax: 0,
23
+ hasValidBooks: false,
24
+ });
15
25
  });
16
26
 
17
- it('should return empty array when orderPositionBooks is empty', () => {
27
+ it('should return empty arrays when orderPositionBooks is undefined', () => {
18
28
  const mockData: GetOrderPositionBooksQuery = {
19
- orderPositionBooks: [],
29
+ orderPositionBooks: {} as any,
20
30
  };
21
- const candleMap = new Map();
22
- expect(processOrderPositionBooks(mockData, candleMap)).toEqual([]);
31
+ const result = processOrderPositionBooks(mockData, []);
32
+ expect(result).toEqual({
33
+ bookPrices: [],
34
+ bookIndexes: [],
35
+ buckets: [],
36
+ bucketWidth: 0,
37
+ sentimentThresholdMin: 0,
38
+ sentimentThresholdMax: 0,
39
+ hasValidBooks: false,
40
+ });
23
41
  });
24
42
 
25
- it('should filter out null books', () => {
43
+ it('should return empty arrays when books array is empty', () => {
26
44
  const mockData: GetOrderPositionBooksQuery = {
27
- orderPositionBooks: [null, createMockOrderPositionBook('2025-01-01')],
45
+ orderPositionBooks: {
46
+ books: [],
47
+ bucketWidth: 0.0005,
48
+ sentimentThresholdMin: 0.15,
49
+ sentimentThresholdMax: 0.55,
50
+ },
28
51
  };
29
- const candleMap = new Map();
30
- const result = processOrderPositionBooks(mockData, candleMap);
31
- expect(result).toHaveLength(1);
32
- expect(result[0]).toEqual(['2025-01-01', null, 0]);
52
+ const result = processOrderPositionBooks(mockData, []);
53
+ expect(result).toEqual({
54
+ bookPrices: [],
55
+ bookIndexes: [],
56
+ buckets: [],
57
+ bucketWidth: 0,
58
+ sentimentThresholdMin: 0,
59
+ sentimentThresholdMax: 0,
60
+ hasValidBooks: false,
61
+ });
33
62
  });
34
63
 
35
- it('should filter out books with no buckets', () => {
64
+ it('should return empty arrays when sentimentThresholdMin is missing', () => {
36
65
  const mockData: GetOrderPositionBooksQuery = {
37
- orderPositionBooks: [
38
- {
39
- bucketWidth: 0.0005,
40
- price: 1.0,
41
- time: '2025-01-01',
42
- buckets: [],
43
- },
44
- createMockOrderPositionBook('2025-01-02'),
45
- ],
66
+ orderPositionBooks: {
67
+ books: [createMockOrderPositionBook('2025-01-01T00:00:00Z')],
68
+ bucketWidth: 0.0005,
69
+ sentimentThresholdMin: null as any,
70
+ sentimentThresholdMax: 0.55,
71
+ },
46
72
  };
47
- const candleMap = new Map();
48
- const result = processOrderPositionBooks(mockData, candleMap);
49
- expect(result).toHaveLength(1);
50
- expect(result[0]).toEqual(['2025-01-02', null, 0]);
73
+ const result = processOrderPositionBooks(mockData, [
74
+ '2025-01-01T00:00:00Z',
75
+ ]);
76
+ expect(result.hasValidBooks).toBe(false);
51
77
  });
52
78
 
53
- it('should use candle high price when available in map', () => {
79
+ it('should process valid order position books and match with dates', () => {
80
+ const dates = [
81
+ '2025-01-01T00:00:00Z',
82
+ '2025-01-01T01:00:00Z',
83
+ '2025-01-01T02:00:00Z',
84
+ ];
54
85
  const mockData: GetOrderPositionBooksQuery = {
55
- orderPositionBooks: [
56
- createMockOrderPositionBook('2025-01-01'),
57
- createMockOrderPositionBook('2025-01-02'),
58
- ],
86
+ orderPositionBooks: {
87
+ books: [
88
+ createMockOrderPositionBook('2025-01-01T00:00:00Z'),
89
+ createMockOrderPositionBook('2025-01-01T01:00:00Z'),
90
+ ],
91
+ bucketWidth: 0.0005,
92
+ sentimentThresholdMin: 0.15,
93
+ sentimentThresholdMax: 0.55,
94
+ },
59
95
  };
60
- const candleMap = new Map([
61
- ['2025-01-01', { high: 1.1234 }],
62
- ['2025-01-02', { high: 1.5678 }],
63
- ]);
64
- const result = processOrderPositionBooks(mockData, candleMap);
65
- expect(result).toHaveLength(2);
66
- expect(result[0]).toEqual(['2025-01-01', 1.1234, 0]);
67
- expect(result[1]).toEqual(['2025-01-02', 1.5678, 1]);
96
+ const result = processOrderPositionBooks(mockData, dates);
97
+ expect(result.hasValidBooks).toBe(true);
98
+ expect(result.bucketWidth).toBe(0.0005);
99
+ expect(result.sentimentThresholdMin).toBe(0.15);
100
+ expect(result.sentimentThresholdMax).toBe(0.55);
101
+ expect(result.bookPrices).toHaveLength(3);
102
+ expect(result.bookIndexes).toHaveLength(3);
103
+ expect(result.buckets).toHaveLength(3);
104
+ expect(result.bookPrices[0]).toBe(1.0);
105
+ expect(result.bookPrices[1]).toBe(1.0);
106
+ expect(result.bookPrices[2]).toBeNull();
107
+ expect(result.bookIndexes).toEqual([0, 1, 2]);
108
+ expect(result.buckets[0]).toHaveLength(2);
109
+ expect(result.buckets[1]).toHaveLength(2);
110
+ expect(result.buckets[2]).toEqual([]);
68
111
  });
69
112
 
70
- it('should use null when candle is not in map', () => {
113
+ it('should handle dates that do not match any book', () => {
114
+ const dates = [
115
+ '2025-01-01T00:00:00Z',
116
+ '2025-01-01T01:00:00Z',
117
+ '2025-01-01T02:00:00Z',
118
+ ];
71
119
  const mockData: GetOrderPositionBooksQuery = {
72
- orderPositionBooks: [createMockOrderPositionBook('2025-01-01')],
120
+ orderPositionBooks: {
121
+ books: [createMockOrderPositionBook('2025-01-01T00:00:00Z')],
122
+ bucketWidth: 0.0005,
123
+ sentimentThresholdMin: 0.15,
124
+ sentimentThresholdMax: 0.55,
125
+ },
73
126
  };
74
- const candleMap = new Map();
75
- const result = processOrderPositionBooks(mockData, candleMap);
76
- expect(result).toHaveLength(1);
77
- expect(result[0]).toEqual(['2025-01-01', null, 0]);
127
+ const result = processOrderPositionBooks(mockData, dates);
128
+ expect(result.bookPrices).toEqual([1.0, null, null]);
129
+ expect(result.buckets[0]).toHaveLength(2);
130
+ expect(result.buckets[1]).toEqual([]);
131
+ expect(result.buckets[2]).toEqual([]);
78
132
  });
79
133
 
80
- it('should use null when candle high is undefined', () => {
134
+ it('should handle books with null price', () => {
135
+ const dates = ['2025-01-01T00:00:00Z'];
81
136
  const mockData: GetOrderPositionBooksQuery = {
82
- orderPositionBooks: [createMockOrderPositionBook('2025-01-01')],
137
+ orderPositionBooks: {
138
+ books: [
139
+ {
140
+ time: '2025-01-01T00:00:00Z',
141
+ price: null,
142
+ buckets: [{ price: 1.0, sentiment: 0.2 }],
143
+ },
144
+ ],
145
+ bucketWidth: 0.0005,
146
+ sentimentThresholdMin: 0.15,
147
+ sentimentThresholdMax: 0.55,
148
+ },
83
149
  };
84
- const candleMap = new Map([
85
- ['2025-01-01', { low: 1.0 }], // no high property
150
+ const result = processOrderPositionBooks(mockData, dates);
151
+ expect(result.bookPrices[0]).toBeNull();
152
+ expect(result.buckets[0]).toHaveLength(1);
153
+ });
154
+
155
+ it('should correctly map buckets structure', () => {
156
+ const dates = ['2025-01-01T00:00:00Z'];
157
+ const mockData: GetOrderPositionBooksQuery = {
158
+ orderPositionBooks: {
159
+ books: [
160
+ {
161
+ time: '2025-01-01T00:00:00Z',
162
+ price: 1.0,
163
+ buckets: [
164
+ { price: 1.0, sentiment: 0.2 },
165
+ { price: 1.0005, sentiment: -0.3 },
166
+ { price: 1.001, sentiment: 0.5 },
167
+ ],
168
+ },
169
+ ],
170
+ bucketWidth: 0.0005,
171
+ sentimentThresholdMin: 0.15,
172
+ sentimentThresholdMax: 0.55,
173
+ },
174
+ };
175
+ const result = processOrderPositionBooks(mockData, dates);
176
+ expect(result.buckets[0]).toEqual([
177
+ { price: 1.0, sentiment: 0.2 },
178
+ { price: 1.0005, sentiment: -0.3 },
179
+ { price: 1.001, sentiment: 0.5 },
86
180
  ]);
87
- const result = processOrderPositionBooks(mockData, candleMap);
88
- expect(result).toHaveLength(1);
89
- expect(result[0]).toEqual(['2025-01-01', null, 0]);
90
181
  });
91
182
 
92
- it('should correctly assign index to each book', () => {
183
+ it('should handle duplicate time values in books array (last one wins)', () => {
184
+ const dates = ['2025-01-01T00:00:00Z'];
93
185
  const mockData: GetOrderPositionBooksQuery = {
94
- orderPositionBooks: [
95
- createMockOrderPositionBook('2025-01-01'),
96
- createMockOrderPositionBook('2025-01-02'),
97
- createMockOrderPositionBook('2025-01-03'),
98
- ],
186
+ orderPositionBooks: {
187
+ books: [
188
+ {
189
+ time: '2025-01-01T00:00:00Z',
190
+ price: 1.0,
191
+ buckets: [{ price: 1.0, sentiment: 0.2 }],
192
+ },
193
+ {
194
+ time: '2025-01-01T00:00:00Z',
195
+ price: 1.5,
196
+ buckets: [{ price: 1.5, sentiment: 0.8 }],
197
+ },
198
+ ],
199
+ bucketWidth: 0.0005,
200
+ sentimentThresholdMin: 0.15,
201
+ sentimentThresholdMax: 0.55,
202
+ },
99
203
  };
100
- const candleMap = new Map();
101
- const result = processOrderPositionBooks(mockData, candleMap);
102
- expect(result).toHaveLength(3);
103
- expect(result[0][2]).toBe(0);
104
- expect(result[1][2]).toBe(1);
105
- expect(result[2][2]).toBe(2);
204
+ const result = processOrderPositionBooks(mockData, dates);
205
+ // Last entry should win
206
+ expect(result.bookPrices[0]).toBe(1.5);
207
+ expect(result.buckets[0]).toEqual([{ price: 1.5, sentiment: 0.8 }]);
106
208
  });
107
209
 
108
- it('should handle mixed cases with and without candles', () => {
210
+ it('should return empty arrays when dates array is empty', () => {
109
211
  const mockData: GetOrderPositionBooksQuery = {
110
- orderPositionBooks: [
111
- createMockOrderPositionBook('2025-01-01'),
112
- createMockOrderPositionBook('2025-01-02'),
113
- createMockOrderPositionBook('2025-01-03'),
114
- ],
212
+ orderPositionBooks: {
213
+ books: [createMockOrderPositionBook('2025-01-01T00:00:00Z')],
214
+ bucketWidth: 0.0005,
215
+ sentimentThresholdMin: 0.15,
216
+ sentimentThresholdMax: 0.55,
217
+ },
115
218
  };
116
- const candleMap = new Map([
117
- ['2025-01-01', { high: 1.1111 }],
118
- // 2025-01-02 missing from map
119
- ['2025-01-03', { high: 1.3333 }],
120
- ]);
121
- const result = processOrderPositionBooks(mockData, candleMap);
122
- expect(result).toHaveLength(3);
123
- expect(result[0]).toEqual(['2025-01-01', 1.1111, 0]);
124
- expect(result[1]).toEqual(['2025-01-02', null, 1]);
125
- expect(result[2]).toEqual(['2025-01-03', 1.3333, 2]);
219
+ const result = processOrderPositionBooks(mockData, []);
220
+ expect(result).toEqual({
221
+ bookPrices: [],
222
+ bookIndexes: [],
223
+ buckets: [],
224
+ bucketWidth: 0,
225
+ sentimentThresholdMin: 0,
226
+ sentimentThresholdMax: 0,
227
+ hasValidBooks: false,
228
+ });
229
+ });
230
+
231
+ it('should return empty arrays when dates is not an array', () => {
232
+ const mockData: GetOrderPositionBooksQuery = {
233
+ orderPositionBooks: {
234
+ books: [createMockOrderPositionBook('2025-01-01T00:00:00Z')],
235
+ bucketWidth: 0.0005,
236
+ sentimentThresholdMin: 0.15,
237
+ sentimentThresholdMax: 0.55,
238
+ },
239
+ };
240
+ // @ts-expect-error - Testing invalid input
241
+ const result = processOrderPositionBooks(mockData, null);
242
+ expect(result.hasValidBooks).toBe(false);
126
243
  });
127
244
  });