@barchart/portfolio-client-js 1.1.29 → 1.1.30
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 +79 -33
- package/lib/gateway/PortfolioGateway.js +41 -13
- 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');
|
|
@@ -215,7 +216,13 @@ module.exports = function () {
|
|
|
215
216
|
_this._readPositionSummariesEndpoint = EndpointBuilder.for('read-position-summaries', 'read position summaries').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
216
217
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('summaries', 'summaries').withVariableParameter('position', 'position', 'position', false);
|
|
217
218
|
}).withQueryBuilder(function (qb) {
|
|
218
|
-
qb.withVariableParameter('
|
|
219
|
+
qb.withVariableParameter('frames', 'frames', 'frames', true, function (frames) {
|
|
220
|
+
return frames.map(function (f) {
|
|
221
|
+
return f.code;
|
|
222
|
+
}).join();
|
|
223
|
+
}).withVariableParameter('periods', 'periods', 'periods', true).withVariableParameter('start', 'start', 'start', true, function (s) {
|
|
224
|
+
return s.format();
|
|
225
|
+
});
|
|
219
226
|
}).withRequestInterceptor(requestInterceptorToUse).withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE).withResponseInterceptor(responseInterceptorForPositionSummaryDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
220
227
|
|
|
221
228
|
_this._readTransactionsEndpoint = EndpointBuilder.for('read-transactions', 'read transactions').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
@@ -401,14 +408,15 @@ module.exports = function () {
|
|
|
401
408
|
* @public
|
|
402
409
|
* @param {String=} portfolio
|
|
403
410
|
* @param {String=} position
|
|
404
|
-
* @param {PositionSummaryFrame
|
|
411
|
+
* @param {Array.<PositionSummaryFrame>=|Array.<String>=} frames
|
|
405
412
|
* @param {Number=} periods
|
|
413
|
+
* @param {Day=|String=} start
|
|
406
414
|
* @returns {Promise.<Position[]>}
|
|
407
415
|
*/
|
|
408
416
|
|
|
409
417
|
}, {
|
|
410
418
|
key: 'readPositionSummaries',
|
|
411
|
-
value: function readPositionSummaries(portfolio, position,
|
|
419
|
+
value: function readPositionSummaries(portfolio, position, frames, periods, start) {
|
|
412
420
|
var _this8 = this;
|
|
413
421
|
|
|
414
422
|
return Promise.resolve().then(function () {
|
|
@@ -417,29 +425,54 @@ module.exports = function () {
|
|
|
417
425
|
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
418
426
|
assert.argumentIsOptional(position, 'position', String);
|
|
419
427
|
|
|
420
|
-
if (
|
|
421
|
-
|
|
428
|
+
if (is.array(frames)) {
|
|
429
|
+
if (frames.length > 0 && is.string(frames[0])) {
|
|
430
|
+
assert.argumentIsArray(frames, 'frames', String);
|
|
431
|
+
} else {
|
|
432
|
+
assert.argumentIsArray(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
433
|
+
}
|
|
434
|
+
} else {
|
|
435
|
+
if (is.string(frames)) {
|
|
436
|
+
assert.argumentIsOptional(frames, 'frames', String);
|
|
437
|
+
} else {
|
|
438
|
+
assert.argumentIsOptional(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
439
|
+
}
|
|
422
440
|
}
|
|
423
441
|
|
|
424
442
|
assert.argumentIsOptional(periods, 'periods', Number);
|
|
443
|
+
assert.argumentIsOptional(start, 'start', Day);
|
|
425
444
|
|
|
426
445
|
var query = {
|
|
427
446
|
portfolio: portfolio || '*',
|
|
428
447
|
position: position || '*'
|
|
429
448
|
};
|
|
430
449
|
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
450
|
+
if (frames) {
|
|
451
|
+
query.frames = frames.map(function (frame) {
|
|
452
|
+
if (is.string(frame)) {
|
|
453
|
+
return Enum.fromCode(PositionSummaryFrame, frame);
|
|
454
|
+
} else {
|
|
455
|
+
return frame;
|
|
456
|
+
}
|
|
457
|
+
});
|
|
437
458
|
}
|
|
438
459
|
|
|
439
460
|
if (periods) {
|
|
440
461
|
query.periods = periods;
|
|
441
462
|
}
|
|
442
463
|
|
|
464
|
+
if (start) {
|
|
465
|
+
var s = void 0;
|
|
466
|
+
|
|
467
|
+
if (is.string(start)) {
|
|
468
|
+
s = Day.parse(start);
|
|
469
|
+
} else {
|
|
470
|
+
s = start;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
query.start = s;
|
|
474
|
+
}
|
|
475
|
+
|
|
443
476
|
return Gateway.invoke(_this8._readPositionSummariesEndpoint, query);
|
|
444
477
|
});
|
|
445
478
|
}
|
|
@@ -740,7 +773,7 @@ module.exports = function () {
|
|
|
740
773
|
return PortfolioGateway;
|
|
741
774
|
}();
|
|
742
775
|
|
|
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){
|
|
776
|
+
},{"./../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
777
|
'use strict';
|
|
745
778
|
|
|
746
779
|
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 +1086,7 @@ module.exports = function () {
|
|
|
1053
1086
|
return {
|
|
1054
1087
|
JwtGateway: JwtGateway,
|
|
1055
1088
|
PortfolioGateway: PortfolioGateway,
|
|
1056
|
-
version: '1.1.
|
|
1089
|
+
version: '1.1.30'
|
|
1057
1090
|
};
|
|
1058
1091
|
}();
|
|
1059
1092
|
|
|
@@ -9482,6 +9515,7 @@ module.exports = (() => {
|
|
|
9482
9515
|
* @extends {Enum}
|
|
9483
9516
|
* @param {String} code
|
|
9484
9517
|
* @param {String} description
|
|
9518
|
+
* @param {String} display
|
|
9485
9519
|
* @param {Boolean} purchase
|
|
9486
9520
|
* @param {Boolean} sale
|
|
9487
9521
|
* @param {Boolean} income
|
|
@@ -9489,15 +9523,17 @@ module.exports = (() => {
|
|
|
9489
9523
|
* @param {Boolean} closing
|
|
9490
9524
|
*/
|
|
9491
9525
|
class TransactionType extends Enum {
|
|
9492
|
-
constructor(code, description, purchase, sale, income, opening, closing) {
|
|
9526
|
+
constructor(code, description, display, purchase, sale, income, opening, closing) {
|
|
9493
9527
|
super(code, description);
|
|
9494
9528
|
|
|
9529
|
+
assert.argumentIsRequired(display, 'display', String);
|
|
9495
9530
|
assert.argumentIsRequired(purchase, 'purchase', Boolean);
|
|
9496
9531
|
assert.argumentIsRequired(sale, 'sale', Boolean);
|
|
9497
9532
|
assert.argumentIsRequired(income, 'income', Boolean);
|
|
9498
9533
|
assert.argumentIsRequired(opening, 'opening', Boolean);
|
|
9499
9534
|
assert.argumentIsRequired(closing, 'closing', Boolean);
|
|
9500
9535
|
|
|
9536
|
+
this._display = display;
|
|
9501
9537
|
this._purchase = purchase;
|
|
9502
9538
|
this._sale = sale;
|
|
9503
9539
|
this._income = income;
|
|
@@ -9505,6 +9541,16 @@ module.exports = (() => {
|
|
|
9505
9541
|
this._closing = closing;
|
|
9506
9542
|
}
|
|
9507
9543
|
|
|
9544
|
+
/**
|
|
9545
|
+
* A human-readable description of the transaction type.
|
|
9546
|
+
*
|
|
9547
|
+
* @public
|
|
9548
|
+
* @returns {String}
|
|
9549
|
+
*/
|
|
9550
|
+
get display() {
|
|
9551
|
+
return this._display;
|
|
9552
|
+
}
|
|
9553
|
+
|
|
9508
9554
|
/**
|
|
9509
9555
|
* Indicates if the transaction was a trade.
|
|
9510
9556
|
*
|
|
@@ -9770,27 +9816,27 @@ module.exports = (() => {
|
|
|
9770
9816
|
}
|
|
9771
9817
|
}
|
|
9772
9818
|
|
|
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);
|
|
9819
|
+
const buy = new TransactionType('B', 'Buy', 'Buy', true, false, false, true, false);
|
|
9820
|
+
const sell = new TransactionType('S', 'Sell', 'Sell', false, true, false, false, true);
|
|
9821
|
+
const buyShort = new TransactionType('BS', 'Buy To Cover', 'Buy To Cover', true, false, false, false, true);
|
|
9822
|
+
const sellShort = new TransactionType('SS', 'Sell Short', 'Sell Short', false, true, false, true, false);
|
|
9823
|
+
const dividend = new TransactionType('DV', 'Dividend', 'Dividend', false, false, true, false, false);
|
|
9824
|
+
const dividendReinvest = new TransactionType('DX', 'Dividend (Reinvested)', 'Dividend Reinvest', false, false, false, true, false);
|
|
9825
|
+
const dividendStock = new TransactionType('DS', 'Dividend (Stock)', 'Dividend Stock', false, false, false, true, false);
|
|
9826
|
+
const split = new TransactionType('SP', 'Split', 'Split', false, false, false, true, false);
|
|
9827
|
+
const fee = new TransactionType('F', 'Fee', 'Fee', false, false, false, true, false);
|
|
9828
|
+
const feeUnits = new TransactionType('FU', 'Fee Units', 'Fee', false, false, false, false, false);
|
|
9783
9829
|
|
|
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);
|
|
9830
|
+
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', 'Cash Distribution', false, false, true, false, false);
|
|
9831
|
+
const distributionFund = new TransactionType('DF', 'Distribution (Units)', 'Unit Distribution', false, false, false, true, false);
|
|
9786
9832
|
|
|
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);
|
|
9833
|
+
const deposit = new TransactionType('D', 'Deposit', 'Deposit', false, false, false, true, false);
|
|
9834
|
+
const withdrawal = new TransactionType('W', 'Withdrawal', 'Withdrawal', false, false, false, false, true);
|
|
9835
|
+
const debit = new TransactionType('DR', 'Debit', 'Debit', false, false, false, false, true);
|
|
9836
|
+
const credit = new TransactionType('CR', 'Credit', 'Credit', false, false, false, true, false);
|
|
9791
9837
|
|
|
9792
|
-
const valuation = new TransactionType('V', 'Valuation', false, false, false, false, false);
|
|
9793
|
-
const income = new TransactionType('I', 'Income', false, false, true, false, false);
|
|
9838
|
+
const valuation = new TransactionType('V', 'Valuation', 'Valuation', false, false, false, false, false);
|
|
9839
|
+
const income = new TransactionType('I', 'Income', 'Income', false, false, true, false, false);
|
|
9794
9840
|
|
|
9795
9841
|
return TransactionType;
|
|
9796
9842
|
})();
|
|
@@ -10444,7 +10490,7 @@ module.exports = (() => {
|
|
|
10444
10490
|
}
|
|
10445
10491
|
|
|
10446
10492
|
toString() {
|
|
10447
|
-
return
|
|
10493
|
+
return `[TransactionSchema (code=${this.code})]`;
|
|
10448
10494
|
}
|
|
10449
10495
|
}
|
|
10450
10496
|
|
|
@@ -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');
|
|
@@ -149,8 +150,9 @@ module.exports = (() => {
|
|
|
149
150
|
.withVariableParameter('position', 'position', 'position', false);
|
|
150
151
|
})
|
|
151
152
|
.withQueryBuilder((qb) => {
|
|
152
|
-
qb.withVariableParameter('
|
|
153
|
-
.withVariableParameter('periods', 'periods', 'periods', true)
|
|
153
|
+
qb.withVariableParameter('frames', 'frames', 'frames', true, frames => frames.map(f => f.code).join())
|
|
154
|
+
.withVariableParameter('periods', 'periods', 'periods', true)
|
|
155
|
+
.withVariableParameter('start', 'start', 'start', true, s => s.format());
|
|
154
156
|
})
|
|
155
157
|
.withRequestInterceptor(requestInterceptorToUse)
|
|
156
158
|
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
@@ -192,7 +194,7 @@ module.exports = (() => {
|
|
|
192
194
|
.withLiteralParameter('transactions', 'transactions');
|
|
193
195
|
})
|
|
194
196
|
.withQueryBuilder((qb) => {
|
|
195
|
-
qb.withVariableParameter('type', 'type', 'type', false,
|
|
197
|
+
qb.withVariableParameter('type', 'type', 'type', false, i => i.code);
|
|
196
198
|
})
|
|
197
199
|
.withBody('portfolio data')
|
|
198
200
|
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
@@ -374,11 +376,12 @@ module.exports = (() => {
|
|
|
374
376
|
* @public
|
|
375
377
|
* @param {String=} portfolio
|
|
376
378
|
* @param {String=} position
|
|
377
|
-
* @param {PositionSummaryFrame
|
|
379
|
+
* @param {Array.<PositionSummaryFrame>=|Array.<String>=} frames
|
|
378
380
|
* @param {Number=} periods
|
|
381
|
+
* @param {Day=|String=} start
|
|
379
382
|
* @returns {Promise.<Position[]>}
|
|
380
383
|
*/
|
|
381
|
-
readPositionSummaries(portfolio, position,
|
|
384
|
+
readPositionSummaries(portfolio, position, frames, periods, start) {
|
|
382
385
|
return Promise.resolve()
|
|
383
386
|
.then(() => {
|
|
384
387
|
checkStart.call(this);
|
|
@@ -386,29 +389,54 @@ module.exports = (() => {
|
|
|
386
389
|
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
387
390
|
assert.argumentIsOptional(position, 'position', String);
|
|
388
391
|
|
|
389
|
-
if (
|
|
390
|
-
|
|
392
|
+
if (is.array(frames)) {
|
|
393
|
+
if (frames.length > 0 && is.string(frames[ 0 ])) {
|
|
394
|
+
assert.argumentIsArray(frames, 'frames', String);
|
|
395
|
+
} else {
|
|
396
|
+
assert.argumentIsArray(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
397
|
+
}
|
|
398
|
+
} else {
|
|
399
|
+
if (is.string(frames)) {
|
|
400
|
+
assert.argumentIsOptional(frames, 'frames', String);
|
|
401
|
+
} else {
|
|
402
|
+
assert.argumentIsOptional(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
403
|
+
}
|
|
391
404
|
}
|
|
392
405
|
|
|
393
406
|
assert.argumentIsOptional(periods, 'periods', Number);
|
|
407
|
+
assert.argumentIsOptional(start, 'start', Day);
|
|
394
408
|
|
|
395
409
|
const query = {
|
|
396
410
|
portfolio: portfolio || '*',
|
|
397
411
|
position: position || '*'
|
|
398
412
|
};
|
|
399
413
|
|
|
400
|
-
if (
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
414
|
+
if (frames) {
|
|
415
|
+
query.frames = frames.map((frame) => {
|
|
416
|
+
if (is.string(frame)) {
|
|
417
|
+
return Enum.fromCode(PositionSummaryFrame, frame);
|
|
418
|
+
} else {
|
|
419
|
+
return frame;
|
|
420
|
+
}
|
|
421
|
+
});
|
|
406
422
|
}
|
|
407
423
|
|
|
408
424
|
if (periods) {
|
|
409
425
|
query.periods = periods;
|
|
410
426
|
}
|
|
411
427
|
|
|
428
|
+
if (start) {
|
|
429
|
+
let s;
|
|
430
|
+
|
|
431
|
+
if (is.string(start)) {
|
|
432
|
+
s = Day.parse(start);
|
|
433
|
+
} else {
|
|
434
|
+
s = start;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
query.start = s;
|
|
438
|
+
}
|
|
439
|
+
|
|
412
440
|
return Gateway.invoke(this._readPositionSummariesEndpoint, query);
|
|
413
441
|
});
|
|
414
442
|
}
|
package/lib/index.js
CHANGED