@barchart/portfolio-api-common 1.15.0 → 1.17.0
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/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @barchart/portfolio-api-common
|
|
2
2
|
|
|
3
3
|
[](https://github.com/barchart/portfolio-api-common)
|
|
4
|
+
[](https://www.npmjs.com/package/@barchart/portfolio-api-common)
|
|
4
5
|
|
|
5
6
|
A *public* library of shared JavaScript code used by Barchart's paper-trading portfolio system.
|
|
6
7
|
|
|
@@ -450,29 +450,29 @@ module.exports = (() => {
|
|
|
450
450
|
}
|
|
451
451
|
|
|
452
452
|
/**
|
|
453
|
-
* A merger
|
|
453
|
+
* A closing transaction as a result of a merger (for the acquired company).
|
|
454
454
|
*
|
|
455
455
|
* @public
|
|
456
456
|
* @static
|
|
457
457
|
* @returns {TransactionType}
|
|
458
458
|
*/
|
|
459
|
-
static get
|
|
460
|
-
return
|
|
459
|
+
static get MERGER_CLOSE() {
|
|
460
|
+
return mergerClose;
|
|
461
461
|
}
|
|
462
462
|
|
|
463
463
|
/**
|
|
464
|
-
* A merger
|
|
464
|
+
* A opening transaction as a result of a merger (for the acquiring company).
|
|
465
465
|
*
|
|
466
466
|
* @public
|
|
467
467
|
* @static
|
|
468
468
|
* @returns {TransactionType}
|
|
469
469
|
*/
|
|
470
|
-
static get
|
|
471
|
-
return
|
|
470
|
+
static get MERGER_OPEN() {
|
|
471
|
+
return mergerOpen;
|
|
472
472
|
}
|
|
473
473
|
|
|
474
474
|
/**
|
|
475
|
-
* A spin-off.
|
|
475
|
+
* A spin-off (transaction applies to the original company).
|
|
476
476
|
*
|
|
477
477
|
* @public
|
|
478
478
|
* @static
|
|
@@ -483,7 +483,7 @@ module.exports = (() => {
|
|
|
483
483
|
}
|
|
484
484
|
|
|
485
485
|
/**
|
|
486
|
-
* A spin-off
|
|
486
|
+
* A spin-off (transaction opens a position in a new company).
|
|
487
487
|
*
|
|
488
488
|
* @public
|
|
489
489
|
* @static
|
|
@@ -510,11 +510,11 @@ module.exports = (() => {
|
|
|
510
510
|
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false, false, false, false, false);
|
|
511
511
|
const delist = new TransactionType('DL', 'Delist', 'Delist', 1, false, false, false, false, false, false, true, false, true, false, false, false, false);
|
|
512
512
|
|
|
513
|
-
const mergerOpen = new TransactionType('MO', 'Merger Open', 'Merger Open', 1, false, false, false, true, false, false, true, true, false, true, false, true, true);
|
|
514
513
|
const mergerClose = new TransactionType('MC', 'Merger Close', 'Merger Close', 1, false, false, false, false, true, false, true, false, true, false, true, false, false);
|
|
514
|
+
const mergerOpen = new TransactionType('MO', 'Merger Open', 'Merger Open', 1, false, false, false, true, false, false, true, true, false, true, false, true, true);
|
|
515
515
|
|
|
516
516
|
const spinoff = new TransactionType('SPF', 'Spinoff', 'Spinoff', 1, false, false, false, false, false, false, true, false, false, false, true, false, false);
|
|
517
|
-
const spinoffOpen = new TransactionType('SPFO', 'Spinoff Open', 'Spinoff Open', 1, false, false, false, true, false, false, true, true, false, true, false,
|
|
517
|
+
const spinoffOpen = new TransactionType('SPFO', 'Spinoff Open', 'Spinoff Open', 1, false, false, false, true, false, false, true, true, false, true, false, true, true);
|
|
518
518
|
|
|
519
519
|
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false, false, false, false, false);
|
|
520
520
|
const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false, false, false, false, false);
|
|
@@ -495,10 +495,10 @@ module.exports = (() => {
|
|
|
495
495
|
formatters.set(TransactionType.WITHDRAWAL, [ basicFormatter, cashFormatter ]);
|
|
496
496
|
formatters.set(TransactionType.DEBIT, [ basicFormatter, cashFormatter, debitFormatter ]);
|
|
497
497
|
formatters.set(TransactionType.CREDIT, [ basicFormatter, cashFormatter, creditFormatter ]);
|
|
498
|
-
formatters.set(TransactionType.MERGER_OPEN, [ basicFormatter ]);
|
|
498
|
+
formatters.set(TransactionType.MERGER_OPEN, [ basicFormatter, averageCostFormatter ]);
|
|
499
499
|
formatters.set(TransactionType.MERGER_CLOSE, [ basicFormatter, mergerFormatter ]);
|
|
500
|
-
formatters.set(TransactionType.SPINOFF, [ basicFormatter, spinoffFormatter ]);
|
|
501
|
-
formatters.set(TransactionType.SPINOFF_OPEN, [ basicFormatter ]);
|
|
500
|
+
formatters.set(TransactionType.SPINOFF, [ basicFormatter, spinoffFormatter, averageCostFormatter ]);
|
|
501
|
+
formatters.set(TransactionType.SPINOFF_OPEN, [ basicFormatter, averageCostFormatter ]);
|
|
502
502
|
|
|
503
503
|
function getInstrumentTypePriority(type) {
|
|
504
504
|
if (type === InstrumentType.CASH) {
|
|
@@ -44,13 +44,14 @@ module.exports = (() => {
|
|
|
44
44
|
* @public
|
|
45
45
|
* @param {PositionTreeDefinition[]} definitions
|
|
46
46
|
* @param {Object[]} portfolios - The portfolios.
|
|
47
|
-
* @param {Object[]} positions - The positions (for all
|
|
48
|
-
* @param {Object[]} summaries - The positions summaries (for all
|
|
47
|
+
* @param {Object[]} positions - The positions (for all portfolios).
|
|
48
|
+
* @param {Object[]} summaries - The positions summaries (for all positions).
|
|
49
49
|
* @param {PositionSummaryFrame=} reportFrame - If specified, locks the current (and previous) periods to a specific frame, use for reporting.
|
|
50
50
|
* @param {Day=} reportDate - The end date for the report frame.
|
|
51
|
+
* @param {Array[]=} currencyPairs - The currency pairs.
|
|
51
52
|
*/
|
|
52
53
|
class PositionContainer {
|
|
53
|
-
constructor(definitions, portfolios, positions, summaries, reportFrame, reportDate) {
|
|
54
|
+
constructor(definitions, portfolios, positions, summaries, reportFrame, reportDate, currencyPairs) {
|
|
54
55
|
assert.argumentIsArray(definitions, 'definitions', PositionTreeDefinition, 'PositionTreeDefinition');
|
|
55
56
|
assert.argumentIsArray(portfolios, 'portfolios');
|
|
56
57
|
assert.argumentIsArray(positions, 'positions');
|
|
@@ -61,6 +62,15 @@ module.exports = (() => {
|
|
|
61
62
|
assert.argumentIsRequired(reportDate, 'reportDate', Day, 'Day');
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
if (currencyPairs) {
|
|
66
|
+
assert.argumentIsArray(currencyPairs, 'currencyPairs');
|
|
67
|
+
|
|
68
|
+
currencyPairs.forEach((currencyPair) => {
|
|
69
|
+
assert.argumentIsArray(currencyPair, 'currencyPair', Currency, 'Currency');
|
|
70
|
+
assert.argumentIsValid(currencyPair.length, 'currencyPair.length', l => l === 2, 'has two items');
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
64
74
|
this._definitions = definitions;
|
|
65
75
|
|
|
66
76
|
this._groupBindings = { };
|
|
@@ -144,15 +154,25 @@ module.exports = (() => {
|
|
|
144
154
|
return map;
|
|
145
155
|
}, { });
|
|
146
156
|
|
|
147
|
-
|
|
157
|
+
if (is.array(currencyPairs)) {
|
|
158
|
+
currencyPairs.forEach((currencyPair) => {
|
|
159
|
+
currencyPair.sort((a, b) => comparators.compareStrings(a.code, b.code));
|
|
160
|
+
});
|
|
148
161
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
this._forexSymbols = array.unique(currencyPairs.map((currencyPair) => {
|
|
163
|
+
return `^${currencyPair[0].code}${currencyPair[1].code}`;
|
|
164
|
+
}));
|
|
165
|
+
} else {
|
|
166
|
+
const forexCurrencyCodes = array.unique(Object.keys(this._currencies).concat(REQUIRED_CURRENCIES.map(c => c.code)));
|
|
153
167
|
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
this._forexSymbols = forexCurrencyCodes.reduce((symbols, code) => {
|
|
169
|
+
if (code !== DEFAULT_CURRENCY.code) {
|
|
170
|
+
symbols.push(`^${code}${DEFAULT_CURRENCY.code}`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return symbols;
|
|
174
|
+
}, [ ]);
|
|
175
|
+
}
|
|
156
176
|
|
|
157
177
|
this._forexQuotes = this._forexSymbols.map((symbol) => {
|
|
158
178
|
return Rate.fromPair(Decimal.ONE, symbol);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barchart/portfolio-api-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "Common JavaScript code used by Barchart's Portfolio Service",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bryan Ingle",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"url": "git+ssh://git@github.com/barchart/portfolio-api-common.git"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@barchart/common-js": "^4.
|
|
18
|
+
"@barchart/common-js": "^4.27.0",
|
|
19
19
|
"uuid": "^8.3.2"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|