@barchart/portfolio-api-common 1.4.3 → 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,3 @@
1
+ **New Features**
2
+
3
+ * Added new ```Schema``` for results of a query by symbol.
@@ -0,0 +1,3 @@
1
+ **Configuration Changes**
2
+
3
+ * The failure message for corrupt corporate actions (e.g. two instruments with same symbol) was updated to indicate an expected time to correction (of 24 to 48 hours).
@@ -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.
@@ -353,7 +353,7 @@ module.exports = (() => {
353
353
  const transactionCreateFailedTypeReserved = new FailureType('TRANSACTION_CREATE_FAILED_TYPE_RESERVED', 'Unable to create {U|type.description} transaction, this type of transaction is managed by the system.');
354
354
  const transactionCreateFailedReinvestPriceUnavailable = new FailureType('TRANSACTION_CREATE_FAILED_REINVEST_PRICE_UNAVAILABLE', 'Unable to create transaction, a dividend was paid on {L|day}; however no historical price is available for this day. To successfully create this transaction, please turn off dividend reinvestment for this position.');
355
355
  const transactionCreateFailedPositionLocked = new FailureType('TRANSACTION_CREATE_FAILED_POSITION_LOCKED', 'Unable to create transaction, your {L|description} history is being recalculated. Please re-enter this transaction in a minute or two.');
356
- const transactionCreateFailedInstrumentCorrupt = new FailureType('TRANSACTION_CREATE_FAILED_INSTRUMENT_CORRUPT', 'Unable to create transaction, corporate action history for {U|symbol} cannot be located.');
356
+ const transactionCreateFailedInstrumentCorrupt = new FailureType('TRANSACTION_CREATE_FAILED_INSTRUMENT_CORRUPT', 'Unable to create transaction, corporate action history for {U|symbol} cannot be located. The issue should be corrected within 24 to 48 hours.');
357
357
 
358
358
  const transactionDeleteFailedOutOfSequence = new FailureType('TRANSACTION_DELETE_FAILED_OUT_OF_SEQUENCE', 'Deleting any transaction, except for the most recent, will cause transaction history to be re-written. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
359
359
  const transactionDeleteFailedNoTransaction = new FailureType('TRANSACTION_DELETE_FAILED_NO_TRANSACTION', 'Unable to delete transaction. The referenced transaction does not exist.', false);
@@ -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)) {
@@ -40,14 +40,14 @@ module.exports = (() => {
40
40
 
41
41
  this._reporting = reporting;
42
42
 
43
- this._data = { };
44
-
45
- this._data.basis = null;
46
-
47
43
  this._currentQuote = null;
48
44
  this._previousQuote = null;
49
45
  this._currentPrice = null;
50
46
 
47
+ this._data = { };
48
+
49
+ this._data.basis = null;
50
+
51
51
  this._data.currentPrice = null;
52
52
  this._data.currentPricePrevious = null;
53
53
 
@@ -67,6 +67,17 @@ module.exports = (() => {
67
67
  return update;
68
68
  }
69
69
 
70
+ /**
71
+ * Result item for query of positions by symbol.
72
+ *
73
+ * @static
74
+ * @public
75
+ * @returns {PositionSchema}
76
+ */
77
+ static get SIMPLE() {
78
+ return simple;
79
+ }
80
+
70
81
  toString() {
71
82
  return '[PositionSchema]';
72
83
  }
@@ -102,8 +113,8 @@ module.exports = (() => {
102
113
  .withField('legacy.portfolio', DataType.STRING, true)
103
114
  .withField('legacy.position', DataType.STRING, true)
104
115
  .withField('system.version', DataType.NUMBER, true)
105
- .withField('system.locked', DataType.BOOLEAN, true)
106
116
  .withField('system.calculate.processors', DataType.NUMBER, true)
117
+ .withField('system.locked', DataType.BOOLEAN, true)
107
118
  .withField('root', DataType.STRING, true)
108
119
  .schema
109
120
  );
@@ -133,8 +144,8 @@ module.exports = (() => {
133
144
  .withField('snapshot.basis', DataType.DECIMAL)
134
145
  .withField('snapshot.income', DataType.DECIMAL)
135
146
  .withField('snapshot.value', DataType.DECIMAL)
136
- .withField('system.locked', DataType.BOOLEAN, true)
137
147
  .withField('system.calculate.processors', DataType.NUMBER, true)
148
+ .withField('system.locked', DataType.BOOLEAN, true)
138
149
  .withField('previous', DataType.NUMBER, true)
139
150
  .schema
140
151
  );
@@ -152,5 +163,17 @@ module.exports = (() => {
152
163
  .schema
153
164
  );
154
165
 
166
+ const simple = new PositionSchema(SchemaBuilder.withName('simple')
167
+ .withField('user', DataType.STRING)
168
+ .withField('portfolio', DataType.STRING)
169
+ .withField('instrument.id', DataType.STRING)
170
+ .withField('instrument.name', DataType.STRING)
171
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
172
+ .withField('instrument.symbol.display', DataType.STRING, true)
173
+ .withField('position', DataType.STRING)
174
+ .withField('open', DataType.BOOLEAN, true)
175
+ .schema
176
+ );
177
+
155
178
  return PositionSchema;
156
179
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.4.3",
3
+ "version": "1.5.2",
4
4
  "description": "Common code used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -272,7 +272,7 @@ module.exports = (() => {
272
272
  return InstrumentType;
273
273
  })();
274
274
 
275
- },{"@barchart/common-js/lang/Enum":24,"@barchart/common-js/lang/assert":29,"uuid":47}],2:[function(require,module,exports){
275
+ },{"@barchart/common-js/lang/Enum":26,"@barchart/common-js/lang/assert":31,"uuid":49}],2:[function(require,module,exports){
276
276
  const assert = require('@barchart/common-js/lang/assert'),
277
277
  Decimal = require('@barchart/common-js/lang/Decimal'),
278
278
  Enum = require('@barchart/common-js/lang/Enum');
@@ -406,7 +406,7 @@ module.exports = (() => {
406
406
  return PositionDirection;
407
407
  })();
408
408
 
409
- },{"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Enum":24,"@barchart/common-js/lang/assert":29}],3:[function(require,module,exports){
409
+ },{"@barchart/common-js/lang/Decimal":24,"@barchart/common-js/lang/Enum":26,"@barchart/common-js/lang/assert":31}],3:[function(require,module,exports){
410
410
  const array = require('@barchart/common-js/lang/array'),
411
411
  assert = require('@barchart/common-js/lang/assert'),
412
412
  Day = require('@barchart/common-js/lang/Day'),
@@ -754,7 +754,7 @@ module.exports = (() => {
754
754
  return PositionSummaryFrame;
755
755
  })();
756
756
 
757
- },{"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Enum":24,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29}],4:[function(require,module,exports){
757
+ },{"@barchart/common-js/lang/Day":23,"@barchart/common-js/lang/Decimal":24,"@barchart/common-js/lang/Enum":26,"@barchart/common-js/lang/array":30,"@barchart/common-js/lang/assert":31}],4:[function(require,module,exports){
758
758
  const assert = require('@barchart/common-js/lang/assert'),
759
759
  Enum = require('@barchart/common-js/lang/Enum');
760
760
 
@@ -1288,7 +1288,7 @@ module.exports = (() => {
1288
1288
  return TransactionType;
1289
1289
  })();
1290
1290
 
1291
- },{"@barchart/common-js/lang/Enum":24,"@barchart/common-js/lang/assert":29}],5:[function(require,module,exports){
1291
+ },{"@barchart/common-js/lang/Enum":26,"@barchart/common-js/lang/assert":31}],5:[function(require,module,exports){
1292
1292
  const assert = require('@barchart/common-js/lang/assert'),
1293
1293
  array = require('@barchart/common-js/lang/array'),
1294
1294
  is = require('@barchart/common-js/lang/is'),
@@ -1595,7 +1595,68 @@ module.exports = (() => {
1595
1595
  return TransactionValidator;
1596
1596
  })();
1597
1597
 
1598
- },{"./InstrumentType":1,"./PositionDirection":2,"./TransactionType":4,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29,"@barchart/common-js/lang/is":33}],6:[function(require,module,exports){
1598
+ },{"./InstrumentType":1,"./PositionDirection":2,"./TransactionType":4,"@barchart/common-js/lang/Day":23,"@barchart/common-js/lang/array":30,"@barchart/common-js/lang/assert":31,"@barchart/common-js/lang/is":35}],6:[function(require,module,exports){
1599
+ const Enum = require('@barchart/common-js/lang/Enum');
1600
+
1601
+ module.exports = (() => {
1602
+ 'use strict';
1603
+
1604
+ /**
1605
+ * An enumeration item that describes a strategy for calculating basis.
1606
+ *
1607
+ * @public
1608
+ * @extends {Enum}
1609
+ * @param {String} description
1610
+ * @param {String} code
1611
+ */
1612
+ class ValuationType extends Enum {
1613
+ constructor(code, description) {
1614
+ super(code, description);
1615
+ }
1616
+
1617
+ /**
1618
+ * Given a code, returns the enumeration item.
1619
+ *
1620
+ * @public
1621
+ * @param {String} code
1622
+ * @returns {ValuationType|null}
1623
+ */
1624
+ static parse(code) {
1625
+ return Enum.fromCode(ValuationType, code);
1626
+ }
1627
+
1628
+ /**
1629
+ * A valuation method that uses average costing.
1630
+ *
1631
+ * @public
1632
+ * @returns {ValuationType}
1633
+ */
1634
+ static get AVERAGE_COST() {
1635
+ return averageCost;
1636
+ }
1637
+
1638
+ /**
1639
+ * A valuation method that uses first-in, first-out methodology.
1640
+ *
1641
+ * @public
1642
+ * @returns {ValuationType}
1643
+ */
1644
+ static get FIFO() {
1645
+ return fifo;
1646
+ }
1647
+
1648
+ toString() {
1649
+ return `[ValuationType (code=${this.code})]`;
1650
+ }
1651
+ }
1652
+
1653
+ const fifo = new ValuationType('FIFO', 'first in, first out');
1654
+ const averageCost = new ValuationType('AVG', 'average cost');
1655
+
1656
+ return ValuationType;
1657
+ })();
1658
+
1659
+ },{"@barchart/common-js/lang/Enum":26}],7:[function(require,module,exports){
1599
1660
  const array = require('@barchart/common-js/lang/array'),
1600
1661
  assert = require('@barchart/common-js/lang/assert'),
1601
1662
  ComparatorBuilder = require('@barchart/common-js/collections/sorting/ComparatorBuilder'),
@@ -1832,7 +1893,7 @@ module.exports = (() => {
1832
1893
  const key = portfolio.portfolio;
1833
1894
 
1834
1895
  if (!this._portfolios.hasOwnProperty(key)) {
1835
- this._portfolios[key] = portfolio;
1896
+ this._portfolios = Object.assign({}, this._portfolios, { [key]: portfolio });
1836
1897
 
1837
1898
  this._definitions.forEach((treeDefinition) => {
1838
1899
  const tree = this._trees[treeDefinition.name];
@@ -1912,6 +1973,8 @@ module.exports = (() => {
1912
1973
 
1913
1974
  delete this._portfolios[portfolio.portfolio];
1914
1975
 
1976
+ this._portfolios = Object.assign({}, this._portfolios);
1977
+
1915
1978
  Object.keys(this._trees).forEach((key) => {
1916
1979
  this._trees[key].walk((group, groupNode) => {
1917
1980
  if (group.definition.type === PositionLevelType.PORTFOLIO && group.key === PositionLevelDefinition.getKeyForPortfolioGroup(portfolio)) {
@@ -2732,7 +2795,7 @@ module.exports = (() => {
2732
2795
  return PositionContainer;
2733
2796
  })();
2734
2797
 
2735
- },{"./../data/PositionSummaryFrame":3,"./PositionGroup":7,"./PositionItem":8,"./definitions/PositionLevelDefinition":9,"./definitions/PositionLevelType":10,"./definitions/PositionTreeDefinition":11,"@barchart/common-js/collections/Tree":15,"@barchart/common-js/collections/sorting/ComparatorBuilder":16,"@barchart/common-js/collections/sorting/comparators":17,"@barchart/common-js/collections/specialized/DisposableStack":18,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Rate":26,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29,"@barchart/common-js/lang/is":33,"@barchart/common-js/messaging/Event":35}],7:[function(require,module,exports){
2798
+ },{"./../data/PositionSummaryFrame":3,"./PositionGroup":8,"./PositionItem":9,"./definitions/PositionLevelDefinition":10,"./definitions/PositionLevelType":11,"./definitions/PositionTreeDefinition":12,"@barchart/common-js/collections/Tree":17,"@barchart/common-js/collections/sorting/ComparatorBuilder":18,"@barchart/common-js/collections/sorting/comparators":19,"@barchart/common-js/collections/specialized/DisposableStack":20,"@barchart/common-js/lang/Currency":22,"@barchart/common-js/lang/Day":23,"@barchart/common-js/lang/Decimal":24,"@barchart/common-js/lang/Rate":28,"@barchart/common-js/lang/array":30,"@barchart/common-js/lang/assert":31,"@barchart/common-js/lang/is":35,"@barchart/common-js/messaging/Event":37}],8:[function(require,module,exports){
2736
2799
  const array = require('@barchart/common-js/lang/array'),
2737
2800
  assert = require('@barchart/common-js/lang/assert'),
2738
2801
  Currency = require('@barchart/common-js/lang/Currency'),
@@ -3761,7 +3824,7 @@ module.exports = (() => {
3761
3824
  return PositionGroup;
3762
3825
  })();
3763
3826
 
3764
- },{"./../data/InstrumentType":1,"./definitions/PositionLevelDefinition":9,"./definitions/PositionLevelType":10,"@barchart/common-js/collections/specialized/DisposableStack":18,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Disposable":23,"@barchart/common-js/lang/Rate":26,"@barchart/common-js/lang/array":28,"@barchart/common-js/lang/assert":29,"@barchart/common-js/lang/formatter":31,"@barchart/common-js/lang/is":33,"@barchart/common-js/messaging/Event":35}],8:[function(require,module,exports){
3827
+ },{"./../data/InstrumentType":1,"./definitions/PositionLevelDefinition":10,"./definitions/PositionLevelType":11,"@barchart/common-js/collections/specialized/DisposableStack":20,"@barchart/common-js/lang/Currency":22,"@barchart/common-js/lang/Decimal":24,"@barchart/common-js/lang/Disposable":25,"@barchart/common-js/lang/Rate":28,"@barchart/common-js/lang/array":30,"@barchart/common-js/lang/assert":31,"@barchart/common-js/lang/formatter":33,"@barchart/common-js/lang/is":35,"@barchart/common-js/messaging/Event":37}],9:[function(require,module,exports){
3765
3828
  const assert = require('@barchart/common-js/lang/assert'),
3766
3829
  Currency = require('@barchart/common-js/lang/Currency'),
3767
3830
  Decimal = require('@barchart/common-js/lang/Decimal'),
@@ -3804,14 +3867,14 @@ module.exports = (() => {
3804
3867
 
3805
3868
  this._reporting = reporting;
3806
3869
 
3807
- this._data = { };
3808
-
3809
- this._data.basis = null;
3810
-
3811
3870
  this._currentQuote = null;
3812
3871
  this._previousQuote = null;
3813
3872
  this._currentPrice = null;
3814
3873
 
3874
+ this._data = { };
3875
+
3876
+ this._data.basis = null;
3877
+
3815
3878
  this._data.currentPrice = null;
3816
3879
  this._data.currentPricePrevious = null;
3817
3880
 
@@ -4546,7 +4609,7 @@ module.exports = (() => {
4546
4609
  return PositionItem;
4547
4610
  })();
4548
4611
 
4549
- },{"./../data/InstrumentType":1,"./../data/PositionDirection":2,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Decimal":22,"@barchart/common-js/lang/Disposable":23,"@barchart/common-js/lang/assert":29,"@barchart/common-js/lang/is":33,"@barchart/common-js/messaging/Event":35}],9:[function(require,module,exports){
4612
+ },{"./../data/InstrumentType":1,"./../data/PositionDirection":2,"@barchart/common-js/lang/Currency":22,"@barchart/common-js/lang/Decimal":24,"@barchart/common-js/lang/Disposable":25,"@barchart/common-js/lang/assert":31,"@barchart/common-js/lang/is":35,"@barchart/common-js/messaging/Event":37}],10:[function(require,module,exports){
4550
4613
  const assert = require('@barchart/common-js/lang/assert'),
4551
4614
  Currency = require('@barchart/common-js/lang/Currency'),
4552
4615
  is = require('@barchart/common-js/lang/is');
@@ -4830,7 +4893,7 @@ module.exports = (() => {
4830
4893
  return PositionLevelDefinition;
4831
4894
  })();
4832
4895
 
4833
- },{"./../../data/InstrumentType":1,"./PositionLevelType":10,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/assert":29,"@barchart/common-js/lang/is":33}],10:[function(require,module,exports){
4896
+ },{"./../../data/InstrumentType":1,"./PositionLevelType":11,"@barchart/common-js/lang/Currency":22,"@barchart/common-js/lang/assert":31,"@barchart/common-js/lang/is":35}],11:[function(require,module,exports){
4834
4897
  const Enum = require('@barchart/common-js/lang/Enum');
4835
4898
 
4836
4899
  module.exports = (() => {
@@ -4891,7 +4954,7 @@ module.exports = (() => {
4891
4954
  return PositionLevelType;
4892
4955
  })();
4893
4956
 
4894
- },{"@barchart/common-js/lang/Enum":24}],11:[function(require,module,exports){
4957
+ },{"@barchart/common-js/lang/Enum":26}],12:[function(require,module,exports){
4895
4958
  const assert = require('@barchart/common-js/lang/assert');
4896
4959
 
4897
4960
  const PositionLevelDefinition = require('./PositionLevelDefinition');
@@ -4963,7 +5026,188 @@ module.exports = (() => {
4963
5026
  return PositionTreeDefinitions;
4964
5027
  })();
4965
5028
 
4966
- },{"./PositionLevelDefinition":9,"@barchart/common-js/lang/assert":29}],12:[function(require,module,exports){
5029
+ },{"./PositionLevelDefinition":10,"@barchart/common-js/lang/assert":31}],13:[function(require,module,exports){
5030
+ const Currency = require('@barchart/common-js/lang/Currency'),
5031
+ DataType = require('@barchart/common-js/serialization/json/DataType'),
5032
+ Enum = require('@barchart/common-js/lang/Enum'),
5033
+ Schema = require('@barchart/common-js/serialization/json/Schema'),
5034
+ SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
5035
+
5036
+ const InstrumentType = require('./../data/InstrumentType'),
5037
+ PositionDirection = require('./../data/PositionDirection'),
5038
+ ValuationType = require('./../data/ValuationType');
5039
+
5040
+ module.exports = (() => {
5041
+ 'use strict';
5042
+
5043
+ /**
5044
+ * The schemas which can be used to represent position objects.
5045
+ *
5046
+ * @public
5047
+ * @extends {Enum}
5048
+ */
5049
+ class PositionSchema extends Enum {
5050
+ constructor(schema) {
5051
+ super(schema.name, schema.name);
5052
+
5053
+ this._schema = schema;
5054
+ }
5055
+
5056
+ /**
5057
+ * The actual {@link Schema}.
5058
+ *
5059
+ * @public
5060
+ * @returns {Schema}
5061
+ */
5062
+ get schema() {
5063
+ return this._schema;
5064
+ }
5065
+
5066
+ /**
5067
+ * The complete position schema.
5068
+ *
5069
+ * @static
5070
+ * @public
5071
+ * @returns {PositionSchema}
5072
+ */
5073
+ static get COMPLETE() {
5074
+ return complete;
5075
+ }
5076
+
5077
+ /**
5078
+ * Position data transmitted to the client, omitting some system data.
5079
+ *
5080
+ * @static
5081
+ * @public
5082
+ * @returns {PositionSchema}
5083
+ */
5084
+ static get CLIENT() {
5085
+ return client;
5086
+ }
5087
+
5088
+ /**
5089
+ * Data required to update a position.
5090
+ *
5091
+ * @static
5092
+ * @public
5093
+ * @returns {PositionSchema}
5094
+ */
5095
+ static get UPDATE() {
5096
+ return update;
5097
+ }
5098
+
5099
+ /**
5100
+ * Result item for query of positions by symbol.
5101
+ *
5102
+ * @static
5103
+ * @public
5104
+ * @returns {PositionSchema}
5105
+ */
5106
+ static get SIMPLE() {
5107
+ return simple;
5108
+ }
5109
+
5110
+ toString() {
5111
+ return '[PositionSchema]';
5112
+ }
5113
+ }
5114
+
5115
+ const complete = new PositionSchema(SchemaBuilder.withName('complete')
5116
+ .withField('user', DataType.STRING)
5117
+ .withField('portfolio', DataType.STRING)
5118
+ .withField('instrument.id', DataType.STRING)
5119
+ .withField('instrument.name', DataType.STRING)
5120
+ .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
5121
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
5122
+ .withField('instrument.delist', DataType.DAY, true)
5123
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
5124
+ .withField('instrument.symbol.display', DataType.STRING, true)
5125
+ .withField('position', DataType.STRING)
5126
+ .withField('open', DataType.BOOLEAN, true)
5127
+ .withField('transaction', DataType.NUMBER)
5128
+ .withField('cash', DataType.BOOLEAN, true)
5129
+ .withField('reinvest', DataType.BOOLEAN, true)
5130
+ .withField('valuation', DataType.forEnum(ValuationType, 'ValuationType'))
5131
+ .withField('snapshot.date', DataType.DAY)
5132
+ .withField('snapshot.open', DataType.DECIMAL)
5133
+ .withField('snapshot.direction', DataType.forEnum(PositionDirection, 'PositionDirection'))
5134
+ .withField('snapshot.buys', DataType.DECIMAL)
5135
+ .withField('snapshot.sells', DataType.DECIMAL)
5136
+ .withField('snapshot.gain', DataType.DECIMAL)
5137
+ .withField('snapshot.basis', DataType.DECIMAL)
5138
+ .withField('snapshot.income', DataType.DECIMAL)
5139
+ .withField('snapshot.value', DataType.DECIMAL)
5140
+ .withField('legacy.system', DataType.STRING, true)
5141
+ .withField('legacy.user', DataType.STRING, true)
5142
+ .withField('legacy.portfolio', DataType.STRING, true)
5143
+ .withField('legacy.position', DataType.STRING, true)
5144
+ .withField('system.version', DataType.NUMBER, true)
5145
+ .withField('system.calculate.processors', DataType.NUMBER, true)
5146
+ .withField('system.locked', DataType.BOOLEAN, true)
5147
+ .withField('root', DataType.STRING, true)
5148
+ .schema
5149
+ );
5150
+
5151
+ const client = new PositionSchema(SchemaBuilder.withName('client')
5152
+ .withField('user', DataType.STRING)
5153
+ .withField('portfolio', DataType.STRING)
5154
+ .withField('instrument.id', DataType.STRING)
5155
+ .withField('instrument.name', DataType.STRING)
5156
+ .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
5157
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
5158
+ .withField('instrument.delist', DataType.DAY, true)
5159
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
5160
+ .withField('instrument.symbol.display', DataType.STRING, true)
5161
+ .withField('position', DataType.STRING)
5162
+ .withField('open', DataType.BOOLEAN, true)
5163
+ .withField('transaction', DataType.NUMBER)
5164
+ .withField('cash', DataType.BOOLEAN, true)
5165
+ .withField('reinvest', DataType.BOOLEAN, true)
5166
+ .withField('valuation', DataType.forEnum(ValuationType, 'ValuationType'))
5167
+ .withField('snapshot.date', DataType.DAY)
5168
+ .withField('snapshot.open', DataType.DECIMAL)
5169
+ .withField('snapshot.direction', DataType.forEnum(PositionDirection, 'PositionDirection'))
5170
+ .withField('snapshot.buys', DataType.DECIMAL)
5171
+ .withField('snapshot.sells', DataType.DECIMAL)
5172
+ .withField('snapshot.gain', DataType.DECIMAL)
5173
+ .withField('snapshot.basis', DataType.DECIMAL)
5174
+ .withField('snapshot.income', DataType.DECIMAL)
5175
+ .withField('snapshot.value', DataType.DECIMAL)
5176
+ .withField('system.calculate.processors', DataType.NUMBER, true)
5177
+ .withField('system.locked', DataType.BOOLEAN, true)
5178
+ .withField('previous', DataType.NUMBER, true)
5179
+ .schema
5180
+ );
5181
+
5182
+ const update = new PositionSchema(SchemaBuilder.withName('update')
5183
+ .withField('portfolio', DataType.STRING)
5184
+ .withField('position', DataType.STRING)
5185
+ .withField('mapping.name', DataType.STRING, true)
5186
+ .withField('mapping.type', DataType.forEnum(InstrumentType, 'InstrumentType'), true)
5187
+ .withField('mapping.currency', DataType.forEnum(Currency, 'Currency'), true)
5188
+ .withField('mapping.symbol.barchart', DataType.STRING, true)
5189
+ .withField('mapping.symbol.display', DataType.STRING, true)
5190
+ .withField('cash', DataType.BOOLEAN, true)
5191
+ .withField('reinvest', DataType.BOOLEAN, true)
5192
+ .schema
5193
+ );
5194
+
5195
+ const simple = new PositionSchema(SchemaBuilder.withName('simple')
5196
+ .withField('user', DataType.STRING)
5197
+ .withField('portfolio', DataType.STRING)
5198
+ .withField('instrument.id', DataType.STRING)
5199
+ .withField('instrument.name', DataType.STRING)
5200
+ .withField('instrument.symbol.barchart', DataType.STRING, true)
5201
+ .withField('instrument.symbol.display', DataType.STRING, true)
5202
+ .withField('position', DataType.STRING)
5203
+ .withField('open', DataType.BOOLEAN, true)
5204
+ .schema
5205
+ );
5206
+
5207
+ return PositionSchema;
5208
+ })();
5209
+
5210
+ },{"./../data/InstrumentType":1,"./../data/PositionDirection":2,"./../data/ValuationType":6,"@barchart/common-js/lang/Currency":22,"@barchart/common-js/lang/Enum":26,"@barchart/common-js/serialization/json/DataType":39,"@barchart/common-js/serialization/json/Schema":41,"@barchart/common-js/serialization/json/builders/SchemaBuilder":43}],14:[function(require,module,exports){
4967
5211
  const is = require('@barchart/common-js/lang/is'),
4968
5212
  Currency = require('@barchart/common-js/lang/Currency'),
4969
5213
  DataType = require('@barchart/common-js/serialization/json/DataType'),
@@ -5345,7 +5589,7 @@ module.exports = (() => {
5345
5589
  return TransactionSchema;
5346
5590
  })();
5347
5591
 
5348
- },{"./../data/InstrumentType":1,"./../data/PositionDirection":2,"./../data/TransactionType":4,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Enum":24,"@barchart/common-js/lang/is":33,"@barchart/common-js/serialization/json/DataType":37,"@barchart/common-js/serialization/json/Schema":39,"@barchart/common-js/serialization/json/builders/SchemaBuilder":41}],13:[function(require,module,exports){
5592
+ },{"./../data/InstrumentType":1,"./../data/PositionDirection":2,"./../data/TransactionType":4,"@barchart/common-js/lang/Currency":22,"@barchart/common-js/lang/Enum":26,"@barchart/common-js/lang/is":35,"@barchart/common-js/serialization/json/DataType":39,"@barchart/common-js/serialization/json/Schema":41,"@barchart/common-js/serialization/json/builders/SchemaBuilder":43}],15:[function(require,module,exports){
5349
5593
  module.exports = (() => {
5350
5594
  'use strict';
5351
5595
  /**
@@ -5424,7 +5668,7 @@ module.exports = (() => {
5424
5668
  return LinkedList;
5425
5669
  })();
5426
5670
 
5427
- },{}],14:[function(require,module,exports){
5671
+ },{}],16:[function(require,module,exports){
5428
5672
  const assert = require('./../lang/assert');
5429
5673
 
5430
5674
  module.exports = (() => {
@@ -5529,7 +5773,7 @@ module.exports = (() => {
5529
5773
  return Stack;
5530
5774
  })();
5531
5775
 
5532
- },{"./../lang/assert":29}],15:[function(require,module,exports){
5776
+ },{"./../lang/assert":31}],17:[function(require,module,exports){
5533
5777
  const is = require('./../lang/is');
5534
5778
 
5535
5779
  module.exports = (() => {
@@ -5847,7 +6091,7 @@ module.exports = (() => {
5847
6091
  return Tree;
5848
6092
  })();
5849
6093
 
5850
- },{"./../lang/is":33}],16:[function(require,module,exports){
6094
+ },{"./../lang/is":35}],18:[function(require,module,exports){
5851
6095
  const assert = require('./../../lang/assert'),
5852
6096
  comparators = require('./comparators');
5853
6097
 
@@ -5966,7 +6210,7 @@ module.exports = (() => {
5966
6210
  return ComparatorBuilder;
5967
6211
  })();
5968
6212
 
5969
- },{"./../../lang/assert":29,"./comparators":17}],17:[function(require,module,exports){
6213
+ },{"./../../lang/assert":31,"./comparators":19}],19:[function(require,module,exports){
5970
6214
  const assert = require('./../../lang/assert');
5971
6215
 
5972
6216
  module.exports = (() => {
@@ -6056,7 +6300,7 @@ module.exports = (() => {
6056
6300
  };
6057
6301
  })();
6058
6302
 
6059
- },{"./../../lang/assert":29}],18:[function(require,module,exports){
6303
+ },{"./../../lang/assert":31}],20:[function(require,module,exports){
6060
6304
  const Stack = require('./../Stack');
6061
6305
 
6062
6306
  const assert = require('./../../lang/assert'),
@@ -6135,7 +6379,7 @@ module.exports = (() => {
6135
6379
  return DisposableStack;
6136
6380
  })();
6137
6381
 
6138
- },{"./../../lang/Disposable":23,"./../../lang/assert":29,"./../../lang/is":33,"./../Stack":14}],19:[function(require,module,exports){
6382
+ },{"./../../lang/Disposable":25,"./../../lang/assert":31,"./../../lang/is":35,"./../Stack":16}],21:[function(require,module,exports){
6139
6383
  const assert = require('./assert');
6140
6384
 
6141
6385
  module.exports = (() => {
@@ -6201,7 +6445,7 @@ module.exports = (() => {
6201
6445
  return AdHoc;
6202
6446
  })();
6203
6447
 
6204
- },{"./assert":29}],20:[function(require,module,exports){
6448
+ },{"./assert":31}],22:[function(require,module,exports){
6205
6449
  const assert = require('./assert'),
6206
6450
  Enum = require('./Enum'),
6207
6451
  is = require('./is');
@@ -6307,7 +6551,7 @@ module.exports = (() => {
6307
6551
  return Currency;
6308
6552
  })();
6309
6553
 
6310
- },{"./Enum":24,"./assert":29,"./is":33}],21:[function(require,module,exports){
6554
+ },{"./Enum":26,"./assert":31,"./is":35}],23:[function(require,module,exports){
6311
6555
  const assert = require('./assert'),
6312
6556
  ComparatorBuilder = require('./../collections/sorting/ComparatorBuilder'),
6313
6557
  comparators = require('./../collections/sorting/comparators'),
@@ -6826,7 +7070,7 @@ module.exports = (() => {
6826
7070
  return Day;
6827
7071
  })();
6828
7072
 
6829
- },{"./../collections/sorting/ComparatorBuilder":16,"./../collections/sorting/comparators":17,"./assert":29,"./is":33}],22:[function(require,module,exports){
7073
+ },{"./../collections/sorting/ComparatorBuilder":18,"./../collections/sorting/comparators":19,"./assert":31,"./is":35}],24:[function(require,module,exports){
6830
7074
  const assert = require('./assert'),
6831
7075
  Enum = require('./Enum'),
6832
7076
  is = require('./is');
@@ -7408,7 +7652,7 @@ module.exports = (() => {
7408
7652
  return Decimal;
7409
7653
  })();
7410
7654
 
7411
- },{"./Enum":24,"./assert":29,"./is":33,"big.js":42}],23:[function(require,module,exports){
7655
+ },{"./Enum":26,"./assert":31,"./is":35,"big.js":44}],25:[function(require,module,exports){
7412
7656
  const assert = require('./assert');
7413
7657
 
7414
7658
  module.exports = (() => {
@@ -7519,7 +7763,7 @@ module.exports = (() => {
7519
7763
  return Disposable;
7520
7764
  })();
7521
7765
 
7522
- },{"./assert":29}],24:[function(require,module,exports){
7766
+ },{"./assert":31}],26:[function(require,module,exports){
7523
7767
  const assert = require('./assert');
7524
7768
 
7525
7769
  module.exports = (() => {
@@ -7639,7 +7883,7 @@ module.exports = (() => {
7639
7883
  return Enum;
7640
7884
  })();
7641
7885
 
7642
- },{"./assert":29}],25:[function(require,module,exports){
7886
+ },{"./assert":31}],27:[function(require,module,exports){
7643
7887
  const assert = require('./assert'),
7644
7888
  is = require('./is');
7645
7889
 
@@ -7740,7 +7984,7 @@ module.exports = (() => {
7740
7984
  return Money;
7741
7985
  })();
7742
7986
 
7743
- },{"./Currency":20,"./Decimal":22,"./assert":29,"./is":33}],26:[function(require,module,exports){
7987
+ },{"./Currency":22,"./Decimal":24,"./assert":31,"./is":35}],28:[function(require,module,exports){
7744
7988
  const assert = require('./assert'),
7745
7989
  memoize = require('./memoize');
7746
7990
 
@@ -7952,7 +8196,7 @@ module.exports = (() => {
7952
8196
  return Rate;
7953
8197
  })();
7954
8198
 
7955
- },{"./Currency":20,"./Decimal":22,"./assert":29,"./memoize":34}],27:[function(require,module,exports){
8199
+ },{"./Currency":22,"./Decimal":24,"./assert":31,"./memoize":36}],29:[function(require,module,exports){
7956
8200
  const assert = require('./assert'),
7957
8201
  is = require('./is');
7958
8202
 
@@ -7960,8 +8204,11 @@ const moment = require('moment-timezone');
7960
8204
 
7961
8205
  module.exports = (() => {
7962
8206
  'use strict';
8207
+
8208
+ const MILLISECONDS_PER_SECOND = 1000;
7963
8209
  /**
7964
- * 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/).
7965
8212
  *
7966
8213
  * @public
7967
8214
  * @param {Number} timestamp
@@ -7977,7 +8224,7 @@ module.exports = (() => {
7977
8224
  this._moment = null;
7978
8225
  }
7979
8226
  /**
7980
- * The timestamp.
8227
+ * The timestamp (milliseconds since epoch).
7981
8228
  *
7982
8229
  * @public
7983
8230
  * @returns {Number}
@@ -8006,6 +8253,34 @@ module.exports = (() => {
8006
8253
 
8007
8254
  return this._moment;
8008
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
+ }
8009
8284
  /**
8010
8285
  * Returns the JSON representation.
8011
8286
  *
@@ -8064,7 +8339,7 @@ module.exports = (() => {
8064
8339
  return Timestamp;
8065
8340
  })();
8066
8341
 
8067
- },{"./assert":29,"./is":33,"moment-timezone":44}],28:[function(require,module,exports){
8342
+ },{"./assert":31,"./is":35,"moment-timezone":46}],30:[function(require,module,exports){
8068
8343
  const assert = require('./assert'),
8069
8344
  is = require('./is');
8070
8345
 
@@ -8519,7 +8794,7 @@ module.exports = (() => {
8519
8794
  }
8520
8795
  })();
8521
8796
 
8522
- },{"./assert":29,"./is":33}],29:[function(require,module,exports){
8797
+ },{"./assert":31,"./is":35}],31:[function(require,module,exports){
8523
8798
  const is = require('./is');
8524
8799
 
8525
8800
  module.exports = (() => {
@@ -8664,7 +8939,7 @@ module.exports = (() => {
8664
8939
  };
8665
8940
  })();
8666
8941
 
8667
- },{"./is":33}],30:[function(require,module,exports){
8942
+ },{"./is":35}],32:[function(require,module,exports){
8668
8943
  const assert = require('./assert'),
8669
8944
  is = require('./is');
8670
8945
 
@@ -8827,7 +9102,7 @@ module.exports = (() => {
8827
9102
  };
8828
9103
  })();
8829
9104
 
8830
- },{"./assert":29,"./is":33}],31:[function(require,module,exports){
9105
+ },{"./assert":31,"./is":35}],33:[function(require,module,exports){
8831
9106
  module.exports = (() => {
8832
9107
  'use strict';
8833
9108
 
@@ -8887,7 +9162,7 @@ module.exports = (() => {
8887
9162
  };
8888
9163
  })();
8889
9164
 
8890
- },{}],32:[function(require,module,exports){
9165
+ },{}],34:[function(require,module,exports){
8891
9166
  module.exports = (() => {
8892
9167
  'use strict';
8893
9168
 
@@ -8930,7 +9205,7 @@ module.exports = (() => {
8930
9205
  };
8931
9206
  })();
8932
9207
 
8933
- },{}],33:[function(require,module,exports){
9208
+ },{}],35:[function(require,module,exports){
8934
9209
  module.exports = (() => {
8935
9210
  'use strict';
8936
9211
  /**
@@ -9149,7 +9424,7 @@ module.exports = (() => {
9149
9424
  };
9150
9425
  })();
9151
9426
 
9152
- },{}],34:[function(require,module,exports){
9427
+ },{}],36:[function(require,module,exports){
9153
9428
  const assert = require('./assert');
9154
9429
 
9155
9430
  module.exports = (() => {
@@ -9213,7 +9488,7 @@ module.exports = (() => {
9213
9488
  };
9214
9489
  })();
9215
9490
 
9216
- },{"./assert":29}],35:[function(require,module,exports){
9491
+ },{"./assert":31}],37:[function(require,module,exports){
9217
9492
  const assert = require('./../lang/assert'),
9218
9493
  Disposable = require('./../lang/Disposable');
9219
9494
 
@@ -9345,7 +9620,7 @@ module.exports = (() => {
9345
9620
  return Event;
9346
9621
  })();
9347
9622
 
9348
- },{"./../lang/Disposable":23,"./../lang/assert":29}],36:[function(require,module,exports){
9623
+ },{"./../lang/Disposable":25,"./../lang/assert":31}],38:[function(require,module,exports){
9349
9624
  const Currency = require('./../../lang/Currency'),
9350
9625
  Money = require('./../../lang/Money');
9351
9626
 
@@ -9421,7 +9696,7 @@ module.exports = (() => {
9421
9696
  return Component;
9422
9697
  })();
9423
9698
 
9424
- },{"./../../lang/Currency":20,"./../../lang/Money":25,"./DataType":37,"./Field":38}],37:[function(require,module,exports){
9699
+ },{"./../../lang/Currency":22,"./../../lang/Money":27,"./DataType":39,"./Field":40}],39:[function(require,module,exports){
9425
9700
  const moment = require('moment');
9426
9701
 
9427
9702
  const AdHoc = require('./../../lang/AdHoc'),
@@ -9737,7 +10012,7 @@ module.exports = (() => {
9737
10012
  return DataType;
9738
10013
  })();
9739
10014
 
9740
- },{"./../../lang/AdHoc":19,"./../../lang/Day":21,"./../../lang/Decimal":22,"./../../lang/Enum":24,"./../../lang/Timestamp":27,"./../../lang/assert":29,"./../../lang/is":33,"moment":46}],38:[function(require,module,exports){
10015
+ },{"./../../lang/AdHoc":21,"./../../lang/Day":23,"./../../lang/Decimal":24,"./../../lang/Enum":26,"./../../lang/Timestamp":29,"./../../lang/assert":31,"./../../lang/is":35,"moment":48}],40:[function(require,module,exports){
9741
10016
  module.exports = (() => {
9742
10017
  'use strict';
9743
10018
  /**
@@ -9798,7 +10073,7 @@ module.exports = (() => {
9798
10073
  return Field;
9799
10074
  })();
9800
10075
 
9801
- },{}],39:[function(require,module,exports){
10076
+ },{}],41:[function(require,module,exports){
9802
10077
  const attributes = require('./../../lang/attributes'),
9803
10078
  functions = require('./../../lang/functions'),
9804
10079
  is = require('./../../lang/is');
@@ -10121,7 +10396,7 @@ module.exports = (() => {
10121
10396
  return Schema;
10122
10397
  })();
10123
10398
 
10124
- },{"./../../collections/LinkedList":13,"./../../collections/Tree":15,"./../../lang/attributes":30,"./../../lang/functions":32,"./../../lang/is":33,"./Component":36,"./Field":38}],40:[function(require,module,exports){
10399
+ },{"./../../collections/LinkedList":15,"./../../collections/Tree":17,"./../../lang/attributes":32,"./../../lang/functions":34,"./../../lang/is":35,"./Component":38,"./Field":40}],42:[function(require,module,exports){
10125
10400
  const assert = require('./../../../lang/assert');
10126
10401
 
10127
10402
  const Component = require('./../Component'),
@@ -10196,7 +10471,7 @@ module.exports = (() => {
10196
10471
  return ComponentBuilder;
10197
10472
  })();
10198
10473
 
10199
- },{"./../../../lang/assert":29,"./../Component":36,"./../DataType":37,"./../Field":38}],41:[function(require,module,exports){
10474
+ },{"./../../../lang/assert":31,"./../Component":38,"./../DataType":39,"./../Field":40}],43:[function(require,module,exports){
10200
10475
  const assert = require('./../../../lang/assert'),
10201
10476
  is = require('./../../../lang/is');
10202
10477
 
@@ -10310,7 +10585,7 @@ module.exports = (() => {
10310
10585
  return SchemaBuilder;
10311
10586
  })();
10312
10587
 
10313
- },{"./../../../lang/assert":29,"./../../../lang/is":33,"./../Component":36,"./../DataType":37,"./../Field":38,"./../Schema":39,"./ComponentBuilder":40}],42:[function(require,module,exports){
10588
+ },{"./../../../lang/assert":31,"./../../../lang/is":35,"./../Component":38,"./../DataType":39,"./../Field":40,"./../Schema":41,"./ComponentBuilder":42}],44:[function(require,module,exports){
10314
10589
  /*
10315
10590
  * big.js v5.2.2
10316
10591
  * A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
@@ -11253,7 +11528,7 @@ module.exports = (() => {
11253
11528
  }
11254
11529
  })(this);
11255
11530
 
11256
- },{}],43:[function(require,module,exports){
11531
+ },{}],45:[function(require,module,exports){
11257
11532
  module.exports={
11258
11533
  "version": "2019b",
11259
11534
  "zones": [
@@ -11854,11 +12129,11 @@ module.exports={
11854
12129
  "Pacific/Tarawa|Pacific/Wallis"
11855
12130
  ]
11856
12131
  }
11857
- },{}],44:[function(require,module,exports){
12132
+ },{}],46:[function(require,module,exports){
11858
12133
  var moment = module.exports = require("./moment-timezone");
11859
12134
  moment.tz.load(require('./data/packed/latest.json'));
11860
12135
 
11861
- },{"./data/packed/latest.json":43,"./moment-timezone":45}],45:[function(require,module,exports){
12136
+ },{"./data/packed/latest.json":45,"./moment-timezone":47}],47:[function(require,module,exports){
11862
12137
  //! moment-timezone.js
11863
12138
  //! version : 0.5.26
11864
12139
  //! Copyright (c) JS Foundation and other contributors
@@ -12487,7 +12762,7 @@ moment.tz.load(require('./data/packed/latest.json'));
12487
12762
  return moment;
12488
12763
  }));
12489
12764
 
12490
- },{"moment":46}],46:[function(require,module,exports){
12765
+ },{"moment":48}],48:[function(require,module,exports){
12491
12766
  //! moment.js
12492
12767
 
12493
12768
  ;(function (global, factory) {
@@ -17091,7 +17366,7 @@ moment.tz.load(require('./data/packed/latest.json'));
17091
17366
 
17092
17367
  })));
17093
17368
 
17094
- },{}],47:[function(require,module,exports){
17369
+ },{}],49:[function(require,module,exports){
17095
17370
  var v1 = require('./v1');
17096
17371
  var v4 = require('./v4');
17097
17372
 
@@ -17101,7 +17376,7 @@ uuid.v4 = v4;
17101
17376
 
17102
17377
  module.exports = uuid;
17103
17378
 
17104
- },{"./v1":50,"./v4":51}],48:[function(require,module,exports){
17379
+ },{"./v1":52,"./v4":53}],50:[function(require,module,exports){
17105
17380
  /**
17106
17381
  * Convert array of 16 byte values to UUID string format of the form:
17107
17382
  * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
@@ -17129,7 +17404,7 @@ function bytesToUuid(buf, offset) {
17129
17404
 
17130
17405
  module.exports = bytesToUuid;
17131
17406
 
17132
- },{}],49:[function(require,module,exports){
17407
+ },{}],51:[function(require,module,exports){
17133
17408
  // Unique ID creation requires a high quality random # generator. In the
17134
17409
  // browser this is a little complicated due to unknown quality of Math.random()
17135
17410
  // and inconsistent support for the `crypto` API. We do the best we can via
@@ -17165,7 +17440,7 @@ if (getRandomValues) {
17165
17440
  };
17166
17441
  }
17167
17442
 
17168
- },{}],50:[function(require,module,exports){
17443
+ },{}],52:[function(require,module,exports){
17169
17444
  var rng = require('./lib/rng');
17170
17445
  var bytesToUuid = require('./lib/bytesToUuid');
17171
17446
 
@@ -17276,7 +17551,7 @@ function v1(options, buf, offset) {
17276
17551
 
17277
17552
  module.exports = v1;
17278
17553
 
17279
- },{"./lib/bytesToUuid":48,"./lib/rng":49}],51:[function(require,module,exports){
17554
+ },{"./lib/bytesToUuid":50,"./lib/rng":51}],53:[function(require,module,exports){
17280
17555
  var rng = require('./lib/rng');
17281
17556
  var bytesToUuid = require('./lib/bytesToUuid');
17282
17557
 
@@ -17307,7 +17582,7 @@ function v4(options, buf, offset) {
17307
17582
 
17308
17583
  module.exports = v4;
17309
17584
 
17310
- },{"./lib/bytesToUuid":48,"./lib/rng":49}],52:[function(require,module,exports){
17585
+ },{"./lib/bytesToUuid":50,"./lib/rng":51}],54:[function(require,module,exports){
17311
17586
  const Day = require('@barchart/common-js/lang/Day'),
17312
17587
  Decimal = require('@barchart/common-js/lang/Decimal');
17313
17588
 
@@ -17938,7 +18213,7 @@ describe('After the PositionSummaryFrame enumeration is initialized', () => {
17938
18213
  });
17939
18214
  });
17940
18215
 
17941
- },{"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/data/TransactionType":4,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22}],53:[function(require,module,exports){
18216
+ },{"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/data/TransactionType":4,"@barchart/common-js/lang/Day":23,"@barchart/common-js/lang/Decimal":24}],55:[function(require,module,exports){
17942
18217
  const Day = require('@barchart/common-js/lang/Day');
17943
18218
 
17944
18219
  const TransactionType = require('./../../../lib/data/TransactionType'),
@@ -18033,7 +18308,7 @@ describe('When requesting all the user-initiated transaction types', () => {
18033
18308
  expect(userInitiated.length).toEqual(9);
18034
18309
  });
18035
18310
  });
18036
- },{"./../../../lib/data/TransactionType":4,"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":21}],54:[function(require,module,exports){
18311
+ },{"./../../../lib/data/TransactionType":4,"./../../../lib/data/TransactionValidator":5,"@barchart/common-js/lang/Day":23}],56:[function(require,module,exports){
18037
18312
  const Currency = require('@barchart/common-js/lang/Currency'),
18038
18313
  Decimal = require('@barchart/common-js/lang/Decimal');
18039
18314
 
@@ -18220,7 +18495,73 @@ describe('When a position container data is gathered', () => {
18220
18495
  });
18221
18496
  });
18222
18497
 
18223
- },{"./../../../lib/data/InstrumentType":1,"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/processing/PositionContainer":6,"./../../../lib/processing/definitions/PositionLevelDefinition":9,"./../../../lib/processing/definitions/PositionLevelType":10,"./../../../lib/processing/definitions/PositionTreeDefinition":11,"@barchart/common-js/lang/Currency":20,"@barchart/common-js/lang/Decimal":22}],55:[function(require,module,exports){
18498
+ },{"./../../../lib/data/InstrumentType":1,"./../../../lib/data/PositionSummaryFrame":3,"./../../../lib/processing/PositionContainer":7,"./../../../lib/processing/definitions/PositionLevelDefinition":10,"./../../../lib/processing/definitions/PositionLevelType":11,"./../../../lib/processing/definitions/PositionTreeDefinition":12,"@barchart/common-js/lang/Currency":22,"@barchart/common-js/lang/Decimal":24}],57:[function(require,module,exports){
18499
+ const PositionSchema = require('./../../../lib/serialization/PositionSchema');
18500
+
18501
+ describe('When positions are serialized', () => {
18502
+ 'use strict';
18503
+
18504
+ describe('for a read operation (user error #1)', () => {
18505
+ let position;
18506
+ let serialized;
18507
+
18508
+ beforeEach(() => {
18509
+ position = {
18510
+ "user": "855e15c0-9e32-40ac-9bd9-5f0cc2780111",
18511
+ "portfolio": "c2a743e8-8efa-4a88-9a6c-9202d3fec29f",
18512
+ "instrument": {
18513
+ "id": "TGAM-CASH-USD",
18514
+ "name": "US Dollar",
18515
+ "type": "CASH",
18516
+ "currency": "USD"
18517
+ },
18518
+ "position": "a5cdc2e8-d9c6-4a1f-8f05-e271a5824f87",
18519
+ "transaction": 2987,
18520
+ "cash": true,
18521
+ "valuation": "AVG",
18522
+ "snapshot": {
18523
+ "date": "2020-06-11",
18524
+ "open": "222105.56",
18525
+ "direction": "LONG",
18526
+ "buys": "0",
18527
+ "sells": "0",
18528
+ "gain": "0",
18529
+ "basis": "0",
18530
+ "income": "0",
18531
+ "value": "0"
18532
+ },
18533
+ "system": {
18534
+ "calculate": {
18535
+ "processors": 1
18536
+ },
18537
+ "locked": false
18538
+ }
18539
+ };
18540
+
18541
+ serialized = JSON.stringify(position);
18542
+ });
18543
+
18544
+ describe('and the data is deserialized', () => {
18545
+ let deserialized;
18546
+
18547
+ beforeEach(() => {
18548
+ const reviver = PositionSchema.CLIENT.schema.getReviver();
18549
+
18550
+ deserialized = JSON.parse(serialized, reviver);
18551
+ });
18552
+
18553
+ it('the deserialized data should be an object', () => {
18554
+ expect(typeof deserialized).toEqual('object');
18555
+ });
18556
+
18557
+ it('the deserialized data should be correct', () => {
18558
+ expect(deserialized.position).toEqual(position.position);
18559
+ });
18560
+ });
18561
+ });
18562
+ });
18563
+
18564
+ },{"./../../../lib/serialization/PositionSchema":13}],58:[function(require,module,exports){
18224
18565
  const Day = require('@barchart/common-js/lang/Day'),
18225
18566
  Decimal = require('@barchart/common-js/lang/Decimal');
18226
18567
 
@@ -18271,7 +18612,7 @@ describe('When transactions are serialized', () => {
18271
18612
  expect(typeof serialized === 'string').toEqual(true);
18272
18613
  });
18273
18614
 
18274
- describe('and the serialized data is deserialized', function() {
18615
+ describe('and the data is deserialized', () => {
18275
18616
  let deserialized;
18276
18617
 
18277
18618
  beforeEach(() => {
@@ -18287,4 +18628,4 @@ describe('When transactions are serialized', () => {
18287
18628
  });
18288
18629
  });
18289
18630
 
18290
- },{"./../../../lib/data/TransactionType":4,"./../../../lib/serialization/TransactionSchema":12,"@barchart/common-js/lang/Day":21,"@barchart/common-js/lang/Decimal":22}]},{},[52,53,54,55]);
18631
+ },{"./../../../lib/data/TransactionType":4,"./../../../lib/serialization/TransactionSchema":14,"@barchart/common-js/lang/Day":23,"@barchart/common-js/lang/Decimal":24}]},{},[54,55,56,57,58]);
@@ -0,0 +1,64 @@
1
+ const PositionSchema = require('./../../../lib/serialization/PositionSchema');
2
+
3
+ describe('When positions are serialized', () => {
4
+ 'use strict';
5
+
6
+ describe('for a read operation (user error #1)', () => {
7
+ let position;
8
+ let serialized;
9
+
10
+ beforeEach(() => {
11
+ position = {
12
+ "user": "855e15c0-9e32-40ac-9bd9-5f0cc2780111",
13
+ "portfolio": "c2a743e8-8efa-4a88-9a6c-9202d3fec29f",
14
+ "instrument": {
15
+ "id": "TGAM-CASH-USD",
16
+ "name": "US Dollar",
17
+ "type": "CASH",
18
+ "currency": "USD"
19
+ },
20
+ "position": "a5cdc2e8-d9c6-4a1f-8f05-e271a5824f87",
21
+ "transaction": 2987,
22
+ "cash": true,
23
+ "valuation": "AVG",
24
+ "snapshot": {
25
+ "date": "2020-06-11",
26
+ "open": "222105.56",
27
+ "direction": "LONG",
28
+ "buys": "0",
29
+ "sells": "0",
30
+ "gain": "0",
31
+ "basis": "0",
32
+ "income": "0",
33
+ "value": "0"
34
+ },
35
+ "system": {
36
+ "calculate": {
37
+ "processors": 1
38
+ },
39
+ "locked": false
40
+ }
41
+ };
42
+
43
+ serialized = JSON.stringify(position);
44
+ });
45
+
46
+ describe('and the data is deserialized', () => {
47
+ let deserialized;
48
+
49
+ beforeEach(() => {
50
+ const reviver = PositionSchema.CLIENT.schema.getReviver();
51
+
52
+ deserialized = JSON.parse(serialized, reviver);
53
+ });
54
+
55
+ it('the deserialized data should be an object', () => {
56
+ expect(typeof deserialized).toEqual('object');
57
+ });
58
+
59
+ it('the deserialized data should be correct', () => {
60
+ expect(deserialized.position).toEqual(position.position);
61
+ });
62
+ });
63
+ });
64
+ });
@@ -48,7 +48,7 @@ describe('When transactions are serialized', () => {
48
48
  expect(typeof serialized === 'string').toEqual(true);
49
49
  });
50
50
 
51
- describe('and the serialized data is deserialized', function() {
51
+ describe('and the data is deserialized', () => {
52
52
  let deserialized;
53
53
 
54
54
  beforeEach(() => {