@barchart/portfolio-api-common 1.5.1 → 1.5.2

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.
@@ -0,0 +1,4 @@
1
+ **Technical Enhancements**
2
+
3
+ * Added a `transaction` field into `basicFormatter` function for the `TransactionFormatter` class.
4
+ * Changed the way to add and remove a portfolio in `PositionContainer` to support reactive changes.
@@ -127,6 +127,7 @@ module.exports = (() => {
127
127
  f.sequence = t.sequence;
128
128
  f.position = t.position;
129
129
  f.open = t.snapshot.open;
130
+ f.transaction = t.transaction;
130
131
  };
131
132
 
132
133
  const averageCostFormatter = (t, f) => {
@@ -234,7 +234,7 @@ module.exports = (() => {
234
234
  const key = portfolio.portfolio;
235
235
 
236
236
  if (!this._portfolios.hasOwnProperty(key)) {
237
- this._portfolios[key] = portfolio;
237
+ this._portfolios = Object.assign({}, this._portfolios, { [key]: portfolio });
238
238
 
239
239
  this._definitions.forEach((treeDefinition) => {
240
240
  const tree = this._trees[treeDefinition.name];
@@ -314,6 +314,8 @@ module.exports = (() => {
314
314
 
315
315
  delete this._portfolios[portfolio.portfolio];
316
316
 
317
+ this._portfolios = Object.assign({}, this._portfolios);
318
+
317
319
  Object.keys(this._trees).forEach((key) => {
318
320
  this._trees[key].walk((group, groupNode) => {
319
321
  if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "Common code used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1893,7 +1893,7 @@ module.exports = (() => {
1893
1893
  const key = portfolio.portfolio;
1894
1894
 
1895
1895
  if (!this._portfolios.hasOwnProperty(key)) {
1896
- this._portfolios[key] = portfolio;
1896
+ this._portfolios = Object.assign({}, this._portfolios, { [key]: portfolio });
1897
1897
 
1898
1898
  this._definitions.forEach((treeDefinition) => {
1899
1899
  const tree = this._trees[treeDefinition.name];
@@ -1973,6 +1973,8 @@ module.exports = (() => {
1973
1973
 
1974
1974
  delete this._portfolios[portfolio.portfolio];
1975
1975
 
1976
+ this._portfolios = Object.assign({}, this._portfolios);
1977
+
1976
1978
  Object.keys(this._trees).forEach((key) => {
1977
1979
  this._trees[key].walk((group, groupNode) => {
1978
1980
  if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio)) {
@@ -8202,8 +8204,11 @@ const moment = require('moment-timezone');
8202
8204
 
8203
8205
  module.exports = (() => {
8204
8206
  'use strict';
8207
+
8208
+ const MILLISECONDS_PER_SECOND = 1000;
8205
8209
  /**
8206
- * A data structure encapsulates (and lazy loads) a moment (see https://momentjs.com/).
8210
+ * An immutable data structure that encapsulates (and lazy loads)
8211
+ * a moment (see https://momentjs.com/).
8207
8212
  *
8208
8213
  * @public
8209
8214
  * @param {Number} timestamp
@@ -8219,7 +8224,7 @@ module.exports = (() => {
8219
8224
  this._moment = null;
8220
8225
  }
8221
8226
  /**
8222
- * The timestamp.
8227
+ * The timestamp (milliseconds since epoch).
8223
8228
  *
8224
8229
  * @public
8225
8230
  * @returns {Number}
@@ -8248,6 +8253,34 @@ module.exports = (() => {
8248
8253
 
8249
8254
  return this._moment;
8250
8255
  }
8256
+ /**
8257
+ * Returns a new {@link Timestamp} instance shifted forward (or backward)
8258
+ * by a specific number of seconds.
8259
+ *
8260
+ * @public
8261
+ * @param {Number} milliseconds
8262
+ * @returns {Timestamp}
8263
+ */
8264
+
8265
+
8266
+ add(milliseconds) {
8267
+ assert.argumentIsRequired(milliseconds, 'seconds', Number);
8268
+ return new Timestamp(this._timestamp + milliseconds, this._timezone);
8269
+ }
8270
+ /**
8271
+ * Returns a new {@link Timestamp} instance shifted forward (or backward)
8272
+ * by a specific number of seconds.
8273
+ *
8274
+ * @public
8275
+ * @param {Number} seconds
8276
+ * @returns {Timestamp}
8277
+ */
8278
+
8279
+
8280
+ addSeconds(seconds) {
8281
+ assert.argumentIsRequired(seconds, 'seconds', Number);
8282
+ return this.add(seconds * MILLISECONDS_PER_SECOND);
8283
+ }
8251
8284
  /**
8252
8285
  * Returns the JSON representation.
8253
8286
  *