@barchart/portfolio-client-js 1.2.19 → 1.2.22
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/example/example.js +85 -37
- package/lib/gateway/PortfolioGateway.js +50 -8
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/example/example.js
CHANGED
|
@@ -131,7 +131,8 @@ var assert = require('@barchart/common-js/lang/assert'),
|
|
|
131
131
|
Day = require('@barchart/common-js/lang/Day'),
|
|
132
132
|
Disposable = require('@barchart/common-js/lang/Disposable'),
|
|
133
133
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
134
|
-
is = require('@barchart/common-js/lang/is')
|
|
134
|
+
is = require('@barchart/common-js/lang/is'),
|
|
135
|
+
promise = require('@barchart/common-js/lang/promise');
|
|
135
136
|
|
|
136
137
|
var TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType');
|
|
137
138
|
|
|
@@ -191,6 +192,8 @@ module.exports = function () {
|
|
|
191
192
|
requestInterceptorToUse = RequestInterceptor.EMPTY;
|
|
192
193
|
}
|
|
193
194
|
|
|
195
|
+
_this._positionObservers = {};
|
|
196
|
+
|
|
194
197
|
_this._readPortfoliosEndpoint = EndpointBuilder.for('read-portfolios', 'read portfolios').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
195
198
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false);
|
|
196
199
|
}).withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE).withRequestInterceptor(requestInterceptorToUse).withResponseInterceptor(responseInterceptorForPortfolioDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
@@ -281,7 +284,7 @@ module.exports = function () {
|
|
|
281
284
|
* Returns a description of the environment (e.g. development or production).
|
|
282
285
|
*
|
|
283
286
|
* @public
|
|
284
|
-
* @
|
|
287
|
+
* @returns {*}
|
|
285
288
|
*/
|
|
286
289
|
|
|
287
290
|
|
|
@@ -321,7 +324,7 @@ module.exports = function () {
|
|
|
321
324
|
*
|
|
322
325
|
* @public
|
|
323
326
|
* @param {String=} portfolio
|
|
324
|
-
* @
|
|
327
|
+
* @returns {Promise.<Portfolio[]>}
|
|
325
328
|
*/
|
|
326
329
|
|
|
327
330
|
}, {
|
|
@@ -343,7 +346,7 @@ module.exports = function () {
|
|
|
343
346
|
*
|
|
344
347
|
* @public
|
|
345
348
|
* @param {Object} portfolio
|
|
346
|
-
* @
|
|
349
|
+
* @returns {Promise.<Portfolio>}
|
|
347
350
|
*/
|
|
348
351
|
|
|
349
352
|
}, {
|
|
@@ -365,7 +368,7 @@ module.exports = function () {
|
|
|
365
368
|
*
|
|
366
369
|
* @public
|
|
367
370
|
* @param {Object} portfolio
|
|
368
|
-
* @
|
|
371
|
+
* @returns {Promise.<Portfolio>}
|
|
369
372
|
*/
|
|
370
373
|
|
|
371
374
|
}, {
|
|
@@ -387,7 +390,7 @@ module.exports = function () {
|
|
|
387
390
|
*
|
|
388
391
|
* @public
|
|
389
392
|
* @param {Object} portfolio
|
|
390
|
-
* @
|
|
393
|
+
* @returns {Promise.<Portfolio>}
|
|
391
394
|
*/
|
|
392
395
|
|
|
393
396
|
}, {
|
|
@@ -409,7 +412,7 @@ module.exports = function () {
|
|
|
409
412
|
*
|
|
410
413
|
* @public
|
|
411
414
|
* @param {String} portfolio - ID of the portfolio to update
|
|
412
|
-
* @
|
|
415
|
+
* @returns {Promise.<Portfolio>}
|
|
413
416
|
*/
|
|
414
417
|
|
|
415
418
|
}, {
|
|
@@ -457,7 +460,7 @@ module.exports = function () {
|
|
|
457
460
|
*
|
|
458
461
|
* @public
|
|
459
462
|
* @param {Object} position
|
|
460
|
-
* @
|
|
463
|
+
* @returns {Promise.<Position>}
|
|
461
464
|
*/
|
|
462
465
|
|
|
463
466
|
}, {
|
|
@@ -474,6 +477,51 @@ module.exports = function () {
|
|
|
474
477
|
});
|
|
475
478
|
}
|
|
476
479
|
|
|
480
|
+
/**
|
|
481
|
+
* Returns a promise which resolves as soon as the position's lock status
|
|
482
|
+
* changes to false.
|
|
483
|
+
*
|
|
484
|
+
* @public
|
|
485
|
+
* @param {String} portfolio
|
|
486
|
+
* @param {String} position
|
|
487
|
+
* @returns {Promise}
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
}, {
|
|
491
|
+
key: 'observePositionLock',
|
|
492
|
+
value: function observePositionLock(portfolio, position) {
|
|
493
|
+
var _this10 = this;
|
|
494
|
+
|
|
495
|
+
return promise.build(function (resolveCallback) {
|
|
496
|
+
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
497
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
498
|
+
|
|
499
|
+
var scheduleCheck = function scheduleCheck(delay) {
|
|
500
|
+
setTimeout(function () {
|
|
501
|
+
Gateway.invoke(_this10._readPositionsEndpoint, { portfolio: portfolio, position: position, includePreviousPrice: false }).then(function (positions) {
|
|
502
|
+
var p = positions.find(function (p) {
|
|
503
|
+
return p.position === position;
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
if (is.object(p)) {
|
|
507
|
+
if (is.object(p.system) && is.object(p.system) && is.boolean(p.system.locked) && p.system.locked) {
|
|
508
|
+
resolveCallback(p);
|
|
509
|
+
} else {
|
|
510
|
+
scheduleCheck(5000);
|
|
511
|
+
}
|
|
512
|
+
} else {
|
|
513
|
+
resolveCallback(null);
|
|
514
|
+
}
|
|
515
|
+
}).catch(function (e) {
|
|
516
|
+
scheduleCheck(delay + 5000);
|
|
517
|
+
});
|
|
518
|
+
}, delay);
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
scheduleCheck(2500);
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
|
|
477
525
|
/**
|
|
478
526
|
* Retrieves positions for a user, a user's portfolio, or a single position.
|
|
479
527
|
*
|
|
@@ -489,10 +537,10 @@ module.exports = function () {
|
|
|
489
537
|
}, {
|
|
490
538
|
key: 'readPositionSummaries',
|
|
491
539
|
value: function readPositionSummaries(portfolio, position, frames, periods, start) {
|
|
492
|
-
var
|
|
540
|
+
var _this11 = this;
|
|
493
541
|
|
|
494
542
|
return Promise.resolve().then(function () {
|
|
495
|
-
checkStart.call(
|
|
543
|
+
checkStart.call(_this11);
|
|
496
544
|
|
|
497
545
|
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
498
546
|
assert.argumentIsOptional(position, 'position', String);
|
|
@@ -545,7 +593,7 @@ module.exports = function () {
|
|
|
545
593
|
query.start = s;
|
|
546
594
|
}
|
|
547
595
|
|
|
548
|
-
return Gateway.invoke(
|
|
596
|
+
return Gateway.invoke(_this11._readPositionSummariesEndpoint, query);
|
|
549
597
|
});
|
|
550
598
|
}
|
|
551
599
|
|
|
@@ -561,15 +609,15 @@ module.exports = function () {
|
|
|
561
609
|
}, {
|
|
562
610
|
key: 'deletePosition',
|
|
563
611
|
value: function deletePosition(portfolio, position) {
|
|
564
|
-
var
|
|
612
|
+
var _this12 = this;
|
|
565
613
|
|
|
566
614
|
return Promise.resolve().then(function () {
|
|
567
|
-
checkStart.call(
|
|
615
|
+
checkStart.call(_this12);
|
|
568
616
|
|
|
569
617
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
570
618
|
assert.argumentIsRequired(position, 'position', String);
|
|
571
619
|
|
|
572
|
-
return Gateway.invoke(
|
|
620
|
+
return Gateway.invoke(_this12._deletePositionEndpoint, { portfolio: portfolio, position: position });
|
|
573
621
|
});
|
|
574
622
|
}
|
|
575
623
|
|
|
@@ -584,10 +632,10 @@ module.exports = function () {
|
|
|
584
632
|
}, {
|
|
585
633
|
key: 'createTransaction',
|
|
586
634
|
value: function createTransaction(transaction) {
|
|
587
|
-
var
|
|
635
|
+
var _this13 = this;
|
|
588
636
|
|
|
589
637
|
return Promise.resolve().then(function () {
|
|
590
|
-
checkStart.call(
|
|
638
|
+
checkStart.call(_this13);
|
|
591
639
|
|
|
592
640
|
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
593
641
|
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
@@ -599,7 +647,7 @@ module.exports = function () {
|
|
|
599
647
|
|
|
600
648
|
var schema = getTransactionSchema(transaction);
|
|
601
649
|
|
|
602
|
-
return Gateway.invoke(
|
|
650
|
+
return Gateway.invoke(_this13._createTransactionEndpoint, schema.schema.format(transaction));
|
|
603
651
|
});
|
|
604
652
|
}
|
|
605
653
|
|
|
@@ -614,10 +662,10 @@ module.exports = function () {
|
|
|
614
662
|
}, {
|
|
615
663
|
key: 'batchTransactions',
|
|
616
664
|
value: function batchTransactions(portfolio, transactions) {
|
|
617
|
-
var
|
|
665
|
+
var _this14 = this;
|
|
618
666
|
|
|
619
667
|
return Promise.resolve().then(function () {
|
|
620
|
-
checkStart.call(
|
|
668
|
+
checkStart.call(_this14);
|
|
621
669
|
|
|
622
670
|
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
623
671
|
assert.argumentIsArray(transactions, 'transactions', Object);
|
|
@@ -642,7 +690,7 @@ module.exports = function () {
|
|
|
642
690
|
batchData.transactionItems.push(JSON.stringify(schema.schema.format(transaction)));
|
|
643
691
|
});
|
|
644
692
|
|
|
645
|
-
return Gateway.invoke(
|
|
693
|
+
return Gateway.invoke(_this14._batchTransactionEndpoint, batchData);
|
|
646
694
|
});
|
|
647
695
|
}
|
|
648
696
|
|
|
@@ -657,10 +705,10 @@ module.exports = function () {
|
|
|
657
705
|
}, {
|
|
658
706
|
key: 'editTransaction',
|
|
659
707
|
value: function editTransaction(transaction) {
|
|
660
|
-
var
|
|
708
|
+
var _this15 = this;
|
|
661
709
|
|
|
662
710
|
return Promise.resolve().then(function () {
|
|
663
|
-
checkStart.call(
|
|
711
|
+
checkStart.call(_this15);
|
|
664
712
|
|
|
665
713
|
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
666
714
|
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
@@ -669,7 +717,7 @@ module.exports = function () {
|
|
|
669
717
|
|
|
670
718
|
var schema = getTransactionSchema(transaction);
|
|
671
719
|
|
|
672
|
-
return Gateway.invoke(
|
|
720
|
+
return Gateway.invoke(_this15._editTransactionEndpoint, schema.schema.format(transaction));
|
|
673
721
|
});
|
|
674
722
|
}
|
|
675
723
|
|
|
@@ -688,10 +736,10 @@ module.exports = function () {
|
|
|
688
736
|
}, {
|
|
689
737
|
key: 'deleteTransaction',
|
|
690
738
|
value: function deleteTransaction(portfolio, position, sequence, force, echo) {
|
|
691
|
-
var
|
|
739
|
+
var _this16 = this;
|
|
692
740
|
|
|
693
741
|
return Promise.resolve().then(function () {
|
|
694
|
-
checkStart.call(
|
|
742
|
+
checkStart.call(_this16);
|
|
695
743
|
|
|
696
744
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
697
745
|
assert.argumentIsRequired(position, 'position', String);
|
|
@@ -699,7 +747,7 @@ module.exports = function () {
|
|
|
699
747
|
assert.argumentIsOptional(force, 'force', Boolean);
|
|
700
748
|
assert.argumentIsOptional(echo, 'echo', Boolean);
|
|
701
749
|
|
|
702
|
-
return Gateway.invoke(
|
|
750
|
+
return Gateway.invoke(_this16._deleteTransactionEndpoint, { portfolio: portfolio, position: position, sequence: sequence, force: is.boolean(force) && force, echo: is.boolean(echo) && echo });
|
|
703
751
|
});
|
|
704
752
|
}
|
|
705
753
|
|
|
@@ -715,15 +763,15 @@ module.exports = function () {
|
|
|
715
763
|
}, {
|
|
716
764
|
key: 'readTransactions',
|
|
717
765
|
value: function readTransactions(portfolio, position) {
|
|
718
|
-
var
|
|
766
|
+
var _this17 = this;
|
|
719
767
|
|
|
720
768
|
return Promise.resolve().then(function () {
|
|
721
|
-
checkStart.call(
|
|
769
|
+
checkStart.call(_this17);
|
|
722
770
|
|
|
723
771
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
724
772
|
assert.argumentIsOptional(position, 'position', String);
|
|
725
773
|
|
|
726
|
-
return Gateway.invoke(
|
|
774
|
+
return Gateway.invoke(_this17._readTransactionsEndpoint, { portfolio: portfolio, position: position || '*' });
|
|
727
775
|
});
|
|
728
776
|
}
|
|
729
777
|
|
|
@@ -742,10 +790,10 @@ module.exports = function () {
|
|
|
742
790
|
}, {
|
|
743
791
|
key: 'readTransactionsFormatted',
|
|
744
792
|
value: function readTransactionsFormatted(portfolio, position, startDay, endDay) {
|
|
745
|
-
var
|
|
793
|
+
var _this18 = this;
|
|
746
794
|
|
|
747
795
|
return Promise.resolve().then(function () {
|
|
748
|
-
checkStart.call(
|
|
796
|
+
checkStart.call(_this18);
|
|
749
797
|
|
|
750
798
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
751
799
|
assert.argumentIsOptional(position, 'position', String);
|
|
@@ -765,16 +813,16 @@ module.exports = function () {
|
|
|
765
813
|
payload.end = endDay;
|
|
766
814
|
}
|
|
767
815
|
|
|
768
|
-
return Gateway.invoke(
|
|
816
|
+
return Gateway.invoke(_this18._readTransactionsReportEndpoint, payload);
|
|
769
817
|
});
|
|
770
818
|
}
|
|
771
819
|
}, {
|
|
772
820
|
key: 'readTransactionsFormattedPage',
|
|
773
821
|
value: function readTransactionsFormattedPage(portfolio, position, sequence, count, descending) {
|
|
774
|
-
var
|
|
822
|
+
var _this19 = this;
|
|
775
823
|
|
|
776
824
|
return Promise.resolve().then(function () {
|
|
777
|
-
checkStart.call(
|
|
825
|
+
checkStart.call(_this19);
|
|
778
826
|
|
|
779
827
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
780
828
|
assert.argumentIsRequired(position, 'position', String);
|
|
@@ -799,7 +847,7 @@ module.exports = function () {
|
|
|
799
847
|
|
|
800
848
|
payload.descending = is.boolean(descending) && descending;
|
|
801
849
|
|
|
802
|
-
return Gateway.invoke(
|
|
850
|
+
return Gateway.invoke(_this19._readTransactionsReportEndpoint, payload);
|
|
803
851
|
});
|
|
804
852
|
}
|
|
805
853
|
|
|
@@ -1039,7 +1087,7 @@ module.exports = function () {
|
|
|
1039
1087
|
return PortfolioGateway;
|
|
1040
1088
|
}();
|
|
1041
1089
|
|
|
1042
|
-
},{"./../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":53,"@barchart/portfolio-api-common/lib/data/TransactionType":54,"@barchart/portfolio-api-common/lib/serialization/PortfolioSchema":56,"@barchart/portfolio-api-common/lib/serialization/PositionSchema":57,"@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema":58,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":59}],4:[function(require,module,exports){
|
|
1090
|
+
},{"./../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/common-js/lang/promise":42,"@barchart/portfolio-api-common/lib/data/PositionSummaryFrame":53,"@barchart/portfolio-api-common/lib/data/TransactionType":54,"@barchart/portfolio-api-common/lib/serialization/PortfolioSchema":56,"@barchart/portfolio-api-common/lib/serialization/PositionSchema":57,"@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema":58,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":59}],4:[function(require,module,exports){
|
|
1043
1091
|
'use strict';
|
|
1044
1092
|
|
|
1045
1093
|
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; }; }();
|
|
@@ -1390,7 +1438,7 @@ module.exports = function () {
|
|
|
1390
1438
|
return {
|
|
1391
1439
|
JwtGateway: JwtGateway,
|
|
1392
1440
|
PortfolioGateway: PortfolioGateway,
|
|
1393
|
-
version: '1.2.
|
|
1441
|
+
version: '1.2.22'
|
|
1394
1442
|
};
|
|
1395
1443
|
}();
|
|
1396
1444
|
|
|
@@ -2,7 +2,8 @@ const assert = require('@barchart/common-js/lang/assert'),
|
|
|
2
2
|
Day = require('@barchart/common-js/lang/Day'),
|
|
3
3
|
Disposable = require('@barchart/common-js/lang/Disposable'),
|
|
4
4
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
5
|
-
is = require('@barchart/common-js/lang/is')
|
|
5
|
+
is = require('@barchart/common-js/lang/is'),
|
|
6
|
+
promise = require('@barchart/common-js/lang/promise');
|
|
6
7
|
|
|
7
8
|
const TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType');
|
|
8
9
|
|
|
@@ -57,6 +58,8 @@ module.exports = (() => {
|
|
|
57
58
|
requestInterceptorToUse = RequestInterceptor.EMPTY;
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
this._positionObservers = { };
|
|
62
|
+
|
|
60
63
|
this._readPortfoliosEndpoint = EndpointBuilder.for('read-portfolios', 'read portfolios')
|
|
61
64
|
.withVerb(VerbType.GET)
|
|
62
65
|
.withProtocol(protocolType)
|
|
@@ -330,7 +333,7 @@ module.exports = (() => {
|
|
|
330
333
|
* Returns a description of the environment (e.g. development or production).
|
|
331
334
|
*
|
|
332
335
|
* @public
|
|
333
|
-
* @
|
|
336
|
+
* @returns {*}
|
|
334
337
|
*/
|
|
335
338
|
get environment() {
|
|
336
339
|
return this._environment;
|
|
@@ -368,7 +371,7 @@ module.exports = (() => {
|
|
|
368
371
|
*
|
|
369
372
|
* @public
|
|
370
373
|
* @param {String=} portfolio
|
|
371
|
-
* @
|
|
374
|
+
* @returns {Promise.<Portfolio[]>}
|
|
372
375
|
*/
|
|
373
376
|
readPortfolios(portfolio) {
|
|
374
377
|
return Promise.resolve()
|
|
@@ -386,7 +389,7 @@ module.exports = (() => {
|
|
|
386
389
|
*
|
|
387
390
|
* @public
|
|
388
391
|
* @param {Object} portfolio
|
|
389
|
-
* @
|
|
392
|
+
* @returns {Promise.<Portfolio>}
|
|
390
393
|
*/
|
|
391
394
|
createPortfolio(portfolio) {
|
|
392
395
|
return Promise.resolve()
|
|
@@ -404,7 +407,7 @@ module.exports = (() => {
|
|
|
404
407
|
*
|
|
405
408
|
* @public
|
|
406
409
|
* @param {Object} portfolio
|
|
407
|
-
* @
|
|
410
|
+
* @returns {Promise.<Portfolio>}
|
|
408
411
|
*/
|
|
409
412
|
importPortfolio(portfolio, transactions) {
|
|
410
413
|
return Promise.resolve()
|
|
@@ -423,7 +426,7 @@ module.exports = (() => {
|
|
|
423
426
|
*
|
|
424
427
|
* @public
|
|
425
428
|
* @param {Object} portfolio
|
|
426
|
-
* @
|
|
429
|
+
* @returns {Promise.<Portfolio>}
|
|
427
430
|
*/
|
|
428
431
|
updatePortfolio(portfolio) {
|
|
429
432
|
return Promise.resolve()
|
|
@@ -441,7 +444,7 @@ module.exports = (() => {
|
|
|
441
444
|
*
|
|
442
445
|
* @public
|
|
443
446
|
* @param {String} portfolio - ID of the portfolio to update
|
|
444
|
-
* @
|
|
447
|
+
* @returns {Promise.<Portfolio>}
|
|
445
448
|
*/
|
|
446
449
|
deletePortfolio(portfolio) {
|
|
447
450
|
return Promise.resolve()
|
|
@@ -481,7 +484,7 @@ module.exports = (() => {
|
|
|
481
484
|
*
|
|
482
485
|
* @public
|
|
483
486
|
* @param {Object} position
|
|
484
|
-
* @
|
|
487
|
+
* @returns {Promise.<Position>}
|
|
485
488
|
*/
|
|
486
489
|
updatePosition(position) {
|
|
487
490
|
return Promise.resolve()
|
|
@@ -494,6 +497,45 @@ module.exports = (() => {
|
|
|
494
497
|
});
|
|
495
498
|
}
|
|
496
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Returns a promise which resolves as soon as the position's lock status
|
|
502
|
+
* changes to false.
|
|
503
|
+
*
|
|
504
|
+
* @public
|
|
505
|
+
* @param {String} portfolio
|
|
506
|
+
* @param {String} position
|
|
507
|
+
* @returns {Promise}
|
|
508
|
+
*/
|
|
509
|
+
observePositionLock(portfolio, position) {
|
|
510
|
+
return promise.build((resolveCallback) => {
|
|
511
|
+
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
512
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
513
|
+
|
|
514
|
+
const scheduleCheck = (delay) => {
|
|
515
|
+
setTimeout(() => {
|
|
516
|
+
Gateway.invoke(this._readPositionsEndpoint, { portfolio: portfolio, position: position, includePreviousPrice: false })
|
|
517
|
+
.then((positions) => {
|
|
518
|
+
const p = positions.find(p => p.position === position);
|
|
519
|
+
|
|
520
|
+
if (is.object(p)) {
|
|
521
|
+
if (is.object(p.system) && is.object(p.system) && is.boolean(p.system.locked) && p.system.locked) {
|
|
522
|
+
resolveCallback(p);
|
|
523
|
+
} else {
|
|
524
|
+
scheduleCheck(5000);
|
|
525
|
+
}
|
|
526
|
+
} else {
|
|
527
|
+
resolveCallback(null);
|
|
528
|
+
}
|
|
529
|
+
}).catch((e) => {
|
|
530
|
+
scheduleCheck(delay + 5000);
|
|
531
|
+
});
|
|
532
|
+
}, delay);
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
scheduleCheck(2500);
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
497
539
|
/**
|
|
498
540
|
* Retrieves positions for a user, a user's portfolio, or a single position.
|
|
499
541
|
*
|
package/lib/index.js
CHANGED