@barchart/portfolio-api-common 1.0.88 → 1.0.89
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.
|
@@ -11,6 +11,7 @@ module.exports = (() => {
|
|
|
11
11
|
* @extends {Enum}
|
|
12
12
|
* @param {String} code
|
|
13
13
|
* @param {String} description
|
|
14
|
+
* @param {String} display
|
|
14
15
|
* @param {Boolean} purchase
|
|
15
16
|
* @param {Boolean} sale
|
|
16
17
|
* @param {Boolean} income
|
|
@@ -18,15 +19,17 @@ module.exports = (() => {
|
|
|
18
19
|
* @param {Boolean} closing
|
|
19
20
|
*/
|
|
20
21
|
class TransactionType extends Enum {
|
|
21
|
-
constructor(code, description, purchase, sale, income, opening, closing) {
|
|
22
|
+
constructor(code, description, display, purchase, sale, income, opening, closing) {
|
|
22
23
|
super(code, description);
|
|
23
24
|
|
|
25
|
+
assert.argumentIsRequired(display, 'display', String);
|
|
24
26
|
assert.argumentIsRequired(purchase, 'purchase', Boolean);
|
|
25
27
|
assert.argumentIsRequired(sale, 'sale', Boolean);
|
|
26
28
|
assert.argumentIsRequired(income, 'income', Boolean);
|
|
27
29
|
assert.argumentIsRequired(opening, 'opening', Boolean);
|
|
28
30
|
assert.argumentIsRequired(closing, 'closing', Boolean);
|
|
29
31
|
|
|
32
|
+
this._display = display;
|
|
30
33
|
this._purchase = purchase;
|
|
31
34
|
this._sale = sale;
|
|
32
35
|
this._income = income;
|
|
@@ -34,6 +37,16 @@ module.exports = (() => {
|
|
|
34
37
|
this._closing = closing;
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
/**
|
|
41
|
+
* A human-readable description of the transaction type.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
* @returns {String}
|
|
45
|
+
*/
|
|
46
|
+
get display() {
|
|
47
|
+
return this._display;
|
|
48
|
+
}
|
|
49
|
+
|
|
37
50
|
/**
|
|
38
51
|
* Indicates if the transaction was a trade.
|
|
39
52
|
*
|
|
@@ -299,27 +312,27 @@ module.exports = (() => {
|
|
|
299
312
|
}
|
|
300
313
|
}
|
|
301
314
|
|
|
302
|
-
const buy = new TransactionType('B', 'Buy', true, false, false, true, false);
|
|
303
|
-
const sell = new TransactionType('S', 'Sell', false, true, false, false, true);
|
|
304
|
-
const buyShort = new TransactionType('BS', 'Buy To Cover', true, false, false, false, true);
|
|
305
|
-
const sellShort = new TransactionType('SS', 'Sell Short',
|
|
306
|
-
const dividend = new TransactionType('DV', 'Dividend', false, false, true, false, false);
|
|
307
|
-
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', false, false, false, true, false);
|
|
308
|
-
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', false, false, false, true, false);
|
|
309
|
-
const split = new TransactionType('SP', 'Split', false, false, false, true, false);
|
|
310
|
-
const fee = new TransactionType('F', 'Fee', false, false, false, true, false);
|
|
311
|
-
const feeUnits = new TransactionType('FU', 'Fee', false, false, false, false, false);
|
|
312
|
-
|
|
313
|
-
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', false, false, true, false, false);
|
|
314
|
-
const distributionFund = new TransactionType('DF', 'Distribution (Units)', false, false, false, true, false);
|
|
315
|
-
|
|
316
|
-
const deposit = new TransactionType('D', 'Deposit', false, false, false, true, false);
|
|
317
|
-
const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false, true);
|
|
318
|
-
const debit = new TransactionType('DR', 'Debit', false, false, false, false, true);
|
|
319
|
-
const credit = new TransactionType('CR', 'Credit', false, false, false, true, false);
|
|
320
|
-
|
|
321
|
-
const valuation = new TransactionType('V', 'Valuation', false, false, false, false, false);
|
|
322
|
-
const income = new TransactionType('I', 'Income', false, false, true, false, false);
|
|
315
|
+
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false);
|
|
316
|
+
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true);
|
|
317
|
+
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true);
|
|
318
|
+
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false);
|
|
319
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false);
|
|
320
|
+
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false);
|
|
321
|
+
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false);
|
|
322
|
+
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false);
|
|
323
|
+
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, true, false);
|
|
324
|
+
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, false);
|
|
325
|
+
|
|
326
|
+
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false);
|
|
327
|
+
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false);
|
|
328
|
+
|
|
329
|
+
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, true, false);
|
|
330
|
+
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, true);
|
|
331
|
+
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, true);
|
|
332
|
+
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, true, false);
|
|
333
|
+
|
|
334
|
+
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false);
|
|
335
|
+
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false);
|
|
323
336
|
|
|
324
337
|
return TransactionType;
|
|
325
338
|
})();
|
|
@@ -35,9 +35,9 @@ module.exports = (() => {
|
|
|
35
35
|
|
|
36
36
|
const positionMap = {};
|
|
37
37
|
|
|
38
|
-
positions.map(
|
|
38
|
+
positions.map(p => positionMap[p.position] = p.instrument);
|
|
39
39
|
|
|
40
|
-
return transactions.filter(
|
|
40
|
+
return transactions.filter(t => positionMap[t.position]).map((transaction) => {
|
|
41
41
|
transaction.instrument = positionMap[transaction.position];
|
|
42
42
|
|
|
43
43
|
let formatted = getBasicTransaction(transaction);
|
|
@@ -76,7 +76,7 @@ module.exports = (() => {
|
|
|
76
76
|
const getBasicTransaction = (t) => {
|
|
77
77
|
const basic = {
|
|
78
78
|
date: t.date,
|
|
79
|
-
type: t.type,
|
|
79
|
+
type: t.type.display,
|
|
80
80
|
sequence: t.sequence,
|
|
81
81
|
instrument: t.instrument
|
|
82
82
|
};
|
|
@@ -98,6 +98,7 @@ module.exports = (() => {
|
|
|
98
98
|
total: t.amount
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
|
+
|
|
101
102
|
formatters.set(TransactionType.BUY, buySellFormatter);
|
|
102
103
|
formatters.set(TransactionType.SELL, buySellFormatter);
|
|
103
104
|
formatters.set(TransactionType.BUY_SHORT, buySellFormatter);
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -388,6 +388,7 @@ module.exports = (() => {
|
|
|
388
388
|
* @extends {Enum}
|
|
389
389
|
* @param {String} code
|
|
390
390
|
* @param {String} description
|
|
391
|
+
* @param {String} display
|
|
391
392
|
* @param {Boolean} purchase
|
|
392
393
|
* @param {Boolean} sale
|
|
393
394
|
* @param {Boolean} income
|
|
@@ -395,15 +396,17 @@ module.exports = (() => {
|
|
|
395
396
|
* @param {Boolean} closing
|
|
396
397
|
*/
|
|
397
398
|
class TransactionType extends Enum {
|
|
398
|
-
constructor(code, description, purchase, sale, income, opening, closing) {
|
|
399
|
+
constructor(code, description, display, purchase, sale, income, opening, closing) {
|
|
399
400
|
super(code, description);
|
|
400
401
|
|
|
402
|
+
assert.argumentIsRequired(display, 'display', String);
|
|
401
403
|
assert.argumentIsRequired(purchase, 'purchase', Boolean);
|
|
402
404
|
assert.argumentIsRequired(sale, 'sale', Boolean);
|
|
403
405
|
assert.argumentIsRequired(income, 'income', Boolean);
|
|
404
406
|
assert.argumentIsRequired(opening, 'opening', Boolean);
|
|
405
407
|
assert.argumentIsRequired(closing, 'closing', Boolean);
|
|
406
408
|
|
|
409
|
+
this._display = display;
|
|
407
410
|
this._purchase = purchase;
|
|
408
411
|
this._sale = sale;
|
|
409
412
|
this._income = income;
|
|
@@ -411,6 +414,16 @@ module.exports = (() => {
|
|
|
411
414
|
this._closing = closing;
|
|
412
415
|
}
|
|
413
416
|
|
|
417
|
+
/**
|
|
418
|
+
* A human-readable description of the transaction type.
|
|
419
|
+
*
|
|
420
|
+
* @public
|
|
421
|
+
* @returns {String}
|
|
422
|
+
*/
|
|
423
|
+
get display() {
|
|
424
|
+
return this._display;
|
|
425
|
+
}
|
|
426
|
+
|
|
414
427
|
/**
|
|
415
428
|
* Indicates if the transaction was a trade.
|
|
416
429
|
*
|
|
@@ -676,27 +689,27 @@ module.exports = (() => {
|
|
|
676
689
|
}
|
|
677
690
|
}
|
|
678
691
|
|
|
679
|
-
const buy = new TransactionType('B', 'Buy', true, false, false, true, false);
|
|
680
|
-
const sell = new TransactionType('S', 'Sell', false, true, false, false, true);
|
|
681
|
-
const buyShort = new TransactionType('BS', 'Buy To Cover', true, false, false, false, true);
|
|
682
|
-
const sellShort = new TransactionType('SS', 'Sell Short',
|
|
683
|
-
const dividend = new TransactionType('DV', 'Dividend', false, false, true, false, false);
|
|
684
|
-
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', false, false, false, true, false);
|
|
685
|
-
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', false, false, false, true, false);
|
|
686
|
-
const split = new TransactionType('SP', 'Split', false, false, false, true, false);
|
|
687
|
-
const fee = new TransactionType('F', 'Fee', false, false, false, true, false);
|
|
688
|
-
const feeUnits = new TransactionType('FU', 'Fee', false, false, false, false, false);
|
|
689
|
-
|
|
690
|
-
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', false, false, true, false, false);
|
|
691
|
-
const distributionFund = new TransactionType('DF', 'Distribution (Units)', false, false, false, true, false);
|
|
692
|
-
|
|
693
|
-
const deposit = new TransactionType('D', 'Deposit', false, false, false, true, false);
|
|
694
|
-
const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false, true);
|
|
695
|
-
const debit = new TransactionType('DR', 'Debit', false, false, false, false, true);
|
|
696
|
-
const credit = new TransactionType('CR', 'Credit', false, false, false, true, false);
|
|
697
|
-
|
|
698
|
-
const valuation = new TransactionType('V', 'Valuation', false, false, false, false, false);
|
|
699
|
-
const income = new TransactionType('I', 'Income', false, false, true, false, false);
|
|
692
|
+
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false);
|
|
693
|
+
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true);
|
|
694
|
+
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true);
|
|
695
|
+
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false);
|
|
696
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false);
|
|
697
|
+
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false);
|
|
698
|
+
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false);
|
|
699
|
+
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false);
|
|
700
|
+
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, true, false);
|
|
701
|
+
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, false);
|
|
702
|
+
|
|
703
|
+
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false);
|
|
704
|
+
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false);
|
|
705
|
+
|
|
706
|
+
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, true, false);
|
|
707
|
+
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, true);
|
|
708
|
+
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, true);
|
|
709
|
+
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, true, false);
|
|
710
|
+
|
|
711
|
+
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false);
|
|
712
|
+
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false);
|
|
700
713
|
|
|
701
714
|
return TransactionType;
|
|
702
715
|
})();
|