@barchart/portfolio-client-js 5.0.1 → 5.1.0

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
+ **Other**
2
+
3
+ * Correct internal implementation of SDK to address breaking changes to remote API.
@@ -0,0 +1,8 @@
1
+ **New Features**
2
+
3
+ * Added `PortfolioGateway.switchTransaction` function, allowing the reinvestment choice for a single dividend or distribution to be changed.
4
+ * Added `readPositionValuationsAvailability` method.
5
+
6
+ **Other**
7
+
8
+ * Removed legacy `observeValuationsForPortfolio` and `observeValuationsForPositions` methods.
@@ -231,6 +231,24 @@ module.exports = (() => {
231
231
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
232
232
  .endpoint;
233
233
 
234
+ this._readPositionValuationsAvailabilityEndpoint = EndpointBuilder.for('read-position-valuations-availability', 'read position valuations availability')
235
+ .withVerb(VerbType.GET)
236
+ .withProtocol(protocolType)
237
+ .withHost(host)
238
+ .withPort(port)
239
+ .withPathBuilder((pb) => {
240
+ pb.withLiteralParameter('version', 'v1')
241
+ .withLiteralParameter('portfolios', 'portfolios')
242
+ .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
243
+ .withLiteralParameter('values', 'values')
244
+ .withLiteralParameter('availability', 'availability');
245
+ })
246
+ .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
247
+ .withRequestInterceptor(requestInterceptor)
248
+ .withResponseInterceptor(responseInterceptorForDeserialization)
249
+ .withErrorInterceptor(ErrorInterceptor.GENERAL)
250
+ .endpoint;
251
+
234
252
  this._readPositionValuationsEndpoint = EndpointBuilder.for('read-position-valuations', 'read position valuations')
235
253
  .withVerb(VerbType.GET)
236
254
  .withProtocol(protocolType)
@@ -332,6 +350,29 @@ module.exports = (() => {
332
350
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
333
351
  .endpoint;
334
352
 
353
+ this._switchTransactionEndpoint = EndpointBuilder.for('switch-transaction', 'switch transaction')
354
+ .withVerb(VerbType.POST)
355
+ .withProtocol(protocolType)
356
+ .withHost(host)
357
+ .withPort(port)
358
+ .withPathBuilder((pb) => {
359
+ pb.withLiteralParameter('version', 'v1')
360
+ .withLiteralParameter('portfolios', 'portfolios')
361
+ .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
362
+ .withLiteralParameter('positions', 'positions')
363
+ .withVariableParameter('position', 'position', 'position', false)
364
+ .withLiteralParameter('transactions', 'transactions')
365
+ .withVariableParameter('sequence', 'sequence', 'sequence', false);
366
+ })
367
+ .withQueryBuilder((qb) => {
368
+ qb.withVariableParameter('switch', 'switch', 'switch', false, x => x.code);
369
+ })
370
+ .withBody()
371
+ .withRequestInterceptor(requestInterceptor)
372
+ .withResponseInterceptor(responseInterceptorForPositionMutateDeserialization)
373
+ .withErrorInterceptor(ErrorInterceptor.GENERAL)
374
+ .endpoint;
375
+
335
376
  this._deleteTransactionEndpoint = EndpointBuilder.for('delete-transaction', 'delete transaction')
336
377
  .withVerb(VerbType.DELETE)
337
378
  .withProtocol(protocolType)
@@ -434,7 +475,7 @@ module.exports = (() => {
434
475
  })
435
476
  .withRequestInterceptor(requestInterceptor)
436
477
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
437
- .withResponseInterceptor(responseInterceptorForVersion)
478
+ .withResponseInterceptor(responseInterceptorForDeserialization)
438
479
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
439
480
  .endpoint;
440
481
 
@@ -762,6 +803,28 @@ module.exports = (() => {
762
803
  });
763
804
  }
764
805
 
806
+ /**
807
+ * Retrieves values availability of the portfolio and it's positions.
808
+ *
809
+ * @public
810
+ * @param {String} portfolio
811
+ * @return {Promise<ValuationsAvailabilityResult>}
812
+ */
813
+ readPositionValuationsAvailability(portfolio) {
814
+ return Promise.resolve()
815
+ .then(() => {
816
+ checkStart.call(this);
817
+
818
+ assert.argumentIsRequired(portfolio, 'portfolio', String);
819
+
820
+ const payload = { };
821
+
822
+ payload.portfolio = portfolio;
823
+
824
+ return Gateway.invoke(this._readPositionValuationsAvailabilityEndpoint, payload);
825
+ });
826
+ }
827
+
765
828
  /**
766
829
  * Retrieves end-of-day position valuations for the entire portfolio or single position.
767
830
  *
@@ -803,108 +866,6 @@ module.exports = (() => {
803
866
  });
804
867
  }
805
868
 
806
- /**
807
- * Returns an array with two items. The fist item is a promise which resolves
808
- * as soon as a position's end-of-day valuation calculations have finished.
809
- * The seconds is a function which cancels the observation when invoked.
810
- *
811
- * @public
812
- * @param {String} portfolio
813
- * @param {String} position
814
- * @returns {Array}
815
- */
816
- observeValuationsForPosition(portfolio, position) {
817
- let disposed = false;
818
-
819
- const cancelFunction = () => {
820
- disposed = true;
821
- };
822
-
823
- const completionPromise = promise.build((resolveCallback) => {
824
- assert.argumentIsRequired(portfolio, 'portfolio', String);
825
- assert.argumentIsRequired(position, 'position', String);
826
-
827
- const scheduleCheck = (delay) => {
828
- if (disposed) {
829
- return;
830
- }
831
-
832
- setTimeout(() => {
833
- Gateway.invoke(this._readPositionsEndpoint, { portfolio: portfolio, position: position, includePreviousPrice: false })
834
- .then((positions) => {
835
- const p = positions.find(p => p.position === position);
836
-
837
- if (is.object(p)) {
838
- if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
839
- scheduleCheck(delay + 1000);
840
- } else {
841
- resolveCallback(p);
842
- }
843
- } else {
844
- resolveCallback(null);
845
- }
846
- }).catch((e) => {
847
- scheduleCheck(delay + 5000);
848
- });
849
- }, delay);
850
- };
851
-
852
- scheduleCheck(2500);
853
- });
854
-
855
- return [ completionPromise, cancelFunction ];
856
- }
857
-
858
- /**
859
- * Returns an array with two items. The fist item is a promise which resolves
860
- * as soon as a portfolio's end-of-day valuation calculations have finished.
861
- * The seconds is a function which cancels the observation when invoked.
862
- *
863
- * @public
864
- * @param {String} portfolio
865
- * @returns {Array}
866
- */
867
- observeValuationsForPortfolio(portfolio) {
868
- let disposed = false;
869
-
870
- const cancelFunction = () => {
871
- disposed = true;
872
- };
873
-
874
- const completionPromise = promise.build((resolveCallback) => {
875
- assert.argumentIsRequired(portfolio, 'portfolio', String);
876
-
877
- const scheduleCheck = (delay) => {
878
- if (disposed) {
879
- return;
880
- }
881
-
882
- setTimeout(() => {
883
- Gateway.invoke(this._readPortfoliosEndpoint, { portfolio: portfolio })
884
- .then((portfolios) => {
885
- const p = portfolios[0];
886
-
887
- if (is.object(p)) {
888
- if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
889
- scheduleCheck(delay + 1000);
890
- } else {
891
- resolveCallback(p);
892
- }
893
- } else {
894
- resolveCallback(null);
895
- }
896
- }).catch((e) => {
897
- scheduleCheck(delay + 5000);
898
- });
899
- }, delay);
900
- };
901
-
902
- scheduleCheck(2500);
903
- });
904
-
905
- return [ completionPromise, cancelFunction ];
906
- }
907
-
908
869
  /**
909
870
  * Deletes a position.
910
871
  *
@@ -974,6 +935,34 @@ module.exports = (() => {
974
935
  });
975
936
  }
976
937
 
938
+ /**
939
+ * Switch the reinvestment strategy for a single transaction.
940
+ *
941
+ * @public
942
+ * @param {Object} transaction
943
+ * @param {TransactionType} type
944
+ * @returns {Promise<TransactionMutateResult>}
945
+ */
946
+ switchTransaction(transaction, type) {
947
+ return Promise.resolve()
948
+ .then(() => {
949
+ checkStart.call(this);
950
+
951
+ assert.argumentIsRequired(transaction, 'transaction', Object);
952
+ assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
953
+ assert.argumentIsRequired(transaction.position, 'transaction.position', String);
954
+ assert.argumentIsRequired(transaction.sequence, 'transaction.sequence', Number);
955
+ assert.argumentIsRequired(type, type, TransactionType, 'TransactionType');
956
+
957
+ const schema = getTransactionSchema(transaction);
958
+ const payload = schema.schema.format(transaction);
959
+
960
+ payload.switch = type;
961
+
962
+ return Gateway.invoke(this._switchTransactionEndpoint, payload);
963
+ });
964
+ }
965
+
977
966
  /**
978
967
  * Deletes a transaction.
979
968
  *
@@ -1456,7 +1445,7 @@ module.exports = (() => {
1456
1445
  }
1457
1446
  });
1458
1447
 
1459
- const responseInterceptorForVersion = ResponseInterceptor.fromDelegate((response, ignored) => {
1448
+ const responseInterceptorForDeserialization = ResponseInterceptor.fromDelegate((response, ignored) => {
1460
1449
  try {
1461
1450
  return JSON.parse(response.data);
1462
1451
  } catch (e) {
@@ -1524,5 +1513,14 @@ module.exports = (() => {
1524
1513
  * @property {Boolean} replaced - If true, the position (and position summaries) need to be replaced.
1525
1514
  */
1526
1515
 
1516
+ /**
1517
+ * The result of valuations availability.
1518
+ *
1519
+ * @typedef ValuationsAvailabilityResult
1520
+ * @type {Object}
1521
+ * @property {Boolean} available - If true, portfolio valuations are up-to-date and ready.
1522
+ * @property {String[]} positions - Array of position id's that are in recalculation state.
1523
+ */
1524
+
1527
1525
  return PortfolioGateway;
1528
1526
  })();
package/lib/index.js CHANGED
@@ -7,6 +7,6 @@ module.exports = (() => {
7
7
  return {
8
8
  JwtProvider: JwtProvider,
9
9
  PortfolioGateway: PortfolioGateway,
10
- version: '5.0.1'
10
+ version: '5.1.0'
11
11
  };
12
12
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-client-js",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "description": "JavaScript library for interfacing with Barchart's Portfolio API",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -1,3 +0,0 @@
1
- **Breaking Changes**
2
-
3
- * The HTTP path structure of the remote service changed. No fucntional changes were made to the SDK.