@barchart/portfolio-client-js 1.1.28 → 1.1.31
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 +78 -137
- package/lib/gateway/PortfolioGateway.js +57 -14
- 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');
|
|
@@ -170,7 +171,7 @@ module.exports = function () {
|
|
|
170
171
|
var PortfolioGateway = function (_Disposable) {
|
|
171
172
|
_inherits(PortfolioGateway, _Disposable);
|
|
172
173
|
|
|
173
|
-
function PortfolioGateway(protocol, host, port, requestInterceptor) {
|
|
174
|
+
function PortfolioGateway(protocol, host, port, environment, requestInterceptor) {
|
|
174
175
|
_classCallCheck(this, PortfolioGateway);
|
|
175
176
|
|
|
176
177
|
var _this = _possibleConstructorReturn(this, (PortfolioGateway.__proto__ || Object.getPrototypeOf(PortfolioGateway)).call(this));
|
|
@@ -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) {
|
|
@@ -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
|
}
|
|
@@ -740,7 +777,7 @@ module.exports = function () {
|
|
|
740
777
|
return PortfolioGateway;
|
|
741
778
|
}();
|
|
742
779
|
|
|
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){
|
|
780
|
+
},{"./../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
781
|
'use strict';
|
|
745
782
|
|
|
746
783
|
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 +1090,7 @@ module.exports = function () {
|
|
|
1053
1090
|
return {
|
|
1054
1091
|
JwtGateway: JwtGateway,
|
|
1055
1092
|
PortfolioGateway: PortfolioGateway,
|
|
1056
|
-
version: '1.1.
|
|
1093
|
+
version: '1.1.31'
|
|
1057
1094
|
};
|
|
1058
1095
|
}();
|
|
1059
1096
|
|
|
@@ -5520,9 +5557,9 @@ module.exports = function () {
|
|
|
5520
5557
|
assert.argumentIsRequired(a, 'a', Decimal, 'Decimal');
|
|
5521
5558
|
assert.argumentIsRequired(b, 'b', Decimal, 'Decimal');
|
|
5522
5559
|
|
|
5523
|
-
if (a._big.gt(b
|
|
5560
|
+
if (a._big.gt(b)) {
|
|
5524
5561
|
return 1;
|
|
5525
|
-
} else if (a._big.lt(b
|
|
5562
|
+
} else if (a._big.lt(b)) {
|
|
5526
5563
|
return -1;
|
|
5527
5564
|
} else {
|
|
5528
5565
|
return 0;
|
|
@@ -9108,27 +9145,15 @@ module.exports = (() => {
|
|
|
9108
9145
|
* @param {String} alternateDescription
|
|
9109
9146
|
* @param {String} code
|
|
9110
9147
|
* @param {Boolean} canReinvest
|
|
9111
|
-
* @param {Boolean} usesSymbols
|
|
9112
9148
|
*/
|
|
9113
9149
|
class InstrumentType extends Enum {
|
|
9114
|
-
constructor(code, description, alternateDescription, canReinvest
|
|
9150
|
+
constructor(code, description, alternateDescription, canReinvest) {
|
|
9115
9151
|
super(code, description);
|
|
9116
9152
|
|
|
9117
|
-
assert.argumentIsRequired(alternateDescription, 'alternateDescription', String);
|
|
9118
|
-
assert.argumentIsRequired(canReinvest, 'canReinvest', Boolean);
|
|
9119
|
-
assert.argumentIsRequired(usesSymbols, 'usesSymbols', Boolean);
|
|
9120
|
-
|
|
9121
9153
|
this._alternateDescription = alternateDescription;
|
|
9122
9154
|
this._canReinvest = canReinvest;
|
|
9123
|
-
this._usesSymbols = usesSymbols;
|
|
9124
9155
|
}
|
|
9125
9156
|
|
|
9126
|
-
/**
|
|
9127
|
-
* A human-readable description.
|
|
9128
|
-
*
|
|
9129
|
-
* @public
|
|
9130
|
-
* @return {String}
|
|
9131
|
-
*/
|
|
9132
9157
|
get alternateDescription() {
|
|
9133
9158
|
return this._alternateDescription;
|
|
9134
9159
|
}
|
|
@@ -9136,28 +9161,16 @@ module.exports = (() => {
|
|
|
9136
9161
|
/**
|
|
9137
9162
|
* Indicates if the instrument type allows automatic reinvestment.
|
|
9138
9163
|
*
|
|
9139
|
-
* @public
|
|
9140
9164
|
* @returns {Boolean}
|
|
9141
9165
|
*/
|
|
9142
9166
|
get canReinvest() {
|
|
9143
9167
|
return this._canReinvest;
|
|
9144
9168
|
}
|
|
9145
9169
|
|
|
9146
|
-
/**
|
|
9147
|
-
* Indicates if an instrument of this type can be represented by a symbol.
|
|
9148
|
-
*
|
|
9149
|
-
* @public
|
|
9150
|
-
* @returns {Boolean}
|
|
9151
|
-
*/
|
|
9152
|
-
get usesSymbols() {
|
|
9153
|
-
return this._usesSymbols;
|
|
9154
|
-
}
|
|
9155
|
-
|
|
9156
9170
|
/**
|
|
9157
9171
|
* Cash.
|
|
9158
9172
|
*
|
|
9159
9173
|
* @public
|
|
9160
|
-
* @static
|
|
9161
9174
|
* @returns {InstrumentType}
|
|
9162
9175
|
*/
|
|
9163
9176
|
static get CASH() {
|
|
@@ -9168,7 +9181,6 @@ module.exports = (() => {
|
|
|
9168
9181
|
* An equity issue.
|
|
9169
9182
|
*
|
|
9170
9183
|
* @public
|
|
9171
|
-
* @static
|
|
9172
9184
|
* @returns {InstrumentType}
|
|
9173
9185
|
*/
|
|
9174
9186
|
static get EQUITY() {
|
|
@@ -9179,7 +9191,6 @@ module.exports = (() => {
|
|
|
9179
9191
|
* A mutual fund.
|
|
9180
9192
|
*
|
|
9181
9193
|
* @public
|
|
9182
|
-
* @static
|
|
9183
9194
|
* @returns {InstrumentType}
|
|
9184
9195
|
*/
|
|
9185
9196
|
static get FUND() {
|
|
@@ -9190,7 +9201,6 @@ module.exports = (() => {
|
|
|
9190
9201
|
* An undefined asset (e.g. a house, or a collectible, or a salvaged alien spaceship).
|
|
9191
9202
|
*
|
|
9192
9203
|
* @public
|
|
9193
|
-
* @static
|
|
9194
9204
|
* @returns {InstrumentType}
|
|
9195
9205
|
*/
|
|
9196
9206
|
static get OTHER() {
|
|
@@ -9202,10 +9212,10 @@ module.exports = (() => {
|
|
|
9202
9212
|
}
|
|
9203
9213
|
}
|
|
9204
9214
|
|
|
9205
|
-
const cash = new InstrumentType('CASH', 'cash', 'Cash', false
|
|
9206
|
-
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true
|
|
9207
|
-
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true
|
|
9208
|
-
const other = new InstrumentType('OTHER', 'other', 'Other', false
|
|
9215
|
+
const cash = new InstrumentType('CASH', 'cash', 'Cash', false);
|
|
9216
|
+
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', true);
|
|
9217
|
+
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', true);
|
|
9218
|
+
const other = new InstrumentType('OTHER', 'other', 'Other', false);
|
|
9209
9219
|
|
|
9210
9220
|
return InstrumentType;
|
|
9211
9221
|
})();
|
|
@@ -9214,7 +9224,6 @@ module.exports = (() => {
|
|
|
9214
9224
|
const array = require('@barchart/common-js/lang/array'),
|
|
9215
9225
|
assert = require('@barchart/common-js/lang/assert'),
|
|
9216
9226
|
Day = require('@barchart/common-js/lang/Day'),
|
|
9217
|
-
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
9218
9227
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
9219
9228
|
is = require('@barchart/common-js/lang/is');
|
|
9220
9229
|
|
|
@@ -9230,68 +9239,23 @@ module.exports = (() => {
|
|
|
9230
9239
|
* @param {String} description
|
|
9231
9240
|
* @param {Function} rangeCalculator
|
|
9232
9241
|
* @param {Function} startDateCalculator
|
|
9233
|
-
* @param {Function} descriptionCalculator
|
|
9234
9242
|
*/
|
|
9235
9243
|
class PositionSummaryFrame extends Enum {
|
|
9236
|
-
constructor(code, description, rangeCalculator, startDateCalculator
|
|
9244
|
+
constructor(code, description, rangeCalculator, startDateCalculator) {
|
|
9237
9245
|
super(code, description);
|
|
9238
9246
|
|
|
9239
9247
|
assert.argumentIsRequired(rangeCalculator, 'rangeCalculator', Function);
|
|
9240
|
-
assert.argumentIsRequired(startDateCalculator, 'startDateCalculator', Function);
|
|
9241
|
-
assert.argumentIsRequired(descriptionCalculator, 'descriptionCalculator', Function);
|
|
9242
9248
|
|
|
9243
9249
|
this._rangeCalculator = rangeCalculator;
|
|
9244
9250
|
this._startDateCalculator = startDateCalculator;
|
|
9245
|
-
this._descriptionCalculator = descriptionCalculator;
|
|
9246
9251
|
}
|
|
9247
9252
|
|
|
9248
|
-
/**
|
|
9249
|
-
* Returns a human-readable description of the frame, given
|
|
9250
|
-
* start and end dates.
|
|
9251
|
-
*
|
|
9252
|
-
* @public
|
|
9253
|
-
* @param {Day} startDate
|
|
9254
|
-
* @param {Day} endDate
|
|
9255
|
-
* @return {String}
|
|
9256
|
-
*/
|
|
9257
|
-
describeRange(startDate, endDate) {
|
|
9258
|
-
return this._descriptionCalculator(startDate, endDate);
|
|
9259
|
-
}
|
|
9260
|
-
|
|
9261
|
-
/**
|
|
9262
|
-
* Returns the most recent ranges for the frame.
|
|
9263
|
-
*
|
|
9264
|
-
* @public
|
|
9265
|
-
* @param {Number} periods
|
|
9266
|
-
* @returns {Array.<PositionSummaryRange>}
|
|
9267
|
-
*/
|
|
9268
|
-
getRecentRanges(periods) {
|
|
9269
|
-
const startDate = this.getStartDate(periods);
|
|
9270
|
-
const transaction = { date: startDate, snapshot: { open: Decimal.ONE } };
|
|
9271
|
-
|
|
9272
|
-
return this.getRanges([ transaction ]);
|
|
9273
|
-
}
|
|
9274
|
-
|
|
9275
|
-
/**
|
|
9276
|
-
* Returns the ranges for the set of {@link Transaction} objects.
|
|
9277
|
-
*
|
|
9278
|
-
* @public
|
|
9279
|
-
* @param {Array.<Transaction>} transactions
|
|
9280
|
-
* @returns {Array.<PositionSummaryRange>}
|
|
9281
|
-
*/
|
|
9282
9253
|
getRanges(transactions) {
|
|
9283
9254
|
assert.argumentIsArray(transactions, 'transactions');
|
|
9284
9255
|
|
|
9285
9256
|
return this._rangeCalculator(getFilteredTransactions(transactions));
|
|
9286
9257
|
}
|
|
9287
9258
|
|
|
9288
|
-
/**
|
|
9289
|
-
* Returns the start date for a frame, a given number of periods ago.
|
|
9290
|
-
*
|
|
9291
|
-
* @public
|
|
9292
|
-
* @param {Number} periods
|
|
9293
|
-
* @returns {Day}
|
|
9294
|
-
*/
|
|
9295
9259
|
getStartDate(periods) {
|
|
9296
9260
|
assert.argumentIsRequired(periods, 'periods', Number);
|
|
9297
9261
|
|
|
@@ -9343,19 +9307,10 @@ module.exports = (() => {
|
|
|
9343
9307
|
}
|
|
9344
9308
|
}
|
|
9345
9309
|
|
|
9346
|
-
const yearly = new PositionSummaryFrame('YEARLY', 'year', getYearlyRanges, getYearlyStartDate
|
|
9347
|
-
const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', getQuarterlyRanges, getQuarterlyStartDate
|
|
9348
|
-
const monthly = new PositionSummaryFrame('MONTH', 'month', getMonthlyRanges, getMonthlyStartDate
|
|
9349
|
-
const ytd = new PositionSummaryFrame('YTD', 'year-to-date', getYearToDateRanges, getYearToDateStartDate
|
|
9350
|
-
|
|
9351
|
-
/**
|
|
9352
|
-
* The start and and date for a {@link PositionSummaryFrame}
|
|
9353
|
-
*
|
|
9354
|
-
* @typedef PositionSummaryRange
|
|
9355
|
-
* @type {Object}
|
|
9356
|
-
* @property {Day} start
|
|
9357
|
-
* @property {Day} end
|
|
9358
|
-
*/
|
|
9310
|
+
const yearly = new PositionSummaryFrame('YEARLY', 'year', getYearlyRanges, getYearlyStartDate);
|
|
9311
|
+
const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', getQuarterlyRanges, getQuarterlyStartDate);
|
|
9312
|
+
const monthly = new PositionSummaryFrame('MONTH', 'month', getMonthlyRanges, getMonthlyStartDate);
|
|
9313
|
+
const ytd = new PositionSummaryFrame('YTD', 'year-to-date', getYearToDateRanges, getYearToDateStartDate);
|
|
9359
9314
|
|
|
9360
9315
|
function getRange(start, end) {
|
|
9361
9316
|
return {
|
|
@@ -9439,22 +9394,6 @@ module.exports = (() => {
|
|
|
9439
9394
|
return null;
|
|
9440
9395
|
}
|
|
9441
9396
|
|
|
9442
|
-
function getYearlyRangeDescription(startDate, endDate) {
|
|
9443
|
-
return endDate.year.toString();
|
|
9444
|
-
}
|
|
9445
|
-
|
|
9446
|
-
function getQuarterlyRangeDescription(startDate, endDate) {
|
|
9447
|
-
return '';
|
|
9448
|
-
}
|
|
9449
|
-
|
|
9450
|
-
function getMonthlyRangeDescription(startDate, endDate) {
|
|
9451
|
-
return '';
|
|
9452
|
-
}
|
|
9453
|
-
|
|
9454
|
-
function getYearToDateRangeDescription(startDate, endDate) {
|
|
9455
|
-
return `${endDate.year.toString()} YTD`;
|
|
9456
|
-
}
|
|
9457
|
-
|
|
9458
9397
|
function getFilteredTransactions(transactions) {
|
|
9459
9398
|
return transactions.reduce((filtered, transaction) => {
|
|
9460
9399
|
if (!transaction.snapshot.open.getIsZero() || transaction.type.closing) {
|
|
@@ -9468,7 +9407,7 @@ module.exports = (() => {
|
|
|
9468
9407
|
return PositionSummaryFrame;
|
|
9469
9408
|
})();
|
|
9470
9409
|
|
|
9471
|
-
},{"@barchart/common-js/lang/Day":29,"@barchart/common-js/lang/
|
|
9410
|
+
},{"@barchart/common-js/lang/Day":29,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/array":36,"@barchart/common-js/lang/assert":37,"@barchart/common-js/lang/is":40}],53:[function(require,module,exports){
|
|
9472
9411
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
9473
9412
|
Enum = require('@barchart/common-js/lang/Enum');
|
|
9474
9413
|
|
|
@@ -10015,7 +9954,6 @@ module.exports = (() => {
|
|
|
10015
9954
|
);
|
|
10016
9955
|
|
|
10017
9956
|
const update = new PortfolioSchema(SchemaBuilder.withName('update')
|
|
10018
|
-
.withField('portfolio', DataType.STRING)
|
|
10019
9957
|
.withField('name', DataType.STRING)
|
|
10020
9958
|
.withField('timezone', DataType.forEnum(Timezones, 'Timezone'), true)
|
|
10021
9959
|
.withField('defaults.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
@@ -10291,8 +10229,7 @@ const assert = require('@barchart/common-js/lang/assert'),
|
|
|
10291
10229
|
Schema = require('@barchart/common-js/serialization/json/Schema'),
|
|
10292
10230
|
SchemaBuilder = require('@barchart/common-js/serialization/json/builders/SchemaBuilder');
|
|
10293
10231
|
|
|
10294
|
-
const
|
|
10295
|
-
TransactionType = require('./../data/TransactionType');
|
|
10232
|
+
const TransactionType = require('./../data/TransactionType');
|
|
10296
10233
|
|
|
10297
10234
|
module.exports = (() => {
|
|
10298
10235
|
'use strict';
|
|
@@ -10530,11 +10467,12 @@ module.exports = (() => {
|
|
|
10530
10467
|
.withField('portfolio', DataType.STRING)
|
|
10531
10468
|
.withField('position', DataType.STRING)
|
|
10532
10469
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10533
|
-
.withField('instrument.name', DataType.STRING)
|
|
10534
|
-
.withField('instrument.type', DataType.
|
|
10535
|
-
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
|
|
10470
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
10471
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
10472
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
10536
10473
|
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
10537
10474
|
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
10475
|
+
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
10538
10476
|
.withField('date', DataType.DAY)
|
|
10539
10477
|
.withField('price', DataType.DECIMAL)
|
|
10540
10478
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -10557,9 +10495,9 @@ module.exports = (() => {
|
|
|
10557
10495
|
.withField('portfolio', DataType.STRING)
|
|
10558
10496
|
.withField('position', DataType.STRING)
|
|
10559
10497
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10560
|
-
.withField('instrument.name', DataType.STRING)
|
|
10561
|
-
.withField('instrument.type', DataType.
|
|
10562
|
-
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'))
|
|
10498
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
10499
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
10500
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
10563
10501
|
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
10564
10502
|
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
10565
10503
|
.withField('date', DataType.DAY)
|
|
@@ -10673,8 +10611,11 @@ module.exports = (() => {
|
|
|
10673
10611
|
.withField('portfolio', DataType.STRING)
|
|
10674
10612
|
.withField('position', DataType.STRING)
|
|
10675
10613
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10676
|
-
.withField('instrument.
|
|
10677
|
-
.withField('instrument.
|
|
10614
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
10615
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
10616
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
10617
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
10618
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
10678
10619
|
.withField('date', DataType.DAY)
|
|
10679
10620
|
.withField('amount', DataType.DECIMAL)
|
|
10680
10621
|
.withField('fee', DataType.DECIMAL, true)
|
|
@@ -10755,7 +10696,7 @@ module.exports = (() => {
|
|
|
10755
10696
|
return TransactionSchema;
|
|
10756
10697
|
})();
|
|
10757
10698
|
|
|
10758
|
-
},{"./../data/
|
|
10699
|
+
},{"./../data/TransactionType":53,"@barchart/common-js/lang/Currency":28,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/assert":37,"@barchart/common-js/lang/is":40,"@barchart/common-js/serialization/json/DataType":45,"@barchart/common-js/serialization/json/Schema":47,"@barchart/common-js/serialization/json/builders/SchemaBuilder":49}],59:[function(require,module,exports){
|
|
10759
10700
|
'use strict';
|
|
10760
10701
|
|
|
10761
10702
|
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; }; }();
|
|
@@ -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');
|
|
@@ -38,7 +39,7 @@ module.exports = (() => {
|
|
|
38
39
|
* @extends {Disposable}
|
|
39
40
|
*/
|
|
40
41
|
class PortfolioGateway extends Disposable {
|
|
41
|
-
constructor(protocol, host, port, requestInterceptor) {
|
|
42
|
+
constructor(protocol, host, port, environment, requestInterceptor) {
|
|
42
43
|
super();
|
|
43
44
|
|
|
44
45
|
this._started = false;
|
|
@@ -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,7 +209,7 @@ 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
215
|
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
@@ -374,11 +391,12 @@ module.exports = (() => {
|
|
|
374
391
|
* @public
|
|
375
392
|
* @param {String=} portfolio
|
|
376
393
|
* @param {String=} position
|
|
377
|
-
* @param {PositionSummaryFrame
|
|
394
|
+
* @param {Array.<PositionSummaryFrame>=|Array.<String>=} frames
|
|
378
395
|
* @param {Number=} periods
|
|
396
|
+
* @param {Day=|String=} start
|
|
379
397
|
* @returns {Promise.<Position[]>}
|
|
380
398
|
*/
|
|
381
|
-
readPositionSummaries(portfolio, position,
|
|
399
|
+
readPositionSummaries(portfolio, position, frames, periods, start) {
|
|
382
400
|
return Promise.resolve()
|
|
383
401
|
.then(() => {
|
|
384
402
|
checkStart.call(this);
|
|
@@ -386,29 +404,54 @@ module.exports = (() => {
|
|
|
386
404
|
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
387
405
|
assert.argumentIsOptional(position, 'position', String);
|
|
388
406
|
|
|
389
|
-
if (
|
|
390
|
-
|
|
407
|
+
if (is.array(frames)) {
|
|
408
|
+
if (frames.length > 0 && is.string(frames[ 0 ])) {
|
|
409
|
+
assert.argumentIsArray(frames, 'frames', String);
|
|
410
|
+
} else {
|
|
411
|
+
assert.argumentIsArray(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
412
|
+
}
|
|
413
|
+
} else {
|
|
414
|
+
if (is.string(frames)) {
|
|
415
|
+
assert.argumentIsOptional(frames, 'frames', String);
|
|
416
|
+
} else {
|
|
417
|
+
assert.argumentIsOptional(frames, 'frames', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
418
|
+
}
|
|
391
419
|
}
|
|
392
420
|
|
|
393
421
|
assert.argumentIsOptional(periods, 'periods', Number);
|
|
422
|
+
assert.argumentIsOptional(start, 'start', Day);
|
|
394
423
|
|
|
395
424
|
const query = {
|
|
396
425
|
portfolio: portfolio || '*',
|
|
397
426
|
position: position || '*'
|
|
398
427
|
};
|
|
399
428
|
|
|
400
|
-
if (
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
429
|
+
if (frames) {
|
|
430
|
+
query.frames = frames.map((frame) => {
|
|
431
|
+
if (is.string(frame)) {
|
|
432
|
+
return Enum.fromCode(PositionSummaryFrame, frame);
|
|
433
|
+
} else {
|
|
434
|
+
return frame;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
406
437
|
}
|
|
407
438
|
|
|
408
439
|
if (periods) {
|
|
409
440
|
query.periods = periods;
|
|
410
441
|
}
|
|
411
442
|
|
|
443
|
+
if (start) {
|
|
444
|
+
let s;
|
|
445
|
+
|
|
446
|
+
if (is.string(start)) {
|
|
447
|
+
s = Day.parse(start);
|
|
448
|
+
} else {
|
|
449
|
+
s = start;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
query.start = s;
|
|
453
|
+
}
|
|
454
|
+
|
|
412
455
|
return Gateway.invoke(this._readPositionSummariesEndpoint, query);
|
|
413
456
|
});
|
|
414
457
|
}
|
package/lib/index.js
CHANGED