@barchart/portfolio-api-common 1.0.101 → 1.0.105
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.
|
@@ -213,12 +213,12 @@ module.exports = (() => {
|
|
|
213
213
|
return Object.keys(this._symbols);
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
assert.
|
|
218
|
-
assert.
|
|
216
|
+
setPositionQuote(symbol, quote) {
|
|
217
|
+
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
218
|
+
assert.argumentIsRequired(quote, 'quote', Object);
|
|
219
219
|
|
|
220
|
-
if (this._symbols.hasOwnProperty(symbol)
|
|
221
|
-
this._symbols[symbol].forEach(item => item.
|
|
220
|
+
if (this._symbols.hasOwnProperty(symbol)) {
|
|
221
|
+
this._symbols[symbol].forEach(item => item.setQuote(quote));
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
@@ -234,9 +234,9 @@ module.exports = (() => {
|
|
|
234
234
|
}, [ ]);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
|
|
238
|
-
assert.
|
|
239
|
-
assert.
|
|
237
|
+
setForexQuote(symbol, quote) {
|
|
238
|
+
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
239
|
+
assert.argumentIsRequired(quote, 'quote', Object);
|
|
240
240
|
|
|
241
241
|
return;
|
|
242
242
|
}
|
|
@@ -35,6 +35,21 @@ module.exports = (() => {
|
|
|
35
35
|
this._dataFormat.key = this._key;
|
|
36
36
|
this._dataFormat.description = this._description;
|
|
37
37
|
|
|
38
|
+
if (this._single) {
|
|
39
|
+
this._dataFormat.instrument = items[0].position.instrument;
|
|
40
|
+
} else {
|
|
41
|
+
this._dataFormat.instrument = null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this._dataFormat.quoteLast = null;
|
|
45
|
+
this._dataFormat.quoteOpen = null;
|
|
46
|
+
this._dataFormat.quoteHigh = null;
|
|
47
|
+
this._dataFormat.quoteLow = null;
|
|
48
|
+
this._dataFormat.quoteChange = null;
|
|
49
|
+
this._dataFormat.quoteChangePercent = null;
|
|
50
|
+
this._dataFormat.quoteTime = null;
|
|
51
|
+
this._dataFormat.quoteVolume = null;
|
|
52
|
+
|
|
38
53
|
this._dataActual.currentPrice = null;
|
|
39
54
|
this._dataActual.previousPrice = null;
|
|
40
55
|
this._dataActual.basis = null;
|
|
@@ -65,10 +80,21 @@ module.exports = (() => {
|
|
|
65
80
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
66
81
|
|
|
67
82
|
this._items.forEach((item) => {
|
|
68
|
-
item.
|
|
83
|
+
item.registerQuoteChangeHandler((quote, sender) => {
|
|
69
84
|
if (this._single) {
|
|
70
|
-
|
|
71
|
-
|
|
85
|
+
const precision = sender.position.instrument.currency.precision;
|
|
86
|
+
|
|
87
|
+
this._dataActual.currentPrice = sender.data.currentPrice;
|
|
88
|
+
this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
|
|
89
|
+
|
|
90
|
+
this._dataFormat.quoteLast = formatNumber(quote.previousPrice, precision);
|
|
91
|
+
this._dataFormat.quoteOpen = formatNumber(quote.openPrice, precision);
|
|
92
|
+
this._dataFormat.quoteHigh = formatNumber(quote.highPrice, precision);
|
|
93
|
+
this._dataFormat.quoteLow = formatNumber(quote.lowPrice, precision);
|
|
94
|
+
this._dataFormat.quoteChange = formatNumber(quote.priceChange, precision);
|
|
95
|
+
this._dataFormat.quoteChangePercent = formatPercent(quote.percentChange, 2);
|
|
96
|
+
this._dataFormat.quoteTime = quote.timeDisplay;
|
|
97
|
+
this._dataFormat.quoteVolume = formatNumber(quote.volume, 0);
|
|
72
98
|
} else {
|
|
73
99
|
this._dataActual.currentPrice = null;
|
|
74
100
|
this._dataFormat.currentPrice = null;
|
|
@@ -157,9 +183,17 @@ module.exports = (() => {
|
|
|
157
183
|
}
|
|
158
184
|
}
|
|
159
185
|
|
|
160
|
-
function formatNumber(
|
|
186
|
+
function formatNumber(number, precision) {
|
|
187
|
+
if (is.number(number)) {
|
|
188
|
+
return formatter.numberToString(number, precision, ',', false);
|
|
189
|
+
} else {
|
|
190
|
+
return '—';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function formatDecimal(decimal, precision) {
|
|
161
195
|
if (decimal !== null) {
|
|
162
|
-
return
|
|
196
|
+
return formatNumber(decimal.toFloat(), precision);
|
|
163
197
|
} else {
|
|
164
198
|
return '—';
|
|
165
199
|
}
|
|
@@ -167,14 +201,14 @@ module.exports = (() => {
|
|
|
167
201
|
|
|
168
202
|
function formatPercent(decimal, precision) {
|
|
169
203
|
if (decimal !== null) {
|
|
170
|
-
return
|
|
204
|
+
return formatDecimal(decimal.multiply(100), precision);
|
|
171
205
|
} else {
|
|
172
206
|
return '—';
|
|
173
207
|
}
|
|
174
208
|
}
|
|
175
209
|
|
|
176
210
|
function formatCurrency(decimal, currency) {
|
|
177
|
-
return
|
|
211
|
+
return formatDecimal(decimal, currency.precision);
|
|
178
212
|
}
|
|
179
213
|
|
|
180
214
|
function calculateStaticData(group) {
|
|
@@ -16,7 +16,7 @@ module.exports = (() => {
|
|
|
16
16
|
constructor(portfolio, position, currentSummary, previousSummaries) {
|
|
17
17
|
this._portfolio = portfolio;
|
|
18
18
|
this._position = position;
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
this._currentSummary = currentSummary || null;
|
|
21
21
|
this._previousSummaries = previousSummaries || [ ];
|
|
22
22
|
|
|
@@ -24,6 +24,9 @@ module.exports = (() => {
|
|
|
24
24
|
|
|
25
25
|
this._data.basis = null;
|
|
26
26
|
|
|
27
|
+
this._currentQuote = null;
|
|
28
|
+
this._previousQuote = null;
|
|
29
|
+
|
|
27
30
|
this._data.currentPrice = null;
|
|
28
31
|
this._data.previousPrice = null;
|
|
29
32
|
|
|
@@ -46,7 +49,7 @@ module.exports = (() => {
|
|
|
46
49
|
calculateStaticData(this);
|
|
47
50
|
calculatePriceData(this, null);
|
|
48
51
|
|
|
49
|
-
this.
|
|
52
|
+
this._quoteChangedEvent = new Event(this);
|
|
50
53
|
this._excludedChangeEvent = new Event(this);
|
|
51
54
|
}
|
|
52
55
|
|
|
@@ -70,17 +73,24 @@ module.exports = (() => {
|
|
|
70
73
|
return this._data;
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
get quote() {
|
|
77
|
+
return this._currentQuote;
|
|
78
|
+
}
|
|
79
|
+
|
|
73
80
|
get excluded() {
|
|
74
81
|
return this._excluded;
|
|
75
82
|
}
|
|
76
83
|
|
|
77
|
-
|
|
78
|
-
assert.argumentIsRequired(
|
|
84
|
+
setQuote(quote) {
|
|
85
|
+
assert.argumentIsRequired(quote, 'quote', Object);
|
|
79
86
|
|
|
80
87
|
if (this._data.price !== price) {
|
|
81
|
-
|
|
88
|
+
this._previousQuote = this._currentQuote;
|
|
89
|
+
this._currentQuote = quote;
|
|
90
|
+
|
|
91
|
+
calculatePriceData(this, this._currentQuote.lastPrice);
|
|
82
92
|
|
|
83
|
-
this.
|
|
93
|
+
this._quoteChangedEvent.fire(this._data, this._currentQuote);
|
|
84
94
|
}
|
|
85
95
|
}
|
|
86
96
|
|
|
@@ -92,8 +102,8 @@ module.exports = (() => {
|
|
|
92
102
|
}
|
|
93
103
|
}
|
|
94
104
|
|
|
95
|
-
|
|
96
|
-
this.
|
|
105
|
+
registerQuoteChangeHandler(handler) {
|
|
106
|
+
this._quoteChangedEvent.register(handler);
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
registerExcludedChangeHandler(handler) {
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -929,12 +929,12 @@ module.exports = (() => {
|
|
|
929
929
|
return Object.keys(this._symbols);
|
|
930
930
|
}
|
|
931
931
|
|
|
932
|
-
|
|
933
|
-
assert.
|
|
934
|
-
assert.
|
|
932
|
+
setPositionQuote(symbol, quote) {
|
|
933
|
+
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
934
|
+
assert.argumentIsRequired(quote, 'quote', Object);
|
|
935
935
|
|
|
936
|
-
if (this._symbols.hasOwnProperty(symbol)
|
|
937
|
-
this._symbols[symbol].forEach(item => item.
|
|
936
|
+
if (this._symbols.hasOwnProperty(symbol)) {
|
|
937
|
+
this._symbols[symbol].forEach(item => item.setQuote(quote));
|
|
938
938
|
}
|
|
939
939
|
}
|
|
940
940
|
|
|
@@ -950,9 +950,9 @@ module.exports = (() => {
|
|
|
950
950
|
}, [ ]);
|
|
951
951
|
}
|
|
952
952
|
|
|
953
|
-
|
|
954
|
-
assert.
|
|
955
|
-
assert.
|
|
953
|
+
setForexQuote(symbol, quote) {
|
|
954
|
+
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
955
|
+
assert.argumentIsRequired(quote, 'quote', Object);
|
|
956
956
|
|
|
957
957
|
return;
|
|
958
958
|
}
|
|
@@ -1038,6 +1038,21 @@ module.exports = (() => {
|
|
|
1038
1038
|
this._dataFormat.key = this._key;
|
|
1039
1039
|
this._dataFormat.description = this._description;
|
|
1040
1040
|
|
|
1041
|
+
if (this._single) {
|
|
1042
|
+
this._dataFormat.instrument = items[0].position.instrument;
|
|
1043
|
+
} else {
|
|
1044
|
+
this._dataFormat.instrument = null;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
this._dataFormat.quoteLast = null;
|
|
1048
|
+
this._dataFormat.quoteOpen = null;
|
|
1049
|
+
this._dataFormat.quoteHigh = null;
|
|
1050
|
+
this._dataFormat.quoteLow = null;
|
|
1051
|
+
this._dataFormat.quoteChange = null;
|
|
1052
|
+
this._dataFormat.quoteChangePercent = null;
|
|
1053
|
+
this._dataFormat.quoteTime = null;
|
|
1054
|
+
this._dataFormat.quoteVolume = null;
|
|
1055
|
+
|
|
1041
1056
|
this._dataActual.currentPrice = null;
|
|
1042
1057
|
this._dataActual.previousPrice = null;
|
|
1043
1058
|
this._dataActual.basis = null;
|
|
@@ -1068,10 +1083,21 @@ module.exports = (() => {
|
|
|
1068
1083
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
1069
1084
|
|
|
1070
1085
|
this._items.forEach((item) => {
|
|
1071
|
-
item.
|
|
1086
|
+
item.registerQuoteChangeHandler((quote, sender) => {
|
|
1072
1087
|
if (this._single) {
|
|
1073
|
-
|
|
1074
|
-
|
|
1088
|
+
const precision = sender.position.instrument.currency.precision;
|
|
1089
|
+
|
|
1090
|
+
this._dataActual.currentPrice = sender.data.currentPrice;
|
|
1091
|
+
this._dataFormat.currentPrice = formatNumber(this._dataActual.currentPrice, precision);
|
|
1092
|
+
|
|
1093
|
+
this._dataFormat.quoteLast = formatNumber(quote.previousPrice, precision);
|
|
1094
|
+
this._dataFormat.quoteOpen = formatNumber(quote.openPrice, precision);
|
|
1095
|
+
this._dataFormat.quoteHigh = formatNumber(quote.highPrice, precision);
|
|
1096
|
+
this._dataFormat.quoteLow = formatNumber(quote.lowPrice, precision);
|
|
1097
|
+
this._dataFormat.quoteChange = formatNumber(quote.priceChange, precision);
|
|
1098
|
+
this._dataFormat.quoteChangePercent = formatPercent(quote.percentChange, 2);
|
|
1099
|
+
this._dataFormat.quoteTime = quote.timeDisplay;
|
|
1100
|
+
this._dataFormat.quoteVolume = formatNumber(quote.volume, 0);
|
|
1075
1101
|
} else {
|
|
1076
1102
|
this._dataActual.currentPrice = null;
|
|
1077
1103
|
this._dataFormat.currentPrice = null;
|
|
@@ -1160,9 +1186,17 @@ module.exports = (() => {
|
|
|
1160
1186
|
}
|
|
1161
1187
|
}
|
|
1162
1188
|
|
|
1163
|
-
function formatNumber(
|
|
1189
|
+
function formatNumber(number, precision) {
|
|
1190
|
+
if (is.number(number)) {
|
|
1191
|
+
return formatter.numberToString(number, precision, ',', false);
|
|
1192
|
+
} else {
|
|
1193
|
+
return '—';
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function formatDecimal(decimal, precision) {
|
|
1164
1198
|
if (decimal !== null) {
|
|
1165
|
-
return
|
|
1199
|
+
return formatNumber(decimal.toFloat(), precision);
|
|
1166
1200
|
} else {
|
|
1167
1201
|
return '—';
|
|
1168
1202
|
}
|
|
@@ -1170,14 +1204,14 @@ module.exports = (() => {
|
|
|
1170
1204
|
|
|
1171
1205
|
function formatPercent(decimal, precision) {
|
|
1172
1206
|
if (decimal !== null) {
|
|
1173
|
-
return
|
|
1207
|
+
return formatDecimal(decimal.multiply(100), precision);
|
|
1174
1208
|
} else {
|
|
1175
1209
|
return '—';
|
|
1176
1210
|
}
|
|
1177
1211
|
}
|
|
1178
1212
|
|
|
1179
1213
|
function formatCurrency(decimal, currency) {
|
|
1180
|
-
return
|
|
1214
|
+
return formatDecimal(decimal, currency.precision);
|
|
1181
1215
|
}
|
|
1182
1216
|
|
|
1183
1217
|
function calculateStaticData(group) {
|
|
@@ -1356,7 +1390,7 @@ module.exports = (() => {
|
|
|
1356
1390
|
constructor(portfolio, position, currentSummary, previousSummaries) {
|
|
1357
1391
|
this._portfolio = portfolio;
|
|
1358
1392
|
this._position = position;
|
|
1359
|
-
|
|
1393
|
+
|
|
1360
1394
|
this._currentSummary = currentSummary || null;
|
|
1361
1395
|
this._previousSummaries = previousSummaries || [ ];
|
|
1362
1396
|
|
|
@@ -1364,6 +1398,9 @@ module.exports = (() => {
|
|
|
1364
1398
|
|
|
1365
1399
|
this._data.basis = null;
|
|
1366
1400
|
|
|
1401
|
+
this._currentQuote = null;
|
|
1402
|
+
this._previousQuote = null;
|
|
1403
|
+
|
|
1367
1404
|
this._data.currentPrice = null;
|
|
1368
1405
|
this._data.previousPrice = null;
|
|
1369
1406
|
|
|
@@ -1386,7 +1423,7 @@ module.exports = (() => {
|
|
|
1386
1423
|
calculateStaticData(this);
|
|
1387
1424
|
calculatePriceData(this, null);
|
|
1388
1425
|
|
|
1389
|
-
this.
|
|
1426
|
+
this._quoteChangedEvent = new Event(this);
|
|
1390
1427
|
this._excludedChangeEvent = new Event(this);
|
|
1391
1428
|
}
|
|
1392
1429
|
|
|
@@ -1410,17 +1447,24 @@ module.exports = (() => {
|
|
|
1410
1447
|
return this._data;
|
|
1411
1448
|
}
|
|
1412
1449
|
|
|
1450
|
+
get quote() {
|
|
1451
|
+
return this._currentQuote;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1413
1454
|
get excluded() {
|
|
1414
1455
|
return this._excluded;
|
|
1415
1456
|
}
|
|
1416
1457
|
|
|
1417
|
-
|
|
1418
|
-
assert.argumentIsRequired(
|
|
1458
|
+
setQuote(quote) {
|
|
1459
|
+
assert.argumentIsRequired(quote, 'quote', Object);
|
|
1419
1460
|
|
|
1420
1461
|
if (this._data.price !== price) {
|
|
1421
|
-
|
|
1462
|
+
this._previousQuote = this._currentQuote;
|
|
1463
|
+
this._currentQuote = quote;
|
|
1464
|
+
|
|
1465
|
+
calculatePriceData(this, this._currentQuote.lastPrice);
|
|
1422
1466
|
|
|
1423
|
-
this.
|
|
1467
|
+
this._quoteChangedEvent.fire(this._data, this._currentQuote);
|
|
1424
1468
|
}
|
|
1425
1469
|
}
|
|
1426
1470
|
|
|
@@ -1432,8 +1476,8 @@ module.exports = (() => {
|
|
|
1432
1476
|
}
|
|
1433
1477
|
}
|
|
1434
1478
|
|
|
1435
|
-
|
|
1436
|
-
this.
|
|
1479
|
+
registerQuoteChangeHandler(handler) {
|
|
1480
|
+
this._quoteChangedEvent.register(handler);
|
|
1437
1481
|
}
|
|
1438
1482
|
|
|
1439
1483
|
registerExcludedChangeHandler(handler) {
|