aiden-shared-calculations-unified 1.0.7 → 1.0.9
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/calculations/pnl/average_daily_pnl_all_users.js +1 -1
- package/calculations/pnl/average_daily_pnl_per_sector.js +1 -1
- package/calculations/pnl/average_daily_pnl_per_stock.js +1 -1
- package/calculations/pnl/average_daily_position_pnl.js +1 -1
- package/calculations/pnl/pnl_distribution_per_stock.js +52 -52
- package/calculations/pnl/profitability_ratio_per_stock.js +50 -50
- package/calculations/pnl/profitability_skew_per_stock.js +58 -58
- package/calculations/sanity/users_processed.js +26 -26
- package/calculations/sectors/total_long_per_sector.js +1 -1
- package/calculations/sectors/total_short_per_sector.js +1 -1
- package/calculations/short_and_long_stats/long_position_per_stock.js +1 -1
- package/calculations/short_and_long_stats/sentiment_per_stock.js +49 -49
- package/calculations/short_and_long_stats/short_position_per_stock.js +1 -1
- package/calculations/short_and_long_stats/total_long_figures.js +1 -1
- package/calculations/short_and_long_stats/total_short_figures.js +1 -1
- package/calculations/socialPosts/social-asset-posts-trend.js +53 -0
- package/calculations/socialPosts/social-top-mentioned-words.js +103 -0
- package/calculations/socialPosts/social-topic-interest-evolution.js +54 -0
- package/calculations/socialPosts/social-word-mentions-trend.js +63 -0
- package/calculations/speculators/distance_to_stop_loss_per_leverage.js +78 -78
- package/calculations/speculators/distance_to_tp_per_leverage.js +76 -76
- package/calculations/speculators/entry_distance_to_sl_per_leverage.js +78 -78
- package/calculations/speculators/entry_distance_to_tp_per_leverage.js +77 -77
- package/calculations/speculators/holding_duration_per_asset.js +55 -55
- package/calculations/speculators/leverage_per_asset.js +46 -46
- package/calculations/speculators/leverage_per_sector.js +44 -44
- package/calculations/speculators/risk_reward_ratio_per_asset.js +60 -60
- package/calculations/speculators/speculator_asset_sentiment.js +81 -81
- package/calculations/speculators/speculator_danger_zone.js +57 -57
- package/calculations/speculators/stop_loss_distance_by_sector_short_long_breakdown.js +91 -91
- package/calculations/speculators/stop_loss_distance_by_ticker_short_long_breakdown.js +73 -73
- package/calculations/speculators/stop_loss_per_asset.js +55 -55
- package/calculations/speculators/take_profit_per_asset.js +55 -55
- package/calculations/speculators/tsl_per_asset.js +51 -51
- package/package.json +1 -1
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Calculates the average stop loss distance (percent and value)
|
|
3
|
-
* for long and short positions, grouped by TICKER.
|
|
4
|
-
*/
|
|
5
|
-
const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
|
|
6
|
-
|
|
7
|
-
class StopLossDistanceByTicker {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.instrumentData = {};
|
|
10
|
-
this.instrumentToTicker = null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
process(portfolioData, userId) {
|
|
14
|
-
if (!portfolioData || !portfolioData.PublicPositions) return;
|
|
15
|
-
|
|
16
|
-
for (const position of portfolioData.PublicPositions) {
|
|
17
|
-
const { InstrumentID, Leverage, StopLossRate, CurrentRate, IsBuy } = position;
|
|
18
|
-
if (Leverage <= 1 || StopLossRate <= 0.0001 || CurrentRate <= 0) continue;
|
|
19
|
-
|
|
20
|
-
const distance_value = IsBuy ? CurrentRate - StopLossRate : StopLossRate - CurrentRate;
|
|
21
|
-
const distance_percent = (distance_value / CurrentRate) * 100;
|
|
22
|
-
|
|
23
|
-
if (distance_percent > 0) {
|
|
24
|
-
const posType = IsBuy ? 'long' : 'short';
|
|
25
|
-
if (!this.instrumentData[InstrumentID]) this.instrumentData[InstrumentID] = {};
|
|
26
|
-
if (!this.instrumentData[InstrumentID][posType]) {
|
|
27
|
-
this.instrumentData[InstrumentID][posType] = {
|
|
28
|
-
distance_percent_sum: 0,
|
|
29
|
-
distance_value_sum: 0,
|
|
30
|
-
count: 0
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const agg = this.instrumentData[InstrumentID][posType];
|
|
34
|
-
agg.distance_percent_sum += distance_percent;
|
|
35
|
-
agg.distance_value_sum += distance_value;
|
|
36
|
-
agg.count++;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async getResult() {
|
|
42
|
-
if (Object.keys(this.instrumentData).length === 0) return {};
|
|
43
|
-
if (!this.instrumentToTicker) {
|
|
44
|
-
const mappings = await loadInstrumentMappings();
|
|
45
|
-
this.instrumentToTicker = mappings.instrumentToTicker;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const result = {};
|
|
49
|
-
for (const instrumentId in this.instrumentData) {
|
|
50
|
-
const ticker = this.instrumentToTicker[instrumentId] || `unknown_${instrumentId}`;
|
|
51
|
-
if (!result[ticker]) result[ticker] = {};
|
|
52
|
-
|
|
53
|
-
for (const posType in this.instrumentData[instrumentId]) {
|
|
54
|
-
const data = this.instrumentData[instrumentId][posType];
|
|
55
|
-
// REFACTOR: Perform final calculation and return in standardized format.
|
|
56
|
-
if (data.count > 0) {
|
|
57
|
-
result[ticker][posType] = {
|
|
58
|
-
average_distance_percent: data.distance_percent_sum / data.count,
|
|
59
|
-
average_distance_value: data.distance_value_sum / data.count,
|
|
60
|
-
count: data.count
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
reset() {
|
|
69
|
-
this.instrumentData = {};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
module.exports = StopLossDistanceByTicker;
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Calculates the average stop loss distance (percent and value)
|
|
3
|
+
* for long and short positions, grouped by TICKER.
|
|
4
|
+
*/
|
|
5
|
+
const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
|
|
6
|
+
|
|
7
|
+
class StopLossDistanceByTicker {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.instrumentData = {};
|
|
10
|
+
this.instrumentToTicker = null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
process(portfolioData, yesterdayPortfolio, userId, context) {
|
|
14
|
+
if (!portfolioData || !portfolioData.PublicPositions) return;
|
|
15
|
+
|
|
16
|
+
for (const position of portfolioData.PublicPositions) {
|
|
17
|
+
const { InstrumentID, Leverage, StopLossRate, CurrentRate, IsBuy } = position;
|
|
18
|
+
if (Leverage <= 1 || StopLossRate <= 0.0001 || CurrentRate <= 0) continue;
|
|
19
|
+
|
|
20
|
+
const distance_value = IsBuy ? CurrentRate - StopLossRate : StopLossRate - CurrentRate;
|
|
21
|
+
const distance_percent = (distance_value / CurrentRate) * 100;
|
|
22
|
+
|
|
23
|
+
if (distance_percent > 0) {
|
|
24
|
+
const posType = IsBuy ? 'long' : 'short';
|
|
25
|
+
if (!this.instrumentData[InstrumentID]) this.instrumentData[InstrumentID] = {};
|
|
26
|
+
if (!this.instrumentData[InstrumentID][posType]) {
|
|
27
|
+
this.instrumentData[InstrumentID][posType] = {
|
|
28
|
+
distance_percent_sum: 0,
|
|
29
|
+
distance_value_sum: 0,
|
|
30
|
+
count: 0
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const agg = this.instrumentData[InstrumentID][posType];
|
|
34
|
+
agg.distance_percent_sum += distance_percent;
|
|
35
|
+
agg.distance_value_sum += distance_value;
|
|
36
|
+
agg.count++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async getResult() {
|
|
42
|
+
if (Object.keys(this.instrumentData).length === 0) return {};
|
|
43
|
+
if (!this.instrumentToTicker) {
|
|
44
|
+
const mappings = await loadInstrumentMappings();
|
|
45
|
+
this.instrumentToTicker = mappings.instrumentToTicker;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const result = {};
|
|
49
|
+
for (const instrumentId in this.instrumentData) {
|
|
50
|
+
const ticker = this.instrumentToTicker[instrumentId] || `unknown_${instrumentId}`;
|
|
51
|
+
if (!result[ticker]) result[ticker] = {};
|
|
52
|
+
|
|
53
|
+
for (const posType in this.instrumentData[instrumentId]) {
|
|
54
|
+
const data = this.instrumentData[instrumentId][posType];
|
|
55
|
+
// REFACTOR: Perform final calculation and return in standardized format.
|
|
56
|
+
if (data.count > 0) {
|
|
57
|
+
result[ticker][posType] = {
|
|
58
|
+
average_distance_percent: data.distance_percent_sum / data.count,
|
|
59
|
+
average_distance_value: data.distance_value_sum / data.count,
|
|
60
|
+
count: data.count
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
reset() {
|
|
69
|
+
this.instrumentData = {};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = StopLossDistanceByTicker;
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Calculates the average stop loss level per asset.
|
|
3
|
-
*/
|
|
4
|
-
const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
|
|
5
|
-
|
|
6
|
-
class StopLossPerAsset {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.stopLossData = {};
|
|
9
|
-
this.mappings = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
process(portfolioData, userId) {
|
|
13
|
-
if (portfolioData && portfolioData.PublicPositions) {
|
|
14
|
-
for (const position of portfolioData.PublicPositions) {
|
|
15
|
-
const instrumentId = position.InstrumentID;
|
|
16
|
-
const stopLoss = position.StopLossRate;
|
|
17
|
-
|
|
18
|
-
if (stopLoss > 0) {
|
|
19
|
-
if (!this.stopLossData[instrumentId]) {
|
|
20
|
-
this.stopLossData[instrumentId] = { sum: 0, count: 0 };
|
|
21
|
-
}
|
|
22
|
-
this.stopLossData[instrumentId].sum += stopLoss;
|
|
23
|
-
this.stopLossData[instrumentId].count++;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async getResult() {
|
|
30
|
-
if (!this.mappings) {
|
|
31
|
-
this.mappings = await loadInstrumentMappings();
|
|
32
|
-
}
|
|
33
|
-
const result = {};
|
|
34
|
-
for (const instrumentId in this.stopLossData) {
|
|
35
|
-
const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
|
|
36
|
-
const data = this.stopLossData[instrumentId];
|
|
37
|
-
|
|
38
|
-
// REFACTOR: Perform final calculation directly.
|
|
39
|
-
if (data.count > 0) {
|
|
40
|
-
result[ticker] = {
|
|
41
|
-
average_stop_loss: data.sum / data.count
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
reset() {
|
|
50
|
-
this.stopLossData = {};
|
|
51
|
-
this.mappings = null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = StopLossPerAsset;
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Calculates the average stop loss level per asset.
|
|
3
|
+
*/
|
|
4
|
+
const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
|
|
5
|
+
|
|
6
|
+
class StopLossPerAsset {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.stopLossData = {};
|
|
9
|
+
this.mappings = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
process(portfolioData, yesterdayPortfolio, userId, context) {
|
|
13
|
+
if (portfolioData && portfolioData.PublicPositions) {
|
|
14
|
+
for (const position of portfolioData.PublicPositions) {
|
|
15
|
+
const instrumentId = position.InstrumentID;
|
|
16
|
+
const stopLoss = position.StopLossRate;
|
|
17
|
+
|
|
18
|
+
if (stopLoss > 0) {
|
|
19
|
+
if (!this.stopLossData[instrumentId]) {
|
|
20
|
+
this.stopLossData[instrumentId] = { sum: 0, count: 0 };
|
|
21
|
+
}
|
|
22
|
+
this.stopLossData[instrumentId].sum += stopLoss;
|
|
23
|
+
this.stopLossData[instrumentId].count++;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getResult() {
|
|
30
|
+
if (!this.mappings) {
|
|
31
|
+
this.mappings = await loadInstrumentMappings();
|
|
32
|
+
}
|
|
33
|
+
const result = {};
|
|
34
|
+
for (const instrumentId in this.stopLossData) {
|
|
35
|
+
const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
|
|
36
|
+
const data = this.stopLossData[instrumentId];
|
|
37
|
+
|
|
38
|
+
// REFACTOR: Perform final calculation directly.
|
|
39
|
+
if (data.count > 0) {
|
|
40
|
+
result[ticker] = {
|
|
41
|
+
average_stop_loss: data.sum / data.count
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
reset() {
|
|
50
|
+
this.stopLossData = {};
|
|
51
|
+
this.mappings = null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = StopLossPerAsset;
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Calculates the average take profit level per asset.
|
|
3
|
-
*/
|
|
4
|
-
const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
|
|
5
|
-
|
|
6
|
-
class TakeProfitPerAsset {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.takeProfitData = {};
|
|
9
|
-
this.mappings = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
process(portfolioData, userId) {
|
|
13
|
-
if (portfolioData && portfolioData.PublicPositions) {
|
|
14
|
-
for (const position of portfolioData.PublicPositions) {
|
|
15
|
-
const instrumentId = position.InstrumentID;
|
|
16
|
-
const takeProfit = position.TakeProfitRate;
|
|
17
|
-
|
|
18
|
-
if (takeProfit > 0) {
|
|
19
|
-
if (!this.takeProfitData[instrumentId]) {
|
|
20
|
-
this.takeProfitData[instrumentId] = { sum: 0, count: 0 };
|
|
21
|
-
}
|
|
22
|
-
this.takeProfitData[instrumentId].sum += takeProfit;
|
|
23
|
-
this.takeProfitData[instrumentId].count++;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async getResult() {
|
|
30
|
-
if (!this.mappings) {
|
|
31
|
-
this.mappings = await loadInstrumentMappings();
|
|
32
|
-
}
|
|
33
|
-
const result = {};
|
|
34
|
-
for (const instrumentId in this.takeProfitData) {
|
|
35
|
-
const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
|
|
36
|
-
const data = this.takeProfitData[instrumentId];
|
|
37
|
-
|
|
38
|
-
// REFACTOR: Perform final calculation directly.
|
|
39
|
-
if (data.count > 0) {
|
|
40
|
-
result[ticker] = {
|
|
41
|
-
average_take_profit: data.sum / data.count
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
reset() {
|
|
50
|
-
this.takeProfitData = {};
|
|
51
|
-
this.mappings = null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = TakeProfitPerAsset;
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Calculates the average take profit level per asset.
|
|
3
|
+
*/
|
|
4
|
+
const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
|
|
5
|
+
|
|
6
|
+
class TakeProfitPerAsset {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.takeProfitData = {};
|
|
9
|
+
this.mappings = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
process(portfolioData, yesterdayPortfolio, userId, context) {
|
|
13
|
+
if (portfolioData && portfolioData.PublicPositions) {
|
|
14
|
+
for (const position of portfolioData.PublicPositions) {
|
|
15
|
+
const instrumentId = position.InstrumentID;
|
|
16
|
+
const takeProfit = position.TakeProfitRate;
|
|
17
|
+
|
|
18
|
+
if (takeProfit > 0) {
|
|
19
|
+
if (!this.takeProfitData[instrumentId]) {
|
|
20
|
+
this.takeProfitData[instrumentId] = { sum: 0, count: 0 };
|
|
21
|
+
}
|
|
22
|
+
this.takeProfitData[instrumentId].sum += takeProfit;
|
|
23
|
+
this.takeProfitData[instrumentId].count++;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getResult() {
|
|
30
|
+
if (!this.mappings) {
|
|
31
|
+
this.mappings = await loadInstrumentMappings();
|
|
32
|
+
}
|
|
33
|
+
const result = {};
|
|
34
|
+
for (const instrumentId in this.takeProfitData) {
|
|
35
|
+
const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
|
|
36
|
+
const data = this.takeProfitData[instrumentId];
|
|
37
|
+
|
|
38
|
+
// REFACTOR: Perform final calculation directly.
|
|
39
|
+
if (data.count > 0) {
|
|
40
|
+
result[ticker] = {
|
|
41
|
+
average_take_profit: data.sum / data.count
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
reset() {
|
|
50
|
+
this.takeProfitData = {};
|
|
51
|
+
this.mappings = null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = TakeProfitPerAsset;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Counts how many users have TSL enabled vs. disabled per asset.
|
|
3
|
-
*/
|
|
4
|
-
const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
|
|
5
|
-
|
|
6
|
-
class TslPerAsset {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.tslData = {};
|
|
9
|
-
this.mappings = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
process(portfolioData, userId) {
|
|
13
|
-
if (portfolioData && portfolioData.PublicPositions) {
|
|
14
|
-
for (const position of portfolioData.PublicPositions) {
|
|
15
|
-
const instrumentId = position.InstrumentID;
|
|
16
|
-
const isTslEnabled = position.IsTslEnabled;
|
|
17
|
-
|
|
18
|
-
if (!this.tslData[instrumentId]) {
|
|
19
|
-
this.tslData[instrumentId] = { enabled: 0, disabled: 0 };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (isTslEnabled) {
|
|
23
|
-
this.tslData[instrumentId].enabled++;
|
|
24
|
-
} else {
|
|
25
|
-
this.tslData[instrumentId].disabled++;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async getResult() {
|
|
32
|
-
if (!this.mappings) {
|
|
33
|
-
this.mappings = await loadInstrumentMappings();
|
|
34
|
-
}
|
|
35
|
-
const result = {};
|
|
36
|
-
for (const instrumentId in this.tslData) {
|
|
37
|
-
const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
|
|
38
|
-
result[ticker] = this.tslData[instrumentId];
|
|
39
|
-
}
|
|
40
|
-
if (Object.keys(result).length === 0) return {};
|
|
41
|
-
return {
|
|
42
|
-
tsl_per_asset: result
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
reset() {
|
|
47
|
-
this.tslData = {};
|
|
48
|
-
this.mappings = null;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Counts how many users have TSL enabled vs. disabled per asset.
|
|
3
|
+
*/
|
|
4
|
+
const { loadInstrumentMappings } = require('../../utils/sector_mapping_provider');
|
|
5
|
+
|
|
6
|
+
class TslPerAsset {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.tslData = {};
|
|
9
|
+
this.mappings = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
process(portfolioData, yesterdayPortfolio, userId, context) {
|
|
13
|
+
if (portfolioData && portfolioData.PublicPositions) {
|
|
14
|
+
for (const position of portfolioData.PublicPositions) {
|
|
15
|
+
const instrumentId = position.InstrumentID;
|
|
16
|
+
const isTslEnabled = position.IsTslEnabled;
|
|
17
|
+
|
|
18
|
+
if (!this.tslData[instrumentId]) {
|
|
19
|
+
this.tslData[instrumentId] = { enabled: 0, disabled: 0 };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (isTslEnabled) {
|
|
23
|
+
this.tslData[instrumentId].enabled++;
|
|
24
|
+
} else {
|
|
25
|
+
this.tslData[instrumentId].disabled++;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async getResult() {
|
|
32
|
+
if (!this.mappings) {
|
|
33
|
+
this.mappings = await loadInstrumentMappings();
|
|
34
|
+
}
|
|
35
|
+
const result = {};
|
|
36
|
+
for (const instrumentId in this.tslData) {
|
|
37
|
+
const ticker = this.mappings.instrumentToTicker[instrumentId] || instrumentId.toString();
|
|
38
|
+
result[ticker] = this.tslData[instrumentId];
|
|
39
|
+
}
|
|
40
|
+
if (Object.keys(result).length === 0) return {};
|
|
41
|
+
return {
|
|
42
|
+
tsl_per_asset: result
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
reset() {
|
|
47
|
+
this.tslData = {};
|
|
48
|
+
this.mappings = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
52
|
module.exports = TslPerAsset;
|