@barchart/portfolio-api-common 1.2.51 → 1.2.55

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.
@@ -19,10 +19,11 @@ module.exports = (() => {
19
19
  * @param {Boolean} canSwitchDirection
20
20
  * @param {Boolean} usesSymbols
21
21
  * @param {Boolean} hasCorporateActions
22
+ * @param {Number} closeFractional
22
23
  * @param {Function} generator
23
24
  */
24
25
  class InstrumentType extends Enum {
25
- constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, generator) {
26
+ constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, generator) {
26
27
  super(code, description);
27
28
 
28
29
  assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
@@ -31,6 +32,7 @@ module.exports = (() => {
31
32
  assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
32
33
  assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
33
34
  assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
35
+ assert.argumentIsRequired(closeFractional, 'closeFractional', Boolean);
34
36
  assert.argumentIsRequired(generator, 'generator', Function);
35
37
 
36
38
  this._alternateDescription = alternateDescription;
@@ -39,6 +41,7 @@ module.exports = (() => {
39
41
  this._canSwitchDirection = canSwitchDirection;
40
42
  this._usesSymbols = usesSymbols;
41
43
  this._hasCorporateActions = hasCorporateActions;
44
+ this._closeFractional = closeFractional;
42
45
 
43
46
  this._generator = generator;
44
47
  }
@@ -104,6 +107,18 @@ module.exports = (() => {
104
107
  return this._hasCorporateActions;
105
108
  }
106
109
 
110
+ /**
111
+ * Indicates if fractional shares should be closed when the position
112
+ * size is less than one.
113
+ *
114
+ * @public
115
+ * @returns {Boolean}
116
+ */
117
+ get closeFractional() {
118
+ return this._closeFractional;
119
+ }
120
+
121
+
107
122
  /**
108
123
  * Generates an identifier for the instrument.
109
124
  *
@@ -201,10 +216,10 @@ module.exports = (() => {
201
216
  }
202
217
  }
203
218
 
204
- const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
205
- const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
206
- const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
207
- const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
219
+ const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
220
+ const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
221
+ const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
222
+ const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
208
223
 
209
224
  const map = { };
210
225
 
@@ -12,6 +12,7 @@ module.exports = (() => {
12
12
  * @param {String} code
13
13
  * @param {String} description
14
14
  * @param {String} display
15
+ * @param {Number} sequence
15
16
  * @param {Boolean} purchase
16
17
  * @param {Boolean} sale
17
18
  * @param {Boolean} income
@@ -21,13 +22,14 @@ module.exports = (() => {
21
22
  * @param {Boolean} corporateAction
22
23
  * @param {Boolean} initial
23
24
  * @param {Boolean} significant
24
- * @param {Boolean} forceZero
25
+ * @param {Boolean} eod
25
26
  */
26
27
  class TransactionType extends Enum {
27
- constructor(code, description, display, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant, forceZero) {
28
+ constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
28
29
  super(code, description);
29
30
 
30
31
  assert.argumentIsRequired(display, 'display', String);
32
+ assert.argumentIsRequired(sequence, 'sequence', Number);
31
33
  assert.argumentIsRequired(purchase, 'purchase', Boolean);
32
34
  assert.argumentIsRequired(sale, 'sale', Boolean);
33
35
  assert.argumentIsRequired(income, 'income', Boolean);
@@ -37,9 +39,9 @@ module.exports = (() => {
37
39
  assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
38
40
  assert.argumentIsRequired(initial, 'initial', Boolean);
39
41
  assert.argumentIsRequired(significant, 'significant', Boolean);
40
- assert.argumentIsRequired(forceZero, 'forceZero', Boolean);
41
42
 
42
43
  this._display = display;
44
+ this._sequence = sequence;
43
45
  this._purchase = purchase;
44
46
  this._sale = sale;
45
47
  this._income = income;
@@ -49,7 +51,6 @@ module.exports = (() => {
49
51
  this._corporateAction = corporateAction;
50
52
  this._initial = initial;
51
53
  this._significant = significant;
52
- this._forceZero = forceZero;
53
54
  }
54
55
 
55
56
  /**
@@ -62,6 +63,17 @@ module.exports = (() => {
62
63
  return this._display;
63
64
  }
64
65
 
66
+ /**
67
+ * Specifies ordering when multiple transactions occur on the same day, for
68
+ * the same position.
69
+ *
70
+ * @public
71
+ * @returns {Number}
72
+ */
73
+ get sequence() {
74
+ return this._sequence;
75
+ }
76
+
65
77
  /**
66
78
  * Indicates if the transaction was a trade.
67
79
  *
@@ -165,17 +177,6 @@ module.exports = (() => {
165
177
  return this._significant;
166
178
  }
167
179
 
168
- /**
169
- * Indicates if closing transaction quantities should be adjusted to zero out
170
- * the position, when they reach a threshold that approximates zero.
171
- *
172
- * @public
173
- * @returns {Boolean}
174
- */
175
- get forceZero() {
176
- return this._forceZero;
177
- }
178
-
179
180
  /**
180
181
  * A purchase.
181
182
  *
@@ -390,28 +391,28 @@ module.exports = (() => {
390
391
  }
391
392
  }
392
393
 
393
- const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false, false, true, true, false);
394
- const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false, false, false, true, true);
395
- const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false, false, false, true, true);
396
- const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false, false, true, true, false);
397
- const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false, true, false, false, false);
398
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false, true, false, false, false);
399
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false, true, false, false, false);
400
- const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false, true, false, false, false);
401
- const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true, false, false, false, false);
402
- const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false, false, false, false, false);
403
-
404
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false, true, false, false, false);
405
- const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', false, false, false, true, false, false, true, false, false, false);
406
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false, true, false, false, false);
407
-
408
- const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false, false, true, true, true);
409
- const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false, false, true, true, true);
410
- const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false, false, true, true, false);
411
- const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false, false, true, true, false);
412
-
413
- const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false, false, false, false, false);
414
- const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false, false, false, false, false);
394
+ const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true);
395
+ const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
396
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
397
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
398
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
399
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
400
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
401
+ const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
402
+ const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
403
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
404
+
405
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false);
406
+ const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false);
407
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false);
408
+
409
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true);
410
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true);
411
+ const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true);
412
+ const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true);
413
+
414
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false);
415
+ const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false);
415
416
 
416
417
  return TransactionType;
417
418
  })();
@@ -82,7 +82,7 @@ module.exports = (() => {
82
82
  static getInvalidIndex(transactions) {
83
83
  assert.argumentIsArray(transactions, 'transactions');
84
84
 
85
- return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(transactions[i - 1].date)));
85
+ return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
86
86
  }
87
87
 
88
88
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.2.51",
3
+ "version": "1.2.55",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -20,10 +20,11 @@ module.exports = (() => {
20
20
  * @param {Boolean} canSwitchDirection
21
21
  * @param {Boolean} usesSymbols
22
22
  * @param {Boolean} hasCorporateActions
23
+ * @param {Number} closeFractional
23
24
  * @param {Function} generator
24
25
  */
25
26
  class InstrumentType extends Enum {
26
- constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, generator) {
27
+ constructor(code, description, alternateDescription, canReinvest, canShort, canSwitchDirection, usesSymbols, hasCorporateActions, closeFractional, generator) {
27
28
  super(code, description);
28
29
 
29
30
  assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
@@ -32,6 +33,7 @@ module.exports = (() => {
32
33
  assert.argumentIsRequired(canSwitchDirection, 'canSwitchDirection', Boolean);
33
34
  assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
34
35
  assert.argumentIsRequired(hasCorporateActions, 'hasCorporateActions', Boolean);
36
+ assert.argumentIsRequired(closeFractional, 'closeFractional', Boolean);
35
37
  assert.argumentIsRequired(generator, 'generator', Function);
36
38
 
37
39
  this._alternateDescription = alternateDescription;
@@ -40,6 +42,7 @@ module.exports = (() => {
40
42
  this._canSwitchDirection = canSwitchDirection;
41
43
  this._usesSymbols = usesSymbols;
42
44
  this._hasCorporateActions = hasCorporateActions;
45
+ this._closeFractional = closeFractional;
43
46
 
44
47
  this._generator = generator;
45
48
  }
@@ -105,6 +108,18 @@ module.exports = (() => {
105
108
  return this._hasCorporateActions;
106
109
  }
107
110
 
111
+ /**
112
+ * Indicates if fractional shares should be closed when the position
113
+ * size is less than one.
114
+ *
115
+ * @public
116
+ * @returns {Boolean}
117
+ */
118
+ get closeFractional() {
119
+ return this._closeFractional;
120
+ }
121
+
122
+
108
123
  /**
109
124
  * Generates an identifier for the instrument.
110
125
  *
@@ -202,10 +217,10 @@ module.exports = (() => {
202
217
  }
203
218
  }
204
219
 
205
- const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
206
- const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
207
- const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
208
- const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
220
+ const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false, true, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
221
+ const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true, false, true, true, true, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
222
+ const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, false, false, true, true, false, (instrument) => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
223
+ const other = new InstrumentType('OTHER', 'other', 'Other', false, false, false, false, false, false, (instrument) => `BARCHART-${instrument.type.code}-${uuid.v4()}`);
209
224
 
210
225
  const map = { };
211
226
 
@@ -635,6 +650,7 @@ module.exports = (() => {
635
650
  * @param {String} code
636
651
  * @param {String} description
637
652
  * @param {String} display
653
+ * @param {Number} sequence
638
654
  * @param {Boolean} purchase
639
655
  * @param {Boolean} sale
640
656
  * @param {Boolean} income
@@ -644,13 +660,14 @@ module.exports = (() => {
644
660
  * @param {Boolean} corporateAction
645
661
  * @param {Boolean} initial
646
662
  * @param {Boolean} significant
647
- * @param {Boolean} forceZero
663
+ * @param {Boolean} eod
648
664
  */
649
665
  class TransactionType extends Enum {
650
- constructor(code, description, display, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant, forceZero) {
666
+ constructor(code, description, display, sequence, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
651
667
  super(code, description);
652
668
 
653
669
  assert.argumentIsRequired(display, 'display', String);
670
+ assert.argumentIsRequired(sequence, 'sequence', Number);
654
671
  assert.argumentIsRequired(purchase, 'purchase', Boolean);
655
672
  assert.argumentIsRequired(sale, 'sale', Boolean);
656
673
  assert.argumentIsRequired(income, 'income', Boolean);
@@ -660,9 +677,9 @@ module.exports = (() => {
660
677
  assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
661
678
  assert.argumentIsRequired(initial, 'initial', Boolean);
662
679
  assert.argumentIsRequired(significant, 'significant', Boolean);
663
- assert.argumentIsRequired(forceZero, 'forceZero', Boolean);
664
680
 
665
681
  this._display = display;
682
+ this._sequence = sequence;
666
683
  this._purchase = purchase;
667
684
  this._sale = sale;
668
685
  this._income = income;
@@ -672,7 +689,6 @@ module.exports = (() => {
672
689
  this._corporateAction = corporateAction;
673
690
  this._initial = initial;
674
691
  this._significant = significant;
675
- this._forceZero = forceZero;
676
692
  }
677
693
 
678
694
  /**
@@ -685,6 +701,17 @@ module.exports = (() => {
685
701
  return this._display;
686
702
  }
687
703
 
704
+ /**
705
+ * Specifies ordering when multiple transactions occur on the same day, for
706
+ * the same position.
707
+ *
708
+ * @public
709
+ * @returns {Number}
710
+ */
711
+ get sequence() {
712
+ return this._sequence;
713
+ }
714
+
688
715
  /**
689
716
  * Indicates if the transaction was a trade.
690
717
  *
@@ -788,17 +815,6 @@ module.exports = (() => {
788
815
  return this._significant;
789
816
  }
790
817
 
791
- /**
792
- * Indicates if closing transaction quantities should be adjusted to zero out
793
- * the position, when they reach a threshold that approximates zero.
794
- *
795
- * @public
796
- * @returns {Boolean}
797
- */
798
- get forceZero() {
799
- return this._forceZero;
800
- }
801
-
802
818
  /**
803
819
  * A purchase.
804
820
  *
@@ -1013,28 +1029,28 @@ module.exports = (() => {
1013
1029
  }
1014
1030
  }
1015
1031
 
1016
- const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false, false, true, true, false);
1017
- const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false, false, false, true, true);
1018
- const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false, false, false, true, true);
1019
- const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false, false, true, true, false);
1020
- const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false, true, false, false, false);
1021
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false, true, false, false, false);
1022
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false, true, false, false, false);
1023
- const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false, true, false, false, false);
1024
- const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true, false, false, false, false);
1025
- const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false, false, false, false, false);
1026
-
1027
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false, true, false, false, false);
1028
- const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', false, false, false, true, false, false, true, false, false, false);
1029
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false, true, false, false, false);
1030
-
1031
- const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false, false, true, true, true);
1032
- const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false, false, true, true, true);
1033
- const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false, false, true, true, false);
1034
- const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false, false, true, true, false);
1035
-
1036
- const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false, false, false, false, false);
1037
- const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false, false, false, false, false);
1032
+ const buy = new TransactionType('B', 'Buy', 'Buy', 0, true, false, false, true, false, false, false, true, true);
1033
+ const sell = new TransactionType('S', 'Sell', 'Sell', 0, false, true, false, false, true, false, false, false, true);
1034
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', 0, true, false, false, false, true, false, false, false, true);
1035
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', 0, false, true, false, true, false, false, false, true, true);
1036
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', 1, false, false, true, false, false, false, true, false, false);
1037
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', 1, false, false, false, true, false, false, true, false, false);
1038
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', 1, false, false, false, true, false, false, true, false, false);
1039
+ const split = new TransactionType('SP', 'Split', 'Split', 1, false, false, false, true, false, false, true, false, false);
1040
+ const fee = new TransactionType('F', 'Fee', 'Fee', 0, false, false, false, false, false, true, false, false, false);
1041
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', 0, false, false, false, false, true, false, false, false, false);
1042
+
1043
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', 1, false, false, true, false, false, false, true, false, false);
1044
+ const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', 1, false, false, false, true, false, false, true, false, false);
1045
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', 1, false, false, false, true, false, false, true, false, false);
1046
+
1047
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', 0, false, false, false, false, false, false, false, true, true);
1048
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', 0, false, false, false, false, false, false, false, true, true);
1049
+ const debit = new TransactionType('DR', 'Debit', 'Debit', 0, false, false, false, false, false, false, false, true, true);
1050
+ const credit = new TransactionType('CR', 'Credit', 'Credit', 0, false, false, false, false, false, false, false, true, true);
1051
+
1052
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', 0, false, false, false, false, false, false, false, false, false);
1053
+ const income = new TransactionType('I', 'Income', 'Income', 0, false, false, true, false, false, false, false, false, false);
1038
1054
 
1039
1055
  return TransactionType;
1040
1056
  })();
@@ -1124,7 +1140,7 @@ module.exports = (() => {
1124
1140
  static getInvalidIndex(transactions) {
1125
1141
  assert.argumentIsArray(transactions, 'transactions');
1126
1142
 
1127
- return transactions.findIndex((t, i) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(transactions[i - 1].date)));
1143
+ return transactions.findIndex((t, i, a) => t.sequence !== (i + 1) || (i !== 0 && t.date.getIsBefore(a[ i - 1 ].date)) || (i !== 0 && t.date.getIsEqual(a[i - 1].date) && t.type.sequence < a[i - 1].type.sequence));
1128
1144
  }
1129
1145
 
1130
1146
  /**
@@ -17211,13 +17227,14 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
17211
17227
  },{"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/data/TransactionType":4,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22}],53:[function(require,module,exports){
17212
17228
  const Day = require('@barchart/common-js/lang/Day');
17213
17229
 
17214
- const TransactionValidator = require('./../../../lib/data/TransactionValidator');
17230
+ const TransactionType = require('./../../../lib/data/TransactionType'),
17231
+ TransactionValidator = require('./../../../lib/data/TransactionValidator');
17215
17232
 
17216
17233
  describe('When validating transaction order', () => {
17217
17234
  'use strict';
17218
17235
 
17219
- const build = (sequence, day) => {
17220
- return { sequence: sequence, date: Day.parse(day) };
17236
+ const build = (sequence, day, type) => {
17237
+ return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY ) };
17221
17238
  };
17222
17239
 
17223
17240
  it('An array of zero transactions should be valid', () => {
@@ -17228,8 +17245,16 @@ describe('When validating transaction order', () => {
17228
17245
  expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
17229
17246
  });
17230
17247
 
17248
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
17249
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
17250
+ });
17251
+
17252
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
17253
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
17254
+ });
17255
+
17231
17256
  it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
17232
- expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02') ])).toEqual(true);
17257
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
17233
17258
  });
17234
17259
 
17235
17260
  it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {
@@ -17290,7 +17315,7 @@ describe('When requesting all the user-initiated transaction types', () => {
17290
17315
  expect(userInitiated.length).toEqual(9);
17291
17316
  });
17292
17317
  });
17293
- },{"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":21}],54:[function(require,module,exports){
17318
+ },{"./../../../lib/data/TransactionType":4,"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":21}],54:[function(require,module,exports){
17294
17319
  const Currency = require('@barchart/common-js/lang/Currency'),
17295
17320
  Decimal = require('@barchart/common-js/lang/Decimal');
17296
17321
 
@@ -1,12 +1,13 @@
1
1
  const Day = require('@barchart/common-js/lang/Day');
2
2
 
3
- const TransactionValidator = require('./../../../lib/data/TransactionValidator');
3
+ const TransactionType = require('./../../../lib/data/TransactionType'),
4
+ TransactionValidator = require('./../../../lib/data/TransactionValidator');
4
5
 
5
6
  describe('When validating transaction order', () => {
6
7
  'use strict';
7
8
 
8
- const build = (sequence, day) => {
9
- return { sequence: sequence, date: Day.parse(day) };
9
+ const build = (sequence, day, type) => {
10
+ return { sequence: sequence, date: Day.parse(day), type: (type || TransactionType.BUY ) };
10
11
  };
11
12
 
12
13
  it('An array of zero transactions should be valid', () => {
@@ -17,8 +18,16 @@ describe('When validating transaction order', () => {
17
18
  expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30'), build(3, '2018-04-30') ])).toEqual(true);
18
19
  });
19
20
 
21
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs last, should be valid', () => {
22
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-04-30', TransactionType.DIVIDEND) ])).toEqual(true);
23
+ });
24
+
25
+ it('An array of transactions with ordered sequences, on the same day should be valid, where a dividend occurs first, should not be valid', () => {
26
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30', TransactionType.DIVIDEND), build(2, '2018-04-30') ])).toEqual(false);
27
+ });
28
+
20
29
  it('An array of transactions with ordered sequences, on the sequential days should be valid', () => {
21
- expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02') ])).toEqual(true);
30
+ expect(TransactionValidator.validateOrder([ build(1, '2018-04-30'), build(2, '2018-05-01'), build(3, '2018-05-02', TransactionType.DIVIDEND) ])).toEqual(true);
22
31
  });
23
32
 
24
33
  it('An array of transactions with ordered sequences (starting after one), on the same day should not be valid', () => {