@barchart/portfolio-api-common 1.0.235 → 1.0.239
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/api/failures/PortfolioFailureType.js +12 -0
- package/lib/formatters/TransactionFormatter.js +13 -15
- package/package.json +1 -1
- package/test/SpecRunner.js +94 -15
- package/package-lock.json +0 -5484
|
@@ -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,7 +36,11 @@ module.exports = (() => {
|
|
|
36
36
|
assert.argumentIsOptional(append, 'append', Boolean);
|
|
37
37
|
|
|
38
38
|
const instruments = positions.reduce((map, p) => {
|
|
39
|
-
|
|
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
|
}, { });
|
|
@@ -45,9 +49,8 @@ module.exports = (() => {
|
|
|
45
49
|
const position = transaction.position;
|
|
46
50
|
|
|
47
51
|
if (instruments.hasOwnProperty(position)) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let formatted = getBasicTransaction(transaction);
|
|
52
|
+
let instrument = instruments[position];
|
|
53
|
+
let formatted = getBasicTransaction(transaction, instrument);
|
|
51
54
|
|
|
52
55
|
if (formatters.has(transaction.type)) {
|
|
53
56
|
const formatterFunction = formatters.get(transaction.type);
|
|
@@ -55,7 +58,7 @@ module.exports = (() => {
|
|
|
55
58
|
|
|
56
59
|
Object.keys(formattedTransaction).map((key) => {
|
|
57
60
|
if (!is.undefined(formattedTransaction[key]) && formattedTransaction[key] instanceof Decimal) {
|
|
58
|
-
const precision =
|
|
61
|
+
const precision = instrument.currency.precision;
|
|
59
62
|
|
|
60
63
|
formattedTransaction[key] = formatter.numberToString(formattedTransaction[key].toFloat(), precision, ',');
|
|
61
64
|
}
|
|
@@ -86,20 +89,14 @@ module.exports = (() => {
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
const getBasicTransaction = (t) => {
|
|
90
|
-
|
|
92
|
+
const getBasicTransaction = (t, i) => {
|
|
93
|
+
return {
|
|
91
94
|
date: t.date,
|
|
92
95
|
type: t.type.display,
|
|
93
96
|
sequence: t.sequence,
|
|
94
|
-
instrument:
|
|
97
|
+
instrument: i,
|
|
95
98
|
position: t.position
|
|
96
99
|
};
|
|
97
|
-
|
|
98
|
-
if (basic.instrument) {
|
|
99
|
-
delete basic.instrument.id;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return basic;
|
|
103
100
|
};
|
|
104
101
|
|
|
105
102
|
const formatters = new Map();
|
|
@@ -170,6 +167,7 @@ module.exports = (() => {
|
|
|
170
167
|
|
|
171
168
|
formatters.set(TransactionType.FEE, (t) => {
|
|
172
169
|
return {
|
|
170
|
+
fee: t.charge.amount,
|
|
173
171
|
total: t.charge.amount
|
|
174
172
|
};
|
|
175
173
|
});
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){function e
|
|
1
|
+
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
|
2
2
|
const uuid = require('uuid');
|
|
3
3
|
|
|
4
4
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
@@ -3516,14 +3516,31 @@ module.exports = function () {
|
|
|
3516
3516
|
}
|
|
3517
3517
|
|
|
3518
3518
|
/**
|
|
3519
|
-
*
|
|
3519
|
+
* Gets the root node.
|
|
3520
3520
|
*
|
|
3521
3521
|
* @public
|
|
3522
|
-
* @returns {Tree
|
|
3522
|
+
* @returns {Tree}
|
|
3523
3523
|
*/
|
|
3524
3524
|
|
|
3525
3525
|
|
|
3526
3526
|
_createClass(Tree, [{
|
|
3527
|
+
key: 'getRoot',
|
|
3528
|
+
value: function getRoot() {
|
|
3529
|
+
if (this.getIsRoot()) {
|
|
3530
|
+
return this;
|
|
3531
|
+
} else {
|
|
3532
|
+
return this._parent.getRoot();
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3536
|
+
/**
|
|
3537
|
+
* Returns the parent node. If this is the root node, a null value is returned.
|
|
3538
|
+
*
|
|
3539
|
+
* @public
|
|
3540
|
+
* @returns {Tree|null}
|
|
3541
|
+
*/
|
|
3542
|
+
|
|
3543
|
+
}, {
|
|
3527
3544
|
key: 'getParent',
|
|
3528
3545
|
value: function getParent() {
|
|
3529
3546
|
return this._parent;
|
|
@@ -3624,6 +3641,23 @@ module.exports = function () {
|
|
|
3624
3641
|
}
|
|
3625
3642
|
}
|
|
3626
3643
|
|
|
3644
|
+
/**
|
|
3645
|
+
* Removes the current node from the parent tree. Use on a root node
|
|
3646
|
+
* has no effect.
|
|
3647
|
+
*
|
|
3648
|
+
* @public
|
|
3649
|
+
*/
|
|
3650
|
+
|
|
3651
|
+
}, {
|
|
3652
|
+
key: 'sever',
|
|
3653
|
+
value: function sever() {
|
|
3654
|
+
if (this.getIsRoot()) {
|
|
3655
|
+
return;
|
|
3656
|
+
}
|
|
3657
|
+
|
|
3658
|
+
this.getParent().removeChild(this);
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3627
3661
|
/**
|
|
3628
3662
|
* Searches the children nodes for the first child node that matches the
|
|
3629
3663
|
* predicate.
|
|
@@ -5018,6 +5052,20 @@ module.exports = function () {
|
|
|
5018
5052
|
return this._big.gt(getBig(other));
|
|
5019
5053
|
}
|
|
5020
5054
|
|
|
5055
|
+
/**
|
|
5056
|
+
* Returns true if the current instance is greater than or equal to the value.
|
|
5057
|
+
*
|
|
5058
|
+
* @public
|
|
5059
|
+
* @param {Decimal|Number|String} other - The value to compare.
|
|
5060
|
+
* @returns {Boolean}
|
|
5061
|
+
*/
|
|
5062
|
+
|
|
5063
|
+
}, {
|
|
5064
|
+
key: 'getIsGreaterThanOrEqual',
|
|
5065
|
+
value: function getIsGreaterThanOrEqual(other) {
|
|
5066
|
+
return this._big.gte(getBig(other));
|
|
5067
|
+
}
|
|
5068
|
+
|
|
5021
5069
|
/**
|
|
5022
5070
|
* Returns true if the current instance is less than the value.
|
|
5023
5071
|
*
|
|
@@ -5032,6 +5080,20 @@ module.exports = function () {
|
|
|
5032
5080
|
return this._big.lt(getBig(other));
|
|
5033
5081
|
}
|
|
5034
5082
|
|
|
5083
|
+
/**
|
|
5084
|
+
* Returns true if the current instance is less than or equal to the value.
|
|
5085
|
+
*
|
|
5086
|
+
* @public
|
|
5087
|
+
* @param {Decimal|Number|String} other - The value to compare.
|
|
5088
|
+
* @returns {Boolean}
|
|
5089
|
+
*/
|
|
5090
|
+
|
|
5091
|
+
}, {
|
|
5092
|
+
key: 'getIsLessThanOrEqual',
|
|
5093
|
+
value: function getIsLessThanOrEqual(other) {
|
|
5094
|
+
return this._big.lte(getBig(other));
|
|
5095
|
+
}
|
|
5096
|
+
|
|
5035
5097
|
/**
|
|
5036
5098
|
* Returns true if the current instance is equal to the value.
|
|
5037
5099
|
*
|
|
@@ -5231,9 +5293,9 @@ module.exports = function () {
|
|
|
5231
5293
|
assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
|
|
5232
5294
|
assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
|
|
5233
5295
|
|
|
5234
|
-
if (a._big.gt(b)) {
|
|
5296
|
+
if (a._big.gt(b._big)) {
|
|
5235
5297
|
return 1;
|
|
5236
|
-
} else if (a._big.lt(b)) {
|
|
5298
|
+
} else if (a._big.lt(b._big)) {
|
|
5237
5299
|
return -1;
|
|
5238
5300
|
} else {
|
|
5239
5301
|
return 0;
|
|
@@ -5694,12 +5756,10 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
|
5694
5756
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5695
5757
|
|
|
5696
5758
|
var assert = require('./assert'),
|
|
5697
|
-
is = require('./is'),
|
|
5698
5759
|
memoize = require('./memoize');
|
|
5699
5760
|
|
|
5700
5761
|
var Currency = require('./Currency'),
|
|
5701
|
-
Decimal = require('./Decimal')
|
|
5702
|
-
Enum = require('./Enum');
|
|
5762
|
+
Decimal = require('./Decimal');
|
|
5703
5763
|
|
|
5704
5764
|
module.exports = function () {
|
|
5705
5765
|
'use strict';
|
|
@@ -5879,12 +5939,7 @@ module.exports = function () {
|
|
|
5879
5939
|
assert.argumentIsRequired(amount, 'amount', Decimal, 'Decimal');
|
|
5880
5940
|
assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
|
|
5881
5941
|
assert.argumentIsRequired(desiredCurrency, 'desiredCurrency', Currency, 'Currency');
|
|
5882
|
-
|
|
5883
|
-
for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
5884
|
-
rates[_key - 3] = arguments[_key];
|
|
5885
|
-
}
|
|
5886
|
-
|
|
5887
|
-
assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
|
|
5942
|
+
//assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
|
|
5888
5943
|
|
|
5889
5944
|
var converted = void 0;
|
|
5890
5945
|
|
|
@@ -5894,6 +5949,10 @@ module.exports = function () {
|
|
|
5894
5949
|
var numerator = desiredCurrency;
|
|
5895
5950
|
var denominator = currency;
|
|
5896
5951
|
|
|
5952
|
+
for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
5953
|
+
rates[_key - 3] = arguments[_key];
|
|
5954
|
+
}
|
|
5955
|
+
|
|
5897
5956
|
var rate = rates.find(function (r) {
|
|
5898
5957
|
return r.numerator === numerator && r.denominator === denominator || r.numerator === denominator && r.denominator === numerator;
|
|
5899
5958
|
});
|
|
@@ -5944,7 +6003,7 @@ module.exports = function () {
|
|
|
5944
6003
|
return Rate;
|
|
5945
6004
|
}();
|
|
5946
6005
|
|
|
5947
|
-
},{"./Currency":15,"./Decimal":17,"./
|
|
6006
|
+
},{"./Currency":15,"./Decimal":17,"./assert":22,"./memoize":25}],21:[function(require,module,exports){
|
|
5948
6007
|
'use strict';
|
|
5949
6008
|
|
|
5950
6009
|
var assert = require('./assert'),
|
|
@@ -6321,6 +6380,26 @@ module.exports = function () {
|
|
|
6321
6380
|
});
|
|
6322
6381
|
|
|
6323
6382
|
return returnRef;
|
|
6383
|
+
},
|
|
6384
|
+
|
|
6385
|
+
|
|
6386
|
+
/**
|
|
6387
|
+
* Removes the first item from an array which matches a predicate.
|
|
6388
|
+
*
|
|
6389
|
+
* @static
|
|
6390
|
+
* @public
|
|
6391
|
+
* @param {Array} a
|
|
6392
|
+
* @param {Function} predicate
|
|
6393
|
+
*/
|
|
6394
|
+
remove: function remove(a, predicate) {
|
|
6395
|
+
assert.argumentIsArray(a, 'a');
|
|
6396
|
+
assert.argumentIsRequired(predicate, 'predicate', Function);
|
|
6397
|
+
|
|
6398
|
+
var index = a.findIndex(predicate);
|
|
6399
|
+
|
|
6400
|
+
if (!(index < 0)) {
|
|
6401
|
+
a.splice(index, 1);
|
|
6402
|
+
}
|
|
6324
6403
|
}
|
|
6325
6404
|
};
|
|
6326
6405
|
}();
|