aiden-shared-calculations-unified 1.0.8 → 1.0.10

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 (32) hide show
  1. package/calculations/pnl/average_daily_pnl_all_users.js +1 -1
  2. package/calculations/pnl/average_daily_pnl_per_sector.js +1 -1
  3. package/calculations/pnl/average_daily_pnl_per_stock.js +1 -1
  4. package/calculations/pnl/average_daily_position_pnl.js +1 -1
  5. package/calculations/pnl/pnl_distribution_per_stock.js +52 -52
  6. package/calculations/pnl/profitability_ratio_per_stock.js +50 -50
  7. package/calculations/pnl/profitability_skew_per_stock.js +58 -58
  8. package/calculations/sanity/users_processed.js +26 -26
  9. package/calculations/sectors/total_long_per_sector.js +1 -1
  10. package/calculations/sectors/total_short_per_sector.js +1 -1
  11. package/calculations/short_and_long_stats/long_position_per_stock.js +1 -1
  12. package/calculations/short_and_long_stats/sentiment_per_stock.js +49 -49
  13. package/calculations/short_and_long_stats/short_position_per_stock.js +1 -1
  14. package/calculations/short_and_long_stats/total_long_figures.js +1 -1
  15. package/calculations/short_and_long_stats/total_short_figures.js +1 -1
  16. package/calculations/socialPosts/social_activity_aggregation.js +5 -1
  17. package/calculations/speculators/distance_to_stop_loss_per_leverage.js +78 -78
  18. package/calculations/speculators/distance_to_tp_per_leverage.js +76 -76
  19. package/calculations/speculators/entry_distance_to_sl_per_leverage.js +78 -78
  20. package/calculations/speculators/entry_distance_to_tp_per_leverage.js +77 -77
  21. package/calculations/speculators/holding_duration_per_asset.js +55 -55
  22. package/calculations/speculators/leverage_per_asset.js +46 -46
  23. package/calculations/speculators/leverage_per_sector.js +44 -44
  24. package/calculations/speculators/risk_reward_ratio_per_asset.js +60 -60
  25. package/calculations/speculators/speculator_asset_sentiment.js +81 -81
  26. package/calculations/speculators/speculator_danger_zone.js +57 -57
  27. package/calculations/speculators/stop_loss_distance_by_sector_short_long_breakdown.js +91 -91
  28. package/calculations/speculators/stop_loss_distance_by_ticker_short_long_breakdown.js +73 -73
  29. package/calculations/speculators/stop_loss_per_asset.js +55 -55
  30. package/calculations/speculators/take_profit_per_asset.js +55 -55
  31. package/calculations/speculators/tsl_per_asset.js +51 -51
  32. package/package.json +1 -1
