@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
@@ -1,148 +0,0 @@
1
- import { getLineCommons } from '@oanda/labs-widget-common';
2
-
3
- import { CHART_CONFIG } from '../../../constants';
4
-
5
- export const getGridLines = ({
6
- isDark,
7
- isDesktop,
8
- }: {
9
- isDark: boolean;
10
- isDesktop: boolean;
11
- }) => {
12
- const {
13
- WIDTH,
14
- MAIN_HEIGHT,
15
- MARGIN_BETWEEN,
16
- SENTIMENT_HEIGHT,
17
- X_LABEL_SIZE,
18
- Y_LABEL_SIZE_DESKTOP,
19
- Y_LABEL_SIZE_MOBILE,
20
- } = CHART_CONFIG;
21
- return [
22
- // Main Top
23
- {
24
- ...getLineCommons(isDark),
25
- top: -2,
26
- shape: {
27
- x1: 0,
28
- y1: 0,
29
- x2: WIDTH,
30
- y2: 0,
31
- },
32
- },
33
- // Main Right
34
- {
35
- ...getLineCommons(isDark),
36
- right: -2,
37
- shape: {
38
- x1: 0,
39
- y1: 0,
40
- x2: 0,
41
- y2: MAIN_HEIGHT + X_LABEL_SIZE + 2,
42
- },
43
- },
44
- // Main Bottom
45
- {
46
- ...getLineCommons(isDark),
47
- top: MAIN_HEIGHT - 2,
48
- shape: {
49
- x1: 0,
50
- y1: 0,
51
- x2: WIDTH,
52
- y2: 0,
53
- },
54
- },
55
- // Main Left
56
- {
57
- ...getLineCommons(isDark),
58
- left: -2,
59
- shape: {
60
- x1: 0,
61
- y1: 0,
62
- x2: 0,
63
- y2: MAIN_HEIGHT + X_LABEL_SIZE + 2,
64
- },
65
- },
66
- // Main Y Label
67
- {
68
- ...getLineCommons(isDark),
69
- right: (isDesktop ? Y_LABEL_SIZE_DESKTOP : Y_LABEL_SIZE_MOBILE) - 2,
70
- top: -2,
71
- shape: {
72
- x1: 0,
73
- y1: 0,
74
- x2: 0,
75
- y2: MAIN_HEIGHT,
76
- },
77
- },
78
- // Main X Label
79
- {
80
- ...getLineCommons(isDark),
81
- top: MAIN_HEIGHT + X_LABEL_SIZE,
82
- shape: {
83
- x1: 0,
84
- y1: 0,
85
- x2: WIDTH,
86
- y2: 0,
87
- },
88
- },
89
- // Sentiment Top
90
- {
91
- ...getLineCommons(isDark),
92
- top: MAIN_HEIGHT + X_LABEL_SIZE + MARGIN_BETWEEN - 2,
93
- shape: {
94
- x1: 0,
95
- y1: 0,
96
- x2: WIDTH,
97
- y2: 0,
98
- },
99
- },
100
- // Sentiment Right
101
- {
102
- ...getLineCommons(isDark),
103
- top: MAIN_HEIGHT + X_LABEL_SIZE + MARGIN_BETWEEN - 2,
104
- right: -2,
105
- shape: {
106
- x1: 0,
107
- y1: 0,
108
- x2: 0,
109
- y2: SENTIMENT_HEIGHT,
110
- },
111
- },
112
- // Sentiment Bottom
113
- {
114
- ...getLineCommons(isDark),
115
- top: MAIN_HEIGHT + X_LABEL_SIZE + MARGIN_BETWEEN + SENTIMENT_HEIGHT - 3,
116
- shape: {
117
- x1: 0,
118
- y1: 0,
119
- x2: WIDTH,
120
- y2: 0,
121
- },
122
- },
123
- // Sentiment Left
124
- {
125
- ...getLineCommons(isDark),
126
- top: MAIN_HEIGHT + X_LABEL_SIZE + MARGIN_BETWEEN - 2,
127
- left: -2,
128
- shape: {
129
- x1: 0,
130
- y1: 0,
131
- x2: 0,
132
- y2: SENTIMENT_HEIGHT,
133
- },
134
- },
135
- // Sentiment Y Label
136
- {
137
- ...getLineCommons(isDark),
138
- right: (isDesktop ? Y_LABEL_SIZE_DESKTOP : Y_LABEL_SIZE_MOBILE) - 3,
139
- top: MAIN_HEIGHT + X_LABEL_SIZE + MARGIN_BETWEEN - 2,
140
- shape: {
141
- x1: 0,
142
- y1: 0,
143
- x2: 0,
144
- y2: SENTIMENT_HEIGHT,
145
- },
146
- },
147
- ];
148
- };
@@ -1,13 +0,0 @@
1
- import { Granularity } from '../../../../gql/types/graphql';
2
- import { BUCKET_CONFIG, INSTRUMENTS_CONFIG } from '../../../constants';
3
- import type { InstrumentId } from '../../../types';
4
-
5
- export const getTargetBucketWidth = (
6
- granularity: Granularity,
7
- instrument: InstrumentId
8
- ): number => {
9
- const bucketWidth = INSTRUMENTS_CONFIG[instrument].defaultBucketWidth;
10
- return granularity === Granularity.H1 || granularity === Granularity.H4
11
- ? bucketWidth * BUCKET_CONFIG.MULTIPLIER
12
- : bucketWidth;
13
- };
@@ -1,9 +0,0 @@
1
- export * from './aggregateBuckets';
2
- export * from './chartUtils';
3
- export * from './getChartStyles';
4
- export * from './getTargetBucketWidth';
5
- export * from './processBuckets';
6
- export * from './processOrderPositionBooks';
7
- export * from './processPriceCandles';
8
- export * from './processSentiments';
9
- export * from './validateData';
@@ -1,43 +0,0 @@
1
- import type { GetOrderPositionBooksQuery } from '../../../../gql/types/graphql';
2
- import { BOOKS_THRESHOLDS } from '../../../constants';
3
- import type { Bucket } from '../types';
4
- import { aggregateBuckets } from './aggregateBuckets';
5
-
6
- export const processBuckets = (
7
- orderPositionData: GetOrderPositionBooksQuery | undefined,
8
- targetBucketWidth: number
9
- ): Bucket[][] => {
10
- if (!orderPositionData?.orderPositionBooks?.length) {
11
- return [];
12
- }
13
-
14
- return orderPositionData.orderPositionBooks
15
- .filter((book): book is NonNullable<typeof book> => {
16
- return book !== null && book.buckets?.length > 0;
17
- })
18
- .map((book) => {
19
- const validBuckets = book.buckets
20
- .filter(
21
- (bucket): bucket is NonNullable<typeof bucket> =>
22
- bucket !== null &&
23
- bucket.price !== undefined &&
24
- bucket.sentiment !== undefined &&
25
- bucket.sentiment !== null
26
- )
27
- .map((bucket) => ({
28
- price: bucket.price!,
29
- sentiment: bucket.sentiment!,
30
- }));
31
-
32
- const bucketsToFilter =
33
- targetBucketWidth > (book.bucketWidth ?? 0)
34
- ? aggregateBuckets(validBuckets, targetBucketWidth)
35
- : validBuckets;
36
-
37
- const filteredBuckets = bucketsToFilter.filter(
38
- (bucket: Bucket) => Math.abs(bucket.sentiment) >= BOOKS_THRESHOLDS.MIN
39
- );
40
-
41
- return filteredBuckets;
42
- });
43
- };
@@ -1,30 +0,0 @@
1
- import type { GetOrderPositionBooksQuery } from '../../../../gql/types/graphql';
2
-
3
- export const processOrderPositionBooks = (
4
- orderPositionData: GetOrderPositionBooksQuery | undefined,
5
- candleMap: Map<
6
- string,
7
- {
8
- point?: string;
9
- high?: number;
10
- low?: number;
11
- open?: number;
12
- close?: number;
13
- }
14
- >
15
- ): [string, number | null, number][] => {
16
- if (!orderPositionData?.orderPositionBooks?.length) {
17
- return [];
18
- }
19
-
20
- return orderPositionData.orderPositionBooks
21
- .filter((book): book is NonNullable<typeof book> => {
22
- return book !== null && book.buckets?.length > 0;
23
- })
24
- .map((book, index) => {
25
- const candle = candleMap.get(book.time);
26
- const price = candle?.high ?? null;
27
-
28
- return [book.time, price, index] as [string, number | null, number];
29
- });
30
- };
@@ -1,53 +0,0 @@
1
- import type { GetPriceCandlesQuery } from '../../../../gql/types/graphql';
2
-
3
- export const processPriceCandles = (
4
- priceCandlesData: GetPriceCandlesQuery | undefined
5
- ) => {
6
- if (!priceCandlesData?.priceCandles?.candle?.length) {
7
- return {
8
- minPrice: 0,
9
- maxPrice: 0,
10
- hasValidCandles: false,
11
- candleMap: new Map(),
12
- candles: [],
13
- };
14
- }
15
-
16
- const candles = priceCandlesData.priceCandles.candle;
17
- let calculatedMinPrice = Number.MAX_VALUE;
18
- let calculatedMaxPrice = Number.MIN_VALUE;
19
-
20
- const candleMap = new Map<
21
- string,
22
- {
23
- point?: string;
24
- high?: number;
25
- low?: number;
26
- open?: number;
27
- close?: number;
28
- }
29
- >();
30
-
31
- candles.forEach((candle) => {
32
- if (!candle) return;
33
-
34
- if (candle.high > calculatedMaxPrice) {
35
- calculatedMaxPrice = candle.high;
36
- }
37
- if (candle.low < calculatedMinPrice) {
38
- calculatedMinPrice = candle.low;
39
- }
40
-
41
- if (candle.point) {
42
- candleMap.set(candle.point, candle);
43
- }
44
- });
45
-
46
- return {
47
- minPrice: calculatedMinPrice,
48
- maxPrice: calculatedMaxPrice,
49
- hasValidCandles: true,
50
- candleMap,
51
- candles,
52
- };
53
- };
@@ -1,42 +0,0 @@
1
- import type { GetSentimentsQuery } from '../../../../gql/types/graphql';
2
- import type { ProcessedSentiment } from '../types';
3
-
4
- export const processSentiments = (
5
- sentimentsData: GetSentimentsQuery | undefined,
6
- xAxisData: string[]
7
- ): ProcessedSentiment[] => {
8
- if (!sentimentsData?.sentiments?.sentiments?.length) {
9
- return [];
10
- }
11
-
12
- const sentimentMap = new Map(
13
- sentimentsData.sentiments.sentiments
14
- .filter(
15
- (item): item is NonNullable<typeof item> =>
16
- item?.time != null &&
17
- item.sentiment?.shortPercent != null &&
18
- item.sentiment?.longPercent != null
19
- )
20
- .map((item) => [
21
- item.time,
22
- {
23
- shortPercent: item.sentiment.shortPercent,
24
- longPercent: item.sentiment.longPercent,
25
- },
26
- ])
27
- );
28
-
29
- return xAxisData
30
- .map((time) => {
31
- const sentiment = sentimentMap.get(time);
32
- if (!sentiment) {
33
- return undefined;
34
- }
35
- return [
36
- time,
37
- sentiment.shortPercent,
38
- sentiment.longPercent,
39
- ] as ProcessedSentiment;
40
- })
41
- .filter((item): item is ProcessedSentiment => item !== undefined);
42
- };
@@ -1,82 +0,0 @@
1
- import { aggregateBuckets } from '../../src/CrowdViewWidget/components';
2
-
3
- describe('aggregateBuckets', () => {
4
- it('should correctly aggregate a standard set of buckets', () => {
5
- const buckets = [
6
- { price: 1, sentiment: 1 },
7
- { price: 1.05, sentiment: 2 },
8
- { price: 1.1, sentiment: 4 },
9
- { price: 1.15, sentiment: 3 },
10
- { price: 1.2, sentiment: 7 },
11
- { price: 1.35, sentiment: 8 },
12
- { price: 1.6, sentiment: 10 },
13
- { price: 1.65, sentiment: 1 },
14
- { price: 1.8, sentiment: 18 },
15
- ];
16
- const newBucketWidth = 0.1;
17
- const expected = [
18
- { price: 1.0, sentiment: 3 },
19
- { price: 1.1, sentiment: 7 },
20
- { price: 1.2, sentiment: 7 },
21
- { price: 1.3, sentiment: 8 },
22
- { price: 1.6, sentiment: 11 },
23
- { price: 1.8, sentiment: 18 },
24
- ];
25
-
26
- expect(aggregateBuckets(buckets, newBucketWidth)).toEqual(expected);
27
- });
28
-
29
- it('should return an empty array if the input array is empty', () => {
30
- expect(aggregateBuckets([], 0.1)).toEqual([]);
31
- });
32
-
33
- it('should correctly process an array with a single bucket', () => {
34
- const buckets = [{ price: 2.58, sentiment: 15 }];
35
- const newBucketWidth = 0.2;
36
- const expected = [{ price: 2.4, sentiment: 15 }];
37
-
38
- expect(aggregateBuckets(buckets, newBucketWidth)).toEqual(expected);
39
- });
40
-
41
- it('should handle gaps in data without creating empty buckets', () => {
42
- const buckets = [
43
- { price: 10.1, sentiment: 5 }, // Belongs to bucket 10.0
44
- { price: 10.9, sentiment: 8 }, // Belongs to bucket 10.8
45
- ];
46
- const newBucketWidth = 0.2;
47
- const expected = [
48
- { price: 10.0, sentiment: 5 },
49
- { price: 10.8, sentiment: 8 },
50
- ];
51
-
52
- expect(aggregateBuckets(buckets, newBucketWidth)).toEqual(expected);
53
- });
54
-
55
- it('should aggregate all items into a single bucket if they fall within the new width', () => {
56
- const buckets = [
57
- { price: 1.1, sentiment: 10 },
58
- { price: 1.5, sentiment: 20 },
59
- { price: 1.9, sentiment: 30 },
60
- ];
61
- const newBucketWidth = 2.0;
62
- const expected = [{ price: 0.0, sentiment: 60 }];
63
-
64
- expect(aggregateBuckets(buckets, newBucketWidth)).toEqual(expected);
65
- });
66
-
67
- it('should correctly sum sentiments including zero and negative values', () => {
68
- const buckets = [
69
- { price: 5.0, sentiment: 100 },
70
- { price: 5.05, sentiment: -20 },
71
- { price: 5.11, sentiment: 0 },
72
- { price: 5.18, sentiment: 5 },
73
- ];
74
- const newBucketWidth = 0.1;
75
- const expected = [
76
- { price: 5.0, sentiment: 80 },
77
- { price: 5.1, sentiment: 5 },
78
- ];
79
-
80
- expect(aggregateBuckets(buckets, newBucketWidth)).toEqual(expected);
81
- });
82
- });
@@ -1,37 +0,0 @@
1
- import { getTargetBucketWidth } from '../../src/CrowdViewWidget/components';
2
- import {
3
- BUCKET_CONFIG,
4
- INSTRUMENTS_CONFIG,
5
- } from '../../src/CrowdViewWidget/constants';
6
- import { InstrumentId } from '../../src/CrowdViewWidget/types';
7
- import { Granularity } from '../../src/gql/types/graphql';
8
-
9
- describe('getTargetBucketWidth', () => {
10
- const instrument = InstrumentId.EUR_AUD;
11
- const { defaultBucketWidth } = INSTRUMENTS_CONFIG[instrument];
12
- const optimizedBucketWidth = defaultBucketWidth * BUCKET_CONFIG.MULTIPLIER;
13
-
14
- it('should return optimized width for H1 granularity', () => {
15
- expect(getTargetBucketWidth(Granularity.H1, instrument)).toBe(
16
- optimizedBucketWidth
17
- );
18
- });
19
-
20
- it('should return optimized width for H4 granularity', () => {
21
- expect(getTargetBucketWidth(Granularity.H4, instrument)).toBe(
22
- optimizedBucketWidth
23
- );
24
- });
25
-
26
- it('should return default width for M5 granularity', () => {
27
- expect(getTargetBucketWidth(Granularity.M5, instrument)).toBe(
28
- defaultBucketWidth
29
- );
30
- });
31
-
32
- it('should return default width for M15 granularity', () => {
33
- expect(getTargetBucketWidth(Granularity.M15, instrument)).toBe(
34
- defaultBucketWidth
35
- );
36
- });
37
- });
@@ -1,153 +0,0 @@
1
- import { processBuckets } from '../../src/CrowdViewWidget/components';
2
- import type { GetOrderPositionBooksQuery } from '../../src/gql/types/graphql';
3
-
4
- describe('processBuckets', () => {
5
- const DEFAULT_BUCKET_WIDTH = 0.0005;
6
- const OPTIMIZED_BUCKET_WIDTH = 0.002; // DEFAULT_BUCKET_WIDTH * 4
7
-
8
- const createMockOrderPositionBook = (
9
- time: string,
10
- buckets: Array<{ price: number; sentiment: number | null } | null>,
11
- bucketWidth: number = DEFAULT_BUCKET_WIDTH
12
- ) => ({
13
- bucketWidth,
14
- price: 1.0,
15
- time,
16
- buckets,
17
- });
18
-
19
- it('should return empty array when orderPositionData is undefined', () => {
20
- expect(processBuckets(undefined, DEFAULT_BUCKET_WIDTH)).toEqual([]);
21
- });
22
-
23
- it('should return empty array when orderPositionBooks is empty', () => {
24
- const mockData: GetOrderPositionBooksQuery = {
25
- orderPositionBooks: [],
26
- };
27
- expect(processBuckets(mockData, DEFAULT_BUCKET_WIDTH)).toEqual([]);
28
- });
29
-
30
- it('should filter out null books', () => {
31
- const mockData: GetOrderPositionBooksQuery = {
32
- orderPositionBooks: [null, createMockOrderPositionBook('2025-01-01', [])],
33
- };
34
- expect(processBuckets(mockData, DEFAULT_BUCKET_WIDTH)).toEqual([]);
35
- });
36
-
37
- it('should filter out books with no buckets', () => {
38
- const mockData: GetOrderPositionBooksQuery = {
39
- orderPositionBooks: [
40
- createMockOrderPositionBook('2025-01-01', []),
41
- createMockOrderPositionBook('2025-01-02', [
42
- { price: 1.0, sentiment: 0.2 },
43
- ]),
44
- ],
45
- };
46
- const result = processBuckets(mockData, DEFAULT_BUCKET_WIDTH);
47
- expect(result).toHaveLength(1);
48
- expect(result[0]).toEqual([{ price: 1.0, sentiment: 0.2 }]);
49
- });
50
-
51
- it('should filter out null buckets and buckets with missing price or sentiment', () => {
52
- const mockData: GetOrderPositionBooksQuery = {
53
- orderPositionBooks: [
54
- createMockOrderPositionBook('2025-01-01', [
55
- null,
56
- { price: 1.0, sentiment: null },
57
- { price: undefined as any, sentiment: 0.2 },
58
- { price: 1.1, sentiment: 0.2 },
59
- ]),
60
- ],
61
- };
62
- const result = processBuckets(mockData, DEFAULT_BUCKET_WIDTH);
63
- expect(result).toHaveLength(1);
64
- expect(result[0]).toEqual([{ price: 1.1, sentiment: 0.2 }]);
65
- });
66
-
67
- it('should filter out buckets below sentiment threshold', () => {
68
- const mockData: GetOrderPositionBooksQuery = {
69
- orderPositionBooks: [
70
- createMockOrderPositionBook('2025-01-01', [
71
- { price: 1.0, sentiment: 0.1 }, // below threshold
72
- { price: 1.1, sentiment: 0.15 }, // at threshold
73
- { price: 1.2, sentiment: 0.2 }, // above threshold
74
- { price: 1.3, sentiment: -0.1 }, // below threshold (absolute)
75
- { price: 1.4, sentiment: -0.15 }, // at threshold (absolute)
76
- { price: 1.5, sentiment: -0.2 }, // above threshold (absolute)
77
- ]),
78
- ],
79
- };
80
- const result = processBuckets(mockData, DEFAULT_BUCKET_WIDTH);
81
- expect(result).toHaveLength(1);
82
- expect(result[0]).toEqual([
83
- { price: 1.1, sentiment: 0.15 },
84
- { price: 1.2, sentiment: 0.2 },
85
- { price: 1.4, sentiment: -0.15 },
86
- { price: 1.5, sentiment: -0.2 },
87
- ]);
88
- });
89
-
90
- it('should aggregate buckets when using optimized width', () => {
91
- const mockData: GetOrderPositionBooksQuery = {
92
- orderPositionBooks: [
93
- createMockOrderPositionBook(
94
- '2025-01-01',
95
- [
96
- { price: 1.0, sentiment: 0.2 },
97
- { price: 1.0003, sentiment: 0.3 },
98
- { price: 1.0007, sentiment: 0.1 },
99
- { price: 1.0012, sentiment: 0.25 },
100
- ],
101
- DEFAULT_BUCKET_WIDTH
102
- ),
103
- ],
104
- };
105
- const result = processBuckets(mockData, OPTIMIZED_BUCKET_WIDTH);
106
- expect(result).toHaveLength(1);
107
- // Buckets should be aggregated: 1.0 + 1.0003 + 1.0007 = 1.0 bucket (0.6 sentiment)
108
- // 1.0012 = 1.001 bucket (0.25 sentiment)
109
- expect(result[0].length).toBeGreaterThan(0);
110
- const aggregatedSentiments = result[0].reduce(
111
- (acc, bucket) => acc + bucket.sentiment,
112
- 0
113
- );
114
- expect(aggregatedSentiments).toBeCloseTo(0.85, 2);
115
- });
116
-
117
- it('should not aggregate buckets when using default width', () => {
118
- const mockData: GetOrderPositionBooksQuery = {
119
- orderPositionBooks: [
120
- createMockOrderPositionBook('2025-01-01', [
121
- { price: 1.0, sentiment: 0.2 },
122
- { price: 1.0003, sentiment: 0.3 },
123
- { price: 1.0012, sentiment: 0.25 },
124
- ]),
125
- ],
126
- };
127
- const result = processBuckets(mockData, DEFAULT_BUCKET_WIDTH);
128
- expect(result).toHaveLength(1);
129
- // Should have same number of buckets as input (assuming all pass threshold)
130
- expect(result[0].length).toBeGreaterThanOrEqual(3);
131
- });
132
-
133
- it('should process multiple books correctly', () => {
134
- const mockData: GetOrderPositionBooksQuery = {
135
- orderPositionBooks: [
136
- createMockOrderPositionBook('2025-01-01', [
137
- { price: 1.0, sentiment: 0.2 },
138
- ]),
139
- createMockOrderPositionBook('2025-01-02', [
140
- { price: 1.1, sentiment: 0.3 },
141
- { price: 1.2, sentiment: 0.4 },
142
- ]),
143
- ],
144
- };
145
- const result = processBuckets(mockData, DEFAULT_BUCKET_WIDTH);
146
- expect(result).toHaveLength(2);
147
- expect(result[0]).toEqual([{ price: 1.0, sentiment: 0.2 }]);
148
- expect(result[1]).toEqual([
149
- { price: 1.1, sentiment: 0.3 },
150
- { price: 1.2, sentiment: 0.4 },
151
- ]);
152
- });
153
- });