@barchart/portfolio-client-js 1.1.27 → 1.1.30

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.
@@ -158,7 +158,7 @@
158
158
  var readPositionSummaries = function() {
159
159
  var action = 'portfolioGateway.readPositionSummaries()';
160
160
 
161
- that.gateway.readPositionSummaries(that.portfolio() || null, that.position() || null, 'YEARLY', 2)
161
+ that.gateway.readPositionSummaries(that.portfolio() || null, that.position() || null, [ 'YEARLY', 'YTD' ], 1)
162
162
  .then((data) => {
163
163
  writeConsoleText(action, true);
164
164
  writeConsoleObject(data);
@@ -81,6 +81,20 @@ module.exports = function () {
81
81
  return 'g4zerhpif5.execute-api.us-east-1.amazonaws.com/dev';
82
82
  }
83
83
 
84
+ /**
85
+ * The host of the staging system.
86
+ *
87
+ * @public
88
+ * @static
89
+ * @returns {String}
90
+ */
91
+
92
+ }, {
93
+ key: 'stagingHost',
94
+ get: function get() {
95
+ return 'g4zerhpif5.execute-api.us-east-1.amazonaws.com/dev';
96
+ }
97
+
84
98
  /**
85
99
  * The host of the production system.
86
100
  *
@@ -114,6 +128,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
114
128
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
115
129
 
116
130
  var assert = require('@barchart/common-js/lang/assert'),
131
+ Day = require('@barchart/common-js/lang/Day'),
117
132
  Disposable = require('@barchart/common-js/lang/Disposable'),
118
133
  Enum = require('@barchart/common-js/lang/Enum'),
119
134
  is = require('@barchart/common-js/lang/is');
@@ -148,6 +163,7 @@ module.exports = function () {
148
163
  * @param {String} protocol - The protocol to use (either HTTP or HTTPS).
149
164
  * @param {String} host - The host name of the Portfolio web service.
150
165
  * @param {Number} port - The TCP port number of the Portfolio web service.
166
+ * @param {String} environment - A description of the environment we're connecting to.
151
167
  * @param {RequestInterceptor=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
152
168
  * @extends {Disposable}
153
169
  */
@@ -155,7 +171,7 @@ module.exports = function () {
155
171
  var PortfolioGateway = function (_Disposable) {
156
172
  _inherits(PortfolioGateway, _Disposable);
157
173
 
158
- function PortfolioGateway(protocol, host, port, requestInterceptor) {
174
+ function PortfolioGateway(protocol, host, port, environment, requestInterceptor) {
159
175
  _classCallCheck(this, PortfolioGateway);
160
176
 
161
177
  var _this = _possibleConstructorReturn(this, (PortfolioGateway.__proto__ || Object.getPrototypeOf(PortfolioGateway)).call(this));
@@ -163,6 +179,8 @@ module.exports = function () {
163
179
  _this._started = false;
164
180
  _this._startPromise = null;
165
181
 
182
+ _this._environment = environment;
183
+
166
184
  var protocolType = Enum.fromCode(ProtocolType, protocol.toUpperCase());
167
185
 
168
186
  var requestInterceptorToUse = void 0;
@@ -198,7 +216,13 @@ module.exports = function () {
198
216
  _this._readPositionSummariesEndpoint = EndpointBuilder.for('read-position-summaries', 'read position summaries').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
199
217
  pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('summaries', 'summaries').withVariableParameter('position', 'position', 'position', false);
200
218
  }).withQueryBuilder(function (qb) {
201
- qb.withVariableParameter('frame', 'frame', 'frame', true).withVariableParameter('periods', 'periods', 'periods', true);
219
+ qb.withVariableParameter('frames', 'frames', 'frames', true, function (frames) {
220
+ return frames.map(function (f) {
221
+ return f.code;
222
+ }).join();
223
+ }).withVariableParameter('periods', 'periods', 'periods', true).withVariableParameter('start', 'start', 'start', true, function (s) {
224
+ return s.format();
225
+ });
202
226
  }).withRequestInterceptor(requestInterceptorToUse).withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE).withResponseInterceptor(responseInterceptorForPositionSummaryDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
203
227
 
204
228
  _this._readTransactionsEndpoint = EndpointBuilder.for('read-transactions', 'read transactions').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
@@ -226,16 +250,24 @@ module.exports = function () {
226
250
  }
227
251
 
228
252
  /**
229
- * Initializes the connection to the remote server and returns a promise
230
- * containing the current instance.
253
+ * Returns a description of the environment (e.g. development or production).
231
254
  *
232
255
  * @public
233
- * @returns {Promise.<PortfolioGateway>}
256
+ * @return {*}
234
257
  */
235
258
 
236
259
 
237
260
  _createClass(PortfolioGateway, [{
238
261
  key: 'start',
262
+
263
+
264
+ /**
265
+ * Initializes the connection to the remote server and returns a promise
266
+ * containing the current instance.
267
+ *
268
+ * @public
269
+ * @returns {Promise.<PortfolioGateway>}
270
+ */
239
271
  value: function start() {
240
272
  var _this2 = this;
241
273
 
@@ -376,14 +408,15 @@ module.exports = function () {
376
408
  * @public
377
409
  * @param {String=} portfolio
378
410
  * @param {String=} position
379
- * @param {PositionSummaryFrame=|String=} frame
411
+ * @param {Array.<PositionSummaryFrame>=|Array.<String>=} frames
380
412
  * @param {Number=} periods
413
+ * @param {Day=|String=} start
381
414
  * @returns {Promise.<Position[]>}
382
415
  */
383
416
 
384
417
  }, {
385
418
  key: 'readPositionSummaries',
386
- value: function readPositionSummaries(portfolio, position, frame, periods) {
419
+ value: function readPositionSummaries(portfolio, position, frames, periods, start) {
387
420
  var _this8 = this;
388
421
 
389
422
  return Promise.resolve().then(function () {
@@ -392,29 +425,54 @@ module.exports = function () {
392
425
  assert.argumentIsOptional(portfolio, 'portfolio', String);
393
426
  assert.argumentIsOptional(position, 'position', String);
394
427
 
395
- if (!is.string(frame)) {
396
- assert.argumentIsOptional(frame, 'frame', PositionSummaryFrame, 'PositionSummaryFrame');
428
+ if (is.array(frames)) {
429
+ if (frames.length > 0 && is.string(frames[0])) {
430
+ assert.argumentIsArray(frames, 'frames', String);
431
+ } else {
432
+ assert.argumentIsArray(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
433
+ }
434
+ } else {
435
+ if (is.string(frames)) {
436
+ assert.argumentIsOptional(frames, 'frames', String);
437
+ } else {
438
+ assert.argumentIsOptional(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
439
+ }
397
440
  }
398
441
 
399
442
  assert.argumentIsOptional(periods, 'periods', Number);
443
+ assert.argumentIsOptional(start, 'start', Day);
400
444
 
401
445
  var query = {
402
446
  portfolio: portfolio || '*',
403
447
  position: position || '*'
404
448
  };
405
449
 
406
- if (frame) {
407
- if (is.string(frame)) {
408
- query.frame = frame;
409
- } else {
410
- query.frame = frame.code;
411
- }
450
+ if (frames) {
451
+ query.frames = frames.map(function (frame) {
452
+ if (is.string(frame)) {
453
+ return Enum.fromCode(PositionSummaryFrame, frame);
454
+ } else {
455
+ return frame;
456
+ }
457
+ });
412
458
  }
413
459
 
414
460
  if (periods) {
415
461
  query.periods = periods;
416
462
  }
417
463
 
464
+ if (start) {
465
+ var s = void 0;
466
+
467
+ if (is.string(start)) {
468
+ s = Day.parse(start);
469
+ } else {
470
+ s = start;
471
+ }
472
+
473
+ query.start = s;
474
+ }
475
+
418
476
  return Gateway.invoke(_this8._readPositionSummariesEndpoint, query);
419
477
  });
420
478
  }
@@ -568,6 +626,11 @@ module.exports = function () {
568
626
  value: function toString() {
569
627
  return '[PortfolioGateway]';
570
628
  }
629
+ }, {
630
+ key: 'environment',
631
+ get: function get() {
632
+ return this._environment;
633
+ }
571
634
  }], [{
572
635
  key: 'forLocal',
573
636
  value: function forLocal(requestInterceptor) {
@@ -593,7 +656,26 @@ module.exports = function () {
593
656
  return Promise.resolve(requestInterceptor).then(function (requestInterceptor) {
594
657
  assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'RequestInterceptor');
595
658
 
596
- return start(new PortfolioGateway('https', Configuration.developmentHost, 443, requestInterceptor));
659
+ return start(new PortfolioGateway('https', Configuration.developmentHost, 443, 'development', requestInterceptor));
660
+ });
661
+ }
662
+
663
+ /**
664
+ * Creates and starts a new {@link PortfolioGateway} for use in the staging environment.
665
+ *
666
+ * @public
667
+ * @static
668
+ * @param {RequestInterceptor=|Promise.<RequestInterceptor>=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
669
+ * @returns {Promise.<PortfolioGateway>}
670
+ */
671
+
672
+ }, {
673
+ key: 'forStaging',
674
+ value: function forStaging(requestInterceptor) {
675
+ return Promise.resolve(requestInterceptor).then(function (requestInterceptor) {
676
+ assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'production', 'RequestInterceptor');
677
+
678
+ return start(new PortfolioGateway('https', Configuration.stagingHost, 443, 'staging', requestInterceptor));
597
679
  });
598
680
  }
599
681
 
@@ -612,7 +694,7 @@ module.exports = function () {
612
694
  return Promise.resolve(requestInterceptor).then(function (requestInterceptor) {
613
695
  assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'RequestInterceptor');
614
696
 
615
- return start(new PortfolioGateway('https', Configuration.productionHost, 443, requestInterceptor));
697
+ return start(new PortfolioGateway('https', Configuration.productionHost, 443, 'production', requestInterceptor));
616
698
  });
617
699
  }
618
700
  }]);
@@ -691,7 +773,7 @@ module.exports = function () {
691
773
  return PortfolioGateway;
692
774
  }();
693
775
 
694
- },{"./../common/Configuration":2,"@barchart/common-js/api/failures/FailureReason":6,"@barchart/common-js/api/http/Gateway":9,"@barchart/common-js/api/http/builders/EndpointBuilder":10,"@barchart/common-js/api/http/definitions/ProtocolType":15,"@barchart/common-js/api/http/definitions/VerbType":16,"@barchart/common-js/api/http/interceptors/ErrorInterceptor":20,"@barchart/common-js/api/http/interceptors/RequestInterceptor":21,"@barchart/common-js/api/http/interceptors/ResponseInterceptor":22,"@barchart/common-js/lang/Disposable":31,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/assert":37,"@barchart/common-js/lang/is":40,"@barchart/portfolio-api-common/lib/data/PositionSummaryFrame":52,"@barchart/portfolio-api-common/lib/data/TransactionType":53,"@barchart/portfolio-api-common/lib/serialization/PortfolioSchema":55,"@barchart/portfolio-api-common/lib/serialization/PositionSchema":56,"@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema":57,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":58}],4:[function(require,module,exports){
776
+ },{"./../common/Configuration":2,"@barchart/common-js/api/failures/FailureReason":6,"@barchart/common-js/api/http/Gateway":9,"@barchart/common-js/api/http/builders/EndpointBuilder":10,"@barchart/common-js/api/http/definitions/ProtocolType":15,"@barchart/common-js/api/http/definitions/VerbType":16,"@barchart/common-js/api/http/interceptors/ErrorInterceptor":20,"@barchart/common-js/api/http/interceptors/RequestInterceptor":21,"@barchart/common-js/api/http/interceptors/ResponseInterceptor":22,"@barchart/common-js/lang/Day":29,"@barchart/common-js/lang/Disposable":31,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/assert":37,"@barchart/common-js/lang/is":40,"@barchart/portfolio-api-common/lib/data/PositionSummaryFrame":52,"@barchart/portfolio-api-common/lib/data/TransactionType":53,"@barchart/portfolio-api-common/lib/serialization/PortfolioSchema":55,"@barchart/portfolio-api-common/lib/serialization/PositionSchema":56,"@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema":57,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":58}],4:[function(require,module,exports){
695
777
  'use strict';
696
778
 
697
779
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -1004,7 +1086,7 @@ module.exports = function () {
1004
1086
  return {
1005
1087
  JwtGateway: JwtGateway,
1006
1088
  PortfolioGateway: PortfolioGateway,
1007
- version: '1.1.27'
1089
+ version: '1.1.30'
1008
1090
  };
1009
1091
  }();
1010
1092
 
@@ -5471,9 +5553,9 @@ module.exports = function () {
5471
5553
  assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
5472
5554
  assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
5473
5555
 
5474
- if (a._big.gt(b)) {
5556
+ if (a._big.gt(b._big)) {
5475
5557
  return 1;
5476
- } else if (a._big.lt(b)) {
5558
+ } else if (a._big.lt(b._big)) {
5477
5559
  return -1;
5478
5560
  } else {
5479
5561
  return 0;
@@ -9059,15 +9141,27 @@ module.exports = (() => {
9059
9141
  * @param {String} alternateDescription
9060
9142
  * @param {String} code
9061
9143
  * @param {Boolean} canReinvest
9144
+ * @param {Boolean} usesSymbols
9062
9145
  */
9063
9146
  class InstrumentType extends Enum {
9064
- constructor(code, description, alternateDescription, canReinvest) {
9147
+ constructor(code, description, alternateDescription, canReinvest, usesSymbols) {
9065
9148
  super(code, description);
9066
9149
 
9150
+ assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
9151
+ assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
9152
+ assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
9153
+
9067
9154
  this._alternateDescription = alternateDescription;
9068
9155
  this._canReinvest = canReinvest;
9156
+ this._usesSymbols = usesSymbols;
9069
9157
  }
9070
9158
 
9159
+ /**
9160
+ * A human-readable description.
9161
+ *
9162
+ * @public
9163
+ * @return {String}
9164
+ */
9071
9165
  get alternateDescription() {
9072
9166
  return this._alternateDescription;
9073
9167
  }
@@ -9075,16 +9169,28 @@ module.exports = (() => {
9075
9169
  /**
9076
9170
  * Indicates if the instrument type allows automatic reinvestment.
9077
9171
  *
9172
+ * @public
9078
9173
  * @returns {Boolean}
9079
9174
  */
9080
9175
  get canReinvest() {
9081
9176
  return this._canReinvest;
9082
9177
  }
9083
9178
 
9179
+ /**
9180
+ * Indicates if an instrument of this type can be represented by a symbol.
9181
+ *
9182
+ * @public
9183
+ * @returns {Boolean}
9184
+ */
9185
+ get usesSymbols() {
9186
+ return this._usesSymbols;
9187
+ }
9188
+
9084
9189
  /**
9085
9190
  * Cash.
9086
9191
  *
9087
9192
  * @public
9193
+ * @static
9088
9194
  * @returns {InstrumentType}
9089
9195
  */
9090
9196
  static get CASH() {
@@ -9095,6 +9201,7 @@ module.exports = (() => {
9095
9201
  * An equity issue.
9096
9202
  *
9097
9203
  * @public
9204
+ * @static
9098
9205
  * @returns {InstrumentType}
9099
9206
  */
9100
9207
  static get EQUITY() {
@@ -9105,6 +9212,7 @@ module.exports = (() => {
9105
9212
  * A mutual fund.
9106
9213
  *
9107
9214
  * @public
9215
+ * @static
9108
9216
  * @returns {InstrumentType}
9109
9217
  */
9110
9218
  static get FUND() {
@@ -9115,6 +9223,7 @@ module.exports = (() => {
9115
9223
  * An undefined asset (e.g. a house, or a collectible, or a salvaged alien spaceship).
9116
9224
  *
9117
9225
  * @public
9226
+ * @static
9118
9227
  * @returns {InstrumentType}
9119
9228
  */
9120
9229
  static get OTHER() {
@@ -9126,10 +9235,10 @@ module.exports = (() => {
9126
9235
  }
9127
9236
  }
9128
9237
 
9129
- const cash = new InstrumentType('CASH', 'cash', 'Cash', false);
9130
- const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true);
9131
- const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true);
9132
- const other = new InstrumentType('OTHER', 'other', 'Other', false);
9238
+ const cash = new InstrumentType('CASH', 'cash', 'Cash', false, false);
9239
+ const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true, true);
9240
+ const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true, true);
9241
+ const other = new InstrumentType('OTHER', 'other', 'Other', false, false);
9133
9242
 
9134
9243
  return InstrumentType;
9135
9244
  })();
@@ -9138,6 +9247,7 @@ module.exports = (() => {
9138
9247
  const array = require('@barchart/common-js/lang/array'),
9139
9248
  assert = require('@barchart/common-js/lang/assert'),
9140
9249
  Day = require('@barchart/common-js/lang/Day'),
9250
+ Decimal = require('@barchart/common-js/lang/Decimal'),
9141
9251
  Enum = require('@barchart/common-js/lang/Enum'),
9142
9252
  is = require('@barchart/common-js/lang/is');
9143
9253
 
@@ -9153,23 +9263,68 @@ module.exports = (() => {
9153
9263
  * @param {String} description
9154
9264
  * @param {Function} rangeCalculator
9155
9265
  * @param {Function} startDateCalculator
9266
+ * @param {Function} descriptionCalculator
9156
9267
  */
9157
9268
  class PositionSummaryFrame extends Enum {
9158
- constructor(code, description, rangeCalculator, startDateCalculator) {
9269
+ constructor(code, description, rangeCalculator, startDateCalculator, descriptionCalculator) {
9159
9270
  super(code, description);
9160
9271
 
9161
9272
  assert.argumentIsRequired(rangeCalculator, 'rangeCalculator', Function);
9273
+ assert.argumentIsRequired(startDateCalculator, 'startDateCalculator', Function);
9274
+ assert.argumentIsRequired(descriptionCalculator, 'descriptionCalculator', Function);
9162
9275
 
9163
9276
  this._rangeCalculator = rangeCalculator;
9164
9277
  this._startDateCalculator = startDateCalculator;
9278
+ this._descriptionCalculator = descriptionCalculator;
9165
9279
  }
9166
9280
 
9281
+ /**
9282
+ * Returns a human-readable description of the frame, given
9283
+ * start and end dates.
9284
+ *
9285
+ * @public
9286
+ * @param {Day} startDate
9287
+ * @param {Day} endDate
9288
+ * @return {String}
9289
+ */
9290
+ describeRange(startDate, endDate) {
9291
+ return this._descriptionCalculator(startDate, endDate);
9292
+ }
9293
+
9294
+ /**
9295
+ * Returns the most recent ranges for the frame.
9296
+ *
9297
+ * @public
9298
+ * @param {Number} periods
9299
+ * @returns {Array.<PositionSummaryRange>}
9300
+ */
9301
+ getRecentRanges(periods) {
9302
+ const startDate = this.getStartDate(periods);
9303
+ const transaction = { date: startDate, snapshot: { open: Decimal.ONE } };
9304
+
9305
+ return this.getRanges([ transaction ]);
9306
+ }
9307
+
9308
+ /**
9309
+ * Returns the ranges for the set of {@link Transaction} objects.
9310
+ *
9311
+ * @public
9312
+ * @param {Array.<Transaction>} transactions
9313
+ * @returns {Array.<PositionSummaryRange>}
9314
+ */
9167
9315
  getRanges(transactions) {
9168
9316
  assert.argumentIsArray(transactions, 'transactions');
9169
9317
 
9170
9318
  return this._rangeCalculator(getFilteredTransactions(transactions));
9171
9319
  }
9172
9320
 
9321
+ /**
9322
+ * Returns the start date for a frame, a given number of periods ago.
9323
+ *
9324
+ * @public
9325
+ * @param {Number} periods
9326
+ * @returns {Day}
9327
+ */
9173
9328
  getStartDate(periods) {
9174
9329
  assert.argumentIsRequired(periods, 'periods', Number);
9175
9330
 
@@ -9221,10 +9376,19 @@ module.exports = (() => {
9221
9376
  }
9222
9377
  }
9223
9378
 
9224
- const yearly = new PositionSummaryFrame('YEARLY', 'year', getYearlyRanges, getYearlyStartDate);
9225
- const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', getQuarterlyRanges, getQuarterlyStartDate);
9226
- const monthly = new PositionSummaryFrame('MONTH', 'month', getMonthlyRanges, getMonthlyStartDate);
9227
- const ytd = new PositionSummaryFrame('YTD', 'year-to-date', getYearToDateRanges, getYearToDateStartDate);
9379
+ const yearly = new PositionSummaryFrame('YEARLY', 'year', getYearlyRanges, getYearlyStartDate, getYearlyRangeDescription);
9380
+ const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', getQuarterlyRanges, getQuarterlyStartDate, getQuarterlyRangeDescription);
9381
+ const monthly = new PositionSummaryFrame('MONTH', 'month', getMonthlyRanges, getMonthlyStartDate, getMonthlyRangeDescription);
9382
+ const ytd = new PositionSummaryFrame('YTD', 'year-to-date', getYearToDateRanges, getYearToDateStartDate, getYearToDateRangeDescription);
9383
+
9384
+ /**
9385
+ * The start and and date for a {@link PositionSummaryFrame}
9386
+ *
9387
+ * @typedef PositionSummaryRange
9388
+ * @type {Object}
9389
+ * @property {Day} start
9390
+ * @property {Day} end
9391
+ */
9228
9392
 
9229
9393
  function getRange(start, end) {
9230
9394
  return {
@@ -9308,6 +9472,22 @@ module.exports = (() => {
9308
9472
  return null;
9309
9473
  }
9310
9474
 
9475
+ function getYearlyRangeDescription(startDate, endDate) {
9476
+ return endDate.year.toString();
9477
+ }
9478
+
9479
+ function getQuarterlyRangeDescription(startDate, endDate) {
9480
+ return '';
9481
+ }
9482
+
9483
+ function getMonthlyRangeDescription(startDate, endDate) {
9484
+ return '';
9485
+ }
9486
+
9487
+ function getYearToDateRangeDescription(startDate, endDate) {
9488
+ return `${endDate.year.toString()} YTD`;
9489
+ }
9490
+
9311
9491
  function getFilteredTransactions(transactions) {
9312
9492
  return transactions.reduce((filtered, transaction) => {
9313
9493
  if (!transaction.snapshot.open.getIsZero() || transaction.type.closing) {
@@ -9321,7 +9501,7 @@ module.exports = (() => {
9321
9501
  return PositionSummaryFrame;
9322
9502
  })();
9323
9503
 
9324
- },{"@barchart/common-js/lang/Day":29,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/array":36,"@barchart/common-js/lang/assert":37,"@barchart/common-js/lang/is":40}],53:[function(require,module,exports){
9504
+ },{"@barchart/common-js/lang/Day":29,"@barchart/common-js/lang/Decimal":30,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/array":36,"@barchart/common-js/lang/assert":37,"@barchart/common-js/lang/is":40}],53:[function(require,module,exports){
9325
9505
  const assert = require('@barchart/common-js/lang/assert'),
9326
9506
  Enum = require('@barchart/common-js/lang/Enum');
9327
9507
 
@@ -9335,6 +9515,7 @@ module.exports = (() => {
9335
9515
  * @extends {Enum}
9336
9516
  * @param {String} code
9337
9517
  * @param {String} description
9518
+ * @param {String} display
9338
9519
  * @param {Boolean} purchase
9339
9520
  * @param {Boolean} sale
9340
9521
  * @param {Boolean} income
@@ -9342,15 +9523,17 @@ module.exports = (() => {
9342
9523
  * @param {Boolean} closing
9343
9524
  */
9344
9525
  class TransactionType extends Enum {
9345
- constructor(code, description, purchase, sale, income, opening, closing) {
9526
+ constructor(code, description, display, purchase, sale, income, opening, closing) {
9346
9527
  super(code, description);
9347
9528
 
9529
+ assert.argumentIsRequired(display, 'display', String);
9348
9530
  assert.argumentIsRequired(purchase, 'purchase', Boolean);
9349
9531
  assert.argumentIsRequired(sale, 'sale', Boolean);
9350
9532
  assert.argumentIsRequired(income, 'income', Boolean);
9351
9533
  assert.argumentIsRequired(opening, 'opening', Boolean);
9352
9534
  assert.argumentIsRequired(closing, 'closing', Boolean);
9353
9535
 
9536
+ this._display = display;
9354
9537
  this._purchase = purchase;
9355
9538
  this._sale = sale;
9356
9539
  this._income = income;
@@ -9358,6 +9541,16 @@ module.exports = (() => {
9358
9541
  this._closing = closing;
9359
9542
  }
9360
9543
 
9544
+ /**
9545
+ * A human-readable description of the transaction type.
9546
+ *
9547
+ * @public
9548
+ * @returns {String}
9549
+ */
9550
+ get display() {
9551
+ return this._display;
9552
+ }
9553
+
9361
9554
  /**
9362
9555
  * Indicates if the transaction was a trade.
9363
9556
  *
@@ -9623,27 +9816,27 @@ module.exports = (() => {
9623
9816
  }
9624
9817
  }
9625
9818
 
9626
- const buy = new TransactionType('B', 'Buy', true, false, false, true, false);
9627
- const sell = new TransactionType('S', 'Sell', false, true, false, false, true);
9628
- const buyShort = new TransactionType('BS', 'Buy To Cover', true, false, false, false, true);
9629
- const sellShort = new TransactionType('SS', 'Sell Short', false, true, false, true, false);
9630
- const dividend = new TransactionType('DV', 'Dividend', false, false, true, false, false);
9631
- const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', false, false, false, true, false);
9632
- const dividendStock = new TransactionType('DS', 'Dividend (Stock)', false, false, false, true, false);
9633
- const split = new TransactionType('SP', 'Split', false, false, false, true, false);
9634
- const fee = new TransactionType('F', 'Fee', false, false, false, true, false);
9635
- const feeUnits = new TransactionType('FU', 'Fee', false, false, false, false, false);
9819
+ const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false);
9820
+ const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true);
9821
+ const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true);
9822
+ const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false);
9823
+ const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false);
9824
+ const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false);
9825
+ const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false);
9826
+ const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false);
9827
+ const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, true, false);
9828
+ const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, false);
9636
9829
 
9637
- const distributionCash = new TransactionType('DC', 'Distribution (Cash)', false, false, true, false, false);
9638
- const distributionFund = new TransactionType('DF', 'Distribution (Units)', false, false, false, true, false);
9830
+ const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false);
9831
+ const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false);
9639
9832
 
9640
- const deposit = new TransactionType('D', 'Deposit', false, false, false, true, false);
9641
- const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false, true);
9642
- const debit = new TransactionType('DR', 'Debit', false, false, false, false, true);
9643
- const credit = new TransactionType('CR', 'Credit', false, false, false, true, false);
9833
+ const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, true, false);
9834
+ const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, true);
9835
+ const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, true);
9836
+ const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, true, false);
9644
9837
 
9645
- const valuation = new TransactionType('V', 'Valuation', false, false, false, false, false);
9646
- const income = new TransactionType('I', 'Income', false, false, true, false, false);
9838
+ const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false);
9839
+ const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false);
9647
9840
 
9648
9841
  return TransactionType;
9649
9842
  })();
@@ -9868,6 +10061,7 @@ module.exports = (() => {
9868
10061
  );
9869
10062
 
9870
10063
  const update = new PortfolioSchema(SchemaBuilder.withName('update')
10064
+ .withField('portfolio', DataType.STRING)
9871
10065
  .withField('name', DataType.STRING)
9872
10066
  .withField('timezone', DataType.forEnum(Timezones, 'Timezone'), true)
9873
10067
  .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'), true)
@@ -10143,7 +10337,8 @@ const assert = require('@barchart/common-js/lang/assert'),
10143
10337
  Schema = require('@barchart/common-js/serialization/json/Schema'),
10144
10338
  SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
10145
10339
 
10146
- const TransactionType = require('./../data/TransactionType');
10340
+ const InstrumentType = require('./../data/InstrumentType'),
10341
+ TransactionType = require('./../data/TransactionType');
10147
10342
 
10148
10343
  module.exports = (() => {
10149
10344
  'use strict';
@@ -10295,7 +10490,7 @@ module.exports = (() => {
10295
10490
  }
10296
10491
 
10297
10492
  toString() {
10298
- return '[TransactionSchema]';
10493
+ return `[TransactionSchema (code=${this.code})]`;
10299
10494
  }
10300
10495
  }
10301
10496
 
@@ -10381,12 +10576,11 @@ module.exports = (() => {
10381
10576
  .withField('portfolio', DataType.STRING)
10382
10577
  .withField('position', DataType.STRING)
10383
10578
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
10384
- .withField('instrument.name', DataType.STRING, true)
10385
- .withField('instrument.type', DataType.STRING, true)
10386
- .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
10579
+ .withField('instrument.name', DataType.STRING)
10580
+ .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
10581
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
10387
10582
  .withField('instrument.symbol.barchart', DataType.STRING, true)
10388
10583
  .withField('instrument.symbol.display', DataType.STRING, true)
10389
- .withField('currency', DataType.forEnum(Currency, 'Currency'))
10390
10584
  .withField('date', DataType.DAY)
10391
10585
  .withField('price', DataType.DECIMAL)
10392
10586
  .withField('quantity', DataType.DECIMAL)
@@ -10409,9 +10603,9 @@ module.exports = (() => {
10409
10603
  .withField('portfolio', DataType.STRING)
10410
10604
  .withField('position', DataType.STRING)
10411
10605
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
10412
- .withField('instrument.name', DataType.STRING, true)
10413
- .withField('instrument.type', DataType.STRING, true)
10414
- .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
10606
+ .withField('instrument.name', DataType.STRING)
10607
+ .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
10608
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
10415
10609
  .withField('instrument.symbol.barchart', DataType.STRING, true)
10416
10610
  .withField('instrument.symbol.display', DataType.STRING, true)
10417
10611
  .withField('date', DataType.DAY)
@@ -10525,11 +10719,8 @@ module.exports = (() => {
10525
10719
  .withField('portfolio', DataType.STRING)
10526
10720
  .withField('position', DataType.STRING)
10527
10721
  .withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
10528
- .withField('instrument.name', DataType.STRING, true)
10529
- .withField('instrument.type', DataType.STRING, true)
10530
- .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
10531
- .withField('instrument.symbol.barchart', DataType.STRING, true)
10532
- .withField('instrument.symbol.display', DataType.STRING, true)
10722
+ .withField('instrument.type', DataType.forEnum(InstrumentType, 'InstrumentType'))
10723
+ .withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
10533
10724
  .withField('date', DataType.DAY)
10534
10725
  .withField('amount', DataType.DECIMAL)
10535
10726
  .withField('fee', DataType.DECIMAL, true)
@@ -10610,7 +10801,7 @@ module.exports = (() => {
10610
10801
  return TransactionSchema;
10611
10802
  })();
10612
10803
 
10613
- },{"./../data/TransactionType":53,"@barchart/common-js/lang/Currency":28,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/assert":37,"@barchart/common-js/lang/is":40,"@barchart/common-js/serialization/json/DataType":45,"@barchart/common-js/serialization/json/Schema":47,"@barchart/common-js/serialization/json/builders/SchemaBuilder":49}],59:[function(require,module,exports){
10804
+ },{"./../data/InstrumentType":51,"./../data/TransactionType":53,"@barchart/common-js/lang/Currency":28,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/assert":37,"@barchart/common-js/lang/is":40,"@barchart/common-js/serialization/json/DataType":45,"@barchart/common-js/serialization/json/Schema":47,"@barchart/common-js/serialization/json/builders/SchemaBuilder":49}],59:[function(require,module,exports){
10614
10805
  'use strict';
10615
10806
 
10616
10807
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -33,6 +33,18 @@ module.exports = (() => {
33
33
  return 'g4zerhpif5.execute-api.us-east-1.amazonaws.com/dev';
34
34
  }
35
35
 
36
+
37
+ /**
38
+ * The host of the staging system.
39
+ *
40
+ * @public
41
+ * @static
42
+ * @returns {String}
43
+ */
44
+ static get stagingHost() {
45
+ return 'g4zerhpif5.execute-api.us-east-1.amazonaws.com/dev';
46
+ }
47
+
36
48
  /**
37
49
  * The host of the production system.
38
50
  *
@@ -1,4 +1,5 @@
1
1
  const assert = require('@barchart/common-js/lang/assert'),
2
+ Day = require('@barchart/common-js/lang/Day'),
2
3
  Disposable = require('@barchart/common-js/lang/Disposable'),
3
4
  Enum = require('@barchart/common-js/lang/Enum'),
4
5
  is = require('@barchart/common-js/lang/is');
@@ -33,16 +34,19 @@ module.exports = (() => {
33
34
  * @param {String} protocol - The protocol to use (either HTTP or HTTPS).
34
35
  * @param {String} host - The host name of the Portfolio web service.
35
36
  * @param {Number} port - The TCP port number of the Portfolio web service.
37
+ * @param {String} environment - A description of the environment we're connecting to.
36
38
  * @param {RequestInterceptor=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
37
39
  * @extends {Disposable}
38
40
  */
39
41
  class PortfolioGateway extends Disposable {
40
- constructor(protocol, host, port, requestInterceptor) {
42
+ constructor(protocol, host, port, environment, requestInterceptor) {
41
43
  super();
42
44
 
43
45
  this._started = false;
44
46
  this._startPromise = null;
45
47
 
48
+ this._environment = environment;
49
+
46
50
  const protocolType = Enum.fromCode(ProtocolType, protocol.toUpperCase());
47
51
 
48
52
  let requestInterceptorToUse;
@@ -146,8 +150,9 @@ module.exports = (() => {
146
150
  .withVariableParameter('position', 'position', 'position', false);
147
151
  })
148
152
  .withQueryBuilder((qb) => {
149
- qb.withVariableParameter('frame', 'frame', 'frame', true)
150
- .withVariableParameter('periods', 'periods', 'periods', true);
153
+ qb.withVariableParameter('frames', 'frames', 'frames', true, frames => frames.map(f => f.code).join())
154
+ .withVariableParameter('periods', 'periods', 'periods', true)
155
+ .withVariableParameter('start', 'start', 'start', true, s => s.format());
151
156
  })
152
157
  .withRequestInterceptor(requestInterceptorToUse)
153
158
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
@@ -189,7 +194,7 @@ module.exports = (() => {
189
194
  .withLiteralParameter('transactions', 'transactions');
190
195
  })
191
196
  .withQueryBuilder((qb) => {
192
- qb.withVariableParameter('type', 'type', 'type', false, (i) => i.code);
197
+ qb.withVariableParameter('type', 'type', 'type', false, i => i.code);
193
198
  })
194
199
  .withBody('portfolio data')
195
200
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
@@ -234,6 +239,16 @@ module.exports = (() => {
234
239
  .endpoint;
235
240
  }
236
241
 
242
+ /**
243
+ * Returns a description of the environment (e.g. development or production).
244
+ *
245
+ * @public
246
+ * @return {*}
247
+ */
248
+ get environment() {
249
+ return this._environment;
250
+ }
251
+
237
252
  /**
238
253
  * Initializes the connection to the remote server and returns a promise
239
254
  * containing the current instance.
@@ -361,11 +376,12 @@ module.exports = (() => {
361
376
  * @public
362
377
  * @param {String=} portfolio
363
378
  * @param {String=} position
364
- * @param {PositionSummaryFrame=|String=} frame
379
+ * @param {Array.<PositionSummaryFrame>=|Array.<String>=} frames
365
380
  * @param {Number=} periods
381
+ * @param {Day=|String=} start
366
382
  * @returns {Promise.<Position[]>}
367
383
  */
368
- readPositionSummaries(portfolio, position, frame, periods) {
384
+ readPositionSummaries(portfolio, position, frames, periods, start) {
369
385
  return Promise.resolve()
370
386
  .then(() => {
371
387
  checkStart.call(this);
@@ -373,29 +389,54 @@ module.exports = (() => {
373
389
  assert.argumentIsOptional(portfolio, 'portfolio', String);
374
390
  assert.argumentIsOptional(position, 'position', String);
375
391
 
376
- if (!is.string(frame)) {
377
- assert.argumentIsOptional(frame, 'frame', PositionSummaryFrame, 'PositionSummaryFrame');
392
+ if (is.array(frames)) {
393
+ if (frames.length > 0 && is.string(frames[ 0 ])) {
394
+ assert.argumentIsArray(frames, 'frames', String);
395
+ } else {
396
+ assert.argumentIsArray(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
397
+ }
398
+ } else {
399
+ if (is.string(frames)) {
400
+ assert.argumentIsOptional(frames, 'frames', String);
401
+ } else {
402
+ assert.argumentIsOptional(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
403
+ }
378
404
  }
379
405
 
380
406
  assert.argumentIsOptional(periods, 'periods', Number);
407
+ assert.argumentIsOptional(start, 'start', Day);
381
408
 
382
409
  const query = {
383
410
  portfolio: portfolio || '*',
384
411
  position: position || '*'
385
412
  };
386
413
 
387
- if (frame) {
388
- if (is.string(frame)) {
389
- query.frame = frame;
390
- } else {
391
- query.frame = frame.code;
392
- }
414
+ if (frames) {
415
+ query.frames = frames.map((frame) => {
416
+ if (is.string(frame)) {
417
+ return Enum.fromCode(PositionSummaryFrame, frame);
418
+ } else {
419
+ return frame;
420
+ }
421
+ });
393
422
  }
394
423
 
395
424
  if (periods) {
396
425
  query.periods = periods;
397
426
  }
398
427
 
428
+ if (start) {
429
+ let s;
430
+
431
+ if (is.string(start)) {
432
+ s = Day.parse(start);
433
+ } else {
434
+ s = start;
435
+ }
436
+
437
+ query.start = s;
438
+ }
439
+
399
440
  return Gateway.invoke(this._readPositionSummariesEndpoint, query);
400
441
  });
401
442
  }
@@ -542,10 +583,27 @@ module.exports = (() => {
542
583
  .then((requestInterceptor) => {
543
584
  assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'RequestInterceptor');
544
585
 
545
- return start(new PortfolioGateway('https', Configuration.developmentHost, 443, requestInterceptor));
586
+ return start(new PortfolioGateway('https', Configuration.developmentHost, 443, 'development', requestInterceptor));
546
587
  });
547
588
  }
548
589
 
590
+ /**
591
+ * Creates and starts a new {@link PortfolioGateway} for use in the staging environment.
592
+ *
593
+ * @public
594
+ * @static
595
+ * @param {RequestInterceptor=|Promise.<RequestInterceptor>=} requestInterceptor - A request interceptor used with each request (typically used to inject JWT tokens).
596
+ * @returns {Promise.<PortfolioGateway>}
597
+ */
598
+ static forStaging(requestInterceptor) {
599
+ return Promise.resolve(requestInterceptor)
600
+ .then((requestInterceptor) => {
601
+ assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'production', 'RequestInterceptor');
602
+
603
+ return start(new PortfolioGateway('https', Configuration.stagingHost, 443, 'staging', requestInterceptor));
604
+ });
605
+ }
606
+
549
607
  /**
550
608
  * Creates and starts a new {@link PortfolioGateway} for use in the production environment.
551
609
  *
@@ -559,7 +617,7 @@ module.exports = (() => {
559
617
  .then((requestInterceptor) => {
560
618
  assert.argumentIsOptional(requestInterceptor, 'requestInterceptor', RequestInterceptor, 'RequestInterceptor');
561
619
 
562
- return start(new PortfolioGateway('https', Configuration.productionHost, 443, requestInterceptor));
620
+ return start(new PortfolioGateway('https', Configuration.productionHost, 443, 'production', requestInterceptor));
563
621
  });
564
622
  }
565
623
 
package/lib/index.js CHANGED
@@ -7,6 +7,6 @@ module.exports = (() => {
7
7
  return {
8
8
  JwtGateway: JwtGateway,
9
9
  PortfolioGateway: PortfolioGateway,
10
- version: '1.1.27'
10
+ version: '1.1.30'
11
11
  };
12
12
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-client-js",
3
- "version": "1.1.27",
3
+ "version": "1.1.30",
4
4
  "description": "JavaScript library for interfacing with Barchart's Portfolio API",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",