@barchart/portfolio-api-common 1.0.76 → 1.0.80

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.
@@ -19,6 +19,10 @@ module.exports = (() => {
19
19
  constructor(code, description, alternateDescription, canReinvest, usesSymbols) {
20
20
  super(code, description);
21
21
 
22
+ assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
23
+ assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
24
+ assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
25
+
22
26
  this._alternateDescription = alternateDescription;
23
27
  this._canReinvest = canReinvest;
24
28
  this._usesSymbols = usesSymbols;
@@ -49,8 +49,12 @@ module.exports = (() => {
49
49
  this._dataFormat.income = null;
50
50
  this._dataFormat.market = null;
51
51
  this._dataFormat.marketPercent = null;
52
+ this._dataFormat.marketDirection = null;
52
53
  this._dataFormat.unrealizedToday = null;
54
+ this._dataFormat.unrealizedTodayNegative = false;
55
+ this._dataFormat.unrealizedTodayDirection = null;
53
56
  this._dataFormat.total = null;
57
+ this._dataFormat.totalNegative = false;
54
58
  this._dataFormat.summaryOneTotal = null;
55
59
  this._dataFormat.summaryTwoTotal = null;
56
60
 
@@ -220,13 +224,17 @@ module.exports = (() => {
220
224
  return updates;
221
225
  }, {
222
226
  market: Decimal.ZERO,
227
+ marketDirection: { up: false, down: false },
228
+ unrealizedToday: Decimal.ZERO,
229
+ unrealizedTodayDirection: { up: false, down: false }
223
230
 
224
- unrealizedToday: Decimal.ZERO
225
231
  });
226
232
  } else {
227
233
  updates = {
228
234
  market: actual.market.add(item.data.marketChange),
229
- unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
235
+ marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
236
+ unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange),
237
+ unrealizedTodayDirection: { up: item.data.unrealizedTodayChange.getIsPositive(), down: item.data.unrealizedTodayChange.getIsNegative() }
230
238
  };
231
239
  }
232
240
 
@@ -249,10 +257,17 @@ module.exports = (() => {
249
257
 
250
258
  format.market = formatCurrency(actual.market, currency);
251
259
  format.marketPercent = formatPercent(actual.marketPercent, 2);
260
+ format.marketDirection = unchanged;
261
+ format.marketDirection = updates.marketDirection;
252
262
  format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
253
263
  format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
264
+ format.unrealizedTodayDirection = unchanged;
265
+ format.unrealizedTodayDirection = updates.unrealizedTodayDirection;
254
266
  format.total = formatCurrency(actual.total, currency);
267
+ format.totalNegative = actual.total.getIsNegative();
255
268
  }
256
269
 
270
+ const unchanged = { up: false, down: false };
271
+
257
272
  return PositionGroup;
258
273
  })();
@@ -6,7 +6,8 @@ const assert = require('@barchart/common-js/lang/assert'),
6
6
  Schema = require('@barchart/common-js/serialization/json/Schema'),
7
7
  SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
8
8
 
9
- const TransactionType = require('./../data/TransactionType');
9
+ const InstrumentType = require('./../data/InstrumentType'),
10
+ TransactionType = require('./../data/TransactionType');
10
11
 
11
12
  module.exports = (() => {
12
13
  'use strict';
@@ -244,9 +245,9 @@ module.exports = (() => {
244
245
  .withField('portfolio', DataType.STRING)
245
246
  .withField('position', DataType.STRING)
246
247
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
247
- .withField('instrument.name', DataType.STRING, true)
248
- .withField('instrument.type', DataType.STRING, true)
249
- .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
248
+ .withField('instrument.name', DataType.STRING)
249
+ .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
250
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
250
251
  .withField('instrument.symbol.barchart', DataType.STRING, true)
251
252
  .withField('instrument.symbol.display', DataType.STRING, true)
252
253
  .withField('date', DataType.DAY)
@@ -271,9 +272,9 @@ module.exports = (() => {
271
272
  .withField('portfolio', DataType.STRING)
272
273
  .withField('position', DataType.STRING)
273
274
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
274
- .withField('instrument.name', DataType.STRING, true)
275
- .withField('instrument.type', DataType.STRING, true)
276
- .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
275
+ .withField('instrument.name', DataType.STRING)
276
+ .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
277
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
277
278
  .withField('instrument.symbol.barchart', DataType.STRING, true)
278
279
  .withField('instrument.symbol.display', DataType.STRING, true)
279
280
  .withField('date', DataType.DAY)
@@ -387,8 +388,8 @@ module.exports = (() => {
387
388
  .withField('portfolio', DataType.STRING)
388
389
  .withField('position', DataType.STRING)
389
390
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
390
- .withField('instrument.type', DataType.STRING, true)
391
- .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
391
+ .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
392
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
392
393
  .withField('date', DataType.DAY)
393
394
  .withField('amount', DataType.DECIMAL)
394
395
  .withField('fee', DataType.DECIMAL, true)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.0.76",
3
+ "version": "1.0.80",
4
4
  "description": "Common classes used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -20,6 +20,10 @@ module.exports = (() => {
20
20
  constructor(code, description, alternateDescription, canReinvest, usesSymbols) {
21
21
  super(code, description);
22
22
 
23
+ assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
24
+ assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
25
+ assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
26
+
23
27
  this._alternateDescription = alternateDescription;
24
28
  this._canReinvest = canReinvest;
25
29
  this._usesSymbols = usesSymbols;
@@ -984,8 +988,12 @@ module.exports = (() => {
984
988
  this._dataFormat.income = null;
985
989
  this._dataFormat.market = null;
986
990
  this._dataFormat.marketPercent = null;
991
+ this._dataFormat.marketDirection = null;
987
992
  this._dataFormat.unrealizedToday = null;
993
+ this._dataFormat.unrealizedTodayNegative = false;
994
+ this._dataFormat.unrealizedTodayDirection = null;
988
995
  this._dataFormat.total = null;
996
+ this._dataFormat.totalNegative = false;
989
997
  this._dataFormat.summaryOneTotal = null;
990
998
  this._dataFormat.summaryTwoTotal = null;
991
999
 
@@ -1155,13 +1163,17 @@ module.exports = (() => {
1155
1163
  return updates;
1156
1164
  }, {
1157
1165
  market: Decimal.ZERO,
1166
+ marketDirection: { up: false, down: false },
1167
+ unrealizedToday: Decimal.ZERO,
1168
+ unrealizedTodayDirection: { up: false, down: false }
1158
1169
 
1159
- unrealizedToday: Decimal.ZERO
1160
1170
  });
1161
1171
  } else {
1162
1172
  updates = {
1163
1173
  market: actual.market.add(item.data.marketChange),
1164
- unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange)
1174
+ marketDirection: { up: item.data.marketChange.getIsPositive(), down: item.data.marketChange.getIsNegative() },
1175
+ unrealizedToday: actual.unrealizedToday.add(item.data.unrealizedTodayChange),
1176
+ unrealizedTodayDirection: { up: item.data.unrealizedTodayChange.getIsPositive(), down: item.data.unrealizedTodayChange.getIsNegative() }
1165
1177
  };
1166
1178
  }
1167
1179
 
@@ -1184,11 +1196,18 @@ module.exports = (() => {
1184
1196
 
1185
1197
  format.market = formatCurrency(actual.market, currency);
1186
1198
  format.marketPercent = formatPercent(actual.marketPercent, 2);
1199
+ format.marketDirection = unchanged;
1200
+ format.marketDirection = updates.marketDirection;
1187
1201
  format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
1188
1202
  format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
1203
+ format.unrealizedTodayDirection = unchanged;
1204
+ format.unrealizedTodayDirection = updates.unrealizedTodayDirection;
1189
1205
  format.total = formatCurrency(actual.total, currency);
1206
+ format.totalNegative = actual.total.getIsNegative();
1190
1207
  }
1191
1208
 
1209
+ const unchanged = { up: false, down: false };
1210
+
1192
1211
  return PositionGroup;
1193
1212
  })();
1194
1213