@oanda/labs-crowd-view-widget 1.0.52 → 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.
- package/CHANGELOG.md +216 -0
- package/dist/main/CrowdViewWidget/Main.js +1 -5
- package/dist/main/CrowdViewWidget/Main.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/Chart.js +16 -6
- package/dist/main/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js +15 -6
- package/dist/main/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js +69 -29
- package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/types.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js +49 -26
- package/dist/main/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js +9 -10
- package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/index.js +0 -33
- package/dist/main/CrowdViewWidget/components/Chart/utils/index.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js +54 -12
- package/dist/main/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/processPriceCandles.js +49 -27
- package/dist/main/CrowdViewWidget/components/Chart/utils/processPriceCandles.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/processSentiments.js +32 -17
- package/dist/main/CrowdViewWidget/components/Chart/utils/processSentiments.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/validateData.js +8 -2
- package/dist/main/CrowdViewWidget/components/Chart/utils/validateData.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Legend/Legend.js +2 -3
- package/dist/main/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
- package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js +2 -2
- package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
- package/dist/main/CrowdViewWidget/constants.js +2 -6
- package/dist/main/CrowdViewWidget/constants.js.map +1 -1
- package/dist/main/gql/getOrderPositionBooks.js +1 -1
- package/dist/main/gql/getOrderPositionBooks.js.map +1 -1
- package/dist/main/gql/getPriceCandles.js +1 -1
- package/dist/main/gql/getPriceCandles.js.map +1 -1
- package/dist/main/gql/types/gql.js +2 -2
- package/dist/main/gql/types/gql.js.map +1 -1
- package/dist/main/gql/types/graphql.js +111 -18
- package/dist/main/gql/types/graphql.js.map +1 -1
- package/dist/module/CrowdViewWidget/Main.js +2 -6
- package/dist/module/CrowdViewWidget/Main.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/Chart.js +17 -7
- package/dist/module/CrowdViewWidget/components/Chart/Chart.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js +15 -6
- package/dist/module/CrowdViewWidget/components/Chart/ChartWithData.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js +70 -30
- package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/types.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js +50 -27
- package/dist/module/CrowdViewWidget/components/Chart/useCrowdViewData.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js +10 -11
- package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/index.js +0 -3
- package/dist/module/CrowdViewWidget/components/Chart/utils/index.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js +54 -12
- package/dist/module/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/processPriceCandles.js +49 -27
- package/dist/module/CrowdViewWidget/components/Chart/utils/processPriceCandles.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/processSentiments.js +32 -17
- package/dist/module/CrowdViewWidget/components/Chart/utils/processSentiments.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/validateData.js +8 -2
- package/dist/module/CrowdViewWidget/components/Chart/utils/validateData.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Legend/Legend.js +2 -3
- package/dist/module/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
- package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js +2 -2
- package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
- package/dist/module/CrowdViewWidget/constants.js +1 -5
- package/dist/module/CrowdViewWidget/constants.js.map +1 -1
- package/dist/module/gql/getOrderPositionBooks.js +1 -1
- package/dist/module/gql/getOrderPositionBooks.js.map +1 -1
- package/dist/module/gql/getPriceCandles.js +1 -1
- package/dist/module/gql/getPriceCandles.js.map +1 -1
- package/dist/module/gql/types/gql.js +2 -2
- package/dist/module/gql/types/gql.js.map +1 -1
- package/dist/module/gql/types/graphql.js +111 -18
- package/dist/module/gql/types/graphql.js.map +1 -1
- package/dist/types/CrowdViewWidget/components/Chart/Chart.d.ts +1 -1
- package/dist/types/CrowdViewWidget/components/Chart/types.d.ts +28 -11
- package/dist/types/CrowdViewWidget/components/Chart/utils/chartUtils.d.ts +3 -4
- package/dist/types/CrowdViewWidget/components/Chart/utils/index.d.ts +0 -3
- package/dist/types/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.d.ts +10 -7
- package/dist/types/CrowdViewWidget/components/Chart/utils/processPriceCandles.d.ts +6 -21
- package/dist/types/CrowdViewWidget/components/Chart/utils/processSentiments.d.ts +5 -2
- package/dist/types/CrowdViewWidget/components/Chart/utils/validateData.d.ts +1 -1
- package/dist/types/CrowdViewWidget/components/Legend/Legend.d.ts +2 -2
- package/dist/types/CrowdViewWidget/components/Legend/LegendBar.d.ts +1 -1
- package/dist/types/CrowdViewWidget/constants.d.ts +1 -5
- package/dist/types/gql/types/gql.d.ts +6 -4
- package/dist/types/gql/types/graphql.d.ts +30 -11
- package/package.json +3 -3
- package/src/CrowdViewWidget/Main.tsx +2 -4
- package/src/CrowdViewWidget/components/Chart/Chart.tsx +15 -6
- package/src/CrowdViewWidget/components/Chart/ChartWithData.tsx +21 -4
- package/src/CrowdViewWidget/components/Chart/chartOptions.ts +78 -30
- package/src/CrowdViewWidget/components/Chart/types.ts +30 -19
- package/src/CrowdViewWidget/components/Chart/useCrowdViewData.ts +82 -65
- package/src/CrowdViewWidget/components/Chart/utils/chartUtils.ts +32 -20
- package/src/CrowdViewWidget/components/Chart/utils/index.ts +0 -3
- package/src/CrowdViewWidget/components/Chart/utils/processOrderPositionBooks.ts +84 -22
- package/src/CrowdViewWidget/components/Chart/utils/processPriceCandles.ts +52 -38
- package/src/CrowdViewWidget/components/Chart/utils/processSentiments.ts +45 -32
- package/src/CrowdViewWidget/components/Chart/utils/validateData.ts +10 -2
- package/src/CrowdViewWidget/components/Legend/Legend.tsx +4 -5
- package/src/CrowdViewWidget/components/Legend/LegendBar.tsx +3 -3
- package/src/CrowdViewWidget/constants.ts +1 -6
- package/src/gql/getOrderPositionBooks.ts +13 -5
- package/src/gql/getPriceCandles.ts +1 -0
- package/src/gql/types/gql.ts +6 -6
- package/src/gql/types/graphql.ts +98 -16
- package/test/components/Chart/utils/chartUtils.test.ts +32 -14
- package/test/components/Chart/utils/processSentiments.test.ts +137 -29
- package/test/utils/processOrderPositionBooks.test.ts +201 -84
- package/test/utils/processPriceCandles.test.ts +93 -67
- package/test/utils/validateData.test.ts +136 -38
- package/dist/main/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js +0 -37
- package/dist/main/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js.map +0 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js +0 -14
- package/dist/main/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js.map +0 -1
- package/dist/main/CrowdViewWidget/components/Chart/utils/processBuckets.js +0 -29
- package/dist/main/CrowdViewWidget/components/Chart/utils/processBuckets.js.map +0 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js +0 -29
- package/dist/module/CrowdViewWidget/components/Chart/utils/aggregateBuckets.js.map +0 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js +0 -7
- package/dist/module/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.js.map +0 -1
- package/dist/module/CrowdViewWidget/components/Chart/utils/processBuckets.js +0 -22
- package/dist/module/CrowdViewWidget/components/Chart/utils/processBuckets.js.map +0 -1
- package/dist/types/CrowdViewWidget/components/Chart/utils/aggregateBuckets.d.ts +0 -2
- package/dist/types/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.d.ts +0 -3
- package/dist/types/CrowdViewWidget/components/Chart/utils/processBuckets.d.ts +0 -3
- package/src/CrowdViewWidget/components/Chart/utils/aggregateBuckets.ts +0 -44
- package/src/CrowdViewWidget/components/Chart/utils/getTargetBucketWidth.ts +0 -13
- package/src/CrowdViewWidget/components/Chart/utils/processBuckets.ts +0 -43
- package/test/utils/aggregateBuckets.test.ts +0 -82
- package/test/utils/getTargetBucketWidth.test.ts +0 -37
- package/test/utils/processBuckets.test.ts +0 -153
|
@@ -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
|
-
});
|