@@ -1,78 +1,78 @@
1
- /**
2
- * @fileoverview Calculates the average distance to the stop loss from the current price for
3
- * both long and short positions, grouped by asset and leverage level.
4
- * It ignores near-zero stop loss values.
5
- */
6
- const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
7
-
8
- class DistanceToStopLossPerLeverage {
9
- constructor() {
10
- this.stopLossData = {};
11
- this.mappings = null;
12
- }
13
-
14
- process(portfolioData, userId) {
15
- if (portfolioData && portfolioData.PublicPositions) {
16
- for (const position of portfolioData.PublicPositions) {
17
- const instrumentId = position.InstrumentID;
18
- const leverage = position.Leverage;
19
- const stopLossRate = position.StopLossRate;
20
- const currentRate = position.CurrentRate;
21
- const isBuy = position.IsBuy;
22
-
23
- if (stopLossRate > 0.0001 && currentRate > 0) {
24
- let distance;
25
-
26
- if (isBuy) {
27
- distance = currentRate - stopLossRate;
28
- } else {
29
- distance = stopLossRate - currentRate;
30
- }
31
-
32
- const distancePercent = (distance / currentRate) * 100;
33
-
34
- if (distancePercent > 0) {
35
- if (!this.stopLossData[instrumentId]) {
36
- this.stopLossData[instrumentId] = {};
37
- }
38
- if (!this.stopLossData[instrumentId][leverage]) {
39
- this.stopLossData[instrumentId][leverage] = { distance_sum_percent: 0, count: 0 };
40
- }
41
- this.stopLossData[instrumentId][leverage].distance_sum_percent += distancePercent;
42
- this.stopLossData[instrumentId][leverage].count++;
43
- }
44
- }
45
- }
46
- }
47
- }
48
-
49
- async getResult() {
50
- if (!this.mappings) {
51
- this.mappings = await loadInstrumentMappings();
52
- }
53
-
54
- const result = {};
55
- for (const instrumentId in this.stopLossData) {
56
- const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
57
- result[ticker] = {};
58
- for (const leverage in this.stopLossData[instrumentId]) {
59
- const data = this.stopLossData[instrumentId][leverage];
60
- // REFACTOR: Perform final calculation directly.
61
- if (data.count > 0) {
62
- result[ticker][leverage] = {
63
- average_distance_percent: data.distance_sum_percent / data.count,
64
- count: data.count
65
- };
66
- }
67
- }
68
- }
69
- return result;
70
- }
71
-
72
- reset() {
73
- this.stopLossData = {};
74
- this.mappings = null;
75
- }
76
- }
77
-
78
- module.exports = DistanceToStopLossPerLeverage;
1
+ /**
2
+ * @fileoverview Calculates the average distance to the stop loss from the current price for
3
+ * both long and short positions, grouped by asset and leverage level.
4
+ * It ignores near-zero stop loss values.
5
+ */
6
+ const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
7
+
8
+ class DistanceToStopLossPerLeverage {
9
+ constructor() {
10
+ this.stopLossData = {};
11
+ this.mappings = null;
12
+ }
13
+
14
+ process(portfolioData, yesterdayPortfolio, userId, context) {
15
+ if (portfolioData && portfolioData.PublicPositions) {
16
+ for (const position of portfolioData.PublicPositions) {
17
+ const instrumentId = position.InstrumentID;
18
+ const leverage = position.Leverage;
19
+ const stopLossRate = position.StopLossRate;
20
+ const currentRate = position.CurrentRate;
21
+ const isBuy = position.IsBuy;
22
+
23
+ if (stopLossRate > 0.0001 && currentRate > 0) {
24
+ let distance;
25
+
26
+ if (isBuy) {
27
+ distance = currentRate - stopLossRate;
28
+ } else {
29
+ distance = stopLossRate - currentRate;
30
+ }
31
+
32
+ const distancePercent = (distance / currentRate) * 100;
33
+
34
+ if (distancePercent > 0) {
35
+ if (!this.stopLossData[instrumentId]) {
36
+ this.stopLossData[instrumentId] = {};
37
+ }
38
+ if (!this.stopLossData[instrumentId][leverage]) {
39
+ this.stopLossData[instrumentId][leverage] = { distance_sum_percent: 0, count: 0 };
40
+ }
41
+ this.stopLossData[instrumentId][leverage].distance_sum_percent += distancePercent;
42
+ this.stopLossData[instrumentId][leverage].count++;
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ async getResult() {
50
+ if (!this.mappings) {
51
+ this.mappings = await loadInstrumentMappings();
52
+ }
53
+
54
+ const result = {};
55
+ for (const instrumentId in this.stopLossData) {
56
+ const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
57
+ result[ticker] = {};
58
+ for (const leverage in this.stopLossData[instrumentId]) {
59
+ const data = this.stopLossData[instrumentId][leverage];
60
+ // REFACTOR: Perform final calculation directly.
61
+ if (data.count > 0) {
62
+ result[ticker][leverage] = {
63
+ average_distance_percent: data.distance_sum_percent / data.count,
64
+ count: data.count
65
+ };
66
+ }
67
+ }
68
+ }
69
+ return result;
70
+ }
71
+
72
+ reset() {
73
+ this.stopLossData = {};
74
+ this.mappings = null;
75
+ }
76
+ }
77
+
78
+ module.exports = DistanceToStopLossPerLeverage;
@@ -1,76 +1,76 @@
1
- /**
2
- * @fileoverview Calculates the average distance to the take profit from the current price for
3
- * both long and short positions, grouped by asset and leverage level.
4
- * It ignores positions where take profit is not set.
5
- */
6
- const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
7
-
8
- class DistanceToTakeProfitPerLeverage {
9
- constructor() {
10
- this.takeProfitData = {};
11
- this.mappings = null;
12
- }
13
-
14
- process(portfolioData, userId) {
15
- if (portfolioData && portfolioData.PublicPositions) {
16
- for (const position of portfolioData.PublicPositions) {
17
- const instrumentId = position.InstrumentID;
18
- const leverage = position.Leverage;
19
- const takeProfitRate = position.TakeProfitRate;
20
- const currentRate = position.CurrentRate;
21
- const isBuy = position.IsBuy;
22
-
23
- if (takeProfitRate > 0.0001 && currentRate > 0) {
24
- let distance;
25
- if (isBuy) {
26
- distance = takeProfitRate - currentRate;
27
- } else {
28
- distance = currentRate - takeProfitRate;
29
- }
30
-
31
- const distancePercent = (distance / currentRate) * 100;
32
-
33
- if (distancePercent > 0) {
34
- if (!this.takeProfitData[instrumentId]) {
35
- this.takeProfitData[instrumentId] = {};
36
- }
37
- if (!this.takeProfitData[instrumentId][leverage]) {
38
- this.takeProfitData[instrumentId][leverage] = { distance_sum_percent: 0, count: 0 };
39
- }
40
- this.takeProfitData[instrumentId][leverage].distance_sum_percent += distancePercent;
41
- this.takeProfitData[instrumentId][leverage].count++;
42
- }
43
- }
44
- }
45
- }
46
- }
47
-
48
- async getResult() {
49
- if (!this.mappings) {
50
- this.mappings = await loadInstrumentMappings();
51
- }
52
- const result = {};
53
- for (const instrumentId in this.takeProfitData) {
54
- const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
55
- result[ticker] = {};
56
- for (const leverage in this.takeProfitData[instrumentId]) {
57
- const data = this.takeProfitData[instrumentId][leverage];
58
- // REFACTOR: Perform final calculation directly.
59
- if (data.count > 0) {
60
- result[ticker][leverage] = {
61
- average_distance_percent: data.distance_sum_percent / data.count,
62
- count: data.count
63
- };
64
- }
65
- }
66
- }
67
- return result;
68
- }
69
-
70
- reset() {
71
- this.takeProfitData = {};
72
- this.mappings = null;
73
- }
74
- }
75
-
76
- module.exports = DistanceToTakeProfitPerLeverage;
1
+ /**
2
+ * @fileoverview Calculates the average distance to the take profit from the current price for
3
+ * both long and short positions, grouped by asset and leverage level.
4
+ * It ignores positions where take profit is not set.
5
+ */
6
+ const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
7
+
8
+ class DistanceToTakeProfitPerLeverage {
9
+ constructor() {
10
+ this.takeProfitData = {};
11
+ this.mappings = null;
12
+ }
13
+
14
+ process(portfolioData, yesterdayPortfolio, userId, context) {
15
+ if (portfolioData && portfolioData.PublicPositions) {
16
+ for (const position of portfolioData.PublicPositions) {
17
+ const instrumentId = position.InstrumentID;
18
+ const leverage = position.Leverage;
19
+ const takeProfitRate = position.TakeProfitRate;
20
+ const currentRate = position.CurrentRate;
21
+ const isBuy = position.IsBuy;
22
+
23
+ if (takeProfitRate > 0.0001 && currentRate > 0) {
24
+ let distance;
25
+ if (isBuy) {
26
+ distance = takeProfitRate - currentRate;
27
+ } else {
28
+ distance = currentRate - takeProfitRate;
29
+ }
30
+
31
+ const distancePercent = (distance / currentRate) * 100;
32
+
33
+ if (distancePercent > 0) {
34
+ if (!this.takeProfitData[instrumentId]) {
35
+ this.takeProfitData[instrumentId] = {};
36
+ }
37
+ if (!this.takeProfitData[instrumentId][leverage]) {
38
+ this.takeProfitData[instrumentId][leverage] = { distance_sum_percent: 0, count: 0 };
39
+ }
40
+ this.takeProfitData[instrumentId][leverage].distance_sum_percent += distancePercent;
41
+ this.takeProfitData[instrumentId][leverage].count++;
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+
48
+ async getResult() {
49
+ if (!this.mappings) {
50
+ this.mappings = await loadInstrumentMappings();
51
+ }
52
+ const result = {};
53
+ for (const instrumentId in this.takeProfitData) {
54
+ const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
55
+ result[ticker] = {};
56
+ for (const leverage in this.takeProfitData[instrumentId]) {
57
+ const data = this.takeProfitData[instrumentId][leverage];
58
+ // REFACTOR: Perform final calculation directly.
59
+ if (data.count > 0) {
60
+ result[ticker][leverage] = {
61
+ average_distance_percent: data.distance_sum_percent / data.count,
62
+ count: data.count
63
+ };
64
+ }
65
+ }
66
+ }
67
+ return result;
68
+ }
69
+
70
+ reset() {
71
+ this.takeProfitData = {};
72
+ this.mappings = null;
73
+ }
74
+ }
75
+
76
+ module.exports = DistanceToTakeProfitPerLeverage;
@@ -1,78 +1,78 @@
1
- /**
2
- * @fileoverview Calculates the average percentage distance from the entry price (OpenRate)
3
- * to the stop loss rate for both long and short positions, grouped by asset and leverage level.
4
- * It ignores near-zero stop loss values, which signify no stop loss is set.
5
- */
6
- const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
7
-
8
- class EntryDistanceToStopLossPerLeverage {
9
- constructor() {
10
- this.stopLossData = {};
11
- this.mappings = null;
12
- }
13
-
14
- process(portfolioData, userId) {
15
- if (portfolioData && portfolioData.PublicPositions) {
16
- for (const position of portfolioData.PublicPositions) {
17
- const instrumentId = position.InstrumentID;
18
- const leverage = position.Leverage;
19
- const stopLossRate = position.StopLossRate;
20
- const openRate = position.OpenRate;
21
- const isBuy = position.IsBuy;
22
-
23
- if (stopLossRate > 0.0001 && openRate > 0) {
24
- let distance;
25
-
26
- if (isBuy) {
27
- distance = openRate - stopLossRate;
28
- } else {
29
- distance = stopLossRate - openRate;
30
- }
31
-
32
- const distancePercent = (distance / openRate) * 100;
33
-
34
- if (distancePercent > 0) {
35
- if (!this.stopLossData[instrumentId]) {
36
- this.stopLossData[instrumentId] = {};
37
- }
38
- if (!this.stopLossData[instrumentId][leverage]) {
39
- this.stopLossData[instrumentId][leverage] = { distance_sum_percent: 0, count: 0 };
40
- }
41
- this.stopLossData[instrumentId][leverage].distance_sum_percent += distancePercent;
42
- this.stopLossData[instrumentId][leverage].count++;
43
- }
44
- }
45
- }
46
- }
47
- }
48
-
49
- async getResult() {
50
- if (!this.mappings) {
51
- this.mappings = await loadInstrumentMappings();
52
- }
53
-
54
- const result = {};
55
- for (const instrumentId in this.stopLossData) {
56
- const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
57
- result[ticker] = {};
58
- for (const leverage in this.stopLossData[instrumentId]) {
59
- const data = this.stopLossData[instrumentId][leverage];
60
- // REFACTOR: Perform final calculation directly.
61
- if (data.count > 0) {
62
- result[ticker][leverage] = {
63
- average_distance_percent: data.distance_sum_percent / data.count,
64
- count: data.count
65
- };
66
- }
67
- }
68
- }
69
- return result;
70
- }
71
-
72
- reset() {
73
- this.stopLossData = {};
74
- this.mappings = null;
75
- }
76
- }
77
-
78
- module.exports = EntryDistanceToStopLossPerLeverage;
1
+ /**
2
+ * @fileoverview Calculates the average percentage distance from the entry price (OpenRate)
3
+ * to the stop loss rate for both long and short positions, grouped by asset and leverage level.
4
+ * It ignores near-zero stop loss values, which signify no stop loss is set.
5
+ */
6
+ const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
7
+
8
+ class EntryDistanceToStopLossPerLeverage {
9
+ constructor() {
10
+ this.stopLossData = {};
11
+ this.mappings = null;
12
+ }
13
+
14
+ process(portfolioData, yesterdayPortfolio, userId, context) {
15
+ if (portfolioData && portfolioData.PublicPositions) {
16
+ for (const position of portfolioData.PublicPositions) {
17
+ const instrumentId = position.InstrumentID;
18
+ const leverage = position.Leverage;
19
+ const stopLossRate = position.StopLossRate;
20
+ const openRate = position.OpenRate;
21
+ const isBuy = position.IsBuy;
22
+
23
+ if (stopLossRate > 0.0001 && openRate > 0) {
24
+ let distance;
25
+
26
+ if (isBuy) {
27
+ distance = openRate - stopLossRate;
28
+ } else {
29
+ distance = stopLossRate - openRate;
30
+ }
31
+
32
+ const distancePercent = (distance / openRate) * 100;
33
+
34
+ if (distancePercent > 0) {
35
+ if (!this.stopLossData[instrumentId]) {
36
+ this.stopLossData[instrumentId] = {};
37
+ }
38
+ if (!this.stopLossData[instrumentId][leverage]) {
39
+ this.stopLossData[instrumentId][leverage] = { distance_sum_percent: 0, count: 0 };
40
+ }
41
+ this.stopLossData[instrumentId][leverage].distance_sum_percent += distancePercent;
42
+ this.stopLossData[instrumentId][leverage].count++;
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ async getResult() {
50
+ if (!this.mappings) {
51
+ this.mappings = await loadInstrumentMappings();
52
+ }
53
+
54
+ const result = {};
55
+ for (const instrumentId in this.stopLossData) {
56
+ const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
57
+ result[ticker] = {};
58
+ for (const leverage in this.stopLossData[instrumentId]) {
59
+ const data = this.stopLossData[instrumentId][leverage];
60
+ // REFACTOR: Perform final calculation directly.
61
+ if (data.count > 0) {
62
+ result[ticker][leverage] = {
63
+ average_distance_percent: data.distance_sum_percent / data.count,
64
+ count: data.count
65
+ };
66
+ }
67
+ }
68
+ }
69
+ return result;
70
+ }
71
+
72
+ reset() {
73
+ this.stopLossData = {};
74
+ this.mappings = null;
75
+ }
76
+ }
77
+
78
+ module.exports = EntryDistanceToStopLossPerLeverage;
@@ -1,77 +1,77 @@
1
- /**
2
- * @fileoverview Calculates the average percentage distance from the entry price (OpenRate)
3
- * to the take profit rate for both long and short positions, grouped by asset and leverage level.
4
- * It ignores positions where the take profit is not meaningfully set.
5
- */
6
- const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
7
-
8
- class EntryDistanceToTakeProfitPerLeverage {
9
- constructor() {
10
- this.takeProfitData = {};
11
- this.mappings = null;
12
- }
13
-
14
- process(portfolioData, userId) {
15
- if (portfolioData && portfolioData.PublicPositions) {
16
- for (const position of portfolioData.PublicPositions) {
17
- const instrumentId = position.InstrumentID;
18
- const leverage = position.Leverage;
19
- const takeProfitRate = position.TakeProfitRate;
20
- const openRate = position.OpenRate;
21
- const isBuy = position.IsBuy;
22
-
23
- if (takeProfitRate > 0.0001 && openRate > 0) {
24
- let distance;
25
-
26
- if (isBuy) {
27
- distance = takeProfitRate - openRate;
28
- } else {
29
- distance = openRate - takeProfitRate;
30
- }
31
-
32
- const distancePercent = (distance / openRate) * 100;
33
-
34
- if (distancePercent > 0) {
35
- if (!this.takeProfitData[instrumentId]) {
36
- this.takeProfitData[instrumentId] = {};
37
- }
38
- if (!this.takeProfitData[instrumentId][leverage]) {
39
- this.takeProfitData[instrumentId][leverage] = { distance_sum_percent: 0, count: 0 };
40
- }
41
- this.takeProfitData[instrumentId][leverage].distance_sum_percent += distancePercent;
42
- this.takeProfitData[instrumentId][leverage].count++;
43
- }
44
- }
45
- }
46
- }
47
- }
48
-
49
- async getResult() {
50
- if (!this.mappings) {
51
- this.mappings = await loadInstrumentMappings();
52
- }
53
- const result = {};
54
- for (const instrumentId in this.takeProfitData) {
55
- const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
56
- result[ticker] = {};
57
- for (const leverage in this.takeProfitData[instrumentId]) {
58
- const data = this.takeProfitData[instrumentId][leverage];
59
- // REFACTOR: Perform final calculation directly.
60
- if (data.count > 0) {
61
- result[ticker][leverage] = {
62
- average_distance_percent: data.distance_sum_percent / data.count,
63
- count: data.count
64
- };
65
- }
66
- }
67
- }
68
- return result;
69
- }
70
-
71
- reset() {
72
- this.takeProfitData = {};
73
- this.mappings = null;
74
- }
75
- }
76
-
77
- module.exports = EntryDistanceToTakeProfitPerLeverage;
1
+ /**
2
+ * @fileoverview Calculates the average percentage distance from the entry price (OpenRate)
3
+ * to the take profit rate for both long and short positions, grouped by asset and leverage level.
4
+ * It ignores positions where the take profit is not meaningfully set.
5
+ */
6
+ const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
7
+
8
+ class EntryDistanceToTakeProfitPerLeverage {
9
+ constructor() {
10
+ this.takeProfitData = {};
11
+ this.mappings = null;
12
+ }
13
+
14
+ process(portfolioData, yesterdayPortfolio, userId, context) {
15
+ if (portfolioData && portfolioData.PublicPositions) {
16
+ for (const position of portfolioData.PublicPositions) {
17
+ const instrumentId = position.InstrumentID;
18
+ const leverage = position.Leverage;
19
+ const takeProfitRate = position.TakeProfitRate;
20
+ const openRate = position.OpenRate;
21
+ const isBuy = position.IsBuy;
22
+
23
+ if (takeProfitRate > 0.0001 && openRate > 0) {
24
+ let distance;
25
+
26
+ if (isBuy) {
27
+ distance = takeProfitRate - openRate;
28
+ } else {
29
+ distance = openRate - takeProfitRate;
30
+ }
31
+
32
+ const distancePercent = (distance / openRate) * 100;
33
+
34
+ if (distancePercent > 0) {
35
+ if (!this.takeProfitData[instrumentId]) {
36
+ this.takeProfitData[instrumentId] = {};
37
+ }
38
+ if (!this.takeProfitData[instrumentId][leverage]) {
39
+ this.takeProfitData[instrumentId][leverage] = { distance_sum_percent: 0, count: 0 };
40
+ }
41
+ this.takeProfitData[instrumentId][leverage].distance_sum_percent += distancePercent;
42
+ this.takeProfitData[instrumentId][leverage].count++;
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ async getResult() {
50
+ if (!this.mappings) {
51
+ this.mappings = await loadInstrumentMappings();
52
+ }
53
+ const result = {};
54
+ for (const instrumentId in this.takeProfitData) {
55
+ const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
56
+ result[ticker] = {};
57
+ for (const leverage in this.takeProfitData[instrumentId]) {
58
+ const data = this.takeProfitData[instrumentId][leverage];
59
+ // REFACTOR: Perform final calculation directly.
60
+ if (data.count > 0) {
61
+ result[ticker][leverage] = {
62
+ average_distance_percent: data.distance_sum_percent / data.count,
63
+ count: data.count
64
+ };
65
+ }
66
+ }
67
+ }
68
+ return result;
69
+ }
70
+
71
+ reset() {
72
+ this.takeProfitData = {};
73
+ this.mappings = null;
74
+ }
75
+ }
76
+
77
+ module.exports = EntryDistanceToTakeProfitPerLeverage;