@barchart/portfolio-client-js 3.4.1 → 5.0.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.
@@ -1,6 +1,5 @@
1
1
  **Breaking Changes**
2
2
 
3
-
4
3
  * The mechanism for passing JSON Web Tokens to the ```PortfolioGateway``` has changed. Consumers are now required to provide ```JwtProvider``` instances instead of a ```RequestInterceptor``` instances. Here are the specifics:
5
4
  * The ```RequestInterceptor``` argument was replaced with a ```JwtProvider``` argument on static factory functions (e.g. ```PortfolioGateway.forProduction```).
6
5
  * The ```RequestInterceptor``` argument was removed from the ```PortfolioGateway``` constructor.
@@ -0,0 +1,6 @@
1
+ **Breaking Changes**
2
+
3
+ * Renamed ```PortfolioGateway.readPositionsValues``` function to ```PortfolioGateway.readPositionValuations```.
4
+ * Renamed ```PortfolioGateway.readMarketValue``` function to ```PortfolioGateway.queryPositionValuations```.
5
+ * Renamed ```PortfolioGateway.observePositionCalculating``` function to ```PortfolioGateway.observeValuationsForPosition```.
6
+ * Renamed ```PortfolioGateway.observePortfolioCalculating``` function to ```PortfolioGateway.observeValuationsForPortfolio```.
@@ -0,0 +1,3 @@
1
+ **New Features**
2
+
3
+ * Added `sequence` parameter for the `readTransactions` function.
@@ -0,0 +1,4 @@
1
+ **Breaking Changes**
2
+
3
+ * The `PortfolioGatway.readTransactions` now accepts a `transaction` parameter.
4
+ * The `PortfolioGatway.readTransactions` no longer accepts a `sequence` parameter.
@@ -231,7 +231,7 @@ module.exports = (() => {
231
231
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
232
232
  .endpoint;
233
233
 
234
- this._readPositionsValuesEndpoint = EndpointBuilder.for('read-positions-values', 'read positions values')
234
+ this._readPositionValuationsEndpoint = EndpointBuilder.for('read-position-valuations', 'read position valuations')
235
235
  .withVerb(VerbType.GET)
236
236
  .withProtocol(protocolType)
237
237
  .withHost(host)
@@ -250,6 +250,23 @@ module.exports = (() => {
250
250
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
251
251
  .endpoint;
252
252
 
253
+ this._queryPositionValuationsEndpoint = EndpointBuilder.for('query-position-valuations', 'query position valuations')
254
+ .withVerb(VerbType.GET)
255
+ .withProtocol(protocolType)
256
+ .withHost(host)
257
+ .withPort(port)
258
+ .withPathBuilder((pb) => {
259
+ pb.withLiteralParameter('version', 'v1')
260
+ .withLiteralParameter('values', 'values');
261
+ })
262
+ .withQueryBuilder((qb) => {
263
+ qb.withVariableParameter('symbol', 'symbol', 'symbol', false);
264
+ })
265
+ .withRequestInterceptor(requestInterceptor)
266
+ .withResponseInterceptor(ResponseInterceptor.DATA)
267
+ .withErrorInterceptor(ErrorInterceptor.GENERAL)
268
+ .endpoint;
269
+
253
270
  this._readTransactionsEndpoint = EndpointBuilder.for('read-transactions', 'read transactions')
254
271
  .withVerb(VerbType.GET)
255
272
  .withProtocol(protocolType)
@@ -261,10 +278,8 @@ module.exports = (() => {
261
278
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
262
279
  .withLiteralParameter('positions', 'positions')
263
280
  .withVariableParameter('position', 'position', 'position', false)
264
- .withLiteralParameter('transactions', 'transactions');
265
- })
266
- .withQueryBuilder((qb) => {
267
- qb.withLiteralParameter('mode', 'mode', 'text');
281
+ .withLiteralParameter('transactions', 'transactions')
282
+ .withVariableParameter('transaction', 'transaction', 'transaction', false);
268
283
  })
269
284
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
270
285
  .withRequestInterceptor(requestInterceptor)
@@ -352,8 +367,7 @@ module.exports = (() => {
352
367
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
353
368
  .withLiteralParameter('positions', 'positions')
354
369
  .withVariableParameter('position', 'position', 'position', true)
355
- .withLiteralParameter('transactions', 'transactions')
356
- .withLiteralParameter('formatted', 'formatted');
370
+ .withLiteralParameter('transactions-formatted', 'transactions-formatted');
357
371
  })
358
372
  .withQueryBuilder((qb) => {
359
373
  qb.withVariableParameter('start', 'start', 'start', true, x => x.format())
@@ -424,23 +438,6 @@ module.exports = (() => {
424
438
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
425
439
  .endpoint;
426
440
 
427
- this._readMarketValueEndpoint = EndpointBuilder.for('read-market-value', 'read market value')
428
- .withVerb(VerbType.GET)
429
- .withProtocol(protocolType)
430
- .withHost(host)
431
- .withPort(port)
432
- .withPathBuilder((pb) => {
433
- pb.withLiteralParameter('version', 'v1')
434
- .withLiteralParameter('values', 'values');
435
- })
436
- .withQueryBuilder((qb) => {
437
- qb.withVariableParameter('symbol', 'symbol', 'symbol', false);
438
- })
439
- .withRequestInterceptor(requestInterceptor)
440
- .withResponseInterceptor(ResponseInterceptor.DATA)
441
- .withErrorInterceptor(ErrorInterceptor.GENERAL)
442
- .endpoint;
443
-
444
441
  this._brokerageReportUrlGenerator = (user, portfolio, frame, end) => {
445
442
  return `https://${Configuration.getBrokerageHost(host)}/reports/portfolios/${portfolio}/frames/${frame.code}/date/${end.format()}/${user}`;
446
443
  };
@@ -694,104 +691,6 @@ module.exports = (() => {
694
691
  });
695
692
  }
696
693
 
697
- /**
698
- * Returns a promise which resolves as soon as the position's calculating finishes.
699
- *
700
- * @public
701
- * @param {String} portfolio
702
- * @param {String} position
703
- * @returns {Array}
704
- */
705
- observePositionCalculating(portfolio, position) {
706
- let disposed = false;
707
-
708
- const query = promise.build((resolveCallback) => {
709
- assert.argumentIsRequired(portfolio, 'portfolio', String);
710
- assert.argumentIsRequired(position, 'position', String);
711
-
712
- const scheduleCheck = (delay) => {
713
- if (disposed) {
714
- return;
715
- }
716
-
717
- setTimeout(() => {
718
- Gateway.invoke(this._readPositionsEndpoint, { portfolio: portfolio, position: position, includePreviousPrice: false })
719
- .then((positions) => {
720
- const p = positions.find(p => p.position === position);
721
-
722
- if (is.object(p)) {
723
- if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
724
- scheduleCheck(delay + 1000);
725
- } else {
726
- resolveCallback(p);
727
- }
728
- } else {
729
- resolveCallback(null);
730
- }
731
- }).catch((e) => {
732
- scheduleCheck(delay + 5000);
733
- });
734
- }, delay);
735
- };
736
-
737
- scheduleCheck(2500);
738
- });
739
-
740
- const dispose = () => {
741
- disposed = true;
742
- };
743
-
744
- return [ query, dispose ];
745
- }
746
-
747
- /**
748
- * Returns a promise which resolves as soon as the portfolio calculating finishes.
749
- *
750
- * @public
751
- * @param {String} portfolio
752
- * @returns {Array}
753
- */
754
- observePortfolioCalculating(portfolio) {
755
- let disposed = false;
756
-
757
- const query = promise.build((resolveCallback) => {
758
- assert.argumentIsRequired(portfolio, 'portfolio', String);
759
-
760
- const scheduleCheck = (delay) => {
761
- if (disposed) {
762
- return;
763
- }
764
-
765
- setTimeout(() => {
766
- Gateway.invoke(this._readPortfoliosEndpoint, { portfolio: portfolio })
767
- .then((portfolios) => {
768
- const p = portfolios[0];
769
-
770
- if (is.object(p)) {
771
- if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
772
- scheduleCheck(delay + 1000);
773
- } else {
774
- resolveCallback(p);
775
- }
776
- } else {
777
- resolveCallback(null);
778
- }
779
- }).catch((e) => {
780
- scheduleCheck(delay + 5000);
781
- });
782
- }, delay);
783
- };
784
-
785
- scheduleCheck(2500);
786
- });
787
-
788
- const dispose = () => {
789
- disposed = true;
790
- };
791
-
792
- return [ query, dispose ];
793
- }
794
-
795
694
  /**
796
695
  * Retrieves positions for a user, a user's portfolio, or a single position.
797
696
  *
@@ -864,14 +763,14 @@ module.exports = (() => {
864
763
  }
865
764
 
866
765
  /**
867
- * Retrieves positions values for the entire portfolio or single position.
766
+ * Retrieves end-of-day position valuations for the entire portfolio or single position.
868
767
  *
869
768
  * @public
870
769
  * @param {String} portfolio
871
770
  * @param {String=} position
872
771
  * @returns {Promise<Object[]>}
873
772
  */
874
- readPositionsValues(portfolio, position) {
773
+ readPositionValuations(portfolio, position) {
875
774
  return Promise.resolve()
876
775
  .then(() => {
877
776
  checkStart.call(this);
@@ -884,10 +783,128 @@ module.exports = (() => {
884
783
  payload.portfolio = portfolio;
885
784
  payload.position = position || '*';
886
785
 
887
- return Gateway.invoke(this._readPositionsValuesEndpoint, payload);
786
+ return Gateway.invoke(this._readPositionValuationsEndpoint, payload);
787
+ });
788
+ }
789
+
790
+ /**
791
+ * Queries end-of-day position valuations across all user portfolios.
792
+ *
793
+ * @public
794
+ * @param {String} symbol
795
+ * @return {Promise<Object[]>}
796
+ */
797
+ queryPositionValuations(symbol) {
798
+ return Promise.resolve()
799
+ .then(() => {
800
+ assert.argumentIsRequired(symbol, 'symbol', String);
801
+
802
+ return Gateway.invoke(this._queryPositionValuationsEndpoint, { symbol });
888
803
  });
889
804
  }
890
805
 
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
+
891
908
  /**
892
909
  * Deletes a position.
893
910
  *
@@ -1006,17 +1023,19 @@ module.exports = (() => {
1006
1023
  * @public
1007
1024
  * @param {String} portfolio
1008
1025
  * @param {String=} position
1026
+ * @param {String=} transaction
1009
1027
  * @returns {Promise<Transaction[]>}
1010
1028
  */
1011
- readTransactions(portfolio, position) {
1029
+ readTransactions(portfolio, position, transaction) {
1012
1030
  return Promise.resolve()
1013
1031
  .then(() => {
1014
1032
  checkStart.call(this);
1015
1033
 
1016
1034
  assert.argumentIsRequired(portfolio, 'portfolio', String);
1017
1035
  assert.argumentIsOptional(position, 'position', String);
1036
+ assert.argumentIsOptional(transaction, 'transaction', String);
1018
1037
 
1019
- return Gateway.invoke(this._readTransactionsEndpoint, { portfolio: portfolio, position: position || '*' });
1038
+ return Gateway.invoke(this._readTransactionsEndpoint, { portfolio: portfolio, position: position || '*', transaction: transaction || '*' });
1020
1039
  });
1021
1040
  }
1022
1041
 
@@ -1029,7 +1048,7 @@ module.exports = (() => {
1029
1048
  * @param {String=} position
1030
1049
  * @param {Day=} startDay
1031
1050
  * @param {Day=} endDay
1032
- * @oaram {Boolean=} descending
1051
+ * @param {Boolean=} descending
1033
1052
  * @returns {Promise<Object[]>}
1034
1053
  */
1035
1054
  readTransactionsFormatted(portfolio, position, startDay, endDay, descending) {
@@ -1146,25 +1165,6 @@ module.exports = (() => {
1146
1165
  });
1147
1166
  }
1148
1167
 
1149
- /**
1150
- * Returns all market value for a symbol.
1151
- *
1152
- * @public
1153
- * @param {String} symbol
1154
- */
1155
- readMarketValue(symbol) {
1156
- return Promise.resolve()
1157
- .then(() => {
1158
- assert.argumentIsRequired(symbol, 'symbol', String);
1159
-
1160
- const payload = { };
1161
-
1162
- payload.symbol = symbol;
1163
-
1164
- return Gateway.invoke(this._readMarketValueEndpoint, payload);
1165
- });
1166
- }
1167
-
1168
1168
  /**
1169
1169
  * Generates a URL suitable for downloading a brokerage report (as a PDF).
1170
1170
  *
package/lib/index.js CHANGED
@@ -7,6 +7,6 @@ module.exports = (() => {
7
7
  return {
8
8
  JwtProvider: JwtProvider,
9
9
  PortfolioGateway: PortfolioGateway,
10
- version: '3.4.1'
10
+ version: '5.0.0'
11
11
  };
12
12
  })();
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-client-js",
3
- "version": "3.4.1",
3
+ "version": "5.0.0",
4
4
  "description": "JavaScript library for interfacing with Barchart's Portfolio API",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",