@barchart/portfolio-api-common 1.0.236 → 1.0.240

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.
@@ -23,6 +23,17 @@ module.exports = (() => {
23
23
  return positionCreateFailedNoPortfolio;
24
24
  }
25
25
 
26
+ /**
27
+ * The referenced position does not exist.
28
+ *
29
+ * @public
30
+ * @static
31
+ * @returns {FailureType}
32
+ */
33
+ static get TRANSACTION_CREATE_FAILED_NO_POSITION() {
34
+ return transactionCreateFailedNoPosition;
35
+ }
36
+
26
37
  /**
27
38
  * The transaction would occur before an existing transaction.
28
39
  *
@@ -94,6 +105,7 @@ module.exports = (() => {
94
105
 
95
106
  const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_NO_PORTFOLIO', 'Unable to create transaction. The referenced portfolio does not exist. Has it been deleted?');
96
107
 
108
+ const transactionCreateFailedNoPosition = new FailureType('TRANSACTION_CREATE_FAILED_NO_POSITION', 'Unable to create transaction. The referenced position does not exist. Has it been deleted?');
97
109
  const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to process 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).');
98
110
  const transactionCreateFailedTypeInvalidForInstrument = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_INSTRUMENT', 'Unable to process transaction, {L|transactionType.description} transactions cannot be used with {L|instrumentType.description} positions.');
99
111
  const transactionCreateFailedTypeInvalidForDirection = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_INVALID_FOR_DIRECTION', 'Unable to process transaction, a {L|positionDirection.description} position would be created (i.e. you would have {L|positionDirection.sign} shares/units). {u|instrumentType.description} positions cannot have {L|positionDirection.description} positions.');
@@ -27,7 +27,7 @@ module.exports = (() => {
27
27
  * @static
28
28
  * @param {Array<Object>} transactions
29
29
  * @param {Array<Object>} positions
30
- * @param {Boolean=} append
30
+ * @param {Boolean=} append - Warning, if true, the transaction array will be mutated.
31
31
  * @returns {Array}
32
32
  */
33
33
  static format(transactions, positions, append) {
@@ -36,18 +36,22 @@ module.exports = (() => {
36
36
  assert.argumentIsOptional(append, 'append', Boolean);
37
37
 
38
38
  const instruments = positions.reduce((map, p) => {
39
- map[p.position] = p.instrument;
39
+ const instrument = Object.assign({ }, p.instrument || { });
40
+
41
+ delete instrument.id;
42
+
43
+ map[p.position] = instrument;
40
44
 
41
45
  return map;
42
46
  }, { });
43
47
 
44
48
  return transactions.reduce((list, transaction) => {
45
49
  const position = transaction.position;
50
+ const position = transaction.position;
46
51
 
47
52
  if (instruments.hasOwnProperty(position)) {
48
- transaction.instrument = instruments[position];
49
-
50
- let formatted = getBasicTransaction(transaction);
53
+ let instrument = instruments[position];
54
+ let formatted = getBasicTransaction(transaction, instrument);
51
55
 
52
56
  if (formatters.has(transaction.type)) {
53
57
  const formatterFunction = formatters.get(transaction.type);
@@ -55,7 +59,7 @@ module.exports = (() => {
55
59
 
56
60
  Object.keys(formattedTransaction).map((key) => {
57
61
  if (!is.undefined(formattedTransaction[key]) && formattedTransaction[key] instanceof Decimal) {
58
- const precision = transaction.instrument.currency.precision;
62
+ const precision = instrument.currency.precision;
59
63
 
60
64
  formattedTransaction[key] = formatter.numberToString(formattedTransaction[key].toFloat(), precision, ',');
61
65
  }
@@ -86,20 +90,14 @@ module.exports = (() => {
86
90
  }
87
91
  }
88
92
 
89
- const getBasicTransaction = (t) => {
90
- const basic = {
93
+ const getBasicTransaction = (t, i) => {
94
+ return {
91
95
  date: t.date,
92
96
  type: t.type.display,
93
97
  sequence: t.sequence,
94
- instrument: t.instrument,
98
+ instrument: i,
95
99
  position: t.position
96
100
  };
97
-
98
- if (basic.instrument) {
99
- delete basic.instrument.id;
100
- }
101
-
102
- return basic;
103
101
  };
104
102
 
105
103
  const formatters = new Map();
@@ -121,7 +119,7 @@ module.exports = (() => {
121
119
  formatters.set(TransactionType.DIVIDEND, (t) => {
122
120
  return {
123
121
  shares: t.snapshot.open,
124
- total: t.dividend.amout,
122
+ total: t.dividend.amount,
125
123
  rate: t.dividend.rate
126
124
  };
127
125
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.236",
3
+ "version": "1.0.240",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",