@barchart/portfolio-api-common 1.0.194 → 1.0.198
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.
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const FailureType = require('@barchart/common-js/api/failures/FailureType');
|
|
2
|
+
|
|
3
|
+
module.exports = (() => {
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A static container for portfolio-specific {@link FailureType} items.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class PortfolioFailureType {
|
|
12
|
+
constructor() {
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The transaction would occur before an existing transaction.
|
|
17
|
+
*
|
|
18
|
+
* @static
|
|
19
|
+
* @returns {FailureType}
|
|
20
|
+
*/
|
|
21
|
+
static get TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE() {
|
|
22
|
+
return transactionCreateFailedOutOfSequence;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The transaction would cause the position to change (from long to
|
|
27
|
+
* short, or vice versa).
|
|
28
|
+
*
|
|
29
|
+
* @static
|
|
30
|
+
* @returns {FailureType}
|
|
31
|
+
*/
|
|
32
|
+
static get TRANSACTION_CREATE_FAILED_DIRECTION_SWITCH() {
|
|
33
|
+
return transactionCreateFailedDirectionSwitch;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toString() {
|
|
37
|
+
return '[PortfolioFailureType]';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to create transaction, because the transaction date is out-of-sequence. In other words, it would occur before an existing transaction. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
|
|
42
|
+
const transactionCreateFailedDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_DIRECTION_SWITCH', 'Unable to create transaction, because the position direction would be switched (from long to short or vice versa). Please close the position (to a zero balance) first, then enter a second transaction.');
|
|
43
|
+
|
|
44
|
+
return PortfolioFailureType;
|
|
45
|
+
})();
|
|
@@ -24,6 +24,11 @@ module.exports = (() => {
|
|
|
24
24
|
|
|
25
25
|
const DEFAULT_CURRENCY = Currency.CAD;
|
|
26
26
|
|
|
27
|
+
const REQUIRED_CURRENCIES = [
|
|
28
|
+
Currency.CAD,
|
|
29
|
+
Currency.USD
|
|
30
|
+
];
|
|
31
|
+
|
|
27
32
|
/**
|
|
28
33
|
* A container for positions which groups the positions into one or more
|
|
29
34
|
* trees for aggregation and display purposes. For example, positions could be
|
|
@@ -114,7 +119,9 @@ module.exports = (() => {
|
|
|
114
119
|
return map;
|
|
115
120
|
}, { });
|
|
116
121
|
|
|
117
|
-
|
|
122
|
+
const forexCurrencyCodes = array.unique(Object.keys(this._currencies).concat(REQUIRED_CURRENCIES.map(c => c.code)));
|
|
123
|
+
|
|
124
|
+
this._forexSymbols = forexCurrencyCodes.reduce((symbols, code) => {
|
|
118
125
|
if (code !== DEFAULT_CURRENCY.code) {
|
|
119
126
|
symbols.push(`^${DEFAULT_CURRENCY.code}${code}`);
|
|
120
127
|
}
|
|
@@ -290,7 +297,7 @@ module.exports = (() => {
|
|
|
290
297
|
|
|
291
298
|
const addedBarchartSymbol = extractSymbolForBarchart(item.position);
|
|
292
299
|
|
|
293
|
-
if (!existingBarchartSymbols.some(existingBarchartSymbol => existingBarchartSymbol === addedBarchartSymbol)) {
|
|
300
|
+
if (addedBarchartSymbol !== null && !existingBarchartSymbols.some(existingBarchartSymbol => existingBarchartSymbol === addedBarchartSymbol)) {
|
|
294
301
|
this._positionSymbolAddedEvent.fire(addedBarchartSymbol);
|
|
295
302
|
}
|
|
296
303
|
});
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -740,6 +740,11 @@ module.exports = (() => {
|
|
|
740
740
|
|
|
741
741
|
const DEFAULT_CURRENCY = Currency.CAD;
|
|
742
742
|
|
|
743
|
+
const REQUIRED_CURRENCIES = [
|
|
744
|
+
Currency.CAD,
|
|
745
|
+
Currency.USD
|
|
746
|
+
];
|
|
747
|
+
|
|
743
748
|
/**
|
|
744
749
|
* A container for positions which groups the positions into one or more
|
|
745
750
|
* trees for aggregation and display purposes. For example, positions could be
|
|
@@ -830,7 +835,9 @@ module.exports = (() => {
|
|
|
830
835
|
return map;
|
|
831
836
|
}, { });
|
|
832
837
|
|
|
833
|
-
|
|
838
|
+
const forexCurrencyCodes = array.unique(Object.keys(this._currencies).concat(REQUIRED_CURRENCIES.map(c => c.code)));
|
|
839
|
+
|
|
840
|
+
this._forexSymbols = forexCurrencyCodes.reduce((symbols, code) => {
|
|
834
841
|
if (code !== DEFAULT_CURRENCY.code) {
|
|
835
842
|
symbols.push(`^${DEFAULT_CURRENCY.code}${code}`);
|
|
836
843
|
}
|
|
@@ -1006,7 +1013,7 @@ module.exports = (() => {
|
|
|
1006
1013
|
|
|
1007
1014
|
const addedBarchartSymbol = extractSymbolForBarchart(item.position);
|
|
1008
1015
|
|
|
1009
|
-
if (!existingBarchartSymbols.some(existingBarchartSymbol => existingBarchartSymbol === addedBarchartSymbol)) {
|
|
1016
|
+
if (addedBarchartSymbol !== null && !existingBarchartSymbols.some(existingBarchartSymbol => existingBarchartSymbol === addedBarchartSymbol)) {
|
|
1010
1017
|
this._positionSymbolAddedEvent.fire(addedBarchartSymbol);
|
|
1011
1018
|
}
|
|
1012
1019
|
});
|