@barchart/portfolio-api-common 1.0.195 → 1.0.199
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,71 @@
|
|
|
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
|
+
* @public
|
|
19
|
+
* @static
|
|
20
|
+
* @returns {FailureType}
|
|
21
|
+
*/
|
|
22
|
+
static get TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE() {
|
|
23
|
+
return transactionCreateFailedOutOfSequence;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The transaction would cause the position to change (from long to
|
|
28
|
+
* short, or vice versa).
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
* @static
|
|
32
|
+
* @returns {FailureType}
|
|
33
|
+
*/
|
|
34
|
+
static get TRANSACTION_CREATE_FAILED_DIRECTION_SWITCH() {
|
|
35
|
+
return transactionCreateFailedDirectionSwitch;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static get TRANSACTION_CREATE_REWRITE_UNSUPPORTED() {
|
|
39
|
+
return transactionCreateRewriteUnsupported;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Deleting any transaction except for the most recent requires
|
|
44
|
+
* re-writing transaction history.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
* @static
|
|
48
|
+
* @returns {FailureType}
|
|
49
|
+
*/
|
|
50
|
+
static get TRANSACTION_DELETE_FAILED_OUT_OF_SEQUENCE() {
|
|
51
|
+
return transactionDeleteFailedOutOfSequence;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static get TRANSACTION_DELETE_UNSUPPORTED() {
|
|
55
|
+
return transactionDeleteUnsupported;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
toString() {
|
|
59
|
+
return '[PortfolioFailureType]';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
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).');
|
|
64
|
+
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.');
|
|
65
|
+
const transactionCreateRewriteUnsupported = new FailureType('TRANSACTION_CREATE_REWRITE_UNSUPPORTED', 'Unable to re-write transaction history. This operation is not currently supported (but will be implemented soon).');
|
|
66
|
+
|
|
67
|
+
const transactionDeleteFailedOutOfSequence = new FailureType('TRANSACTION_DELETE_FAILED_OUT_OF_SEQUENCE', 'Deleting any transaction, except for the most recent, will cause transaction history to be re-written. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
|
|
68
|
+
const transactionDeleteUnsupported = new FailureType('TRANSACTION_DELETE_UNSUPPORTED', 'Unable to delete transaction. This operation is not currently supported (but will be implemented soon).');
|
|
69
|
+
|
|
70
|
+
return PortfolioFailureType;
|
|
71
|
+
})();
|
|
@@ -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
|
}
|
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
|
}
|