@barchart/portfolio-api-common 1.0.75 → 1.0.79

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,9 +257,12 @@ module.exports = (() => {
249
257
 
250
258
  format.market = formatCurrency(actual.market, currency);
251
259
  format.marketPercent = formatPercent(actual.marketPercent, 2);
260
+ format.marketDirection = updates.marketDirection;
252
261
  format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
253
262
  format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
263
+ format.unrealizedTodayDirection = updates.unrealizedTodayDirection;
254
264
  format.total = formatCurrency(actual.total, currency);
265
+ format.totalNegative = actual.total.getIsNegative();
255
266
  }
256
267
 
257
268
  return PositionGroup;
@@ -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,12 +245,11 @@ 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
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
253
253
  .withField('date', DataType.DAY)
254
254
  .withField('price', DataType.DECIMAL)
255
255
  .withField('quantity', DataType.DECIMAL)
@@ -272,9 +272,9 @@ module.exports = (() => {
272
272
  .withField('portfolio', DataType.STRING)
273
273
  .withField('position', DataType.STRING)
274
274
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
275
- .withField('instrument.name', DataType.STRING, true)
276
- .withField('instrument.type', DataType.STRING, true)
277
- .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'))
278
278
  .withField('instrument.symbol.barchart', DataType.STRING, true)
279
279
  .withField('instrument.symbol.display', DataType.STRING, true)
280
280
  .withField('date', DataType.DAY)
@@ -388,8 +388,8 @@ module.exports = (() => {
388
388
  .withField('portfolio', DataType.STRING)
389
389
  .withField('position', DataType.STRING)
390
390
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
391
- .withField('instrument.type', DataType.STRING, true)
392
- .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
391
+ .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
392
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
393
393
  .withField('date', DataType.DAY)
394
394
  .withField('amount', DataType.DECIMAL)
395
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.75",
3
+ "version": "1.0.79",
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,9 +1196,12 @@ module.exports = (() => {
1184
1196
 
1185
1197
  format.market = formatCurrency(actual.market, currency);
1186
1198
  format.marketPercent = formatPercent(actual.marketPercent, 2);
1199
+ format.marketDirection = updates.marketDirection;
1187
1200
  format.unrealizedToday = formatCurrency(actual.unrealizedToday, currency);
1188
1201
  format.unrealizedTodayNegative = actual.unrealizedToday.getIsNegative();
1202
+ format.unrealizedTodayDirection = updates.unrealizedTodayDirection;
1189
1203
  format.total = formatCurrency(actual.total, currency);
1204
+ format.totalNegative = actual.total.getIsNegative();
1190
1205
  }
1191
1206
 
1192
1207
  return PositionGroup;