@barchart/portfolio-client-js 9.0.0 → 10.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/lib/data/.meta.js +1 -0
- package/lib/gateway/PortfolioGateway.js +318 -396
- package/lib/index.js +1 -1
- package/lib/security/JwtProvider.js +26 -28
- package/package.json +2 -2
package/lib/data/.meta.js
CHANGED
|
@@ -510,70 +510,64 @@ module.exports = (() => {
|
|
|
510
510
|
* connection has been established and other instance methods can be used.
|
|
511
511
|
*
|
|
512
512
|
* @public
|
|
513
|
+
* @async
|
|
513
514
|
* @param {JwtProvider} jwtProvider
|
|
514
515
|
* @returns {Promise<PortfolioGateway>}
|
|
515
516
|
*/
|
|
516
|
-
connect(jwtProvider) {
|
|
517
|
-
|
|
518
|
-
.then(() => {
|
|
519
|
-
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
517
|
+
async connect(jwtProvider) {
|
|
518
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
520
519
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
520
|
+
if (this._startPromise === null) {
|
|
521
|
+
this._startPromise = Promise.resolve()
|
|
522
|
+
.then(() => {
|
|
523
|
+
this._started = true;
|
|
525
524
|
|
|
526
|
-
|
|
525
|
+
this._jwtProvider = jwtProvider;
|
|
527
526
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
527
|
+
return this;
|
|
528
|
+
}).catch((e) => {
|
|
529
|
+
this._started = false;
|
|
530
|
+
this._startPromise = null;
|
|
532
531
|
|
|
533
|
-
|
|
532
|
+
this._jwtProvider = null;
|
|
534
533
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
534
|
+
throw e;
|
|
535
|
+
});
|
|
536
|
+
}
|
|
538
537
|
|
|
539
|
-
|
|
540
|
-
});
|
|
538
|
+
return this._startPromise;
|
|
541
539
|
}
|
|
542
540
|
|
|
543
541
|
/**
|
|
544
542
|
* Creates a new portfolio for the current user.
|
|
545
543
|
*
|
|
546
544
|
* @public
|
|
545
|
+
* @async
|
|
547
546
|
* @param {Schema.PortfolioCreate} portfolio - Data regarding the portfolio to create.
|
|
548
547
|
* @returns {Promise<Schema.Portfolio>}
|
|
549
548
|
*/
|
|
550
|
-
createPortfolio(portfolio) {
|
|
551
|
-
|
|
552
|
-
.then(() => {
|
|
553
|
-
checkStart.call(this);
|
|
549
|
+
async createPortfolio(portfolio) {
|
|
550
|
+
checkStart.call(this);
|
|
554
551
|
|
|
555
|
-
|
|
552
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
556
553
|
|
|
557
|
-
|
|
558
|
-
});
|
|
554
|
+
return Gateway.invoke(this._createPortfolioEndpoint, PortfolioSchema.CREATE.schema.format(portfolio));
|
|
559
555
|
}
|
|
560
556
|
|
|
561
557
|
/**
|
|
562
558
|
* Updates a portfolio.
|
|
563
559
|
*
|
|
564
560
|
* @public
|
|
561
|
+
* @async
|
|
565
562
|
* @param {Schema.PortfolioUpdate} portfolio
|
|
566
563
|
* @returns {Promise<Schema.Portfolio>}
|
|
567
564
|
*/
|
|
568
|
-
updatePortfolio(portfolio) {
|
|
569
|
-
|
|
570
|
-
.then(() => {
|
|
571
|
-
checkStart.call(this);
|
|
565
|
+
async updatePortfolio(portfolio) {
|
|
566
|
+
checkStart.call(this);
|
|
572
567
|
|
|
573
|
-
|
|
568
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
574
569
|
|
|
575
|
-
|
|
576
|
-
});
|
|
570
|
+
return Gateway.invoke(this._updatePortfolioEndpoint, PortfolioSchema.UPDATE.schema.format(portfolio));
|
|
577
571
|
}
|
|
578
572
|
|
|
579
573
|
/**
|
|
@@ -581,54 +575,48 @@ module.exports = (() => {
|
|
|
581
575
|
* deleted (e.g. positions, transactions, etc).
|
|
582
576
|
*
|
|
583
577
|
* @public
|
|
578
|
+
* @async
|
|
584
579
|
* @param {String} portfolio - The identifier of the portfolio to delete.
|
|
585
580
|
* @returns {Promise}
|
|
586
581
|
*/
|
|
587
|
-
deletePortfolio(portfolio) {
|
|
588
|
-
|
|
589
|
-
.then(() => {
|
|
590
|
-
checkStart.call(this);
|
|
582
|
+
async deletePortfolio(portfolio) {
|
|
583
|
+
checkStart.call(this);
|
|
591
584
|
|
|
592
|
-
|
|
585
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
593
586
|
|
|
594
|
-
|
|
595
|
-
});
|
|
587
|
+
return Gateway.invoke(this._deletePortfolioEndpoint, { portfolio: portfolio });
|
|
596
588
|
}
|
|
597
589
|
|
|
598
590
|
/**
|
|
599
591
|
* Reads all portfolios (or a single portfolio) for the current user.
|
|
600
592
|
*
|
|
601
593
|
* @public
|
|
594
|
+
* @async
|
|
602
595
|
* @param {String=} portfolio - A portfolio identifier. If omitted, all portfolios for the current user will be returned.
|
|
603
596
|
* @returns {Promise<Schema.Portfolio[]>}
|
|
604
597
|
*/
|
|
605
|
-
readPortfolios(portfolio) {
|
|
606
|
-
|
|
607
|
-
.then(() => {
|
|
608
|
-
checkStart.call(this);
|
|
598
|
+
async readPortfolios(portfolio) {
|
|
599
|
+
checkStart.call(this);
|
|
609
600
|
|
|
610
|
-
|
|
601
|
+
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
611
602
|
|
|
612
|
-
|
|
613
|
-
});
|
|
603
|
+
return Gateway.invoke(this._readPortfoliosEndpoint, { portfolio: portfolio || '*' });
|
|
614
604
|
}
|
|
615
605
|
|
|
616
606
|
/**
|
|
617
607
|
* Updates a position.
|
|
618
608
|
*
|
|
619
609
|
* @public
|
|
610
|
+
* @async
|
|
620
611
|
* @param {Schema.PositionUpdate} position
|
|
621
612
|
* @returns {Promise<Schema.Position>}
|
|
622
613
|
*/
|
|
623
|
-
updatePosition(position) {
|
|
624
|
-
|
|
625
|
-
.then(() => {
|
|
626
|
-
checkStart.call(this);
|
|
614
|
+
async updatePosition(position) {
|
|
615
|
+
checkStart.call(this);
|
|
627
616
|
|
|
628
|
-
|
|
617
|
+
assert.argumentIsRequired(position, 'position', Object);
|
|
629
618
|
|
|
630
|
-
|
|
631
|
-
});
|
|
619
|
+
return Gateway.invoke(this._updatePositionEndpoint, PositionSchema.UPDATE.schema.format(position));
|
|
632
620
|
}
|
|
633
621
|
|
|
634
622
|
/**
|
|
@@ -637,76 +625,69 @@ module.exports = (() => {
|
|
|
637
625
|
* may cause other positions to be be deleted — for example, a position which was spun-off).
|
|
638
626
|
*
|
|
639
627
|
* @public
|
|
628
|
+
* @async
|
|
640
629
|
* @param {String} portfolio - The identifier of the portfolio which contains the position to delete.
|
|
641
630
|
* @param {String} position - The identifier of the position to delete.
|
|
642
631
|
* @returns {Promise<Schema.Position[]>}
|
|
643
632
|
*/
|
|
644
|
-
deletePosition(portfolio, position) {
|
|
645
|
-
|
|
646
|
-
.then(() => {
|
|
647
|
-
checkStart.call(this);
|
|
633
|
+
async deletePosition(portfolio, position) {
|
|
634
|
+
checkStart.call(this);
|
|
648
635
|
|
|
649
|
-
|
|
650
|
-
|
|
636
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
637
|
+
assert.argumentIsRequired(position, 'position', String);
|
|
651
638
|
|
|
652
|
-
|
|
653
|
-
});
|
|
639
|
+
return Gateway.invoke(this._deletePositionEndpoint, { portfolio: portfolio, position: position });
|
|
654
640
|
}
|
|
655
641
|
|
|
656
|
-
|
|
657
642
|
/**
|
|
658
643
|
* Retrieves all positions for a user, a user's portfolio, or a single position.
|
|
659
644
|
*
|
|
660
645
|
* @public
|
|
646
|
+
* @async
|
|
661
647
|
* @param {String=} portfolio - The identifier of the portfolio containing the desired positions. If omitted, all positions for the current user, regardless of portfolio, will be returned.
|
|
662
648
|
* @param {String=} position - The identifier of the specific position to read. If included, the "portfolio" parameter must be specified.
|
|
663
649
|
* @param {Boolean=} includePreviousPrice
|
|
664
650
|
* @returns {Promise<Schema.Position[]>}
|
|
665
651
|
*/
|
|
666
|
-
readPositions(portfolio, position, includePreviousPrice) {
|
|
667
|
-
|
|
668
|
-
.then(() => {
|
|
669
|
-
checkStart.call(this);
|
|
652
|
+
async readPositions(portfolio, position, includePreviousPrice) {
|
|
653
|
+
checkStart.call(this);
|
|
670
654
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
655
|
+
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
656
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
657
|
+
assert.argumentIsOptional(includePreviousPrice, 'includePreviousPrice', Boolean);
|
|
674
658
|
|
|
675
|
-
|
|
676
|
-
});
|
|
659
|
+
return Gateway.invoke(this._readPositionsEndpoint, { portfolio: portfolio || '*', position: position || '*', includePreviousPrice: includePreviousPrice || false });
|
|
677
660
|
}
|
|
678
661
|
|
|
679
662
|
/**
|
|
680
663
|
* Queries positions.
|
|
681
664
|
*
|
|
682
665
|
* @public
|
|
666
|
+
* @async
|
|
683
667
|
* @ignore
|
|
684
668
|
* @param {String} symbol
|
|
685
669
|
* @param {Boolean=} open
|
|
686
670
|
* @param {PositionSchema=} schema
|
|
687
671
|
* @returns {Promise<Schema.Position[]>}
|
|
688
672
|
*/
|
|
689
|
-
queryPositionsForSymbol(symbol, open, schema) {
|
|
690
|
-
|
|
691
|
-
.then(() => {
|
|
692
|
-
checkStart.call(this);
|
|
673
|
+
async queryPositionsForSymbol(symbol, open, schema) {
|
|
674
|
+
checkStart.call(this);
|
|
693
675
|
|
|
694
|
-
|
|
695
|
-
|
|
676
|
+
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
677
|
+
assert.argumentIsOptional(open, 'open', Boolean);
|
|
696
678
|
|
|
697
|
-
|
|
679
|
+
const payload = { };
|
|
698
680
|
|
|
699
|
-
|
|
700
|
-
|
|
681
|
+
payload.portfolio = '*';
|
|
682
|
+
payload.position = '*';
|
|
701
683
|
|
|
702
|
-
|
|
684
|
+
payload.symbol = symbol;
|
|
703
685
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
686
|
+
if (open) {
|
|
687
|
+
payload.open = open;
|
|
688
|
+
}
|
|
707
689
|
|
|
708
|
-
|
|
709
|
-
});
|
|
690
|
+
return Gateway.invoke(this._readPositionsEndpoint, payload);
|
|
710
691
|
}
|
|
711
692
|
|
|
712
693
|
/**
|
|
@@ -714,12 +695,13 @@ module.exports = (() => {
|
|
|
714
695
|
* changes to false.
|
|
715
696
|
*
|
|
716
697
|
* @public
|
|
698
|
+
* @async
|
|
717
699
|
* @ignore
|
|
718
700
|
* @param {String} portfolio
|
|
719
701
|
* @param {String} position
|
|
720
702
|
* @returns {Promise}
|
|
721
703
|
*/
|
|
722
|
-
observePositionLock(portfolio, position) {
|
|
704
|
+
async observePositionLock(portfolio, position) {
|
|
723
705
|
return promise.build((resolveCallback) => {
|
|
724
706
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
725
707
|
assert.argumentIsRequired(position, 'position', String);
|
|
@@ -753,6 +735,7 @@ module.exports = (() => {
|
|
|
753
735
|
* Retrieves summaries for a user, a user's portfolio, or a single position.
|
|
754
736
|
*
|
|
755
737
|
* @public
|
|
738
|
+
* @async
|
|
756
739
|
* @ignore
|
|
757
740
|
* @param {String=} portfolio
|
|
758
741
|
* @param {String=} position
|
|
@@ -761,101 +744,96 @@ module.exports = (() => {
|
|
|
761
744
|
* @param {Day=|String=} start
|
|
762
745
|
* @returns {Promise<Schema.Position[]>}
|
|
763
746
|
*/
|
|
764
|
-
readPositionSummaries(portfolio, position, frames, periods, start) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
}
|
|
784
|
-
}
|
|
747
|
+
async readPositionSummaries(portfolio, position, frames, periods, start) {
|
|
748
|
+
checkStart.call(this);
|
|
749
|
+
|
|
750
|
+
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
751
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
752
|
+
|
|
753
|
+
if (is.array(frames)) {
|
|
754
|
+
if (frames.length > 0 && is.string(frames[ 0 ])) {
|
|
755
|
+
assert.argumentIsArray(frames, 'frames', String);
|
|
756
|
+
} else {
|
|
757
|
+
assert.argumentIsArray(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
758
|
+
}
|
|
759
|
+
} else {
|
|
760
|
+
if (is.string(frames)) {
|
|
761
|
+
assert.argumentIsOptional(frames, 'frames', String);
|
|
762
|
+
} else {
|
|
763
|
+
assert.argumentIsOptional(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
764
|
+
}
|
|
765
|
+
}
|
|
785
766
|
|
|
786
|
-
|
|
787
|
-
|
|
767
|
+
assert.argumentIsOptional(periods, 'periods', Number);
|
|
768
|
+
assert.argumentIsOptional(start, 'start', Day);
|
|
788
769
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
770
|
+
const payload = {
|
|
771
|
+
portfolio: portfolio || '*',
|
|
772
|
+
position: position || '*'
|
|
773
|
+
};
|
|
793
774
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}
|
|
801
|
-
});
|
|
775
|
+
if (frames) {
|
|
776
|
+
payload.frames = frames.map((frame) => {
|
|
777
|
+
if (is.string(frame)) {
|
|
778
|
+
return Enum.fromCode(PositionSummaryFrame, frame);
|
|
779
|
+
} else {
|
|
780
|
+
return frame;
|
|
802
781
|
}
|
|
782
|
+
});
|
|
783
|
+
}
|
|
803
784
|
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
785
|
+
if (periods) {
|
|
786
|
+
payload.periods = periods;
|
|
787
|
+
}
|
|
807
788
|
|
|
808
|
-
|
|
809
|
-
|
|
789
|
+
if (start) {
|
|
790
|
+
let s;
|
|
810
791
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
792
|
+
if (is.string(start)) {
|
|
793
|
+
s = Day.parse(start);
|
|
794
|
+
} else {
|
|
795
|
+
s = start;
|
|
796
|
+
}
|
|
816
797
|
|
|
817
|
-
|
|
818
|
-
|
|
798
|
+
payload.start = s;
|
|
799
|
+
}
|
|
819
800
|
|
|
820
|
-
|
|
821
|
-
});
|
|
801
|
+
return Gateway.invoke(this._readPositionSummariesEndpoint, payload);
|
|
822
802
|
}
|
|
823
803
|
|
|
824
804
|
/**
|
|
825
805
|
* Retrieves end-of-day valuations for the entire portfolio (or a single position).
|
|
826
806
|
*
|
|
827
807
|
* @public
|
|
808
|
+
* @async
|
|
828
809
|
* @ignore
|
|
829
810
|
* @param {String} portfolio - The identifier of the portfolio.
|
|
830
811
|
* @param {String=} position - The identifier of the position. If omitted, that valuation history will be returned for the entire portfolio (i.e. sum of valuations for all positions contained in the portfolio).
|
|
831
812
|
* @param {Boolean=} parse - If true, the result will be a {@link Schema.ValuationContainer} object. Otherwise, the result will be a JSON-formatted string.
|
|
832
813
|
* @returns {Promise<String|Schema.ValuationContainer>}
|
|
833
814
|
*/
|
|
834
|
-
readPositionValuations(portfolio, position, parse) {
|
|
835
|
-
|
|
836
|
-
.then(() => {
|
|
837
|
-
checkStart.call(this);
|
|
815
|
+
async readPositionValuations(portfolio, position, parse) {
|
|
816
|
+
checkStart.call(this);
|
|
838
817
|
|
|
839
|
-
|
|
840
|
-
|
|
818
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
819
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
841
820
|
|
|
842
|
-
|
|
821
|
+
const payload = { };
|
|
843
822
|
|
|
844
|
-
|
|
845
|
-
|
|
823
|
+
payload.portfolio = portfolio;
|
|
824
|
+
payload.position = position || '*';
|
|
846
825
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
826
|
+
return Gateway.invoke(this._readPositionValuationsEndpoint, payload)
|
|
827
|
+
.then((json) => {
|
|
828
|
+
let result;
|
|
850
829
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
830
|
+
if (parse) {
|
|
831
|
+
result = JSON.parse(json);
|
|
832
|
+
} else {
|
|
833
|
+
result = json;
|
|
834
|
+
}
|
|
856
835
|
|
|
857
|
-
|
|
858
|
-
});
|
|
836
|
+
return result;
|
|
859
837
|
});
|
|
860
838
|
}
|
|
861
839
|
|
|
@@ -863,131 +841,118 @@ module.exports = (() => {
|
|
|
863
841
|
* Retrieves values availability of the portfolio and it's positions.
|
|
864
842
|
*
|
|
865
843
|
* @public
|
|
844
|
+
* @async
|
|
866
845
|
* @ignore
|
|
867
846
|
* @param {String} portfolio
|
|
868
847
|
* @return {Promise<Schema.ValuationsAvailabilityResult>}
|
|
869
848
|
*/
|
|
870
|
-
readPositionValuationsAvailability(portfolio) {
|
|
871
|
-
|
|
872
|
-
.then(() => {
|
|
873
|
-
checkStart.call(this);
|
|
849
|
+
async readPositionValuationsAvailability(portfolio) {
|
|
850
|
+
checkStart.call(this);
|
|
874
851
|
|
|
875
|
-
|
|
852
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
876
853
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
payload.portfolio = portfolio;
|
|
880
|
-
|
|
881
|
-
return Gateway.invoke(this._readPositionValuationsAvailabilityEndpoint, payload);
|
|
882
|
-
});
|
|
854
|
+
return Gateway.invoke(this._readPositionValuationsAvailabilityEndpoint, { portfolio });
|
|
883
855
|
}
|
|
884
856
|
|
|
885
857
|
/**
|
|
886
858
|
* Queries end-of-day position valuations across all user portfolios.
|
|
887
859
|
*
|
|
888
860
|
* @public
|
|
861
|
+
* @async
|
|
889
862
|
* @ignore
|
|
890
863
|
* @param {String} symbol
|
|
891
864
|
* @return {Promise<Object[]>}
|
|
892
865
|
*/
|
|
893
|
-
queryPositionValuations(symbol) {
|
|
894
|
-
|
|
895
|
-
.then(() => {
|
|
896
|
-
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
866
|
+
async queryPositionValuations(symbol) {
|
|
867
|
+
assert.argumentIsRequired(symbol, 'symbol', String);
|
|
897
868
|
|
|
898
|
-
|
|
899
|
-
});
|
|
869
|
+
return Gateway.invoke(this._queryPositionValuationsEndpoint, { symbol });
|
|
900
870
|
}
|
|
901
871
|
|
|
902
872
|
/**
|
|
903
873
|
* Creates a new transaction.
|
|
904
874
|
*
|
|
905
875
|
* @public
|
|
876
|
+
* @async
|
|
906
877
|
* @param {Schema.TransactionCreate} transaction
|
|
907
878
|
* @param {Object=} options
|
|
908
879
|
* @returns {Promise<Schema.TransactionMutateResult>}
|
|
909
880
|
*/
|
|
910
|
-
createTransaction(transaction, options) {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
assert.argumentIsOptional(transaction.position, 'transaction.position', String);
|
|
918
|
-
assert.argumentIsOptional(options, 'options', Object);
|
|
919
|
-
|
|
920
|
-
if (!transaction.position) {
|
|
921
|
-
transaction.position = 'new';
|
|
922
|
-
}
|
|
881
|
+
async createTransaction(transaction, options) {
|
|
882
|
+
checkStart.call(this);
|
|
883
|
+
|
|
884
|
+
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
885
|
+
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
886
|
+
assert.argumentIsOptional(transaction.position, 'transaction.position', String);
|
|
887
|
+
assert.argumentIsOptional(options, 'options', Object);
|
|
923
888
|
|
|
924
|
-
|
|
889
|
+
if (!transaction.position) {
|
|
890
|
+
transaction.position = 'new';
|
|
891
|
+
}
|
|
925
892
|
|
|
926
|
-
|
|
893
|
+
const schema = getTransactionSchema(transaction);
|
|
927
894
|
|
|
928
|
-
|
|
929
|
-
payload.options = options || { };
|
|
895
|
+
const payload = { };
|
|
930
896
|
|
|
931
|
-
|
|
932
|
-
|
|
897
|
+
payload.transaction = schema.schema.format(transaction);
|
|
898
|
+
payload.options = options || { };
|
|
899
|
+
|
|
900
|
+
return Gateway.invoke(this._createTransactionEndpoint, payload);
|
|
933
901
|
}
|
|
934
902
|
|
|
935
903
|
/**
|
|
936
904
|
* Edits a transaction (e.g. change the date, price, quantity, etc).
|
|
937
905
|
*
|
|
938
906
|
* @public
|
|
907
|
+
* @async
|
|
939
908
|
* @param {Schema.Transaction} transaction
|
|
940
909
|
* @returns {Promise<Schema.TransactionMutateResult>}
|
|
941
910
|
*/
|
|
942
|
-
editTransaction(transaction) {
|
|
943
|
-
|
|
944
|
-
.then(() => {
|
|
945
|
-
checkStart.call(this);
|
|
911
|
+
async editTransaction(transaction) {
|
|
912
|
+
checkStart.call(this);
|
|
946
913
|
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
914
|
+
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
915
|
+
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
916
|
+
assert.argumentIsRequired(transaction.position, 'transaction.position', String);
|
|
917
|
+
assert.argumentIsRequired(transaction.sequence, 'transaction.sequence', Number);
|
|
951
918
|
|
|
952
|
-
|
|
919
|
+
const schema = getTransactionSchema(transaction);
|
|
953
920
|
|
|
954
|
-
|
|
955
|
-
});
|
|
921
|
+
return Gateway.invoke(this._editTransactionEndpoint, schema.schema.format(transaction));
|
|
956
922
|
}
|
|
957
923
|
|
|
958
924
|
/**
|
|
959
925
|
* Switch the reinvestment strategy for a single transaction.
|
|
960
926
|
*
|
|
961
927
|
* @public
|
|
928
|
+
* @async
|
|
962
929
|
* @ignore
|
|
963
930
|
* @param {Schema.Transaction} transaction
|
|
964
931
|
* @param {TransactionType} type
|
|
965
932
|
* @returns {Promise<Schema.TransactionMutateResult>}
|
|
966
933
|
*/
|
|
967
|
-
switchTransaction(transaction, type) {
|
|
968
|
-
|
|
969
|
-
.then(() => {
|
|
970
|
-
checkStart.call(this);
|
|
934
|
+
async switchTransaction(transaction, type) {
|
|
935
|
+
checkStart.call(this);
|
|
971
936
|
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
937
|
+
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
938
|
+
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
939
|
+
assert.argumentIsRequired(transaction.position, 'transaction.position', String);
|
|
940
|
+
assert.argumentIsRequired(transaction.sequence, 'transaction.sequence', Number);
|
|
941
|
+
assert.argumentIsRequired(type, type, TransactionType, 'TransactionType');
|
|
977
942
|
|
|
978
|
-
|
|
979
|
-
|
|
943
|
+
const schema = getTransactionSchema(transaction);
|
|
944
|
+
const payload = schema.schema.format(transaction);
|
|
980
945
|
|
|
981
|
-
|
|
946
|
+
payload.switch = type;
|
|
982
947
|
|
|
983
|
-
|
|
984
|
-
});
|
|
948
|
+
return Gateway.invoke(this._switchTransactionEndpoint, payload);
|
|
985
949
|
}
|
|
986
950
|
|
|
987
951
|
/**
|
|
988
952
|
* Deletes a transaction.
|
|
989
953
|
*
|
|
990
954
|
* @public
|
|
955
|
+
* @async
|
|
991
956
|
* @param {String} portfolio - The identifier of the portfolio which contains the targeted position.
|
|
992
957
|
* @param {String} position - The identifier of the targeted position.
|
|
993
958
|
* @param {Number} sequence - The sequence number of the transaction to delete.
|
|
@@ -996,57 +961,52 @@ module.exports = (() => {
|
|
|
996
961
|
* @param {Day=} echoEnd
|
|
997
962
|
* @returns {Promise<Schema.TransactionMutateResult>}
|
|
998
963
|
*/
|
|
999
|
-
deleteTransaction(portfolio, position, sequence, force, echoStart, echoEnd) {
|
|
1000
|
-
|
|
1001
|
-
.then(() => {
|
|
1002
|
-
checkStart.call(this);
|
|
1003
|
-
|
|
1004
|
-
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
1005
|
-
assert.argumentIsRequired(position, 'position', String);
|
|
1006
|
-
assert.argumentIsRequired(sequence, 'sequence', Number);
|
|
1007
|
-
assert.argumentIsOptional(force, 'force', Boolean);
|
|
1008
|
-
assert.argumentIsOptional(echoStart, 'echoStart', Day, 'Day');
|
|
1009
|
-
assert.argumentIsOptional(echoEnd, 'echoEnd', Day, 'Day');
|
|
1010
|
-
|
|
1011
|
-
let payload = { };
|
|
1012
|
-
|
|
1013
|
-
payload.portfolio = portfolio;
|
|
1014
|
-
payload.position = position;
|
|
1015
|
-
payload.sequence = sequence;
|
|
1016
|
-
payload.force = is.boolean(force) && force;
|
|
1017
|
-
|
|
1018
|
-
if (echoStart) {
|
|
1019
|
-
payload.echoStart = echoStart;
|
|
1020
|
-
}
|
|
964
|
+
async deleteTransaction(portfolio, position, sequence, force, echoStart, echoEnd) {
|
|
965
|
+
checkStart.call(this);
|
|
1021
966
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
967
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
968
|
+
assert.argumentIsRequired(position, 'position', String);
|
|
969
|
+
assert.argumentIsRequired(sequence, 'sequence', Number);
|
|
970
|
+
assert.argumentIsOptional(force, 'force', Boolean);
|
|
971
|
+
assert.argumentIsOptional(echoStart, 'echoStart', Day, 'Day');
|
|
972
|
+
assert.argumentIsOptional(echoEnd, 'echoEnd', Day, 'Day');
|
|
1025
973
|
|
|
1026
|
-
|
|
1027
|
-
|
|
974
|
+
let payload = { };
|
|
975
|
+
|
|
976
|
+
payload.portfolio = portfolio;
|
|
977
|
+
payload.position = position;
|
|
978
|
+
payload.sequence = sequence;
|
|
979
|
+
payload.force = is.boolean(force) && force;
|
|
980
|
+
|
|
981
|
+
if (echoStart) {
|
|
982
|
+
payload.echoStart = echoStart;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
if (echoEnd) {
|
|
986
|
+
payload.echoEnd = echoEnd;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
return Gateway.invoke(this._deleteTransactionEndpoint, payload);
|
|
1028
990
|
}
|
|
1029
991
|
|
|
1030
992
|
/**
|
|
1031
993
|
* Retrieves transactions for a portfolio, or a single position.
|
|
1032
994
|
*
|
|
1033
995
|
* @public
|
|
996
|
+
* @async
|
|
1034
997
|
* @param {String} portfolio - The identifier of the portfolio containing the desired transactions.
|
|
1035
998
|
* @param {String=} position - The identifier for the position to read transactions for. If included, the resulting transactions will be limited to the specified position. Otherwise, transactions for all positions in the portfolio, will be returned.
|
|
1036
999
|
* @param {Number=} sequence - The sequence number of the specific transaction to read. If included, both the "portfolio" and "position" parameters must be specified.
|
|
1037
1000
|
* @returns {Promise<Schema.Transaction[]>}
|
|
1038
1001
|
*/
|
|
1039
|
-
readTransactions(portfolio, position, sequence) {
|
|
1040
|
-
|
|
1041
|
-
.then(() => {
|
|
1042
|
-
checkStart.call(this);
|
|
1002
|
+
async readTransactions(portfolio, position, sequence) {
|
|
1003
|
+
checkStart.call(this);
|
|
1043
1004
|
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1005
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
1006
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
1007
|
+
assert.argumentIsOptional(sequence, 'sequence', Number);
|
|
1047
1008
|
|
|
1048
|
-
|
|
1049
|
-
});
|
|
1009
|
+
return Gateway.invoke(this._readTransactionsEndpoint, { portfolio: portfolio, position: position || '*', sequence: is.number(sequence) ? sequence.toString() : '*' });
|
|
1050
1010
|
}
|
|
1051
1011
|
|
|
1052
1012
|
/**
|
|
@@ -1054,6 +1014,7 @@ module.exports = (() => {
|
|
|
1054
1014
|
* for a portfolio, or a single position.
|
|
1055
1015
|
*
|
|
1056
1016
|
* @public
|
|
1017
|
+
* @async
|
|
1057
1018
|
* @ignore
|
|
1058
1019
|
* @param {String} portfolio
|
|
1059
1020
|
* @param {String=} position
|
|
@@ -1062,40 +1023,38 @@ module.exports = (() => {
|
|
|
1062
1023
|
* @param {Boolean=} descending
|
|
1063
1024
|
* @returns {Promise<Object[]>}
|
|
1064
1025
|
*/
|
|
1065
|
-
readTransactionsFormatted(portfolio, position, startDay, endDay, descending) {
|
|
1066
|
-
|
|
1067
|
-
.then(() => {
|
|
1068
|
-
checkStart.call(this);
|
|
1026
|
+
async readTransactionsFormatted(portfolio, position, startDay, endDay, descending) {
|
|
1027
|
+
checkStart.call(this);
|
|
1069
1028
|
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1029
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
1030
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
1031
|
+
assert.argumentIsOptional(startDay, 'startDay', Day, 'Day');
|
|
1032
|
+
assert.argumentIsOptional(endDay, 'endDay', Day, 'Day');
|
|
1033
|
+
assert.argumentIsOptional(descending, 'descending', Boolean);
|
|
1075
1034
|
|
|
1076
|
-
|
|
1035
|
+
const payload = { };
|
|
1077
1036
|
|
|
1078
|
-
|
|
1079
|
-
|
|
1037
|
+
payload.portfolio = portfolio;
|
|
1038
|
+
payload.position = position || '*';
|
|
1080
1039
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1040
|
+
if (startDay) {
|
|
1041
|
+
payload.start = startDay;
|
|
1042
|
+
}
|
|
1084
1043
|
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1044
|
+
if (endDay) {
|
|
1045
|
+
payload.end = endDay;
|
|
1046
|
+
}
|
|
1088
1047
|
|
|
1089
|
-
|
|
1048
|
+
payload.descending = is.boolean(descending) && descending;
|
|
1090
1049
|
|
|
1091
|
-
|
|
1092
|
-
});
|
|
1050
|
+
return Gateway.invoke(this._readTransactionsReportEndpoint, payload);
|
|
1093
1051
|
}
|
|
1094
1052
|
|
|
1095
1053
|
/**
|
|
1096
1054
|
* Reads a single page of formatted transactions.
|
|
1097
1055
|
*
|
|
1098
1056
|
* @public
|
|
1057
|
+
* @async
|
|
1099
1058
|
* @ignore
|
|
1100
1059
|
* @param {String} portfolio
|
|
1101
1060
|
* @param {String} position
|
|
@@ -1104,47 +1063,45 @@ module.exports = (() => {
|
|
|
1104
1063
|
* @param {Boolean=} descending
|
|
1105
1064
|
* @returns {Promise<Object[]>}
|
|
1106
1065
|
*/
|
|
1107
|
-
readTransactionsFormattedPage(portfolio, position, sequence, count, descending) {
|
|
1108
|
-
|
|
1109
|
-
.then(() => {
|
|
1110
|
-
checkStart.call(this);
|
|
1066
|
+
async readTransactionsFormattedPage(portfolio, position, sequence, count, descending) {
|
|
1067
|
+
checkStart.call(this);
|
|
1111
1068
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1069
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
1070
|
+
assert.argumentIsRequired(position, 'position', String);
|
|
1071
|
+
assert.argumentIsOptional(sequence, 'sequence', Number);
|
|
1072
|
+
assert.argumentIsOptional(count, 'count', Number);
|
|
1073
|
+
assert.argumentIsOptional(descending, 'descending', Boolean);
|
|
1117
1074
|
|
|
1118
|
-
|
|
1075
|
+
const payload = { };
|
|
1119
1076
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1077
|
+
payload.portfolio = portfolio;
|
|
1078
|
+
payload.position = position;
|
|
1122
1079
|
|
|
1123
|
-
|
|
1080
|
+
payload.page = true;
|
|
1124
1081
|
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1082
|
+
if (sequence) {
|
|
1083
|
+
payload.sequence = sequence;
|
|
1084
|
+
}
|
|
1128
1085
|
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1086
|
+
if (count) {
|
|
1087
|
+
payload.count = count;
|
|
1088
|
+
}
|
|
1132
1089
|
|
|
1133
|
-
|
|
1090
|
+
payload.descending = is.boolean(descending) && descending;
|
|
1134
1091
|
|
|
1135
|
-
|
|
1136
|
-
});
|
|
1092
|
+
return Gateway.invoke(this._readTransactionsReportEndpoint, payload);
|
|
1137
1093
|
}
|
|
1138
1094
|
|
|
1139
1095
|
/**
|
|
1140
1096
|
* Retrieves end-of-day valuations for the entire portfolio (or a single position).
|
|
1141
1097
|
*
|
|
1142
1098
|
* @public
|
|
1099
|
+
* @async
|
|
1143
1100
|
* @param {String} portfolio - The identifier of the portfolio.
|
|
1144
1101
|
* @param {String=} position - The identifier of the position. If omitted, that valuation history will be returned for the entire portfolio (i.e. sum of valuations for all positions contained in the portfolio).
|
|
1145
1102
|
* @returns {Promise<Schema.ValuationContainer>}
|
|
1146
1103
|
*/
|
|
1147
|
-
readValuations(portfolio, position) {
|
|
1104
|
+
async readValuations(portfolio, position) {
|
|
1148
1105
|
return this.readPositionValuations(portfolio, position, true);
|
|
1149
1106
|
}
|
|
1150
1107
|
|
|
@@ -1153,10 +1110,11 @@ module.exports = (() => {
|
|
|
1153
1110
|
* within a portfolio.
|
|
1154
1111
|
*
|
|
1155
1112
|
* @public
|
|
1113
|
+
* @async
|
|
1156
1114
|
* @param {String} portfolio - The identifier of the portfolio.
|
|
1157
1115
|
* @returns {Promise<Schema.ValuationsAvailabilityResult>}
|
|
1158
1116
|
*/
|
|
1159
|
-
checkValuations(portfolio) {
|
|
1117
|
+
async checkValuations(portfolio) {
|
|
1160
1118
|
return this.readPositionValuationsAvailability(portfolio);
|
|
1161
1119
|
}
|
|
1162
1120
|
|
|
@@ -1164,26 +1122,21 @@ module.exports = (() => {
|
|
|
1164
1122
|
* Returns all position summary definitions for a portfolio.
|
|
1165
1123
|
*
|
|
1166
1124
|
* @public
|
|
1125
|
+
* @async
|
|
1167
1126
|
* @ignore
|
|
1168
1127
|
* @param {String} portfolio
|
|
1169
1128
|
*/
|
|
1170
|
-
readBrokerageReportAvailability(portfolio) {
|
|
1171
|
-
|
|
1172
|
-
.then(() => {
|
|
1173
|
-
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
1174
|
-
|
|
1175
|
-
const payload = { };
|
|
1129
|
+
async readBrokerageReportAvailability(portfolio) {
|
|
1130
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
1176
1131
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
return Gateway.invoke(this._readBrokerageReportAvailabilityEndpoint, payload);
|
|
1180
|
-
});
|
|
1132
|
+
return Gateway.invoke(this._readBrokerageReportAvailabilityEndpoint, { portfolio });
|
|
1181
1133
|
}
|
|
1182
1134
|
|
|
1183
1135
|
/**
|
|
1184
1136
|
* Generates a URL suitable for downloading a brokerage report (as a PDF).
|
|
1185
1137
|
*
|
|
1186
1138
|
* @public
|
|
1139
|
+
* @async
|
|
1187
1140
|
* @ignore
|
|
1188
1141
|
* @param {String} user
|
|
1189
1142
|
* @param {String} portfolio
|
|
@@ -1191,31 +1144,26 @@ module.exports = (() => {
|
|
|
1191
1144
|
* @param {Day} end
|
|
1192
1145
|
* @return {Promise<String>}
|
|
1193
1146
|
*/
|
|
1194
|
-
getBrokerageReportUrl(user, portfolio, frame, end) {
|
|
1195
|
-
|
|
1196
|
-
.then(() => {
|
|
1197
|
-
checkStart.call(this);
|
|
1147
|
+
async getBrokerageReportUrl(user, portfolio, frame, end) {
|
|
1148
|
+
checkStart.call(this);
|
|
1198
1149
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1150
|
+
assert.argumentIsRequired(user, 'user', String);
|
|
1151
|
+
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
1152
|
+
assert.argumentIsRequired(frame, 'frame', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
1153
|
+
assert.argumentIsRequired(end, 'end', Day, 'Day');
|
|
1203
1154
|
|
|
1204
|
-
|
|
1205
|
-
});
|
|
1155
|
+
return this._brokerageReportUrlGenerator(user, portfolio, frame, end);
|
|
1206
1156
|
}
|
|
1207
1157
|
|
|
1208
1158
|
/**
|
|
1209
1159
|
* Returns current version of the Portfolio Service.
|
|
1210
1160
|
*
|
|
1211
1161
|
* @public
|
|
1162
|
+
* @async
|
|
1212
1163
|
* @returns {Promise<Object>}
|
|
1213
1164
|
*/
|
|
1214
|
-
readVersion() {
|
|
1215
|
-
return
|
|
1216
|
-
.then(() => {
|
|
1217
|
-
return Gateway.invoke(this._readVersionEndpoint);
|
|
1218
|
-
});
|
|
1165
|
+
async readVersion() {
|
|
1166
|
+
return Gateway.invoke(this._readVersionEndpoint);
|
|
1219
1167
|
}
|
|
1220
1168
|
|
|
1221
1169
|
/**
|
|
@@ -1248,78 +1196,70 @@ module.exports = (() => {
|
|
|
1248
1196
|
*
|
|
1249
1197
|
* @public
|
|
1250
1198
|
* @static
|
|
1199
|
+
* @async
|
|
1251
1200
|
* @param {JwtProvider} jwtProvider
|
|
1252
1201
|
* @param {String=} product
|
|
1253
1202
|
* @returns {Promise<PortfolioGateway>}
|
|
1254
1203
|
*/
|
|
1255
|
-
static forTest(jwtProvider, product) {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1259
|
-
assert.argumentIsOptional(product, 'product', String);
|
|
1204
|
+
static async forTest(jwtProvider, product) {
|
|
1205
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1206
|
+
assert.argumentIsOptional(product, 'product', String);
|
|
1260
1207
|
|
|
1261
|
-
|
|
1262
|
-
});
|
|
1208
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.testHost, REST_API_SECURE_PORT, 'test', product), jwtProvider);
|
|
1263
1209
|
}
|
|
1264
1210
|
|
|
1265
1211
|
/**
|
|
1266
1212
|
* Creates and starts a new {@link PortfolioGateway} for use in the private development environment.
|
|
1267
1213
|
*
|
|
1268
1214
|
* @public
|
|
1269
|
-
* @ignore
|
|
1270
1215
|
* @static
|
|
1216
|
+
* @async
|
|
1217
|
+
* @ignore
|
|
1271
1218
|
* @param {JwtProvider} jwtProvider
|
|
1272
1219
|
* @param {String=} product
|
|
1273
1220
|
* @returns {Promise<PortfolioGateway>}
|
|
1274
1221
|
*/
|
|
1275
|
-
static forDevelopment(jwtProvider, product) {
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1279
|
-
assert.argumentIsOptional(product, 'product', String);
|
|
1222
|
+
static async forDevelopment(jwtProvider, product) {
|
|
1223
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1224
|
+
assert.argumentIsOptional(product, 'product', String);
|
|
1280
1225
|
|
|
1281
|
-
|
|
1282
|
-
});
|
|
1226
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.developmentHost, REST_API_SECURE_PORT, 'development', product), jwtProvider);
|
|
1283
1227
|
}
|
|
1284
1228
|
|
|
1285
1229
|
/**
|
|
1286
1230
|
* Creates and starts a new {@link PortfolioGateway} for use in the private staging environment.
|
|
1287
1231
|
*
|
|
1288
1232
|
* @public
|
|
1289
|
-
* @ignore
|
|
1290
1233
|
* @static
|
|
1234
|
+
* @async
|
|
1235
|
+
* @ignore
|
|
1291
1236
|
* @param {JwtProvider} jwtProvider
|
|
1292
1237
|
* @param {String=} product
|
|
1293
1238
|
* @returns {Promise<PortfolioGateway>}
|
|
1294
1239
|
*/
|
|
1295
|
-
static forStaging(jwtProvider, product) {
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1299
|
-
assert.argumentIsOptional(product, 'product', String);
|
|
1240
|
+
static async forStaging(jwtProvider, product) {
|
|
1241
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1242
|
+
assert.argumentIsOptional(product, 'product', String);
|
|
1300
1243
|
|
|
1301
|
-
|
|
1302
|
-
});
|
|
1244
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.stagingHost, REST_API_SECURE_PORT, 'staging', product), jwtProvider);
|
|
1303
1245
|
}
|
|
1304
1246
|
|
|
1305
1247
|
/**
|
|
1306
1248
|
* Creates and starts a new {@link PortfolioGateway} for use in the private staging WWW environment.
|
|
1307
1249
|
*
|
|
1308
1250
|
* @public
|
|
1309
|
-
* @ignore
|
|
1310
1251
|
* @static
|
|
1252
|
+
* @async
|
|
1253
|
+
* @ignore
|
|
1311
1254
|
* @param {JwtProvider} jwtProvider
|
|
1312
1255
|
* @param {String=} product
|
|
1313
1256
|
* @returns {Promise<PortfolioGateway>}
|
|
1314
1257
|
*/
|
|
1315
|
-
static forStagingWww(jwtProvider, product) {
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1319
|
-
assert.argumentIsOptional(product, 'product', String);
|
|
1258
|
+
static async forStagingWww(jwtProvider, product) {
|
|
1259
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1260
|
+
assert.argumentIsOptional(product, 'product', String);
|
|
1320
1261
|
|
|
1321
|
-
|
|
1322
|
-
});
|
|
1262
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.stagingWwwHost, REST_API_SECURE_PORT, 'www-staging', product), jwtProvider);
|
|
1323
1263
|
}
|
|
1324
1264
|
|
|
1325
1265
|
/**
|
|
@@ -1327,18 +1267,16 @@ module.exports = (() => {
|
|
|
1327
1267
|
*
|
|
1328
1268
|
* @public
|
|
1329
1269
|
* @static
|
|
1270
|
+
* @async
|
|
1330
1271
|
* @param {JwtProvider} jwtProvider
|
|
1331
1272
|
* @param {String=} product
|
|
1332
1273
|
* @returns {Promise<PortfolioGateway>}
|
|
1333
1274
|
*/
|
|
1334
|
-
static forDemo(jwtProvider, product) {
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1338
|
-
assert.argumentIsOptional(product, 'product', String);
|
|
1275
|
+
static async forDemo(jwtProvider, product) {
|
|
1276
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1277
|
+
assert.argumentIsOptional(product, 'product', String);
|
|
1339
1278
|
|
|
1340
|
-
|
|
1341
|
-
});
|
|
1279
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.demoHost, REST_API_SECURE_PORT, 'demo', product), jwtProvider);
|
|
1342
1280
|
}
|
|
1343
1281
|
|
|
1344
1282
|
/**
|
|
@@ -1346,18 +1284,16 @@ module.exports = (() => {
|
|
|
1346
1284
|
*
|
|
1347
1285
|
* @public
|
|
1348
1286
|
* @static
|
|
1287
|
+
* @async
|
|
1349
1288
|
* @param {JwtProvider} jwtProvider
|
|
1350
1289
|
* @param {String=} product
|
|
1351
1290
|
* @returns {Promise<PortfolioGateway>}
|
|
1352
1291
|
*/
|
|
1353
|
-
static forProduction(jwtProvider, product) {
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1357
|
-
assert.argumentIsOptional(product, 'product', String);
|
|
1292
|
+
static async forProduction(jwtProvider, product) {
|
|
1293
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1294
|
+
assert.argumentIsOptional(product, 'product', String);
|
|
1358
1295
|
|
|
1359
|
-
|
|
1360
|
-
});
|
|
1296
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.productionHost, REST_API_SECURE_PORT, 'production', product), jwtProvider);
|
|
1361
1297
|
}
|
|
1362
1298
|
|
|
1363
1299
|
/**
|
|
@@ -1370,34 +1306,29 @@ module.exports = (() => {
|
|
|
1370
1306
|
* @param {String=} product
|
|
1371
1307
|
* @returns {Promise<PortfolioGateway>}
|
|
1372
1308
|
*/
|
|
1373
|
-
static forProductionWww(jwtProvider, product) {
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1377
|
-
assert.argumentIsOptional(product, 'product', String);
|
|
1309
|
+
static async forProductionWww(jwtProvider, product) {
|
|
1310
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1311
|
+
assert.argumentIsOptional(product, 'product', String);
|
|
1378
1312
|
|
|
1379
|
-
|
|
1380
|
-
});
|
|
1313
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.productionWwwHost, REST_API_SECURE_PORT, 'www-production', product), jwtProvider);
|
|
1381
1314
|
}
|
|
1382
1315
|
|
|
1383
1316
|
/**
|
|
1384
1317
|
* Creates and starts a new {@link PortfolioGateway} for use in the private admin environment.
|
|
1385
1318
|
*
|
|
1386
1319
|
* @public
|
|
1387
|
-
* @ignore
|
|
1388
1320
|
* @static
|
|
1321
|
+
* @async
|
|
1322
|
+
* @ignore
|
|
1389
1323
|
* @param {JwtProvider} jwtProvider
|
|
1390
1324
|
* @param {String=} product
|
|
1391
1325
|
* @returns {Promise<PortfolioGateway>}
|
|
1392
1326
|
*/
|
|
1393
|
-
static forAdmin(jwtProvider, product) {
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1397
|
-
assert.argumentIsOptional(product, 'product', String);
|
|
1327
|
+
static async forAdmin(jwtProvider, product) {
|
|
1328
|
+
assert.argumentIsRequired(jwtProvider, 'jwtProvider', JwtProvider, 'JwtProvider');
|
|
1329
|
+
assert.argumentIsOptional(product, 'product', String);
|
|
1398
1330
|
|
|
1399
|
-
|
|
1400
|
-
});
|
|
1331
|
+
return start(new PortfolioGateway(REST_API_SECURE_PROTOCOL, Configuration.adminHost, REST_API_SECURE_PORT, 'admin', product), jwtProvider);
|
|
1401
1332
|
}
|
|
1402
1333
|
|
|
1403
1334
|
_onDispose() {
|
|
@@ -1519,14 +1450,6 @@ module.exports = (() => {
|
|
|
1519
1450
|
}
|
|
1520
1451
|
});
|
|
1521
1452
|
|
|
1522
|
-
const responseInterceptorForWealthscopeToken = ResponseInterceptor.fromDelegate((response, ignored) => {
|
|
1523
|
-
try {
|
|
1524
|
-
return JSON.parse(response.data).token;
|
|
1525
|
-
} catch (e) {
|
|
1526
|
-
console.error('Error deserializing data', e);
|
|
1527
|
-
}
|
|
1528
|
-
});
|
|
1529
|
-
|
|
1530
1453
|
const responseInterceptorForDeserialization = ResponseInterceptor.fromDelegate((response, ignored) => {
|
|
1531
1454
|
try {
|
|
1532
1455
|
return JSON.parse(response.data);
|
|
@@ -1535,11 +1458,10 @@ module.exports = (() => {
|
|
|
1535
1458
|
}
|
|
1536
1459
|
});
|
|
1537
1460
|
|
|
1538
|
-
function start(gateway, jwtProvider) {
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
});
|
|
1461
|
+
async function start(gateway, jwtProvider) {
|
|
1462
|
+
await gateway.connect(jwtProvider);
|
|
1463
|
+
|
|
1464
|
+
return gateway;
|
|
1543
1465
|
}
|
|
1544
1466
|
|
|
1545
1467
|
function checkStart() {
|
package/lib/index.js
CHANGED
|
@@ -55,36 +55,34 @@ module.exports = (() => {
|
|
|
55
55
|
* Reads the current token, refreshing if necessary.
|
|
56
56
|
*
|
|
57
57
|
* @public
|
|
58
|
+
* @async
|
|
58
59
|
* @returns {Promise<String>}
|
|
59
60
|
*/
|
|
60
|
-
getToken() {
|
|
61
|
-
|
|
62
|
-
.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return this._tokenPromise;
|
|
87
|
-
});
|
|
61
|
+
async getToken() {
|
|
62
|
+
if (this._refreshPending) {
|
|
63
|
+
return this._tokenPromise;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (this._tokenPromise === null || this._refreshInterval === null || (this._refreshInterval > 0 && getTime() > (this._refreshTimestamp + this._refreshInterval + this._refreshJitter))) {
|
|
67
|
+
this._refreshPending = true;
|
|
68
|
+
|
|
69
|
+
this._tokenPromise = this._scheduler.backoff(() => this._tokenGenerator(), 100, 'Read JWT token', 3)
|
|
70
|
+
.then((token) => {
|
|
71
|
+
this._refreshTimestamp = getTime();
|
|
72
|
+
this._refreshPending = false;
|
|
73
|
+
|
|
74
|
+
return token;
|
|
75
|
+
}).catch((e) => {
|
|
76
|
+
this._tokenPromise = null;
|
|
77
|
+
|
|
78
|
+
this._refreshTimestamp = null;
|
|
79
|
+
this._refreshPending = false;
|
|
80
|
+
|
|
81
|
+
return Promise.reject(e);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return this._tokenPromise;
|
|
88
86
|
}
|
|
89
87
|
|
|
90
88
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barchart/portfolio-client-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "JavaScript SDK for Barchart's Portfolio Service",
|
|
5
5
|
"homepage": "https://docs.barchart.com/portfolio/#/",
|
|
6
6
|
"author": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@barchart/common-js": "^4.58.0",
|
|
32
|
-
"@barchart/portfolio-api-common": "^
|
|
32
|
+
"@barchart/portfolio-api-common": "^7.0.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@babel/core": "^7.11.1",
|