@barchart/portfolio-client-js 3.3.1 → 4.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.
- package/.releases/3.0.0.md +0 -1
- package/.releases/3.3.0.md +1 -1
- package/.releases/3.4.0.md +3 -0
- package/.releases/3.4.1.md +3 -0
- package/.releases/4.0.0.md +6 -0
- package/lib/gateway/PortfolioGateway.js +140 -103
- package/lib/index.js +1 -1
- package/lib/security/{meta.js → .meta.js} +0 -0
- package/package.json +1 -1
package/.releases/3.0.0.md
CHANGED
|
@@ -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.
|
package/.releases/3.3.0.md
CHANGED
|
@@ -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```.
|
|
@@ -44,7 +44,7 @@ module.exports = (() => {
|
|
|
44
44
|
* @param {String} host - The hostname of the Portfolio web service.
|
|
45
45
|
* @param {Number} port - The TCP port number of the Portfolio web service.
|
|
46
46
|
* @param {String} environment - A description of the environment we're connecting to.
|
|
47
|
-
* @param {String=} product - A product
|
|
47
|
+
* @param {String=} product - A code for the product which is using the gateway.
|
|
48
48
|
* @extends {Disposable}
|
|
49
49
|
*/
|
|
50
50
|
class PortfolioGateway extends Disposable {
|
|
@@ -231,7 +231,7 @@ module.exports = (() => {
|
|
|
231
231
|
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
232
232
|
.endpoint;
|
|
233
233
|
|
|
234
|
-
this.
|
|
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)
|
|
@@ -677,104 +694,6 @@ module.exports = (() => {
|
|
|
677
694
|
});
|
|
678
695
|
}
|
|
679
696
|
|
|
680
|
-
/**
|
|
681
|
-
* Returns a promise which resolves as soon as the position's calculating finishes.
|
|
682
|
-
*
|
|
683
|
-
* @public
|
|
684
|
-
* @param {String} portfolio
|
|
685
|
-
* @param {String} position
|
|
686
|
-
* @returns {Array}
|
|
687
|
-
*/
|
|
688
|
-
observePositionCalculating(portfolio, position) {
|
|
689
|
-
let disposed = false;
|
|
690
|
-
|
|
691
|
-
const query = promise.build((resolveCallback) => {
|
|
692
|
-
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
693
|
-
assert.argumentIsRequired(position, 'position', String);
|
|
694
|
-
|
|
695
|
-
const scheduleCheck = (delay) => {
|
|
696
|
-
if (disposed) {
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
setTimeout(() => {
|
|
701
|
-
Gateway.invoke(this._readPositionsEndpoint, { portfolio: portfolio, position: position, includePreviousPrice: false })
|
|
702
|
-
.then((positions) => {
|
|
703
|
-
const p = positions.find(p => p.position === position);
|
|
704
|
-
|
|
705
|
-
if (is.object(p)) {
|
|
706
|
-
if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
|
|
707
|
-
scheduleCheck(delay + 1000);
|
|
708
|
-
} else {
|
|
709
|
-
resolveCallback(p);
|
|
710
|
-
}
|
|
711
|
-
} else {
|
|
712
|
-
resolveCallback(null);
|
|
713
|
-
}
|
|
714
|
-
}).catch((e) => {
|
|
715
|
-
scheduleCheck(delay + 5000);
|
|
716
|
-
});
|
|
717
|
-
}, delay);
|
|
718
|
-
};
|
|
719
|
-
|
|
720
|
-
scheduleCheck(2500);
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
const dispose = () => {
|
|
724
|
-
disposed = true;
|
|
725
|
-
};
|
|
726
|
-
|
|
727
|
-
return [ query, dispose ];
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
/**
|
|
731
|
-
* Returns a promise which resolves as soon as the portfolio calculating finishes.
|
|
732
|
-
*
|
|
733
|
-
* @public
|
|
734
|
-
* @param {String} portfolio
|
|
735
|
-
* @returns {Array}
|
|
736
|
-
*/
|
|
737
|
-
observePortfolioCalculating(portfolio) {
|
|
738
|
-
let disposed = false;
|
|
739
|
-
|
|
740
|
-
const query = promise.build((resolveCallback) => {
|
|
741
|
-
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
742
|
-
|
|
743
|
-
const scheduleCheck = (delay) => {
|
|
744
|
-
if (disposed) {
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
setTimeout(() => {
|
|
749
|
-
Gateway.invoke(this._readPortfoliosEndpoint, { portfolio: portfolio })
|
|
750
|
-
.then((portfolios) => {
|
|
751
|
-
const p = portfolios[0];
|
|
752
|
-
|
|
753
|
-
if (is.object(p)) {
|
|
754
|
-
if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
|
|
755
|
-
scheduleCheck(delay + 1000);
|
|
756
|
-
} else {
|
|
757
|
-
resolveCallback(p);
|
|
758
|
-
}
|
|
759
|
-
} else {
|
|
760
|
-
resolveCallback(null);
|
|
761
|
-
}
|
|
762
|
-
}).catch((e) => {
|
|
763
|
-
scheduleCheck(delay + 5000);
|
|
764
|
-
});
|
|
765
|
-
}, delay);
|
|
766
|
-
};
|
|
767
|
-
|
|
768
|
-
scheduleCheck(2500);
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
const dispose = () => {
|
|
772
|
-
disposed = true;
|
|
773
|
-
};
|
|
774
|
-
|
|
775
|
-
return [ query, dispose ];
|
|
776
|
-
}
|
|
777
|
-
|
|
778
697
|
/**
|
|
779
698
|
* Retrieves positions for a user, a user's portfolio, or a single position.
|
|
780
699
|
*
|
|
@@ -847,14 +766,14 @@ module.exports = (() => {
|
|
|
847
766
|
}
|
|
848
767
|
|
|
849
768
|
/**
|
|
850
|
-
* Retrieves
|
|
769
|
+
* Retrieves end-of-day position valuations for the entire portfolio or single position.
|
|
851
770
|
*
|
|
852
771
|
* @public
|
|
853
772
|
* @param {String} portfolio
|
|
854
773
|
* @param {String=} position
|
|
855
774
|
* @returns {Promise<Object[]>}
|
|
856
775
|
*/
|
|
857
|
-
|
|
776
|
+
readPositionValuations(portfolio, position) {
|
|
858
777
|
return Promise.resolve()
|
|
859
778
|
.then(() => {
|
|
860
779
|
checkStart.call(this);
|
|
@@ -867,10 +786,128 @@ module.exports = (() => {
|
|
|
867
786
|
payload.portfolio = portfolio;
|
|
868
787
|
payload.position = position || '*';
|
|
869
788
|
|
|
870
|
-
return Gateway.invoke(this.
|
|
789
|
+
return Gateway.invoke(this._readPositionValuationsEndpoint, payload);
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Queries end-of-day position valuations across all user portfolios.
|
|
795
|
+
*
|
|
796
|
+
* @public
|
|
797
|
+
* @param {String} symbol
|
|
798
|
+
* @return {Promise<Object[]>}
|
|
799
|
+
*/
|
|
800
|
+
queryPositionValuations(symbol) {
|
|
801
|
+
return Promise.resolve()
|
|
802
|
+
.then(() => {
|
|
803
|
+
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
804
|
+
|
|
805
|
+
return Gateway.invoke(this._queryPositionValuationsEndpoint, { symbol });
|
|
871
806
|
});
|
|
872
807
|
}
|
|
873
808
|
|
|
809
|
+
/**
|
|
810
|
+
* Returns an array with two items. The fist item is a promise which resolves
|
|
811
|
+
* as soon as a position's end-of-day valuation calculations have finished.
|
|
812
|
+
* The seconds is a function which cancels the observation when invoked.
|
|
813
|
+
*
|
|
814
|
+
* @public
|
|
815
|
+
* @param {String} portfolio
|
|
816
|
+
* @param {String} position
|
|
817
|
+
* @returns {Array}
|
|
818
|
+
*/
|
|
819
|
+
observeValuationsForPosition(portfolio, position) {
|
|
820
|
+
let disposed = false;
|
|
821
|
+
|
|
822
|
+
const cancelFunction = () => {
|
|
823
|
+
disposed = true;
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
const completionPromise = promise.build((resolveCallback) => {
|
|
827
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
828
|
+
assert.argumentIsRequired(position, 'position', String);
|
|
829
|
+
|
|
830
|
+
const scheduleCheck = (delay) => {
|
|
831
|
+
if (disposed) {
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
setTimeout(() => {
|
|
836
|
+
Gateway.invoke(this._readPositionsEndpoint, { portfolio: portfolio, position: position, includePreviousPrice: false })
|
|
837
|
+
.then((positions) => {
|
|
838
|
+
const p = positions.find(p => p.position === position);
|
|
839
|
+
|
|
840
|
+
if (is.object(p)) {
|
|
841
|
+
if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
|
|
842
|
+
scheduleCheck(delay + 1000);
|
|
843
|
+
} else {
|
|
844
|
+
resolveCallback(p);
|
|
845
|
+
}
|
|
846
|
+
} else {
|
|
847
|
+
resolveCallback(null);
|
|
848
|
+
}
|
|
849
|
+
}).catch((e) => {
|
|
850
|
+
scheduleCheck(delay + 5000);
|
|
851
|
+
});
|
|
852
|
+
}, delay);
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
scheduleCheck(2500);
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
return [ completionPromise, cancelFunction ];
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Returns an array with two items. The fist item is a promise which resolves
|
|
863
|
+
* as soon as a portfolio's end-of-day valuation calculations have finished.
|
|
864
|
+
* The seconds is a function which cancels the observation when invoked.
|
|
865
|
+
*
|
|
866
|
+
* @public
|
|
867
|
+
* @param {String} portfolio
|
|
868
|
+
* @returns {Array}
|
|
869
|
+
*/
|
|
870
|
+
observeValuationsForPortfolio(portfolio) {
|
|
871
|
+
let disposed = false;
|
|
872
|
+
|
|
873
|
+
const cancelFunction = () => {
|
|
874
|
+
disposed = true;
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
const completionPromise = promise.build((resolveCallback) => {
|
|
878
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
879
|
+
|
|
880
|
+
const scheduleCheck = (delay) => {
|
|
881
|
+
if (disposed) {
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
setTimeout(() => {
|
|
886
|
+
Gateway.invoke(this._readPortfoliosEndpoint, { portfolio: portfolio })
|
|
887
|
+
.then((portfolios) => {
|
|
888
|
+
const p = portfolios[0];
|
|
889
|
+
|
|
890
|
+
if (is.object(p)) {
|
|
891
|
+
if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
|
|
892
|
+
scheduleCheck(delay + 1000);
|
|
893
|
+
} else {
|
|
894
|
+
resolveCallback(p);
|
|
895
|
+
}
|
|
896
|
+
} else {
|
|
897
|
+
resolveCallback(null);
|
|
898
|
+
}
|
|
899
|
+
}).catch((e) => {
|
|
900
|
+
scheduleCheck(delay + 5000);
|
|
901
|
+
});
|
|
902
|
+
}, delay);
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
scheduleCheck(2500);
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
return [ completionPromise, cancelFunction ];
|
|
909
|
+
}
|
|
910
|
+
|
|
874
911
|
/**
|
|
875
912
|
* Deletes a position.
|
|
876
913
|
*
|
package/lib/index.js
CHANGED
|
File without changes
|