@barchart/portfolio-api-common 1.0.104 → 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
|
}
|
|
@@ -41,6 +41,15 @@ module.exports = (() => {
|
|
|
41
41
|
this._dataFormat.instrument = null;
|
|
42
42
|
}
|
|
43
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
|
+
|
|
44
53
|
this._dataActual.currentPrice = null;
|
|
45
54
|
this._dataActual.previousPrice = null;
|
|
46
55
|
this._dataActual.basis = null;
|
|
@@ -71,10 +80,21 @@ module.exports = (() => {
|
|
|
71
80
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
72
81
|
|
|
73
82
|
this._items.forEach((item) => {
|
|
74
|
-
item.
|
|
83
|
+
item.registerQuoteChangeHandler((quote, sender) => {
|
|
75
84
|
if (this._single) {
|
|
76
|
-
|
|
77
|
-
|
|
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);
|
|
78
98
|
} else {
|
|
79
99
|
this._dataActual.currentPrice = null;
|
|
80
100
|
this._dataFormat.currentPrice = null;
|
|
@@ -163,9 +183,17 @@ module.exports = (() => {
|
|
|
163
183
|
}
|
|
164
184
|
}
|
|
165
185
|
|
|
166
|
-
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) {
|
|
167
195
|
if (decimal !== null) {
|
|
168
|
-
return
|
|
196
|
+
return formatNumber(decimal.toFloat(), precision);
|
|
169
197
|
} else {
|
|
170
198
|
return '—';
|
|
171
199
|
}
|
|
@@ -173,14 +201,14 @@ module.exports = (() => {
|
|
|
173
201
|
|
|
174
202
|
function formatPercent(decimal, precision) {
|
|
175
203
|
if (decimal !== null) {
|
|
176
|
-
return
|
|
204
|
+
return formatDecimal(decimal.multiply(100), precision);
|
|
177
205
|
} else {
|
|
178
206
|
return '—';
|
|
179
207
|
}
|
|
180
208
|
}
|
|
181
209
|
|
|
182
210
|
function formatCurrency(decimal, currency) {
|
|
183
|
-
return
|
|
211
|
+
return formatDecimal(decimal, currency.precision);
|
|
184
212
|
}
|
|
185
213
|
|
|
186
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
|
}
|
|
@@ -1044,6 +1044,15 @@ module.exports = (() => {
|
|
|
1044
1044
|
this._dataFormat.instrument = null;
|
|
1045
1045
|
}
|
|
1046
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
|
+
|
|
1047
1056
|
this._dataActual.currentPrice = null;
|
|
1048
1057
|
this._dataActual.previousPrice = null;
|
|
1049
1058
|
this._dataActual.basis = null;
|
|
@@ -1074,10 +1083,21 @@ module.exports = (() => {
|
|
|
1074
1083
|
this._dataFormat.summaryTotalPreviousNegative = false;
|
|
1075
1084
|
|
|
1076
1085
|
this._items.forEach((item) => {
|
|
1077
|
-
item.
|
|
1086
|
+
item.registerQuoteChangeHandler((quote, sender) => {
|
|
1078
1087
|
if (this._single) {
|
|
1079
|
-
|
|
1080
|
-
|
|
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);
|
|
1081
1101
|
} else {
|
|
1082
1102
|
this._dataActual.currentPrice = null;
|
|
1083
1103
|
this._dataFormat.currentPrice = null;
|
|
@@ -1166,9 +1186,17 @@ module.exports = (() => {
|
|
|
1166
1186
|
}
|
|
1167
1187
|
}
|
|
1168
1188
|
|
|
1169
|
-
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) {
|
|
1170
1198
|
if (decimal !== null) {
|
|
1171
|
-
return
|
|
1199
|
+
return formatNumber(decimal.toFloat(), precision);
|
|
1172
1200
|
} else {
|
|
1173
1201
|
return '—';
|
|
1174
1202
|
}
|
|
@@ -1176,14 +1204,14 @@ module.exports = (() => {
|
|
|
1176
1204
|
|
|
1177
1205
|
function formatPercent(decimal, precision) {
|
|
1178
1206
|
if (decimal !== null) {
|
|
1179
|
-
return
|
|
1207
|
+
return formatDecimal(decimal.multiply(100), precision);
|
|
1180
1208
|
} else {
|
|
1181
1209
|
return '—';
|
|
1182
1210
|
}
|
|
1183
1211
|
}
|
|
1184
1212
|
|
|
1185
1213
|
function formatCurrency(decimal, currency) {
|
|
1186
|
-
return
|
|
1214
|
+
return formatDecimal(decimal, currency.precision);
|
|
1187
1215
|
}
|
|
1188
1216
|
|
|
1189
1217
|
function calculateStaticData(group) {
|
|
@@ -1362,7 +1390,7 @@ module.exports = (() => {
|
|
|
1362
1390
|
constructor(portfolio, position, currentSummary, previousSummaries) {
|
|
1363
1391
|
this._portfolio = portfolio;
|
|
1364
1392
|
this._position = position;
|
|
1365
|
-
|
|
1393
|
+
|
|
1366
1394
|
this._currentSummary = currentSummary || null;
|
|
1367
1395
|
this._previousSummaries = previousSummaries || [ ];
|
|
1368
1396
|
|
|
@@ -1370,6 +1398,9 @@ module.exports = (() => {
|
|
|
1370
1398
|
|
|
1371
1399
|
this._data.basis = null;
|
|
1372
1400
|
|
|
1401
|
+
this._currentQuote = null;
|
|
1402
|
+
this._previousQuote = null;
|
|
1403
|
+
|
|
1373
1404
|
this._data.currentPrice = null;
|
|
1374
1405
|
this._data.previousPrice = null;
|
|
1375
1406
|
|
|
@@ -1392,7 +1423,7 @@ module.exports = (() => {
|
|
|
1392
1423
|
calculateStaticData(this);
|
|
1393
1424
|
calculatePriceData(this, null);
|
|
1394
1425
|
|
|
1395
|
-
this.
|
|
1426
|
+
this._quoteChangedEvent = new Event(this);
|
|
1396
1427
|
this._excludedChangeEvent = new Event(this);
|
|
1397
1428
|
}
|
|
1398
1429
|
|
|
@@ -1416,17 +1447,24 @@ module.exports = (() => {
|
|
|
1416
1447
|
return this._data;
|
|
1417
1448
|
}
|
|
1418
1449
|
|
|
1450
|
+
get quote() {
|
|
1451
|
+
return this._currentQuote;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1419
1454
|
get excluded() {
|
|
1420
1455
|
return this._excluded;
|
|
1421
1456
|
}
|
|
1422
1457
|
|
|
1423
|
-
|
|
1424
|
-
assert.argumentIsRequired(
|
|
1458
|
+
setQuote(quote) {
|
|
1459
|
+
assert.argumentIsRequired(quote, 'quote', Object);
|
|
1425
1460
|
|
|
1426
1461
|
if (this._data.price !== price) {
|
|
1427
|
-
|
|
1462
|
+
this._previousQuote = this._currentQuote;
|
|
1463
|
+
this._currentQuote = quote;
|
|
1464
|
+
|
|
1465
|
+
calculatePriceData(this, this._currentQuote.lastPrice);
|
|
1428
1466
|
|
|
1429
|
-
this.
|
|
1467
|
+
this._quoteChangedEvent.fire(this._data, this._currentQuote);
|
|
1430
1468
|
}
|
|
1431
1469
|
}
|
|
1432
1470
|
|
|
@@ -1438,8 +1476,8 @@ module.exports = (() => {
|
|
|
1438
1476
|
}
|
|
1439
1477
|
}
|
|
1440
1478
|
|
|
1441
|
-
|
|
1442
|
-
this.
|
|
1479
|
+
registerQuoteChangeHandler(handler) {
|
|
1480
|
+
this._quoteChangedEvent.register(handler);
|
|
1443
1481
|
}
|
|
1444
1482
|
|
|
1445
1483
|
registerExcludedChangeHandler(handler) {
|