@oanda/labs-crowd-view-widget 1.0.45 → 1.0.47
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.
- package/CHANGELOG.md +380 -0
- package/dist/main/CrowdViewWidget/Main.js +9 -5
- package/dist/main/CrowdViewWidget/Main.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/Chart.js +3 -2
- package/dist/main/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js +5 -14
- package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js +20 -8
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/index.js +4 -4
- package/dist/main/CrowdViewWidget/components/Chart/index.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/types.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js +17 -101
- package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js +37 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js +19 -4
- package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js +14 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/index.js +83 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/index.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/processBuckets.js +29 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/processBuckets.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js +23 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/processPriceCandles.js +43 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/processPriceCandles.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/validateData.js +23 -0
- package/dist/main/CrowdViewWidget/components/Chart/utils/validateData.js.map +1 -0
- package/dist/main/CrowdViewWidget/components/Legend/Legend.js +6 -4
- package/dist/main/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js +5 -3
- package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
- package/dist/main/CrowdViewWidget/constants.js +105 -5
- package/dist/main/CrowdViewWidget/constants.js.map +1 -1
- package/dist/main/CrowdViewWidget/selectConfig.js +18 -60
- package/dist/main/CrowdViewWidget/selectConfig.js.map +1 -1
- package/dist/main/CrowdViewWidget/types.js +20 -0
- package/dist/main/CrowdViewWidget/types.js.map +1 -1
- package/dist/main/translations/sources/en.json +21 -16
- package/dist/module/CrowdViewWidget/Main.js +9 -5
- package/dist/module/CrowdViewWidget/Main.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/Chart.js +3 -2
- package/dist/module/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js +5 -14
- package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js +20 -8
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/index.js +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/index.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/types.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js +13 -97
- package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js +29 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js +20 -5
- package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js +7 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/index.js +8 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/index.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/processBuckets.js +22 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/processBuckets.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js +16 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/processPriceCandles.js +36 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/processPriceCandles.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/validateData.js +16 -0
- package/dist/module/CrowdViewWidget/components/Chart/utils/validateData.js.map +1 -0
- package/dist/module/CrowdViewWidget/components/Legend/Legend.js +6 -4
- package/dist/module/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js +5 -3
- package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
- package/dist/module/CrowdViewWidget/constants.js +104 -4
- package/dist/module/CrowdViewWidget/constants.js.map +1 -1
- package/dist/module/CrowdViewWidget/selectConfig.js +3 -45
- package/dist/module/CrowdViewWidget/selectConfig.js.map +1 -1
- package/dist/module/CrowdViewWidget/types.js +19 -1
- package/dist/module/CrowdViewWidget/types.js.map +1 -1
- package/dist/module/translations/sources/en.json +21 -16
- package/dist/types/CrowdViewWidget/components/Chart/Chart.d.ts +1 -1
- package/dist/types/CrowdViewWidget/components/Chart/index.d.ts +1 -1
- package/dist/types/CrowdViewWidget/components/Chart/types.d.ts +13 -8
- package/dist/types/CrowdViewWidget/components/Chart/utils/aggregateBuckets.d.ts +2 -0
- package/dist/types/CrowdViewWidget/components/Chart/utils/chartUtils.d.ts +11 -6
- package/dist/types/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.d.ts +3 -0
- package/dist/types/CrowdViewWidget/components/Chart/utils/index.d.ts +7 -0
- package/dist/types/CrowdViewWidget/components/Chart/utils/processBuckets.d.ts +3 -0
- package/dist/types/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.d.ts +8 -0
- package/dist/types/CrowdViewWidget/components/Chart/utils/processPriceCandles.d.ts +27 -0
- package/dist/types/CrowdViewWidget/components/Chart/utils/validateData.d.ts +2 -0
- package/dist/types/CrowdViewWidget/components/Legend/Legend.d.ts +3 -1
- package/dist/types/CrowdViewWidget/constants.d.ts +12 -4
- package/dist/types/CrowdViewWidget/selectConfig.d.ts +2 -2
- package/dist/types/CrowdViewWidget/types.d.ts +18 -1
- package/dist/types/CrowdViewWidget/utils/instrumentUtils.d.ts +1 -4
- package/package.json +4 -3
- package/src/CrowdViewWidget/Main.tsx +46 -40
- package/src/CrowdViewWidget/components/Chart/Chart.tsx +2 -2
- package/src/CrowdViewWidget/components/Chart/ChartWithData.tsx +4 -26
- package/src/CrowdViewWidget/components/Chart/chartOptions.ts +41 -27
- package/src/CrowdViewWidget/components/Chart/index.ts +1 -1
- package/src/CrowdViewWidget/components/Chart/types.ts +14 -4
- package/src/CrowdViewWidget/components/Chart/useCrowdViewData.ts +30 -154
- package/src/CrowdViewWidget/components/Chart/utils/aggregateBuckets.ts +44 -0
- package/src/CrowdViewWidget/components/Chart/utils/chartUtils.ts +41 -12
- package/src/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.ts +13 -0
- package/src/CrowdViewWidget/components/Chart/utils/index.ts +7 -0
- package/src/CrowdViewWidget/components/Chart/utils/processBuckets.ts +43 -0
- package/src/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.ts +30 -0
- package/src/CrowdViewWidget/components/Chart/utils/processPriceCandles.ts +53 -0
- package/src/CrowdViewWidget/components/Chart/utils/validateData.ts +27 -0
- package/src/CrowdViewWidget/components/Legend/Legend.tsx +14 -3
- package/src/CrowdViewWidget/components/Legend/LegendBar.tsx +5 -2
- package/src/CrowdViewWidget/constants.ts +114 -4
- package/src/CrowdViewWidget/selectConfig.ts +5 -60
- package/src/CrowdViewWidget/types.ts +18 -1
- package/src/translations/sources/en.json +21 -16
- package/test/Main.test.tsx +1 -1
- package/test/components/Chart/utils/chartUtils.test.ts +13 -27
- package/test/components/Legend.test.tsx +8 -3
- package/test/components/LegendBar.test.tsx +3 -2
- package/test/utils/aggregateBuckets.test.ts +82 -0
- package/test/utils/getTargetBucketWidth.test.ts +37 -0
- package/test/utils/instrumentUtils.test.ts +13 -7
- package/test/utils/processBuckets.test.ts +153 -0
- package/test/utils/processOrderPositionBooks.test.ts +127 -0
- package/test/utils/processPriceCandles.test.ts +245 -0
- package/test/utils/validateData.test.ts +201 -0
- package/dist/main/CrowdViewWidget/types/index.js +0 -17
- package/dist/main/CrowdViewWidget/types/index.js.map +0 -1
- package/dist/main/CrowdViewWidget/types/instruments.js +0 -45
- package/dist/main/CrowdViewWidget/types/instruments.js.map +0 -1
- package/dist/module/CrowdViewWidget/types/index.js +0 -2
- package/dist/module/CrowdViewWidget/types/index.js.map +0 -1
- package/dist/module/CrowdViewWidget/types/instruments.js +0 -39
- package/dist/module/CrowdViewWidget/types/instruments.js.map +0 -1
- package/dist/types/CrowdViewWidget/types/index.d.ts +0 -1
- package/dist/types/CrowdViewWidget/types/instruments.d.ts +0 -36
- package/src/CrowdViewWidget/types/index.ts +0 -1
- package/src/CrowdViewWidget/types/instruments.ts +0 -37
|
@@ -10,7 +10,11 @@ import {
|
|
|
10
10
|
BOOKS_THRESHOLDS,
|
|
11
11
|
COLOR_MAP,
|
|
12
12
|
} from '../../../../src/CrowdViewWidget/constants';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
BookType,
|
|
15
|
+
Granularity,
|
|
16
|
+
TimeSpan,
|
|
17
|
+
} from '../../../../src/gql/types/graphql';
|
|
14
18
|
|
|
15
19
|
describe('chartUtils', () => {
|
|
16
20
|
describe('getTimeSpanForGranularity', () => {
|
|
@@ -131,13 +135,15 @@ describe('chartUtils', () => {
|
|
|
131
135
|
],
|
|
132
136
|
];
|
|
133
137
|
|
|
134
|
-
const html = getTooltipFormatter(
|
|
138
|
+
const html = getTooltipFormatter({
|
|
135
139
|
params,
|
|
136
140
|
buckets,
|
|
137
|
-
0.0005,
|
|
138
|
-
1.3306,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
bucketWidth: 0.0005,
|
|
142
|
+
selectedPrice: 1.3306,
|
|
143
|
+
precision: 5,
|
|
144
|
+
bookType: BookType.Order,
|
|
145
|
+
labelCallback,
|
|
146
|
+
});
|
|
141
147
|
expect(html).toContain('candle');
|
|
142
148
|
expect(html).toContain('open_price');
|
|
143
149
|
expect(html).toContain('close_price');
|
|
@@ -146,27 +152,7 @@ describe('chartUtils', () => {
|
|
|
146
152
|
expect(html).toContain('orders');
|
|
147
153
|
expect(html).toContain('price_range');
|
|
148
154
|
// Selected price 1.3306 falls into second bucket 1.3305 - 1.3310 which has negative sentiment
|
|
149
|
-
expect(html).toContain('
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('omits sections when data is missing', () => {
|
|
153
|
-
const params = [
|
|
154
|
-
{
|
|
155
|
-
axisValue: '2025-03-15T10:30:00Z',
|
|
156
|
-
value: [0, 0, 0, 0, 0], // no candle values
|
|
157
|
-
},
|
|
158
|
-
{ value: ['2025-03-15T10:30:00Z', 0, 0] },
|
|
159
|
-
];
|
|
160
|
-
const buckets: Array<Array<{ price: number; sentiment: number }>> = [[]];
|
|
161
|
-
const html = getTooltipFormatter(
|
|
162
|
-
params,
|
|
163
|
-
buckets,
|
|
164
|
-
0.0005,
|
|
165
|
-
0,
|
|
166
|
-
labelCallback
|
|
167
|
-
);
|
|
168
|
-
expect(html).not.toContain('open_price');
|
|
169
|
-
expect(html).not.toContain('orders');
|
|
155
|
+
expect(html).toContain('sell_overbalance');
|
|
170
156
|
});
|
|
171
157
|
});
|
|
172
158
|
});
|
|
@@ -6,17 +6,22 @@ import { render } from '@testing-library/react';
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { Legend } from '../../src/CrowdViewWidget/components';
|
|
9
|
+
import { BookType } from '../../src/gql/types/graphql';
|
|
9
10
|
|
|
10
11
|
describe('Crowd View Widget', () => {
|
|
11
12
|
describe('components', () => {
|
|
12
13
|
describe('<Legend />', () => {
|
|
13
14
|
it('renders two LegendBar components', () => {
|
|
14
15
|
const { getAllByText } = render(
|
|
15
|
-
<Legend
|
|
16
|
+
<Legend
|
|
17
|
+
bookType={BookType.Position}
|
|
18
|
+
longValues={[0.15, 0.55]}
|
|
19
|
+
shortValues={[0.15, 0.55]}
|
|
20
|
+
/>
|
|
16
21
|
);
|
|
17
22
|
|
|
18
|
-
expect(getAllByText(/long/)).toHaveLength(
|
|
19
|
-
expect(getAllByText(/short/)).toHaveLength(
|
|
23
|
+
expect(getAllByText(/long/)).toHaveLength(1);
|
|
24
|
+
expect(getAllByText(/short/)).toHaveLength(1);
|
|
20
25
|
});
|
|
21
26
|
});
|
|
22
27
|
});
|
|
@@ -17,8 +17,9 @@ describe('Crowd View Widget', () => {
|
|
|
17
17
|
<LegendBar label="long" type="long" values={mockValues} />
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
expect(getByText('
|
|
21
|
-
expect(getByText('0.
|
|
20
|
+
expect(getByText('long')).toBeInTheDocument();
|
|
21
|
+
expect(getByText('0.15%')).toBeInTheDocument();
|
|
22
|
+
expect(getByText('≤ 0.55%')).toBeInTheDocument();
|
|
22
23
|
});
|
|
23
24
|
|
|
24
25
|
it('renders exactly 1 segment', () => {
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
});
|
|
@@ -14,11 +14,13 @@ describe('instrumentUtils', () => {
|
|
|
14
14
|
expect(Array.isArray(result)).toBe(true);
|
|
15
15
|
expect(result.length).toBeGreaterThan(0);
|
|
16
16
|
|
|
17
|
-
// Check that the first instrument has the expected
|
|
17
|
+
// Check that the first instrument has the expected structure
|
|
18
18
|
const firstInstrument = result[0];
|
|
19
19
|
expect(firstInstrument).toHaveProperty('id');
|
|
20
20
|
expect(firstInstrument).toHaveProperty('label');
|
|
21
|
-
|
|
21
|
+
// Instrument IDs are now enum values like 'EURAUD', not 'EUR_AUD'
|
|
22
|
+
expect(typeof firstInstrument.id).toBe('string');
|
|
23
|
+
expect(firstInstrument.id.length).toBeGreaterThan(0);
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
it('should return OAP instrument config for OAP division', () => {
|
|
@@ -28,11 +30,13 @@ describe('instrumentUtils', () => {
|
|
|
28
30
|
expect(Array.isArray(result)).toBe(true);
|
|
29
31
|
expect(result.length).toBeGreaterThan(0);
|
|
30
32
|
|
|
31
|
-
// Check that the first instrument has the expected
|
|
33
|
+
// Check that the first instrument has the expected structure
|
|
32
34
|
const firstInstrument = result[0];
|
|
33
35
|
expect(firstInstrument).toHaveProperty('id');
|
|
34
36
|
expect(firstInstrument).toHaveProperty('label');
|
|
35
|
-
|
|
37
|
+
// Instrument IDs are now enum values like 'EURAUD', not 'EURUSD'
|
|
38
|
+
expect(typeof firstInstrument.id).toBe('string');
|
|
39
|
+
expect(firstInstrument.id.length).toBeGreaterThan(0);
|
|
36
40
|
});
|
|
37
41
|
|
|
38
42
|
it('should return different configs for different divisions', () => {
|
|
@@ -41,12 +45,14 @@ describe('instrumentUtils', () => {
|
|
|
41
45
|
|
|
42
46
|
expect(ocConfig).not.toEqual(oapConfig);
|
|
43
47
|
|
|
44
|
-
//
|
|
48
|
+
// Both configs should have valid instrument IDs
|
|
45
49
|
const ocFirstId = ocConfig[0].id;
|
|
46
50
|
const oapFirstId = oapConfig[0].id;
|
|
47
51
|
|
|
48
|
-
expect(ocFirstId).
|
|
49
|
-
expect(oapFirstId).
|
|
52
|
+
expect(typeof ocFirstId).toBe('string');
|
|
53
|
+
expect(typeof oapFirstId).toBe('string');
|
|
54
|
+
// OAP config includes XAU_USD and XAG_USD which OC doesn't have
|
|
55
|
+
expect(oapConfig.length).toBeGreaterThan(ocConfig.length);
|
|
50
56
|
});
|
|
51
57
|
});
|
|
52
58
|
});
|
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { processOrderPositionBooks } from '../../src/CrowdViewWidget/components';
|
|
2
|
+
import type { GetOrderPositionBooksQuery } from '../../src/gql/types/graphql';
|
|
3
|
+
|
|
4
|
+
describe('processOrderPositionBooks', () => {
|
|
5
|
+
const createMockOrderPositionBook = (time: string) => ({
|
|
6
|
+
bucketWidth: 0.0005,
|
|
7
|
+
price: 1.0,
|
|
8
|
+
time,
|
|
9
|
+
buckets: [{ price: 1.0, sentiment: 0.2 }],
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should return empty array when orderPositionData is undefined', () => {
|
|
13
|
+
const candleMap = new Map();
|
|
14
|
+
expect(processOrderPositionBooks(undefined, candleMap)).toEqual([]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should return empty array when orderPositionBooks is empty', () => {
|
|
18
|
+
const mockData: GetOrderPositionBooksQuery = {
|
|
19
|
+
orderPositionBooks: [],
|
|
20
|
+
};
|
|
21
|
+
const candleMap = new Map();
|
|
22
|
+
expect(processOrderPositionBooks(mockData, candleMap)).toEqual([]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should filter out null books', () => {
|
|
26
|
+
const mockData: GetOrderPositionBooksQuery = {
|
|
27
|
+
orderPositionBooks: [null, createMockOrderPositionBook('2025-01-01')],
|
|
28
|
+
};
|
|
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]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should filter out books with no buckets', () => {
|
|
36
|
+
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
|
+
],
|
|
46
|
+
};
|
|
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]);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should use candle high price when available in map', () => {
|
|
54
|
+
const mockData: GetOrderPositionBooksQuery = {
|
|
55
|
+
orderPositionBooks: [
|
|
56
|
+
createMockOrderPositionBook('2025-01-01'),
|
|
57
|
+
createMockOrderPositionBook('2025-01-02'),
|
|
58
|
+
],
|
|
59
|
+
};
|
|
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]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should use null when candle is not in map', () => {
|
|
71
|
+
const mockData: GetOrderPositionBooksQuery = {
|
|
72
|
+
orderPositionBooks: [createMockOrderPositionBook('2025-01-01')],
|
|
73
|
+
};
|
|
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]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should use null when candle high is undefined', () => {
|
|
81
|
+
const mockData: GetOrderPositionBooksQuery = {
|
|
82
|
+
orderPositionBooks: [createMockOrderPositionBook('2025-01-01')],
|
|
83
|
+
};
|
|
84
|
+
const candleMap = new Map([
|
|
85
|
+
['2025-01-01', { low: 1.0 }], // no high property
|
|
86
|
+
]);
|
|
87
|
+
const result = processOrderPositionBooks(mockData, candleMap);
|
|
88
|
+
expect(result).toHaveLength(1);
|
|
89
|
+
expect(result[0]).toEqual(['2025-01-01', null, 0]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should correctly assign index to each book', () => {
|
|
93
|
+
const mockData: GetOrderPositionBooksQuery = {
|
|
94
|
+
orderPositionBooks: [
|
|
95
|
+
createMockOrderPositionBook('2025-01-01'),
|
|
96
|
+
createMockOrderPositionBook('2025-01-02'),
|
|
97
|
+
createMockOrderPositionBook('2025-01-03'),
|
|
98
|
+
],
|
|
99
|
+
};
|
|
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);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should handle mixed cases with and without candles', () => {
|
|
109
|
+
const mockData: GetOrderPositionBooksQuery = {
|
|
110
|
+
orderPositionBooks: [
|
|
111
|
+
createMockOrderPositionBook('2025-01-01'),
|
|
112
|
+
createMockOrderPositionBook('2025-01-02'),
|
|
113
|
+
createMockOrderPositionBook('2025-01-03'),
|
|
114
|
+
],
|
|
115
|
+
};
|
|
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]);
|
|
126
|
+
});
|
|
127
|
+
});
|