@barchart/portfolio-client-js 1.1.29 → 1.1.32
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.html +1 -1
- package/example/example.js +98 -34
- package/lib/gateway/PortfolioGateway.js +72 -16
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/example/example.html
CHANGED
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
var readPositionSummaries = function() {
|
|
159
159
|
var action = 'portfolioGateway.readPositionSummaries()';
|
|
160
160
|
|
|
161
|
-
that.gateway.readPositionSummaries(that.portfolio() || null, that.position() || null, 'YEARLY',
|
|
161
|
+
that.gateway.readPositionSummaries(that.portfolio() || null, that.position() || null, [ 'YEARLY', 'YTD' ], 1)
|
|
162
162
|
.then((data) => {
|
|
163
163
|
writeConsoleText(action, true);
|
|
164
164
|
writeConsoleObject(data);
|
package/example/example.js
CHANGED
|
@@ -128,6 +128,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
128
128
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
129
129
|
|
|
130
130
|
var assert = require('@barchart/common-js/lang/assert'),
|
|
131
|
+
Day = require('@barchart/common-js/lang/Day'),
|
|
131
132
|
Disposable = require('@barchart/common-js/lang/Disposable'),
|
|
132
133
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
133
134
|
is = require('@barchart/common-js/lang/is');
|
|
@@ -212,10 +213,20 @@ module.exports = function () {
|
|
|
212
213
|
qb.withVariableParameter('includePreviousPrice', 'includePreviousPrice', 'includePreviousPrice', true);
|
|
213
214
|
}).withRequestInterceptor(requestInterceptorToUse).withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE).withResponseInterceptor(responseInterceptorForPositionDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
214
215
|
|
|
216
|
+
_this._deletePositionEndpoint = EndpointBuilder.for('delete-portfolio', 'delete portfolios').withVerb(VerbType.DELETE).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
217
|
+
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withVariableParameter('position', 'position', 'position', false);
|
|
218
|
+
}).withRequestInterceptor(requestInterceptorToUse).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
219
|
+
|
|
215
220
|
_this._readPositionSummariesEndpoint = EndpointBuilder.for('read-position-summaries', 'read position summaries').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
216
221
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('summaries', 'summaries').withVariableParameter('position', 'position', 'position', false);
|
|
217
222
|
}).withQueryBuilder(function (qb) {
|
|
218
|
-
qb.withVariableParameter('
|
|
223
|
+
qb.withVariableParameter('frames', 'frames', 'frames', true, function (frames) {
|
|
224
|
+
return frames.map(function (f) {
|
|
225
|
+
return f.code;
|
|
226
|
+
}).join();
|
|
227
|
+
}).withVariableParameter('periods', 'periods', 'periods', true).withVariableParameter('start', 'start', 'start', true, function (s) {
|
|
228
|
+
return s.format();
|
|
229
|
+
});
|
|
219
230
|
}).withRequestInterceptor(requestInterceptorToUse).withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE).withResponseInterceptor(responseInterceptorForPositionSummaryDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
220
231
|
|
|
221
232
|
_this._readTransactionsEndpoint = EndpointBuilder.for('read-transactions', 'read transactions').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
@@ -230,7 +241,7 @@ module.exports = function () {
|
|
|
230
241
|
qb.withVariableParameter('type', 'type', 'type', false, function (i) {
|
|
231
242
|
return i.code;
|
|
232
243
|
});
|
|
233
|
-
}).withBody('portfolio data').withRequestInterceptor(
|
|
244
|
+
}).withBody('portfolio data').withRequestInterceptor(requestInterceptorToUse).withResponseInterceptor(responseInterceptorForTransactionCreateDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
234
245
|
|
|
235
246
|
_this._deleteTransactionsEndpoint = EndpointBuilder.for('read-transactions', 'read transactions').withVerb(VerbType.DELETE).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
236
247
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withVariableParameter('position', 'position', 'position', false).withLiteralParameter('transactions', 'transactions').withVariableParameter('transaction', 'transaction', 'transaction', false);
|
|
@@ -401,14 +412,15 @@ module.exports = function () {
|
|
|
401
412
|
* @public
|
|
402
413
|
* @param {String=} portfolio
|
|
403
414
|
* @param {String=} position
|
|
404
|
-
* @param {PositionSummaryFrame
|
|
415
|
+
* @param {Array.<PositionSummaryFrame>=|Array.<String>=} frames
|
|
405
416
|
* @param {Number=} periods
|
|
417
|
+
* @param {Day=|String=} start
|
|
406
418
|
* @returns {Promise.<Position[]>}
|
|
407
419
|
*/
|
|
408
420
|
|
|
409
421
|
}, {
|
|
410
422
|
key: 'readPositionSummaries',
|
|
411
|
-
value: function readPositionSummaries(portfolio, position,
|
|
423
|
+
value: function readPositionSummaries(portfolio, position, frames, periods, start) {
|
|
412
424
|
var _this8 = this;
|
|
413
425
|
|
|
414
426
|
return Promise.resolve().then(function () {
|
|
@@ -417,29 +429,54 @@ module.exports = function () {
|
|
|
417
429
|
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
418
430
|
assert.argumentIsOptional(position, 'position', String);
|
|
419
431
|
|
|
420
|
-
if (
|
|
421
|
-
|
|
432
|
+
if (is.array(frames)) {
|
|
433
|
+
if (frames.length > 0 && is.string(frames[0])) {
|
|
434
|
+
assert.argumentIsArray(frames, 'frames', String);
|
|
435
|
+
} else {
|
|
436
|
+
assert.argumentIsArray(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
437
|
+
}
|
|
438
|
+
} else {
|
|
439
|
+
if (is.string(frames)) {
|
|
440
|
+
assert.argumentIsOptional(frames, 'frames', String);
|
|
441
|
+
} else {
|
|
442
|
+
assert.argumentIsOptional(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
443
|
+
}
|
|
422
444
|
}
|
|
423
445
|
|
|
424
446
|
assert.argumentIsOptional(periods, 'periods', Number);
|
|
447
|
+
assert.argumentIsOptional(start, 'start', Day);
|
|
425
448
|
|
|
426
449
|
var query = {
|
|
427
450
|
portfolio: portfolio || '*',
|
|
428
451
|
position: position || '*'
|
|
429
452
|
};
|
|
430
453
|
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
454
|
+
if (frames) {
|
|
455
|
+
query.frames = frames.map(function (frame) {
|
|
456
|
+
if (is.string(frame)) {
|
|
457
|
+
return Enum.fromCode(PositionSummaryFrame, frame);
|
|
458
|
+
} else {
|
|
459
|
+
return frame;
|
|
460
|
+
}
|
|
461
|
+
});
|
|
437
462
|
}
|
|
438
463
|
|
|
439
464
|
if (periods) {
|
|
440
465
|
query.periods = periods;
|
|
441
466
|
}
|
|
442
467
|
|
|
468
|
+
if (start) {
|
|
469
|
+
var s = void 0;
|
|
470
|
+
|
|
471
|
+
if (is.string(start)) {
|
|
472
|
+
s = Day.parse(start);
|
|
473
|
+
} else {
|
|
474
|
+
s = start;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
query.start = s;
|
|
478
|
+
}
|
|
479
|
+
|
|
443
480
|
return Gateway.invoke(_this8._readPositionSummariesEndpoint, query);
|
|
444
481
|
});
|
|
445
482
|
}
|
|
@@ -721,6 +758,20 @@ module.exports = function () {
|
|
|
721
758
|
}
|
|
722
759
|
});
|
|
723
760
|
|
|
761
|
+
var responseInterceptorForTransactionCreateDeserialization = ResponseInterceptor.fromDelegate(function (response, ignored) {
|
|
762
|
+
try {
|
|
763
|
+
var positions = JSON.parse(response.data.positions, PositionSchema.CLIENT.schema.getReviver());
|
|
764
|
+
var summaries = JSON.parse(response.data.summaries, PositionSummarySchema.CLIENT.schema.getReviver());
|
|
765
|
+
|
|
766
|
+
return {
|
|
767
|
+
positions: positions,
|
|
768
|
+
summaries: summaries
|
|
769
|
+
};
|
|
770
|
+
} catch (e) {
|
|
771
|
+
console.error('Error serializing transaction data', e);
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
|
|
724
775
|
function start(gateway) {
|
|
725
776
|
return gateway.start().then(function () {
|
|
726
777
|
return gateway;
|
|
@@ -740,7 +791,7 @@ module.exports = function () {
|
|
|
740
791
|
return PortfolioGateway;
|
|
741
792
|
}();
|
|
742
793
|
|
|
743
|
-
},{"./../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/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":52,"@barchart/portfolio-api-common/lib/data/TransactionType":53,"@barchart/portfolio-api-common/lib/serialization/PortfolioSchema":55,"@barchart/portfolio-api-common/lib/serialization/PositionSchema":56,"@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema":57,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":58}],4:[function(require,module,exports){
|
|
794
|
+
},{"./../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":52,"@barchart/portfolio-api-common/lib/data/TransactionType":53,"@barchart/portfolio-api-common/lib/serialization/PortfolioSchema":55,"@barchart/portfolio-api-common/lib/serialization/PositionSchema":56,"@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema":57,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":58}],4:[function(require,module,exports){
|
|
744
795
|
'use strict';
|
|
745
796
|
|
|
746
797
|
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; }; }();
|
|
@@ -1053,7 +1104,7 @@ module.exports = function () {
|
|
|
1053
1104
|
return {
|
|
1054
1105
|
JwtGateway: JwtGateway,
|
|
1055
1106
|
PortfolioGateway: PortfolioGateway,
|
|
1056
|
-
version: '1.1.
|
|
1107
|
+
version: '1.1.32'
|
|
1057
1108
|
};
|
|
1058
1109
|
}();
|
|
1059
1110
|
|
|
@@ -9482,6 +9533,7 @@ module.exports = (() => {
|
|
|
9482
9533
|
* @extends {Enum}
|
|
9483
9534
|
* @param {String} code
|
|
9484
9535
|
* @param {String} description
|
|
9536
|
+
* @param {String} display
|
|
9485
9537
|
* @param {Boolean} purchase
|
|
9486
9538
|
* @param {Boolean} sale
|
|
9487
9539
|
* @param {Boolean} income
|
|
@@ -9489,15 +9541,17 @@ module.exports = (() => {
|
|
|
9489
9541
|
* @param {Boolean} closing
|
|
9490
9542
|
*/
|
|
9491
9543
|
class TransactionType extends Enum {
|
|
9492
|
-
constructor(code, description, purchase, sale, income, opening, closing) {
|
|
9544
|
+
constructor(code, description, display, purchase, sale, income, opening, closing) {
|
|
9493
9545
|
super(code, description);
|
|
9494
9546
|
|
|
9547
|
+
assert.argumentIsRequired(display, 'display', String);
|
|
9495
9548
|
assert.argumentIsRequired(purchase, 'purchase', Boolean);
|
|
9496
9549
|
assert.argumentIsRequired(sale, 'sale', Boolean);
|
|
9497
9550
|
assert.argumentIsRequired(income, 'income', Boolean);
|
|
9498
9551
|
assert.argumentIsRequired(opening, 'opening', Boolean);
|
|
9499
9552
|
assert.argumentIsRequired(closing, 'closing', Boolean);
|
|
9500
9553
|
|
|
9554
|
+
this._display = display;
|
|
9501
9555
|
this._purchase = purchase;
|
|
9502
9556
|
this._sale = sale;
|
|
9503
9557
|
this._income = income;
|
|
@@ -9505,6 +9559,16 @@ module.exports = (() => {
|
|
|
9505
9559
|
this._closing = closing;
|
|
9506
9560
|
}
|
|
9507
9561
|
|
|
9562
|
+
/**
|
|
9563
|
+
* A human-readable description of the transaction type.
|
|
9564
|
+
*
|
|
9565
|
+
* @public
|
|
9566
|
+
* @returns {String}
|
|
9567
|
+
*/
|
|
9568
|
+
get display() {
|
|
9569
|
+
return this._display;
|
|
9570
|
+
}
|
|
9571
|
+
|
|
9508
9572
|
/**
|
|
9509
9573
|
* Indicates if the transaction was a trade.
|
|
9510
9574
|
*
|
|
@@ -9770,27 +9834,27 @@ module.exports = (() => {
|
|
|
9770
9834
|
}
|
|
9771
9835
|
}
|
|
9772
9836
|
|
|
9773
|
-
const buy = new TransactionType('B', 'Buy', true, false, false, true, false);
|
|
9774
|
-
const sell = new TransactionType('S', 'Sell', false, true, false, false, true);
|
|
9775
|
-
const buyShort = new TransactionType('BS', 'Buy To Cover', true, false, false, false, true);
|
|
9776
|
-
const sellShort = new TransactionType('SS', 'Sell Short',
|
|
9777
|
-
const dividend = new TransactionType('DV', 'Dividend', false, false, true, false, false);
|
|
9778
|
-
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', false, false, false, true, false);
|
|
9779
|
-
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', false, false, false, true, false);
|
|
9780
|
-
const split = new TransactionType('SP', 'Split', false, false, false, true, false);
|
|
9781
|
-
const fee = new TransactionType('F', 'Fee', false, false, false, true, false);
|
|
9782
|
-
const feeUnits = new TransactionType('FU', 'Fee', false, false, false, false, false);
|
|
9837
|
+
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false);
|
|
9838
|
+
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true);
|
|
9839
|
+
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true);
|
|
9840
|
+
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false);
|
|
9841
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false);
|
|
9842
|
+
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false);
|
|
9843
|
+
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false);
|
|
9844
|
+
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false);
|
|
9845
|
+
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, true, false);
|
|
9846
|
+
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, false);
|
|
9783
9847
|
|
|
9784
|
-
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', false, false, true, false, false);
|
|
9785
|
-
const distributionFund = new TransactionType('DF', 'Distribution (Units)', false, false, false, true, false);
|
|
9848
|
+
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false);
|
|
9849
|
+
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false);
|
|
9786
9850
|
|
|
9787
|
-
const deposit = new TransactionType('D', 'Deposit', false, false, false, true, false);
|
|
9788
|
-
const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false, true);
|
|
9789
|
-
const debit = new TransactionType('DR', 'Debit', false, false, false, false, true);
|
|
9790
|
-
const credit = new TransactionType('CR', 'Credit', false, false, false, true, false);
|
|
9851
|
+
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, true, false);
|
|
9852
|
+
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, true);
|
|
9853
|
+
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, true);
|
|
9854
|
+
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, true, false);
|
|
9791
9855
|
|
|
9792
|
-
const valuation = new TransactionType('V', 'Valuation', false, false, false, false, false);
|
|
9793
|
-
const income = new TransactionType('I', 'Income', false, false, true, false, false);
|
|
9856
|
+
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false);
|
|
9857
|
+
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false);
|
|
9794
9858
|
|
|
9795
9859
|
return TransactionType;
|
|
9796
9860
|
})();
|
|
@@ -10444,7 +10508,7 @@ module.exports = (() => {
|
|
|
10444
10508
|
}
|
|
10445
10509
|
|
|
10446
10510
|
toString() {
|
|
10447
|
-
return
|
|
10511
|
+
return `[TransactionSchema (code=${this.code})]`;
|
|
10448
10512
|
}
|
|
10449
10513
|
}
|
|
10450
10514
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
Day = require('@barchart/common-js/lang/Day'),
|
|
2
3
|
Disposable = require('@barchart/common-js/lang/Disposable'),
|
|
3
4
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
4
5
|
is = require('@barchart/common-js/lang/is');
|
|
@@ -137,6 +138,21 @@ module.exports = (() => {
|
|
|
137
138
|
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
138
139
|
.endpoint;
|
|
139
140
|
|
|
141
|
+
this._deletePositionEndpoint = EndpointBuilder.for('delete-portfolio', 'delete portfolios')
|
|
142
|
+
.withVerb(VerbType.DELETE)
|
|
143
|
+
.withProtocol(protocolType)
|
|
144
|
+
.withHost(host)
|
|
145
|
+
.withPort(port)
|
|
146
|
+
.withPathBuilder((pb) => {
|
|
147
|
+
pb.withLiteralParameter('portfolios', 'portfolios')
|
|
148
|
+
.withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
|
|
149
|
+
.withLiteralParameter('positions', 'positions')
|
|
150
|
+
.withVariableParameter('position', 'position', 'position', false);
|
|
151
|
+
})
|
|
152
|
+
.withRequestInterceptor(requestInterceptorToUse)
|
|
153
|
+
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
154
|
+
.endpoint;
|
|
155
|
+
|
|
140
156
|
this._readPositionSummariesEndpoint = EndpointBuilder.for('read-position-summaries', 'read position summaries')
|
|
141
157
|
.withVerb(VerbType.GET)
|
|
142
158
|
.withProtocol(protocolType)
|
|
@@ -149,8 +165,9 @@ module.exports = (() => {
|
|
|
149
165
|
.withVariableParameter('position', 'position', 'position', false);
|
|
150
166
|
})
|
|
151
167
|
.withQueryBuilder((qb) => {
|
|
152
|
-
qb.withVariableParameter('
|
|
153
|
-
.withVariableParameter('periods', 'periods', 'periods', true)
|
|
168
|
+
qb.withVariableParameter('frames', 'frames', 'frames', true, frames => frames.map(f => f.code).join())
|
|
169
|
+
.withVariableParameter('periods', 'periods', 'periods', true)
|
|
170
|
+
.withVariableParameter('start', 'start', 'start', true, s => s.format());
|
|
154
171
|
})
|
|
155
172
|
.withRequestInterceptor(requestInterceptorToUse)
|
|
156
173
|
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
@@ -192,12 +209,11 @@ module.exports = (() => {
|
|
|
192
209
|
.withLiteralParameter('transactions', 'transactions');
|
|
193
210
|
})
|
|
194
211
|
.withQueryBuilder((qb) => {
|
|
195
|
-
qb.withVariableParameter('type', 'type', 'type', false,
|
|
212
|
+
qb.withVariableParameter('type', 'type', 'type', false, i => i.code);
|
|
196
213
|
})
|
|
197
214
|
.withBody('portfolio data')
|
|
198
|
-
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
199
215
|
.withRequestInterceptor(requestInterceptorToUse)
|
|
200
|
-
.withResponseInterceptor(
|
|
216
|
+
.withResponseInterceptor(responseInterceptorForTransactionCreateDeserialization)
|
|
201
217
|
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
202
218
|
.endpoint;
|
|
203
219
|
|
|
@@ -374,11 +390,12 @@ module.exports = (() => {
|
|
|
374
390
|
* @public
|
|
375
391
|
* @param {String=} portfolio
|
|
376
392
|
* @param {String=} position
|
|
377
|
-
* @param {PositionSummaryFrame
|
|
393
|
+
* @param {Array.<PositionSummaryFrame>=|Array.<String>=} frames
|
|
378
394
|
* @param {Number=} periods
|
|
395
|
+
* @param {Day=|String=} start
|
|
379
396
|
* @returns {Promise.<Position[]>}
|
|
380
397
|
*/
|
|
381
|
-
readPositionSummaries(portfolio, position,
|
|
398
|
+
readPositionSummaries(portfolio, position, frames, periods, start) {
|
|
382
399
|
return Promise.resolve()
|
|
383
400
|
.then(() => {
|
|
384
401
|
checkStart.call(this);
|
|
@@ -386,29 +403,54 @@ module.exports = (() => {
|
|
|
386
403
|
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
387
404
|
assert.argumentIsOptional(position, 'position', String);
|
|
388
405
|
|
|
389
|
-
if (
|
|
390
|
-
|
|
406
|
+
if (is.array(frames)) {
|
|
407
|
+
if (frames.length > 0 && is.string(frames[ 0 ])) {
|
|
408
|
+
assert.argumentIsArray(frames, 'frames', String);
|
|
409
|
+
} else {
|
|
410
|
+
assert.argumentIsArray(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
411
|
+
}
|
|
412
|
+
} else {
|
|
413
|
+
if (is.string(frames)) {
|
|
414
|
+
assert.argumentIsOptional(frames, 'frames', String);
|
|
415
|
+
} else {
|
|
416
|
+
assert.argumentIsOptional(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
417
|
+
}
|
|
391
418
|
}
|
|
392
419
|
|
|
393
420
|
assert.argumentIsOptional(periods, 'periods', Number);
|
|
421
|
+
assert.argumentIsOptional(start, 'start', Day);
|
|
394
422
|
|
|
395
423
|
const query = {
|
|
396
424
|
portfolio: portfolio || '*',
|
|
397
425
|
position: position || '*'
|
|
398
426
|
};
|
|
399
427
|
|
|
400
|
-
if (
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
428
|
+
if (frames) {
|
|
429
|
+
query.frames = frames.map((frame) => {
|
|
430
|
+
if (is.string(frame)) {
|
|
431
|
+
return Enum.fromCode(PositionSummaryFrame, frame);
|
|
432
|
+
} else {
|
|
433
|
+
return frame;
|
|
434
|
+
}
|
|
435
|
+
});
|
|
406
436
|
}
|
|
407
437
|
|
|
408
438
|
if (periods) {
|
|
409
439
|
query.periods = periods;
|
|
410
440
|
}
|
|
411
441
|
|
|
442
|
+
if (start) {
|
|
443
|
+
let s;
|
|
444
|
+
|
|
445
|
+
if (is.string(start)) {
|
|
446
|
+
s = Day.parse(start);
|
|
447
|
+
} else {
|
|
448
|
+
s = start;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
query.start = s;
|
|
452
|
+
}
|
|
453
|
+
|
|
412
454
|
return Gateway.invoke(this._readPositionSummariesEndpoint, query);
|
|
413
455
|
});
|
|
414
456
|
}
|
|
@@ -605,7 +647,7 @@ module.exports = (() => {
|
|
|
605
647
|
const createPortfolioRequestInterceptor = (request) => {
|
|
606
648
|
return FailureReason.validateSchema(PortfolioSchema.CREATE, request.data)
|
|
607
649
|
.then(() => {
|
|
608
|
-
return Promise.resolve(request)
|
|
650
|
+
return Promise.resolve(request);
|
|
609
651
|
}).catch(e => {
|
|
610
652
|
console.error('Error serializing data to create a portfolio', e);
|
|
611
653
|
|
|
@@ -656,6 +698,20 @@ module.exports = (() => {
|
|
|
656
698
|
}
|
|
657
699
|
});
|
|
658
700
|
|
|
701
|
+
const responseInterceptorForTransactionCreateDeserialization = ResponseInterceptor.fromDelegate((response, ignored) => {
|
|
702
|
+
try {
|
|
703
|
+
const positions = JSON.parse(response.data.positions, PositionSchema.CLIENT.schema.getReviver());
|
|
704
|
+
const summaries = JSON.parse(response.data.summaries, PositionSummarySchema.CLIENT.schema.getReviver());
|
|
705
|
+
|
|
706
|
+
return {
|
|
707
|
+
positions: positions,
|
|
708
|
+
summaries: summaries
|
|
709
|
+
};
|
|
710
|
+
} catch (e) {
|
|
711
|
+
console.error('Error serializing transaction data', e);
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
|
|
659
715
|
function start(gateway) {
|
|
660
716
|
return gateway.start()
|
|
661
717
|
.then(() => {
|
package/lib/index.js
CHANGED