@barchart/portfolio-api-common 1.2.50 → 1.2.51
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/lib/data/InstrumentType.js +1 -1
- package/lib/data/TransactionType.js +38 -24
- package/package.json +1 -1
- package/test/SpecRunner.js +39 -25
|
@@ -192,7 +192,7 @@ module.exports = (() => {
|
|
|
192
192
|
} else if (code === 5 || code == 15) {
|
|
193
193
|
return InstrumentType.FUND;
|
|
194
194
|
} else {
|
|
195
|
-
throw new Error(
|
|
195
|
+
throw new Error(`Unable to determine InstrumentType for [ ${code} ]`);
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -21,9 +21,10 @@ module.exports = (() => {
|
|
|
21
21
|
* @param {Boolean} corporateAction
|
|
22
22
|
* @param {Boolean} initial
|
|
23
23
|
* @param {Boolean} significant
|
|
24
|
-
|
|
24
|
+
* @param {Boolean} forceZero
|
|
25
|
+
*/
|
|
25
26
|
class TransactionType extends Enum {
|
|
26
|
-
constructor(code, description, display, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
|
|
27
|
+
constructor(code, description, display, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant, forceZero) {
|
|
27
28
|
super(code, description);
|
|
28
29
|
|
|
29
30
|
assert.argumentIsRequired(display, 'display', String);
|
|
@@ -36,6 +37,7 @@ module.exports = (() => {
|
|
|
36
37
|
assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
|
|
37
38
|
assert.argumentIsRequired(initial, 'initial', Boolean);
|
|
38
39
|
assert.argumentIsRequired(significant, 'significant', Boolean);
|
|
40
|
+
assert.argumentIsRequired(forceZero, 'forceZero', Boolean);
|
|
39
41
|
|
|
40
42
|
this._display = display;
|
|
41
43
|
this._purchase = purchase;
|
|
@@ -47,6 +49,7 @@ module.exports = (() => {
|
|
|
47
49
|
this._corporateAction = corporateAction;
|
|
48
50
|
this._initial = initial;
|
|
49
51
|
this._significant = significant;
|
|
52
|
+
this._forceZero = forceZero;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
/**
|
|
@@ -162,6 +165,17 @@ module.exports = (() => {
|
|
|
162
165
|
return this._significant;
|
|
163
166
|
}
|
|
164
167
|
|
|
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
|
+
|
|
165
179
|
/**
|
|
166
180
|
* A purchase.
|
|
167
181
|
*
|
|
@@ -376,28 +390,28 @@ module.exports = (() => {
|
|
|
376
390
|
}
|
|
377
391
|
}
|
|
378
392
|
|
|
379
|
-
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false, false, true, true);
|
|
380
|
-
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false, false, false, true);
|
|
381
|
-
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false, false, false, true);
|
|
382
|
-
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false, false, true, true);
|
|
383
|
-
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false, true, false, false);
|
|
384
|
-
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false, true, false, false);
|
|
385
|
-
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false, true, false, false);
|
|
386
|
-
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false, true, false, false);
|
|
387
|
-
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true, false, false, false);
|
|
388
|
-
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false, false, false, false);
|
|
389
|
-
|
|
390
|
-
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false, true, false, false);
|
|
391
|
-
const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', false, false, false, true, false, false, true, false, false);
|
|
392
|
-
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false, true, false, false);
|
|
393
|
-
|
|
394
|
-
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false, false, true, true);
|
|
395
|
-
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false, false, true, true);
|
|
396
|
-
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false, false, true, true);
|
|
397
|
-
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false, false, true, true);
|
|
398
|
-
|
|
399
|
-
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false, false, false, false);
|
|
400
|
-
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false, false, false, false);
|
|
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);
|
|
401
415
|
|
|
402
416
|
return TransactionType;
|
|
403
417
|
})();
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -193,7 +193,7 @@ module.exports = (() => {
|
|
|
193
193
|
} else if (code === 5 || code == 15) {
|
|
194
194
|
return InstrumentType.FUND;
|
|
195
195
|
} else {
|
|
196
|
-
throw new Error(
|
|
196
|
+
throw new Error(`Unable to determine InstrumentType for [ ${code} ]`);
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -644,9 +644,10 @@ module.exports = (() => {
|
|
|
644
644
|
* @param {Boolean} corporateAction
|
|
645
645
|
* @param {Boolean} initial
|
|
646
646
|
* @param {Boolean} significant
|
|
647
|
-
|
|
647
|
+
* @param {Boolean} forceZero
|
|
648
|
+
*/
|
|
648
649
|
class TransactionType extends Enum {
|
|
649
|
-
constructor(code, description, display, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant) {
|
|
650
|
+
constructor(code, description, display, purchase, sale, income, opening, closing, fee, corporateAction, initial, significant, forceZero) {
|
|
650
651
|
super(code, description);
|
|
651
652
|
|
|
652
653
|
assert.argumentIsRequired(display, 'display', String);
|
|
@@ -659,6 +660,7 @@ module.exports = (() => {
|
|
|
659
660
|
assert.argumentIsRequired(corporateAction, 'corporateAction', Boolean);
|
|
660
661
|
assert.argumentIsRequired(initial, 'initial', Boolean);
|
|
661
662
|
assert.argumentIsRequired(significant, 'significant', Boolean);
|
|
663
|
+
assert.argumentIsRequired(forceZero, 'forceZero', Boolean);
|
|
662
664
|
|
|
663
665
|
this._display = display;
|
|
664
666
|
this._purchase = purchase;
|
|
@@ -670,6 +672,7 @@ module.exports = (() => {
|
|
|
670
672
|
this._corporateAction = corporateAction;
|
|
671
673
|
this._initial = initial;
|
|
672
674
|
this._significant = significant;
|
|
675
|
+
this._forceZero = forceZero;
|
|
673
676
|
}
|
|
674
677
|
|
|
675
678
|
/**
|
|
@@ -785,6 +788,17 @@ module.exports = (() => {
|
|
|
785
788
|
return this._significant;
|
|
786
789
|
}
|
|
787
790
|
|
|
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
|
+
|
|
788
802
|
/**
|
|
789
803
|
* A purchase.
|
|
790
804
|
*
|
|
@@ -999,28 +1013,28 @@ module.exports = (() => {
|
|
|
999
1013
|
}
|
|
1000
1014
|
}
|
|
1001
1015
|
|
|
1002
|
-
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false, false, false, true, true);
|
|
1003
|
-
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true, false, false, false, true);
|
|
1004
|
-
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true, false, false, false, true);
|
|
1005
|
-
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false, false, false, true, true);
|
|
1006
|
-
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false, false, true, false, false);
|
|
1007
|
-
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false, false, true, false, false);
|
|
1008
|
-
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false, false, true, false, false);
|
|
1009
|
-
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false, false, true, false, false);
|
|
1010
|
-
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, false, false, true, false, false, false);
|
|
1011
|
-
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, true, false, false, false, false);
|
|
1012
|
-
|
|
1013
|
-
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false, false, true, false, false);
|
|
1014
|
-
const distributionReinvest = new TransactionType('DY', 'Distribution (Reinvested)', 'Distribution Reinvest', false, false, false, true, false, false, true, false, false);
|
|
1015
|
-
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false, false, true, false, false);
|
|
1016
|
-
|
|
1017
|
-
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, false, false, false, false, true, true);
|
|
1018
|
-
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, false, false, false, true, true);
|
|
1019
|
-
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, false, false, false, true, true);
|
|
1020
|
-
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, false, false, false, false, true, true);
|
|
1021
|
-
|
|
1022
|
-
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false, false, false, false, false);
|
|
1023
|
-
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false, false, false, false, false);
|
|
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);
|
|
1024
1038
|
|
|
1025
1039
|
return TransactionType;
|
|
1026
1040
|
})();
|