@oanda/labs-crowd-view-widget 1.0.51 → 1.0.53

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 (153) hide show
  1. package/CHANGELOG.md +428 -0
  2. package/dist/main/CrowdViewWidget/Main.js +1 -5
  3. package/dist/main/CrowdViewWidget/Main.js.map +1 -1
  4. package/dist/main/CrowdViewWidget/components/Chart/Chart.js +73 -24
  5. package/dist/main/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
  6. package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js +18 -9
  7. package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
  8. package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js +265 -59
  9. package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -1
  10. package/dist/main/CrowdViewWidget/components/Chart/types.js.map +1 -1
  11. package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js +68 -26
  12. package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
  13. package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js +20 -19
  14. package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -1
  15. package/dist/main/CrowdViewWidget/components/Chart/utils/getChartStyles.js +27 -0
  16. package/dist/main/CrowdViewWidget/components/Chart/utils/getChartStyles.js.map +1 -0
  17. package/dist/main/CrowdViewWidget/components/Chart/utils/getGridLines.js +123 -0
  18. package/dist/main/CrowdViewWidget/components/Chart/utils/getGridLines.js.map +1 -0
  19. package/dist/main/CrowdViewWidget/components/Chart/utils/index.js +15 -26
  20. package/dist/main/CrowdViewWidget/components/Chart/utils/index.js.map +1 -1
  21. package/dist/main/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js +54 -12
  22. package/dist/main/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js.map +1 -1
  23. package/dist/main/CrowdViewWidget/components/Chart/utils/processPriceCandles.js +49 -27
  24. package/dist/main/CrowdViewWidget/components/Chart/utils/processPriceCandles.js.map +1 -1
  25. package/dist/main/CrowdViewWidget/components/Chart/utils/processSentiments.js +43 -0
  26. package/dist/main/CrowdViewWidget/components/Chart/utils/processSentiments.js.map +1 -0
  27. package/dist/main/CrowdViewWidget/components/Chart/utils/validateData.js +8 -2
  28. package/dist/main/CrowdViewWidget/components/Chart/utils/validateData.js.map +1 -1
  29. package/dist/main/CrowdViewWidget/components/Legend/Legend.js +3 -4
  30. package/dist/main/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
  31. package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js +2 -2
  32. package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
  33. package/dist/main/CrowdViewWidget/constants.js +14 -8
  34. package/dist/main/CrowdViewWidget/constants.js.map +1 -1
  35. package/dist/main/gql/getOrderPositionBooks.js +1 -1
  36. package/dist/main/gql/getOrderPositionBooks.js.map +1 -1
  37. package/dist/main/gql/getPriceCandles.js +1 -1
  38. package/dist/main/gql/getPriceCandles.js.map +1 -1
  39. package/dist/main/gql/getSentiments.js +11 -0
  40. package/dist/main/gql/getSentiments.js.map +1 -0
  41. package/dist/main/gql/types/gql.js +3 -2
  42. package/dist/main/gql/types/gql.js.map +1 -1
  43. package/dist/main/gql/types/graphql.js +273 -19
  44. package/dist/main/gql/types/graphql.js.map +1 -1
  45. package/dist/module/CrowdViewWidget/Main.js +2 -6
  46. package/dist/module/CrowdViewWidget/Main.js.map +1 -1
  47. package/dist/module/CrowdViewWidget/components/Chart/Chart.js +76 -27
  48. package/dist/module/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
  49. package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js +18 -9
  50. package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
  51. package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js +265 -60
  52. package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -1
  53. package/dist/module/CrowdViewWidget/components/Chart/types.js.map +1 -1
  54. package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js +69 -27
  55. package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
  56. package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js +21 -20
  57. package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -1
  58. package/dist/module/CrowdViewWidget/components/Chart/utils/getChartStyles.js +20 -0
  59. package/dist/module/CrowdViewWidget/components/Chart/utils/getChartStyles.js.map +1 -0
  60. package/dist/module/CrowdViewWidget/components/Chart/utils/getGridLines.js +116 -0
  61. package/dist/module/CrowdViewWidget/components/Chart/utils/getGridLines.js.map +1 -0
  62. package/dist/module/CrowdViewWidget/components/Chart/utils/index.js +2 -3
  63. package/dist/module/CrowdViewWidget/components/Chart/utils/index.js.map +1 -1
  64. package/dist/module/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js +54 -12
  65. package/dist/module/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js.map +1 -1
  66. package/dist/module/CrowdViewWidget/components/Chart/utils/processPriceCandles.js +49 -27
  67. package/dist/module/CrowdViewWidget/components/Chart/utils/processPriceCandles.js.map +1 -1
  68. package/dist/module/CrowdViewWidget/components/Chart/utils/processSentiments.js +36 -0
  69. package/dist/module/CrowdViewWidget/components/Chart/utils/processSentiments.js.map +1 -0
  70. package/dist/module/CrowdViewWidget/components/Chart/utils/validateData.js +8 -2
  71. package/dist/module/CrowdViewWidget/components/Chart/utils/validateData.js.map +1 -1
  72. package/dist/module/CrowdViewWidget/components/Legend/Legend.js +3 -4
  73. package/dist/module/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
  74. package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js +2 -2
  75. package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
  76. package/dist/module/CrowdViewWidget/constants.js +13 -7
  77. package/dist/module/CrowdViewWidget/constants.js.map +1 -1
  78. package/dist/module/gql/getOrderPositionBooks.js +1 -1
  79. package/dist/module/gql/getOrderPositionBooks.js.map +1 -1
  80. package/dist/module/gql/getPriceCandles.js +1 -1
  81. package/dist/module/gql/getPriceCandles.js.map +1 -1
  82. package/dist/module/gql/getSentiments.js +6 -0
  83. package/dist/module/gql/getSentiments.js.map +1 -0
  84. package/dist/module/gql/types/gql.js +3 -2
  85. package/dist/module/gql/types/gql.js.map +1 -1
  86. package/dist/module/gql/types/graphql.js +272 -18
  87. package/dist/module/gql/types/graphql.js.map +1 -1
  88. package/dist/types/CrowdViewWidget/components/Chart/Chart.d.ts +1 -1
  89. package/dist/types/CrowdViewWidget/components/Chart/types.d.ts +69 -9
  90. package/dist/types/CrowdViewWidget/components/Chart/utils/chartUtils.d.ts +5 -6
  91. package/dist/types/CrowdViewWidget/components/Chart/utils/getChartStyles.d.ts +10 -0
  92. package/dist/types/CrowdViewWidget/components/Chart/utils/getGridLines.d.ts +97 -0
  93. package/dist/types/CrowdViewWidget/components/Chart/utils/index.d.ts +2 -3
  94. package/dist/types/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.d.ts +10 -7
  95. package/dist/types/CrowdViewWidget/components/Chart/utils/processPriceCandles.d.ts +6 -21
  96. package/dist/types/CrowdViewWidget/components/Chart/utils/processSentiments.d.ts +6 -0
  97. package/dist/types/CrowdViewWidget/components/Chart/utils/validateData.d.ts +1 -1
  98. package/dist/types/CrowdViewWidget/components/Legend/Legend.d.ts +2 -2
  99. package/dist/types/CrowdViewWidget/components/Legend/LegendBar.d.ts +1 -1
  100. package/dist/types/CrowdViewWidget/constants.d.ts +12 -6
  101. package/dist/types/gql/getSentiments.d.ts +2 -0
  102. package/dist/types/gql/types/gql.d.ts +15 -4
  103. package/dist/types/gql/types/graphql.d.ts +66 -11
  104. package/package.json +3 -3
  105. package/src/CrowdViewWidget/Main.tsx +2 -4
  106. package/src/CrowdViewWidget/components/Chart/Chart.tsx +99 -38
  107. package/src/CrowdViewWidget/components/Chart/ChartWithData.tsx +24 -7
  108. package/src/CrowdViewWidget/components/Chart/chartOptions.ts +305 -87
  109. package/src/CrowdViewWidget/components/Chart/types.ts +82 -16
  110. package/src/CrowdViewWidget/components/Chart/useCrowdViewData.ts +105 -56
  111. package/src/CrowdViewWidget/components/Chart/utils/chartUtils.ts +65 -34
  112. package/src/CrowdViewWidget/components/Chart/utils/getChartStyles.ts +42 -0
  113. package/src/CrowdViewWidget/components/Chart/utils/getGridLines.ts +148 -0
  114. package/src/CrowdViewWidget/components/Chart/utils/index.ts +2 -3
  115. package/src/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.ts +84 -22
  116. package/src/CrowdViewWidget/components/Chart/utils/processPriceCandles.ts +52 -38
  117. package/src/CrowdViewWidget/components/Chart/utils/processSentiments.ts +55 -0
  118. package/src/CrowdViewWidget/components/Chart/utils/validateData.ts +10 -2
  119. package/src/CrowdViewWidget/components/Legend/Legend.tsx +5 -6
  120. package/src/CrowdViewWidget/components/Legend/LegendBar.tsx +3 -3
  121. package/src/CrowdViewWidget/constants.ts +18 -7
  122. package/src/gql/getOrderPositionBooks.ts +13 -5
  123. package/src/gql/getPriceCandles.ts +1 -0
  124. package/src/gql/getSentiments.ts +25 -0
  125. package/src/gql/types/gql.ts +14 -6
  126. package/src/gql/types/graphql.ts +259 -16
  127. package/test/components/Chart/utils/chartUtils.test.ts +105 -13
  128. package/test/components/Chart/utils/getChartStyles.test.ts +64 -0
  129. package/test/components/Chart/utils/processSentiments.test.ts +238 -0
  130. package/test/utils/processOrderPositionBooks.test.ts +201 -84
  131. package/test/utils/processPriceCandles.test.ts +93 -67
  132. package/test/utils/validateData.test.ts +136 -38
  133. package/dist/main/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js +0 -37
  134. package/dist/main/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js.map +0 -1
  135. package/dist/main/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js +0 -14
  136. package/dist/main/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js.map +0 -1
  137. package/dist/main/CrowdViewWidget/components/Chart/utils/processBuckets.js +0 -29
  138. package/dist/main/CrowdViewWidget/components/Chart/utils/processBuckets.js.map +0 -1
  139. package/dist/module/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js +0 -29
  140. package/dist/module/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js.map +0 -1
  141. package/dist/module/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js +0 -7
  142. package/dist/module/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js.map +0 -1
  143. package/dist/module/CrowdViewWidget/components/Chart/utils/processBuckets.js +0 -22
  144. package/dist/module/CrowdViewWidget/components/Chart/utils/processBuckets.js.map +0 -1
  145. package/dist/types/CrowdViewWidget/components/Chart/utils/aggregateBuckets.d.ts +0 -2
  146. package/dist/types/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.d.ts +0 -3
  147. package/dist/types/CrowdViewWidget/components/Chart/utils/processBuckets.d.ts +0 -3
  148. package/src/CrowdViewWidget/components/Chart/utils/aggregateBuckets.ts +0 -44
  149. package/src/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.ts +0 -13
  150. package/src/CrowdViewWidget/components/Chart/utils/processBuckets.ts +0 -43
  151. package/test/utils/aggregateBuckets.test.ts +0 -82
  152. package/test/utils/getTargetBucketWidth.test.ts +0 -37
  153. package/test/utils/processBuckets.test.ts +0 -153
