@barchart/portfolio-api-common 1.0.138 → 1.0.142
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/processing/PositionContainer.js +28 -3
- package/lib/processing/PositionGroup.js +43 -9
- package/package.json +1 -1
- package/test/SpecRunner.js +101 -28
|
@@ -214,9 +214,15 @@ module.exports = (() => {
|
|
|
214
214
|
|
|
215
215
|
compositeGroups.sort(builder.toComparator());
|
|
216
216
|
|
|
217
|
+
const initializeGroupObservers = (group, groupTree) => {
|
|
218
|
+
|
|
219
|
+
};
|
|
220
|
+
|
|
217
221
|
compositeGroups.forEach((group) => {
|
|
218
222
|
const childTree = currentTree.addChild(group);
|
|
219
223
|
|
|
224
|
+
initializeGroupObservers(group, childTree);
|
|
225
|
+
|
|
220
226
|
group.registerMarketPercentChangeHandler(() => {
|
|
221
227
|
currentTree.walk((childGroup) => childGroup.refreshMarketPercent());
|
|
222
228
|
});
|
|
@@ -332,12 +338,21 @@ module.exports = (() => {
|
|
|
332
338
|
* @param {String} symbol
|
|
333
339
|
* @param {Object} data
|
|
334
340
|
*/
|
|
335
|
-
setPositionFundamentalData(symbol, data) {
|
|
341
|
+
setPositionFundamentalData(symbol, display, data) {
|
|
336
342
|
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
343
|
+
assert.argumentIsRequired(display, 'display', Boolean);
|
|
337
344
|
assert.argumentIsRequired(data, 'data', Object);
|
|
338
345
|
|
|
339
|
-
|
|
340
|
-
|
|
346
|
+
let map;
|
|
347
|
+
|
|
348
|
+
if (display) {
|
|
349
|
+
map = this._symbolsDisplay;
|
|
350
|
+
} else {
|
|
351
|
+
map = this._symbols;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (map.hasOwnProperty(symbol)) {
|
|
355
|
+
map[symbol].forEach(item => item.setPositionFundamentalData(data));
|
|
341
356
|
}
|
|
342
357
|
}
|
|
343
358
|
|
|
@@ -396,6 +411,16 @@ module.exports = (() => {
|
|
|
396
411
|
return findNode(this._trees[name], keys).getChildren().map(node => node.getValue());
|
|
397
412
|
}
|
|
398
413
|
|
|
414
|
+
getPositions(portfolio) {
|
|
415
|
+
return this._items.reduce((positions, item) => {
|
|
416
|
+
if (item.position.portfolio === portfolio) {
|
|
417
|
+
positions.push(item);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return positions;
|
|
421
|
+
}, []);
|
|
422
|
+
}
|
|
423
|
+
|
|
399
424
|
startTransaction(name, executor) {
|
|
400
425
|
assert.argumentIsRequired(name, 'name', String);
|
|
401
426
|
assert.argumentIsRequired(executor, 'executor', Function);
|
|
@@ -44,6 +44,8 @@ module.exports = (() => {
|
|
|
44
44
|
this._excludedChangeEvent = new Event(this);
|
|
45
45
|
this._showClosedPositionsChangeEvent = new Event(this);
|
|
46
46
|
|
|
47
|
+
this._excludedItems = { };
|
|
48
|
+
|
|
47
49
|
this._dataFormat = { };
|
|
48
50
|
this._dataActual = { };
|
|
49
51
|
|
|
@@ -74,6 +76,15 @@ module.exports = (() => {
|
|
|
74
76
|
this._dataFormat.fundamental = { };
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
this._dataActual.quoteLast = null;
|
|
80
|
+
this._dataActual.quoteOpen = null;
|
|
81
|
+
this._dataActual.quoteHigh = null;
|
|
82
|
+
this._dataActual.quoteLow = null;
|
|
83
|
+
this._dataActual.quoteChange = null;
|
|
84
|
+
this._dataActual.quoteChangePercent = null;
|
|
85
|
+
this._dataActual.quoteTime = null;
|
|
86
|
+
this._dataActual.quoteVolume = null;
|
|
87
|
+
|
|
77
88
|
this._dataFormat.quoteLast = null;
|
|
78
89
|
this._dataFormat.quoteOpen = null;
|
|
79
90
|
this._dataFormat.quoteHigh = null;
|
|
@@ -124,14 +135,23 @@ module.exports = (() => {
|
|
|
124
135
|
this._dataActual.currentPrice = quote.lastPrice;
|
|
125
136
|
this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
|
|
126
137
|
|
|
127
|
-
this.
|
|
128
|
-
this.
|
|
129
|
-
this.
|
|
130
|
-
this.
|
|
131
|
-
this.
|
|
132
|
-
this.
|
|
133
|
-
this.
|
|
134
|
-
this.
|
|
138
|
+
this._dataActual.quoteLast = quote.previousPrice;
|
|
139
|
+
this._dataActual.quoteOpen = quote.openPrice;
|
|
140
|
+
this._dataActual.quoteHigh = quote.highPrice;
|
|
141
|
+
this._dataActual.quoteLow = quote.lowPrice;
|
|
142
|
+
this._dataActual.quoteChange = quote.priceChange;
|
|
143
|
+
this._dataActual.quoteChangePercent = quote.percentChange;
|
|
144
|
+
this._dataActual.quoteTime = quote.timeDisplay;
|
|
145
|
+
this._dataActual.quoteVolume = quote.volume;
|
|
146
|
+
|
|
147
|
+
this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
|
|
148
|
+
this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
|
|
149
|
+
this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
|
|
150
|
+
this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
|
|
151
|
+
this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
|
|
152
|
+
this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
|
|
153
|
+
this._dataFormat.quoteTime = this._dataActual.quoteTime;
|
|
154
|
+
this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
|
|
135
155
|
} else {
|
|
136
156
|
this._dataActual.currentPrice = null;
|
|
137
157
|
this._dataFormat.currentPrice = null;
|
|
@@ -240,6 +260,20 @@ module.exports = (() => {
|
|
|
240
260
|
return this._excluded;
|
|
241
261
|
}
|
|
242
262
|
|
|
263
|
+
addExcludedItems(items) {
|
|
264
|
+
items.forEach((item) => {
|
|
265
|
+
const key = item.position.position;
|
|
266
|
+
|
|
267
|
+
if (this._excludedItems.hasOwnProperty(key)) {
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
removeExcludedItems(items) {
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
|
|
243
277
|
/**
|
|
244
278
|
* Causes aggregated data to be recalculated using a new exchange rate.
|
|
245
279
|
*
|
|
@@ -264,7 +298,7 @@ module.exports = (() => {
|
|
|
264
298
|
assert.argumentIsRequired(value, 'value', Boolean);
|
|
265
299
|
|
|
266
300
|
if (this._showClosedPositions !== value) {
|
|
267
|
-
this._showClosedPositionsChangeEvent(this._showClosedPositions = value);
|
|
301
|
+
this._showClosedPositionsChangeEvent.fire(this._showClosedPositions = value);
|
|
268
302
|
}
|
|
269
303
|
}
|
|
270
304
|
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -930,9 +930,15 @@ module.exports = (() => {
|
|
|
930
930
|
|
|
931
931
|
compositeGroups.sort(builder.toComparator());
|
|
932
932
|
|
|
933
|
+
const initializeGroupObservers = (group, groupTree) => {
|
|
934
|
+
|
|
935
|
+
};
|
|
936
|
+
|
|
933
937
|
compositeGroups.forEach((group) => {
|
|
934
938
|
const childTree = currentTree.addChild(group);
|
|
935
939
|
|
|
940
|
+
initializeGroupObservers(group, childTree);
|
|
941
|
+
|
|
936
942
|
group.registerMarketPercentChangeHandler(() => {
|
|
937
943
|
currentTree.walk((childGroup) => childGroup.refreshMarketPercent());
|
|
938
944
|
});
|
|
@@ -1048,12 +1054,21 @@ module.exports = (() => {
|
|
|
1048
1054
|
* @param {String} symbol
|
|
1049
1055
|
* @param {Object} data
|
|
1050
1056
|
*/
|
|
1051
|
-
setPositionFundamentalData(symbol, data) {
|
|
1057
|
+
setPositionFundamentalData(symbol, display, data) {
|
|
1052
1058
|
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
1059
|
+
assert.argumentIsRequired(display, 'display', Boolean);
|
|
1053
1060
|
assert.argumentIsRequired(data, 'data', Object);
|
|
1054
1061
|
|
|
1055
|
-
|
|
1056
|
-
|
|
1062
|
+
let map;
|
|
1063
|
+
|
|
1064
|
+
if (display) {
|
|
1065
|
+
map = this._symbolsDisplay;
|
|
1066
|
+
} else {
|
|
1067
|
+
map = this._symbols;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
if (map.hasOwnProperty(symbol)) {
|
|
1071
|
+
map[symbol].forEach(item => item.setPositionFundamentalData(data));
|
|
1057
1072
|
}
|
|
1058
1073
|
}
|
|
1059
1074
|
|
|
@@ -1112,6 +1127,16 @@ module.exports = (() => {
|
|
|
1112
1127
|
return findNode(this._trees[name], keys).getChildren().map(node => node.getValue());
|
|
1113
1128
|
}
|
|
1114
1129
|
|
|
1130
|
+
getPositions(portfolio) {
|
|
1131
|
+
return this._items.reduce((positions, item) => {
|
|
1132
|
+
if (item.position.portfolio === portfolio) {
|
|
1133
|
+
positions.push(item);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
return positions;
|
|
1137
|
+
}, []);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1115
1140
|
startTransaction(name, executor) {
|
|
1116
1141
|
assert.argumentIsRequired(name, 'name', String);
|
|
1117
1142
|
assert.argumentIsRequired(executor, 'executor', Function);
|
|
@@ -1203,6 +1228,8 @@ module.exports = (() => {
|
|
|
1203
1228
|
this._excludedChangeEvent = new Event(this);
|
|
1204
1229
|
this._showClosedPositionsChangeEvent = new Event(this);
|
|
1205
1230
|
|
|
1231
|
+
this._excludedItems = { };
|
|
1232
|
+
|
|
1206
1233
|
this._dataFormat = { };
|
|
1207
1234
|
this._dataActual = { };
|
|
1208
1235
|
|
|
@@ -1233,6 +1260,15 @@ module.exports = (() => {
|
|
|
1233
1260
|
this._dataFormat.fundamental = { };
|
|
1234
1261
|
}
|
|
1235
1262
|
|
|
1263
|
+
this._dataActual.quoteLast = null;
|
|
1264
|
+
this._dataActual.quoteOpen = null;
|
|
1265
|
+
this._dataActual.quoteHigh = null;
|
|
1266
|
+
this._dataActual.quoteLow = null;
|
|
1267
|
+
this._dataActual.quoteChange = null;
|
|
1268
|
+
this._dataActual.quoteChangePercent = null;
|
|
1269
|
+
this._dataActual.quoteTime = null;
|
|
1270
|
+
this._dataActual.quoteVolume = null;
|
|
1271
|
+
|
|
1236
1272
|
this._dataFormat.quoteLast = null;
|
|
1237
1273
|
this._dataFormat.quoteOpen = null;
|
|
1238
1274
|
this._dataFormat.quoteHigh = null;
|
|
@@ -1283,14 +1319,23 @@ module.exports = (() => {
|
|
|
1283
1319
|
this._dataActual.currentPrice = quote.lastPrice;
|
|
1284
1320
|
this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
|
|
1285
1321
|
|
|
1286
|
-
this.
|
|
1287
|
-
this.
|
|
1288
|
-
this.
|
|
1289
|
-
this.
|
|
1290
|
-
this.
|
|
1291
|
-
this.
|
|
1292
|
-
this.
|
|
1293
|
-
this.
|
|
1322
|
+
this._dataActual.quoteLast = quote.previousPrice;
|
|
1323
|
+
this._dataActual.quoteOpen = quote.openPrice;
|
|
1324
|
+
this._dataActual.quoteHigh = quote.highPrice;
|
|
1325
|
+
this._dataActual.quoteLow = quote.lowPrice;
|
|
1326
|
+
this._dataActual.quoteChange = quote.priceChange;
|
|
1327
|
+
this._dataActual.quoteChangePercent = quote.percentChange;
|
|
1328
|
+
this._dataActual.quoteTime = quote.timeDisplay;
|
|
1329
|
+
this._dataActual.quoteVolume = quote.volume;
|
|
1330
|
+
|
|
1331
|
+
this._dataFormat.quoteLast = formatNumber(this._dataActual.quoteLast , precision);
|
|
1332
|
+
this._dataFormat.quoteOpen = formatNumber(this._dataActual.quoteOpen, precision);
|
|
1333
|
+
this._dataFormat.quoteHigh = formatNumber(this._dataActual.quoteHigh, precision);
|
|
1334
|
+
this._dataFormat.quoteLow = formatNumber(this._dataActual.quoteLow, precision);
|
|
1335
|
+
this._dataFormat.quoteChange = formatNumber(this._dataActual.quoteChange, precision);
|
|
1336
|
+
this._dataFormat.quoteChangePercent = formatPercent(new Decimal(this._dataActual.quoteChangePercent || 0), 2);
|
|
1337
|
+
this._dataFormat.quoteTime = this._dataActual.quoteTime;
|
|
1338
|
+
this._dataFormat.quoteVolume = formatNumber(this._dataActual.quoteVolume, 0);
|
|
1294
1339
|
} else {
|
|
1295
1340
|
this._dataActual.currentPrice = null;
|
|
1296
1341
|
this._dataFormat.currentPrice = null;
|
|
@@ -1399,6 +1444,20 @@ module.exports = (() => {
|
|
|
1399
1444
|
return this._excluded;
|
|
1400
1445
|
}
|
|
1401
1446
|
|
|
1447
|
+
addExcludedItems(items) {
|
|
1448
|
+
items.forEach((item) => {
|
|
1449
|
+
const key = item.position.position;
|
|
1450
|
+
|
|
1451
|
+
if (this._excludedItems.hasOwnProperty(key)) {
|
|
1452
|
+
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
removeExcludedItems(items) {
|
|
1458
|
+
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1402
1461
|
/**
|
|
1403
1462
|
* Causes aggregated data to be recalculated using a new exchange rate.
|
|
1404
1463
|
*
|
|
@@ -1423,7 +1482,7 @@ module.exports = (() => {
|
|
|
1423
1482
|
assert.argumentIsRequired(value, 'value', Boolean);
|
|
1424
1483
|
|
|
1425
1484
|
if (this._showClosedPositions !== value) {
|
|
1426
|
-
this._showClosedPositionsChangeEvent(this._showClosedPositions = value);
|
|
1485
|
+
this._showClosedPositionsChangeEvent.fire(this._showClosedPositions = value);
|
|
1427
1486
|
}
|
|
1428
1487
|
}
|
|
1429
1488
|
|
|
@@ -2859,7 +2918,7 @@ module.exports = function () {
|
|
|
2859
2918
|
var Currency = function (_Enum) {
|
|
2860
2919
|
_inherits(Currency, _Enum);
|
|
2861
2920
|
|
|
2862
|
-
function Currency(code, description, precision) {
|
|
2921
|
+
function Currency(code, description, precision, alternateDescription) {
|
|
2863
2922
|
_classCallCheck(this, Currency);
|
|
2864
2923
|
|
|
2865
2924
|
var _this = _possibleConstructorReturn(this, (Currency.__proto__ || Object.getPrototypeOf(Currency)).call(this, code, description));
|
|
@@ -2867,7 +2926,11 @@ module.exports = function () {
|
|
|
2867
2926
|
assert.argumentIsRequired(precision, 'precision', Number);
|
|
2868
2927
|
assert.argumentIsValid(precision, 'precision', is.integer, 'is an integer');
|
|
2869
2928
|
|
|
2929
|
+
assert.argumentIsOptional(alternateDescription, 'alternateDescription', String);
|
|
2930
|
+
|
|
2870
2931
|
_this._precision = precision;
|
|
2932
|
+
|
|
2933
|
+
_this._alternateDescription = alternateDescription || description;
|
|
2871
2934
|
return _this;
|
|
2872
2935
|
}
|
|
2873
2936
|
|
|
@@ -2890,6 +2953,19 @@ module.exports = function () {
|
|
|
2890
2953
|
return this._precision;
|
|
2891
2954
|
}
|
|
2892
2955
|
|
|
2956
|
+
/**
|
|
2957
|
+
* An alternate human-readable description.
|
|
2958
|
+
*
|
|
2959
|
+
* @public
|
|
2960
|
+
* @returns {String}
|
|
2961
|
+
*/
|
|
2962
|
+
|
|
2963
|
+
}, {
|
|
2964
|
+
key: 'alternateDescription',
|
|
2965
|
+
get: function get() {
|
|
2966
|
+
return this._alternateDescription;
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2893
2969
|
/**
|
|
2894
2970
|
* Given a code, returns the enumeration item.
|
|
2895
2971
|
*
|
|
@@ -2947,9 +3023,9 @@ module.exports = function () {
|
|
|
2947
3023
|
return Currency;
|
|
2948
3024
|
}(Enum);
|
|
2949
3025
|
|
|
2950
|
-
var cad = new Currency('CAD', 'Canadian Dollar', 2);
|
|
2951
|
-
var eur = new Currency('EUR', 'Euro', 2);
|
|
2952
|
-
var usd = new Currency('USD', 'US Dollar', 2);
|
|
3026
|
+
var cad = new Currency('CAD', 'Canadian Dollar', 2, 'CAD$');
|
|
3027
|
+
var eur = new Currency('EUR', 'Euro', 2, 'EUR');
|
|
3028
|
+
var usd = new Currency('USD', 'US Dollar', 2, 'US$');
|
|
2953
3029
|
|
|
2954
3030
|
return Currency;
|
|
2955
3031
|
}();
|
|
@@ -3923,9 +3999,9 @@ module.exports = function () {
|
|
|
3923
3999
|
assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
|
|
3924
4000
|
assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
|
|
3925
4001
|
|
|
3926
|
-
if (a._big.gt(b)) {
|
|
4002
|
+
if (a._big.gt(b._big)) {
|
|
3927
4003
|
return 1;
|
|
3928
|
-
} else if (a._big.lt(b)) {
|
|
4004
|
+
} else if (a._big.lt(b._big)) {
|
|
3929
4005
|
return -1;
|
|
3930
4006
|
} else {
|
|
3931
4007
|
return 0;
|
|
@@ -4386,12 +4462,10 @@ var _createClass = function () { function defineProperties(target, props) { for
|
|
|
4386
4462
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4387
4463
|
|
|
4388
4464
|
var assert = require('./assert'),
|
|
4389
|
-
is = require('./is'),
|
|
4390
4465
|
memoize = require('./memoize');
|
|
4391
4466
|
|
|
4392
4467
|
var Currency = require('./Currency'),
|
|
4393
|
-
Decimal = require('./Decimal')
|
|
4394
|
-
Enum = require('./Enum');
|
|
4468
|
+
Decimal = require('./Decimal');
|
|
4395
4469
|
|
|
4396
4470
|
module.exports = function () {
|
|
4397
4471
|
'use strict';
|
|
@@ -4571,12 +4645,7 @@ module.exports = function () {
|
|
|
4571
4645
|
assert.argumentIsRequired(amount, 'amount', Decimal, 'Decimal');
|
|
4572
4646
|
assert.argumentIsRequired(currency, 'currency', Currency, 'Currency');
|
|
4573
4647
|
assert.argumentIsRequired(desiredCurrency, 'desiredCurrency', Currency, 'Currency');
|
|
4574
|
-
|
|
4575
|
-
for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
4576
|
-
rates[_key - 3] = arguments[_key];
|
|
4577
|
-
}
|
|
4578
|
-
|
|
4579
|
-
assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
|
|
4648
|
+
//assert.argumentIsArray(rates, 'rates', Rate, 'Rate');
|
|
4580
4649
|
|
|
4581
4650
|
var converted = void 0;
|
|
4582
4651
|
|
|
@@ -4586,6 +4655,10 @@ module.exports = function () {
|
|
|
4586
4655
|
var numerator = desiredCurrency;
|
|
4587
4656
|
var denominator = currency;
|
|
4588
4657
|
|
|
4658
|
+
for (var _len = arguments.length, rates = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
4659
|
+
rates[_key - 3] = arguments[_key];
|
|
4660
|
+
}
|
|
4661
|
+
|
|
4589
4662
|
var rate = rates.find(function (r) {
|
|
4590
4663
|
return r.numerator === numerator && r.denominator === denominator || r.numerator === denominator && r.denominator === numerator;
|
|
4591
4664
|
});
|
|
@@ -4636,7 +4709,7 @@ module.exports = function () {
|
|
|
4636
4709
|
return Rate;
|
|
4637
4710
|
}();
|
|
4638
4711
|
|
|
4639
|
-
},{"./Currency":12,"./Decimal":14,"./
|
|
4712
|
+
},{"./Currency":12,"./Decimal":14,"./assert":19,"./memoize":22}],18:[function(require,module,exports){
|
|
4640
4713
|
'use strict';
|
|
4641
4714
|
|
|
4642
4715
|
var assert = require('./assert'),
|