@@ -1,29 +0,0 @@
1
- import Decimal from 'decimal.js';
2
- export const aggregateBuckets = (buckets, newBucketWidth) => {
3
- if (!buckets.length) {
4
- return [];
5
- }
6
- const bucketWidthDecimal = new Decimal(newBucketWidth);
7
- const aggregatedMap = new Map();
8
- for (const bucket of buckets) {
9
- var _aggregatedMap$get;
10
- const priceDecimal = new Decimal(bucket.price);
11
- const sentimentDecimal = new Decimal(bucket.sentiment);
12
- const bucketIndex = priceDecimal.div(bucketWidthDecimal).floor();
13
- const groupingKey = bucketIndex.mul(bucketWidthDecimal);
14
- const groupingKeyStr = groupingKey.toString();
15
- const currentSentiment = (_aggregatedMap$get = aggregatedMap.get(groupingKeyStr)) !== null && _aggregatedMap$get !== void 0 ? _aggregatedMap$get : new Decimal(0);
16
- aggregatedMap.set(groupingKeyStr, currentSentiment.add(sentimentDecimal));
17
- }
18
- const aggregatedBuckets = Array.from(aggregatedMap.entries()).map(_ref => {
19
- let [priceStr, sentimentDecimal] = _ref;
20
- const price = new Decimal(priceStr).toNumber();
21
- const sentiment = sentimentDecimal.toNumber();
22
- return {
23
- price,
24
- sentiment
25
- };
26
- });
27
- return aggregatedBuckets;
28
- };
29
- //# sourceMappingURL=aggregateBuckets.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"aggregateBuckets.js","names":["Decimal","aggregateBuckets","buckets","newBucketWidth","length","bucketWidthDecimal","aggregatedMap","Map","bucket","_aggregatedMap$get","priceDecimal","price","sentimentDecimal","sentiment","bucketIndex","div","floor","groupingKey","mul","groupingKeyStr","toString","currentSentiment","get","set","add","aggregatedBuckets","Array","from","entries","map","_ref","priceStr","toNumber"],"sources":["../../../../../../src/CrowdViewWidget/components/Chart/utils/aggregateBuckets.ts"],"sourcesContent":["import Decimal from 'decimal.js';\n\nimport type { Bucket } from '../types';\n\nexport const aggregateBuckets = (\n buckets: Bucket[],\n newBucketWidth: number\n): Bucket[] => {\n if (!buckets.length) {\n return [];\n }\n\n const bucketWidthDecimal = new Decimal(newBucketWidth);\n\n const aggregatedMap = new Map<string, Decimal>();\n\n for (const bucket of buckets) {\n const priceDecimal = new Decimal(bucket.price);\n const sentimentDecimal = new Decimal(bucket.sentiment);\n\n const bucketIndex = priceDecimal.div(bucketWidthDecimal).floor();\n const groupingKey = bucketIndex.mul(bucketWidthDecimal);\n\n const groupingKeyStr = groupingKey.toString();\n\n const currentSentiment =\n aggregatedMap.get(groupingKeyStr) ?? new Decimal(0);\n aggregatedMap.set(groupingKeyStr, currentSentiment.add(sentimentDecimal));\n }\n\n const aggregatedBuckets = Array.from(aggregatedMap.entries()).map(\n ([priceStr, sentimentDecimal]) => {\n const price = new Decimal(priceStr).toNumber();\n const sentiment = sentimentDecimal.toNumber();\n\n return {\n price,\n sentiment,\n };\n }\n );\n\n return aggregatedBuckets;\n};\n"],"mappings":"AAAA,OAAOA,OAAO,MAAM,YAAY;AAIhC,OAAO,MAAMC,gBAAgB,GAAGA,CAC9BC,OAAiB,EACjBC,cAAsB,KACT;EACb,IAAI,CAACD,OAAO,CAACE,MAAM,EAAE;IACnB,OAAO,EAAE;EACX;EAEA,MAAMC,kBAAkB,GAAG,IAAIL,OAAO,CAACG,cAAc,CAAC;EAEtD,MAAMG,aAAa,GAAG,IAAIC,GAAG,CAAkB,CAAC;EAEhD,KAAK,MAAMC,MAAM,IAAIN,OAAO,EAAE;IAAA,IAAAO,kBAAA;IAC5B,MAAMC,YAAY,GAAG,IAAIV,OAAO,CAACQ,MAAM,CAACG,KAAK,CAAC;IAC9C,MAAMC,gBAAgB,GAAG,IAAIZ,OAAO,CAACQ,MAAM,CAACK,SAAS,CAAC;IAEtD,MAAMC,WAAW,GAAGJ,YAAY,CAACK,GAAG,CAACV,kBAAkB,CAAC,CAACW,KAAK,CAAC,CAAC;IAChE,MAAMC,WAAW,GAAGH,WAAW,CAACI,GAAG,CAACb,kBAAkB,CAAC;IAEvD,MAAMc,cAAc,GAAGF,WAAW,CAACG,QAAQ,CAAC,CAAC;IAE7C,MAAMC,gBAAgB,IAAAZ,kBAAA,GACpBH,aAAa,CAACgB,GAAG,CAACH,cAAc,CAAC,cAAAV,kBAAA,cAAAA,kBAAA,GAAI,IAAIT,OAAO,CAAC,CAAC,CAAC;IACrDM,aAAa,CAACiB,GAAG,CAACJ,cAAc,EAAEE,gBAAgB,CAACG,GAAG,CAACZ,gBAAgB,CAAC,CAAC;EAC3E;EAEA,MAAMa,iBAAiB,GAAGC,KAAK,CAACC,IAAI,CAACrB,aAAa,CAACsB,OAAO,CAAC,CAAC,CAAC,CAACC,GAAG,CAC/DC,IAAA,IAAkC;IAAA,IAAjC,CAACC,QAAQ,EAAEnB,gBAAgB,CAAC,GAAAkB,IAAA;IAC3B,MAAMnB,KAAK,GAAG,IAAIX,OAAO,CAAC+B,QAAQ,CAAC,CAACC,QAAQ,CAAC,CAAC;IAC9C,MAAMnB,SAAS,GAAGD,gBAAgB,CAACoB,QAAQ,CAAC,CAAC;IAE7C,OAAO;MACLrB,KAAK;MACLE;IACF,CAAC;EACH,CACF,CAAC;EAED,OAAOY,iBAAiB;AAC1B,CAAC","ignoreList":[]}
@@ -1,7 +0,0 @@
1
- import { Granularity } from '../../../../gql/types/graphql';
2
- import { BUCKET_CONFIG, INSTRUMENTS_CONFIG } from '../../../constants';
3
- export const getTargetBucketWidth = (granularity, instrument) => {
4
- const bucketWidth = INSTRUMENTS_CONFIG[instrument].defaultBucketWidth;
5
- return granularity === Granularity.H1 || granularity === Granularity.H4 ? bucketWidth * BUCKET_CONFIG.MULTIPLIER : bucketWidth;
6
- };
7
- //# sourceMappingURL=getTargetBucketWidth.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getTargetBucketWidth.js","names":["Granularity","BUCKET_CONFIG","INSTRUMENTS_CONFIG","getTargetBucketWidth","granularity","instrument","bucketWidth","defaultBucketWidth","H1","H4","MULTIPLIER"],"sources":["../../../../../../src/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.ts"],"sourcesContent":["import { Granularity } from '../../../../gql/types/graphql';\nimport { BUCKET_CONFIG, INSTRUMENTS_CONFIG } from '../../../constants';\nimport type { InstrumentId } from '../../../types';\n\nexport const getTargetBucketWidth = (\n granularity: Granularity,\n instrument: InstrumentId\n): number => {\n const bucketWidth = INSTRUMENTS_CONFIG[instrument].defaultBucketWidth;\n return granularity === Granularity.H1 || granularity === Granularity.H4\n ? bucketWidth * BUCKET_CONFIG.MULTIPLIER\n : bucketWidth;\n};\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,+BAA+B;AAC3D,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,oBAAoB;AAGtE,OAAO,MAAMC,oBAAoB,GAAGA,CAClCC,WAAwB,EACxBC,UAAwB,KACb;EACX,MAAMC,WAAW,GAAGJ,kBAAkB,CAACG,UAAU,CAAC,CAACE,kBAAkB;EACrE,OAAOH,WAAW,KAAKJ,WAAW,CAACQ,EAAE,IAAIJ,WAAW,KAAKJ,WAAW,CAACS,EAAE,GACnEH,WAAW,GAAGL,aAAa,CAACS,UAAU,GACtCJ,WAAW;AACjB,CAAC","ignoreList":[]}
@@ -1,22 +0,0 @@
1
- import { BOOKS_THRESHOLDS } from '../../../constants';
2
- import { aggregateBuckets } from './aggregateBuckets';
3
- export const processBuckets = (orderPositionData, targetBucketWidth) => {
4
- var _orderPositionData$or;
5
- if (!(orderPositionData !== null && orderPositionData !== void 0 && (_orderPositionData$or = orderPositionData.orderPositionBooks) !== null && _orderPositionData$or !== void 0 && _orderPositionData$or.length)) {
6
- return [];
7
- }
8
- return orderPositionData.orderPositionBooks.filter(book => {
9
- var _book$buckets;
10
- return book !== null && ((_book$buckets = book.buckets) === null || _book$buckets === void 0 ? void 0 : _book$buckets.length) > 0;
11
- }).map(book => {
12
- var _book$bucketWidth;
13
- const validBuckets = book.buckets.filter(bucket => bucket !== null && bucket.price !== undefined && bucket.sentiment !== undefined && bucket.sentiment !== null).map(bucket => ({
14
- price: bucket.price,
15
- sentiment: bucket.sentiment
16
- }));
17
- const bucketsToFilter = targetBucketWidth > ((_book$bucketWidth = book.bucketWidth) !== null && _book$bucketWidth !== void 0 ? _book$bucketWidth : 0) ? aggregateBuckets(validBuckets, targetBucketWidth) : validBuckets;
18
- const filteredBuckets = bucketsToFilter.filter(bucket => Math.abs(bucket.sentiment) >= BOOKS_THRESHOLDS.MIN);
19
- return filteredBuckets;
20
- });
21
- };
22
- //# sourceMappingURL=processBuckets.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"processBuckets.js","names":["BOOKS_THRESHOLDS","aggregateBuckets","processBuckets","orderPositionData","targetBucketWidth","_orderPositionData$or","orderPositionBooks","length","filter","book","_book$buckets","buckets","map","_book$bucketWidth","validBuckets","bucket","price","undefined","sentiment","bucketsToFilter","bucketWidth","filteredBuckets","Math","abs","MIN"],"sources":["../../../../../../src/CrowdViewWidget/components/Chart/utils/processBuckets.ts"],"sourcesContent":["import type { GetOrderPositionBooksQuery } from '../../../../gql/types/graphql';\nimport { BOOKS_THRESHOLDS } from '../../../constants';\nimport type { Bucket } from '../types';\nimport { aggregateBuckets } from './aggregateBuckets';\n\nexport const processBuckets = (\n orderPositionData: GetOrderPositionBooksQuery | undefined,\n targetBucketWidth: number\n): Bucket[][] => {\n if (!orderPositionData?.orderPositionBooks?.length) {\n return [];\n }\n\n return orderPositionData.orderPositionBooks\n .filter((book): book is NonNullable<typeof book> => {\n return book !== null && book.buckets?.length > 0;\n })\n .map((book) => {\n const validBuckets = book.buckets\n .filter(\n (bucket): bucket is NonNullable<typeof bucket> =>\n bucket !== null &&\n bucket.price !== undefined &&\n bucket.sentiment !== undefined &&\n bucket.sentiment !== null\n )\n .map((bucket) => ({\n price: bucket.price!,\n sentiment: bucket.sentiment!,\n }));\n\n const bucketsToFilter =\n targetBucketWidth > (book.bucketWidth ?? 0)\n ? aggregateBuckets(validBuckets, targetBucketWidth)\n : validBuckets;\n\n const filteredBuckets = bucketsToFilter.filter(\n (bucket: Bucket) => Math.abs(bucket.sentiment) >= BOOKS_THRESHOLDS.MIN\n );\n\n return filteredBuckets;\n });\n};\n"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,oBAAoB;AAErD,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,OAAO,MAAMC,cAAc,GAAGA,CAC5BC,iBAAyD,EACzDC,iBAAyB,KACV;EAAA,IAAAC,qBAAA;EACf,IAAI,EAACF,iBAAiB,aAAjBA,iBAAiB,gBAAAE,qBAAA,GAAjBF,iBAAiB,CAAEG,kBAAkB,cAAAD,qBAAA,eAArCA,qBAAA,CAAuCE,MAAM,GAAE;IAClD,OAAO,EAAE;EACX;EAEA,OAAOJ,iBAAiB,CAACG,kBAAkB,CACxCE,MAAM,CAAEC,IAAI,IAAuC;IAAA,IAAAC,aAAA;IAClD,OAAOD,IAAI,KAAK,IAAI,IAAI,EAAAC,aAAA,GAAAD,IAAI,CAACE,OAAO,cAAAD,aAAA,uBAAZA,aAAA,CAAcH,MAAM,IAAG,CAAC;EAClD,CAAC,CAAC,CACDK,GAAG,CAAEH,IAAI,IAAK;IAAA,IAAAI,iBAAA;IACb,MAAMC,YAAY,GAAGL,IAAI,CAACE,OAAO,CAC9BH,MAAM,CACJO,MAAM,IACLA,MAAM,KAAK,IAAI,IACfA,MAAM,CAACC,KAAK,KAAKC,SAAS,IAC1BF,MAAM,CAACG,SAAS,KAAKD,SAAS,IAC9BF,MAAM,CAACG,SAAS,KAAK,IACzB,CAAC,CACAN,GAAG,CAAEG,MAAM,KAAM;MAChBC,KAAK,EAAED,MAAM,CAACC,KAAM;MACpBE,SAAS,EAAEH,MAAM,CAACG;IACpB,CAAC,CAAC,CAAC;IAEL,MAAMC,eAAe,GACnBf,iBAAiB,KAAAS,iBAAA,GAAIJ,IAAI,CAACW,WAAW,cAAAP,iBAAA,cAAAA,iBAAA,GAAI,CAAC,CAAC,GACvCZ,gBAAgB,CAACa,YAAY,EAAEV,iBAAiB,CAAC,GACjDU,YAAY;IAElB,MAAMO,eAAe,GAAGF,eAAe,CAACX,MAAM,CAC3CO,MAAc,IAAKO,IAAI,CAACC,GAAG,CAACR,MAAM,CAACG,SAAS,CAAC,IAAIlB,gBAAgB,CAACwB,GACrE,CAAC;IAED,OAAOH,eAAe;EACxB,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
@@ -1,2 +0,0 @@
1
- import type { Bucket } from '../types';
2
- export declare const aggregateBuckets: (buckets: Bucket[], newBucketWidth: number) => Bucket[];
@@ -1,3 +0,0 @@
1
- import { Granularity } from '../../../../gql/types/graphql';
2
- import type { InstrumentId } from '../../../types';
3
- export declare const getTargetBucketWidth: (granularity: Granularity, instrument: InstrumentId) => number;
@@ -1,3 +0,0 @@
1
- import type { GetOrderPositionBooksQuery } from '../../../../gql/types/graphql';
2
- import type { Bucket } from '../types';
3
- export declare const processBuckets: (orderPositionData: GetOrderPositionBooksQuery | undefined, targetBucketWidth: number) => Bucket[][];
@@ -1,44 +0,0 @@
1
- import Decimal from 'decimal.js';
2
-
3
- import type { Bucket } from '../types';
4
-
5
- export const aggregateBuckets = (
6
- buckets: Bucket[],
7
- newBucketWidth: number
8
- ): Bucket[] => {
9
- if (!buckets.length) {
10
- return [];
11
- }
12
-
13
- const bucketWidthDecimal = new Decimal(newBucketWidth);
14
-
15
- const aggregatedMap = new Map<string, Decimal>();
16
-
17
- for (const bucket of buckets) {
18
- const priceDecimal = new Decimal(bucket.price);
19
- const sentimentDecimal = new Decimal(bucket.sentiment);
20
-
21
- const bucketIndex = priceDecimal.div(bucketWidthDecimal).floor();
22
- const groupingKey = bucketIndex.mul(bucketWidthDecimal);
23
-
24
- const groupingKeyStr = groupingKey.toString();
25
-
26
- const currentSentiment =
27
- aggregatedMap.get(groupingKeyStr) ?? new Decimal(0);
28
- aggregatedMap.set(groupingKeyStr, currentSentiment.add(sentimentDecimal));
29
- }
30
-
31
- const aggregatedBuckets = Array.from(aggregatedMap.entries()).map(
32
- ([priceStr, sentimentDecimal]) => {
33
- const price = new Decimal(priceStr).toNumber();
34
- const sentiment = sentimentDecimal.toNumber();
35
-
36
- return {
37
- price,
38
- sentiment,
39
- };
40
- }
41
- );
42
-
43
- return aggregatedBuckets;
44
- };
@@ -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,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,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
- });