@barchart/portfolio-client-js 1.1.17 → 1.1.18
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 +132 -99
- package/lib/gateway/PortfolioGateway.js +33 -14
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/example/example.js
CHANGED
|
@@ -124,6 +124,8 @@ var PortfolioSchema = require('@barchart/portfolio-api-common/lib/serialization/
|
|
|
124
124
|
PositionSummarySchema = require('@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema'),
|
|
125
125
|
TransactionSchema = require('@barchart/portfolio-api-common/lib/serialization/TransactionSchema');
|
|
126
126
|
|
|
127
|
+
var PositionSummaryFrame = require('@barchart/portfolio-api-common/lib/data/PositionSummaryFrame');
|
|
128
|
+
|
|
127
129
|
var EndpointBuilder = require('@barchart/common-js/api/http/builders/EndpointBuilder'),
|
|
128
130
|
Gateway = require('@barchart/common-js/api/http/Gateway'),
|
|
129
131
|
FailureReason = require('@barchart/common-js/api/failures/FailureReason'),
|
|
@@ -193,8 +195,8 @@ module.exports = function () {
|
|
|
193
195
|
_this._readPositionSummariesEndpoint = EndpointBuilder.for('read-position-summaries', 'read position summaries').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
194
196
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('summaries', 'summaries').withVariableParameter('position', 'position', 'position', false);
|
|
195
197
|
}).withQueryBuilder(function (qb) {
|
|
196
|
-
qb.withVariableParameter('frame', 'frame', 'frame', true).withVariableParameter('
|
|
197
|
-
}).withRequestInterceptor(
|
|
198
|
+
qb.withVariableParameter('frame', 'frame', 'frame', true).withVariableParameter('periods', 'periods', 'periods', true);
|
|
199
|
+
}).withRequestInterceptor(requestInterceptorToUse).withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE).withResponseInterceptor(responseInterceptorForPositionSummaryDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
198
200
|
|
|
199
201
|
_this._deletePortfoliosEndpoint = EndpointBuilder.for('delete-portfolio', 'delete portfolios').withVerb(VerbType.DELETE).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
200
202
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withVariableParameter('position', 'position', 'position', false);
|
|
@@ -373,29 +375,47 @@ module.exports = function () {
|
|
|
373
375
|
* @public
|
|
374
376
|
* @param {String=} portfolio
|
|
375
377
|
* @param {String=} position
|
|
378
|
+
* @param {PositionSummaryFrame=|String=} frame
|
|
379
|
+
* @param {Number=} periods
|
|
376
380
|
* @returns {Promise.<Position[]>}
|
|
377
381
|
*/
|
|
378
382
|
|
|
379
383
|
}, {
|
|
380
384
|
key: 'readPositionSummaries',
|
|
381
|
-
value: function readPositionSummaries(
|
|
385
|
+
value: function readPositionSummaries(portfolio, position, frame, periods) {
|
|
382
386
|
var _this8 = this;
|
|
383
387
|
|
|
384
388
|
return Promise.resolve().then(function () {
|
|
385
389
|
checkStart.call(_this8);
|
|
386
390
|
|
|
387
|
-
assert.
|
|
388
|
-
assert.argumentIsOptional(
|
|
389
|
-
|
|
391
|
+
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
392
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
393
|
+
|
|
394
|
+
if (!is.string(frame)) {
|
|
395
|
+
assert.argumentIsOptional(frame, 'frame', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
assert.argumentIsOptional(periods, 'periods', Number);
|
|
390
399
|
|
|
391
400
|
var query = {
|
|
392
|
-
portfolio:
|
|
393
|
-
position:
|
|
394
|
-
frame: data.frame,
|
|
395
|
-
start: data.start,
|
|
396
|
-
end: data.end
|
|
401
|
+
portfolio: portfolio || '*',
|
|
402
|
+
position: position || '*'
|
|
397
403
|
};
|
|
398
404
|
|
|
405
|
+
if (frame) {
|
|
406
|
+
if (is.string(frame)) {
|
|
407
|
+
query.frame = frame;
|
|
408
|
+
} else {
|
|
409
|
+
query.frame = frame.code;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (periods) {
|
|
414
|
+
query.periods = periods;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
console.log(query);
|
|
418
|
+
|
|
399
419
|
return Gateway.invoke(_this8._readPositionSummariesEndpoint, query);
|
|
400
420
|
});
|
|
401
421
|
}
|
|
@@ -621,7 +641,7 @@ module.exports = function () {
|
|
|
621
641
|
try {
|
|
622
642
|
return JSON.parse(response.data, PortfolioSchema.CLIENT.schema.getReviver());
|
|
623
643
|
} catch (e) {
|
|
624
|
-
console.log(e);
|
|
644
|
+
console.log('Error deserializing positions', e);
|
|
625
645
|
}
|
|
626
646
|
});
|
|
627
647
|
|
|
@@ -633,7 +653,7 @@ module.exports = function () {
|
|
|
633
653
|
try {
|
|
634
654
|
return JSON.parse(response.data, PositionSummarySchema.CLIENT.schema.getReviver());
|
|
635
655
|
} catch (e) {
|
|
636
|
-
console.log(e);
|
|
656
|
+
console.log('Error deserializing position summaries', e);
|
|
637
657
|
}
|
|
638
658
|
});
|
|
639
659
|
|
|
@@ -664,7 +684,7 @@ module.exports = function () {
|
|
|
664
684
|
return PortfolioGateway;
|
|
665
685
|
}();
|
|
666
686
|
|
|
667
|
-
},{"./../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/TransactionType":52,"@barchart/portfolio-api-common/lib/serialization/PortfolioSchema":54,"@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema":55,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":56}],4:[function(require,module,exports){
|
|
687
|
+
},{"./../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":51,"@barchart/portfolio-api-common/lib/data/TransactionType":52,"@barchart/portfolio-api-common/lib/serialization/PortfolioSchema":54,"@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema":55,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":56}],4:[function(require,module,exports){
|
|
668
688
|
'use strict';
|
|
669
689
|
|
|
670
690
|
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; }; }();
|
|
@@ -977,7 +997,7 @@ module.exports = function () {
|
|
|
977
997
|
return {
|
|
978
998
|
JwtGateway: JwtGateway,
|
|
979
999
|
PortfolioGateway: PortfolioGateway,
|
|
980
|
-
version: '1.1.
|
|
1000
|
+
version: '1.1.18'
|
|
981
1001
|
};
|
|
982
1002
|
}();
|
|
983
1003
|
|
|
@@ -6972,7 +6992,7 @@ module.exports = function () {
|
|
|
6972
6992
|
*
|
|
6973
6993
|
* @static
|
|
6974
6994
|
* @public
|
|
6975
|
-
* @param candidate {*}
|
|
6995
|
+
* @param {*} candidate {*}
|
|
6976
6996
|
* @returns {boolean}
|
|
6977
6997
|
*/
|
|
6978
6998
|
number: function number(candidate) {
|
|
@@ -7025,7 +7045,7 @@ module.exports = function () {
|
|
|
7025
7045
|
*
|
|
7026
7046
|
* @static
|
|
7027
7047
|
* @public
|
|
7028
|
-
* @param candidate
|
|
7048
|
+
* @param {*} candidate
|
|
7029
7049
|
* @returns {boolean}
|
|
7030
7050
|
*/
|
|
7031
7051
|
positive: function positive(candidate) {
|
|
@@ -7038,7 +7058,7 @@ module.exports = function () {
|
|
|
7038
7058
|
*
|
|
7039
7059
|
* @static
|
|
7040
7060
|
* @public
|
|
7041
|
-
* @param candidate
|
|
7061
|
+
* @param {*} candidate
|
|
7042
7062
|
* @returns {*|boolean}
|
|
7043
7063
|
*/
|
|
7044
7064
|
negative: function negative(candidate) {
|
|
@@ -7051,7 +7071,7 @@ module.exports = function () {
|
|
|
7051
7071
|
*
|
|
7052
7072
|
* @static
|
|
7053
7073
|
* @public
|
|
7054
|
-
* @param candidate
|
|
7074
|
+
* @param {*} candidate
|
|
7055
7075
|
* @returns {boolean}
|
|
7056
7076
|
*/
|
|
7057
7077
|
string: function string(candidate) {
|
|
@@ -7064,7 +7084,7 @@ module.exports = function () {
|
|
|
7064
7084
|
*
|
|
7065
7085
|
* @static
|
|
7066
7086
|
* @public
|
|
7067
|
-
* @param candidate
|
|
7087
|
+
* @param {*} candidate
|
|
7068
7088
|
* @returns {boolean}
|
|
7069
7089
|
*/
|
|
7070
7090
|
date: function date(candidate) {
|
|
@@ -7077,7 +7097,7 @@ module.exports = function () {
|
|
|
7077
7097
|
*
|
|
7078
7098
|
* @static
|
|
7079
7099
|
* @public
|
|
7080
|
-
* @param candidate
|
|
7100
|
+
* @param {*} candidate
|
|
7081
7101
|
* @returns {boolean}
|
|
7082
7102
|
*/
|
|
7083
7103
|
fn: function fn(candidate) {
|
|
@@ -7090,7 +7110,7 @@ module.exports = function () {
|
|
|
7090
7110
|
*
|
|
7091
7111
|
* @static
|
|
7092
7112
|
* @public
|
|
7093
|
-
* @param candidate
|
|
7113
|
+
* @param {*} candidate
|
|
7094
7114
|
* @returns {boolean}
|
|
7095
7115
|
*/
|
|
7096
7116
|
array: function array(candidate) {
|
|
@@ -7103,7 +7123,7 @@ module.exports = function () {
|
|
|
7103
7123
|
*
|
|
7104
7124
|
* @static
|
|
7105
7125
|
* @public
|
|
7106
|
-
* @param candidate
|
|
7126
|
+
* @param {*} candidate
|
|
7107
7127
|
* @returns {boolean}
|
|
7108
7128
|
*/
|
|
7109
7129
|
boolean: function boolean(candidate) {
|
|
@@ -7116,7 +7136,7 @@ module.exports = function () {
|
|
|
7116
7136
|
*
|
|
7117
7137
|
* @static
|
|
7118
7138
|
* @public
|
|
7119
|
-
* @param candidate
|
|
7139
|
+
* @param {*} candidate
|
|
7120
7140
|
* @returns {boolean}
|
|
7121
7141
|
*/
|
|
7122
7142
|
object: function object(candidate) {
|
|
@@ -7129,7 +7149,7 @@ module.exports = function () {
|
|
|
7129
7149
|
*
|
|
7130
7150
|
* @static
|
|
7131
7151
|
* @public
|
|
7132
|
-
* @param candidate
|
|
7152
|
+
* @param {*} candidate
|
|
7133
7153
|
* @returns {boolean}
|
|
7134
7154
|
*/
|
|
7135
7155
|
null: function _null(candidate) {
|
|
@@ -7142,7 +7162,7 @@ module.exports = function () {
|
|
|
7142
7162
|
*
|
|
7143
7163
|
* @static
|
|
7144
7164
|
* @public
|
|
7145
|
-
* @param candidate
|
|
7165
|
+
* @param {*} candidate
|
|
7146
7166
|
* @returns {boolean}
|
|
7147
7167
|
*/
|
|
7148
7168
|
undefined: function (_undefined) {
|
|
@@ -8142,7 +8162,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
8142
8162
|
|
|
8143
8163
|
var attributes = require('./../../lang/attributes'),
|
|
8144
8164
|
functions = require('./../../lang/functions'),
|
|
8145
|
-
array = require('./../../lang/array'),
|
|
8146
8165
|
is = require('./../../lang/is');
|
|
8147
8166
|
|
|
8148
8167
|
var LinkedList = require('./../../collections/LinkedList'),
|
|
@@ -8234,45 +8253,6 @@ module.exports = function () {
|
|
|
8234
8253
|
*
|
|
8235
8254
|
* @public
|
|
8236
8255
|
* @returns {Function}
|
|
8237
|
-
*/
|
|
8238
|
-
|
|
8239
|
-
}, {
|
|
8240
|
-
key: 'getSimpleReviver',
|
|
8241
|
-
value: function getSimpleReviver() {
|
|
8242
|
-
var _this = this;
|
|
8243
|
-
|
|
8244
|
-
return function (key, value) {
|
|
8245
|
-
var field = _this.fields.find(function (f) {
|
|
8246
|
-
var fieldName = array.last(f.name.split('.'));
|
|
8247
|
-
|
|
8248
|
-
return fieldName === key;
|
|
8249
|
-
});
|
|
8250
|
-
|
|
8251
|
-
if (is.object(value)) {
|
|
8252
|
-
return value;
|
|
8253
|
-
}
|
|
8254
|
-
|
|
8255
|
-
var returnVal = void 0;
|
|
8256
|
-
|
|
8257
|
-
try {
|
|
8258
|
-
returnVal = field.dataType.reviver(value);
|
|
8259
|
-
} catch (e) {
|
|
8260
|
-
if (_this._strict) {
|
|
8261
|
-
throw Error(e);
|
|
8262
|
-
} else {
|
|
8263
|
-
returnVal = value;
|
|
8264
|
-
}
|
|
8265
|
-
}
|
|
8266
|
-
|
|
8267
|
-
return returnVal;
|
|
8268
|
-
};
|
|
8269
|
-
}
|
|
8270
|
-
|
|
8271
|
-
/**
|
|
8272
|
-
* Generates a function suitable for use by JSON.parse.
|
|
8273
|
-
*
|
|
8274
|
-
* @public
|
|
8275
|
-
* @returns {Function}
|
|
8276
8256
|
*/
|
|
8277
8257
|
|
|
8278
8258
|
}, {
|
|
@@ -8319,10 +8299,10 @@ module.exports = function () {
|
|
|
8319
8299
|
}, {
|
|
8320
8300
|
key: 'getReviverFactory',
|
|
8321
8301
|
value: function getReviverFactory() {
|
|
8322
|
-
var
|
|
8302
|
+
var _this = this;
|
|
8323
8303
|
|
|
8324
8304
|
return function () {
|
|
8325
|
-
return
|
|
8305
|
+
return _this.getReviver();
|
|
8326
8306
|
};
|
|
8327
8307
|
}
|
|
8328
8308
|
}, {
|
|
@@ -8386,11 +8366,11 @@ module.exports = function () {
|
|
|
8386
8366
|
function SchemaError(key, name, message) {
|
|
8387
8367
|
_classCallCheck(this, SchemaError);
|
|
8388
8368
|
|
|
8389
|
-
var
|
|
8369
|
+
var _this2 = _possibleConstructorReturn(this, (SchemaError.__proto__ || Object.getPrototypeOf(SchemaError)).call(this, message));
|
|
8390
8370
|
|
|
8391
|
-
|
|
8392
|
-
|
|
8393
|
-
return
|
|
8371
|
+
_this2.key = key;
|
|
8372
|
+
_this2.name = name;
|
|
8373
|
+
return _this2;
|
|
8394
8374
|
}
|
|
8395
8375
|
|
|
8396
8376
|
_createClass(SchemaError, [{
|
|
@@ -8531,7 +8511,7 @@ module.exports = function () {
|
|
|
8531
8511
|
return Schema;
|
|
8532
8512
|
}();
|
|
8533
8513
|
|
|
8534
|
-
},{"./../../collections/LinkedList":23,"./../../collections/Tree":24,"./../../lang/
|
|
8514
|
+
},{"./../../collections/LinkedList":23,"./../../collections/Tree":24,"./../../lang/attributes":38,"./../../lang/functions":39,"./../../lang/is":40,"./Component":44,"./Field":46}],48:[function(require,module,exports){
|
|
8535
8515
|
'use strict';
|
|
8536
8516
|
|
|
8537
8517
|
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; }; }();
|
|
@@ -9037,20 +9017,28 @@ module.exports = (() => {
|
|
|
9037
9017
|
* @param {String} code
|
|
9038
9018
|
* @param {String} description
|
|
9039
9019
|
* @param {Function} rangeCalculator
|
|
9020
|
+
* @param {Function} startDateCalculator
|
|
9040
9021
|
*/
|
|
9041
9022
|
class PositionSummaryFrame extends Enum {
|
|
9042
|
-
constructor(code, description, rangeCalculator) {
|
|
9023
|
+
constructor(code, description, rangeCalculator, startDateCalculator) {
|
|
9043
9024
|
super(code, description);
|
|
9044
9025
|
|
|
9045
9026
|
assert.argumentIsRequired(rangeCalculator, 'rangeCalculator', Function);
|
|
9046
9027
|
|
|
9047
9028
|
this._rangeCalculator = rangeCalculator;
|
|
9029
|
+
this._startDateCalculator = startDateCalculator;
|
|
9048
9030
|
}
|
|
9049
9031
|
|
|
9050
9032
|
getRanges(transactions) {
|
|
9051
9033
|
assert.argumentIsArray(transactions, 'transactions');
|
|
9052
9034
|
|
|
9053
|
-
return this._rangeCalculator(transactions);
|
|
9035
|
+
return this._rangeCalculator(getFilteredTransactions(transactions));
|
|
9036
|
+
}
|
|
9037
|
+
|
|
9038
|
+
getStartDate(periods) {
|
|
9039
|
+
assert.argumentIsRequired(periods, 'periods', Number);
|
|
9040
|
+
|
|
9041
|
+
return this._startDateCalculator(periods);
|
|
9054
9042
|
}
|
|
9055
9043
|
|
|
9056
9044
|
/**
|
|
@@ -9098,10 +9086,10 @@ module.exports = (() => {
|
|
|
9098
9086
|
}
|
|
9099
9087
|
}
|
|
9100
9088
|
|
|
9101
|
-
const yearly = new PositionSummaryFrame('YEARLY', 'year', getYearlyRanges);
|
|
9102
|
-
const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', getQuarterlyRanges);
|
|
9103
|
-
const monthly = new PositionSummaryFrame('MONTH', 'month', getMonthlyRanges);
|
|
9104
|
-
const ytd = new PositionSummaryFrame('YTD', 'year-to-date', getYearToDateRanges);
|
|
9089
|
+
const yearly = new PositionSummaryFrame('YEARLY', 'year', getYearlyRanges, getYearlyStartDate);
|
|
9090
|
+
const quarterly = new PositionSummaryFrame('QUARTER', 'quarter', getQuarterlyRanges, getQuarterlyStartDate);
|
|
9091
|
+
const monthly = new PositionSummaryFrame('MONTH', 'month', getMonthlyRanges, getMonthlyStartDate);
|
|
9092
|
+
const ytd = new PositionSummaryFrame('YTD', 'year-to-date', getYearToDateRanges, getYearToDateStartDate);
|
|
9105
9093
|
|
|
9106
9094
|
function getRange(start, end) {
|
|
9107
9095
|
return {
|
|
@@ -9164,6 +9152,37 @@ module.exports = (() => {
|
|
|
9164
9152
|
return ranges;
|
|
9165
9153
|
}
|
|
9166
9154
|
|
|
9155
|
+
function getYearlyStartDate(periods) {
|
|
9156
|
+
const today = Day.getToday();
|
|
9157
|
+
|
|
9158
|
+
return Day.getToday()
|
|
9159
|
+
.subtractMonths(today.month - 1)
|
|
9160
|
+
.subtractDays(today.day)
|
|
9161
|
+
.subtractYears(periods);
|
|
9162
|
+
}
|
|
9163
|
+
|
|
9164
|
+
function getQuarterlyStartDate(periods) {
|
|
9165
|
+
return null;
|
|
9166
|
+
}
|
|
9167
|
+
|
|
9168
|
+
function getMonthlyStartDate(periods) {
|
|
9169
|
+
return null;
|
|
9170
|
+
}
|
|
9171
|
+
|
|
9172
|
+
function getYearToDateStartDate(periods) {
|
|
9173
|
+
return null;
|
|
9174
|
+
}
|
|
9175
|
+
|
|
9176
|
+
function getFilteredTransactions(transactions) {
|
|
9177
|
+
return transactions.reduce((filtered, transaction) => {
|
|
9178
|
+
if (!transaction.snapshot.open.getIsZero() || transaction.type.closing) {
|
|
9179
|
+
filtered.push(transaction);
|
|
9180
|
+
}
|
|
9181
|
+
|
|
9182
|
+
return filtered;
|
|
9183
|
+
}, [ ]);
|
|
9184
|
+
}
|
|
9185
|
+
|
|
9167
9186
|
return PositionSummaryFrame;
|
|
9168
9187
|
})();
|
|
9169
9188
|
|
|
@@ -9483,10 +9502,10 @@ module.exports = (() => {
|
|
|
9483
9502
|
const distributionCash = new TransactionType('DC', 'Distribution (Cash)', false, false, true, false, false);
|
|
9484
9503
|
const distributionFund = new TransactionType('DF', 'Distribution (Units)', false, false, false, true, false);
|
|
9485
9504
|
|
|
9486
|
-
const deposit = new TransactionType('D', 'Deposit', false, false, false,
|
|
9487
|
-
const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false,
|
|
9488
|
-
const debit = new TransactionType('DR', 'Debit', false, false, false, false,
|
|
9489
|
-
const credit = new TransactionType('CR', 'Credit', false, false, false,
|
|
9505
|
+
const deposit = new TransactionType('D', 'Deposit', false, false, false, true, false);
|
|
9506
|
+
const withdrawal = new TransactionType('W', 'Withdrawal', false, false, false, false, true);
|
|
9507
|
+
const debit = new TransactionType('DR', 'Debit', false, false, false, false, true);
|
|
9508
|
+
const credit = new TransactionType('CR', 'Credit', false, false, false, true, false);
|
|
9490
9509
|
|
|
9491
9510
|
const valuation = new TransactionType('V', 'Valuation', false, false, false, false, false);
|
|
9492
9511
|
const income = new TransactionType('I', 'Income', false, false, true, false, false);
|
|
@@ -9616,6 +9635,17 @@ module.exports = (() => {
|
|
|
9616
9635
|
return client;
|
|
9617
9636
|
}
|
|
9618
9637
|
|
|
9638
|
+
/**
|
|
9639
|
+
* Only returns identifiers and portfolio name.
|
|
9640
|
+
*
|
|
9641
|
+
* @static
|
|
9642
|
+
* @public
|
|
9643
|
+
* @returns {PortfolioSchema}
|
|
9644
|
+
*/
|
|
9645
|
+
static get NAME() {
|
|
9646
|
+
return name;
|
|
9647
|
+
}
|
|
9648
|
+
|
|
9619
9649
|
/**
|
|
9620
9650
|
* Data required to create a portfolio.
|
|
9621
9651
|
*
|
|
@@ -9684,6 +9714,13 @@ module.exports = (() => {
|
|
|
9684
9714
|
.schema
|
|
9685
9715
|
);
|
|
9686
9716
|
|
|
9717
|
+
const name = new PortfolioSchema(SchemaBuilder.withName('name')
|
|
9718
|
+
.withField('user', DataType.STRING)
|
|
9719
|
+
.withField('portfolio', DataType.STRING)
|
|
9720
|
+
.withField('name', DataType.STRING)
|
|
9721
|
+
.schema
|
|
9722
|
+
);
|
|
9723
|
+
|
|
9687
9724
|
const create = new PortfolioSchema(SchemaBuilder.withName('create')
|
|
9688
9725
|
.withField('name', DataType.STRING)
|
|
9689
9726
|
.withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
|
|
@@ -10111,6 +10148,11 @@ module.exports = (() => {
|
|
|
10111
10148
|
.withField('portfolio', DataType.STRING)
|
|
10112
10149
|
.withField('position', DataType.STRING)
|
|
10113
10150
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10151
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
10152
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
10153
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
10154
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
10155
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
10114
10156
|
.withField('date', DataType.DAY)
|
|
10115
10157
|
.withField('price', DataType.DECIMAL)
|
|
10116
10158
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -10122,11 +10164,6 @@ module.exports = (() => {
|
|
|
10122
10164
|
.withField('portfolio', DataType.STRING)
|
|
10123
10165
|
.withField('position', DataType.STRING)
|
|
10124
10166
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10125
|
-
.withField('instrument.name', DataType.STRING, true)
|
|
10126
|
-
.withField('instrument.type', DataType.STRING, true)
|
|
10127
|
-
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
10128
|
-
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
10129
|
-
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
10130
10167
|
.withField('date', DataType.DAY)
|
|
10131
10168
|
.withField('price', DataType.DECIMAL)
|
|
10132
10169
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -10140,8 +10177,7 @@ module.exports = (() => {
|
|
|
10140
10177
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10141
10178
|
.withField('date', DataType.DAY)
|
|
10142
10179
|
.withField('rate', DataType.DECIMAL)
|
|
10143
|
-
.withField('
|
|
10144
|
-
.withField('effective', DataType.DAY, true)
|
|
10180
|
+
.withField('effective', DataType.DAY)
|
|
10145
10181
|
.withField('fee', DataType.DECIMAL, true)
|
|
10146
10182
|
.schema
|
|
10147
10183
|
);
|
|
@@ -10152,8 +10188,7 @@ module.exports = (() => {
|
|
|
10152
10188
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10153
10189
|
.withField('date', DataType.DAY)
|
|
10154
10190
|
.withField('rate', DataType.DECIMAL)
|
|
10155
|
-
.withField('
|
|
10156
|
-
.withField('effective', DataType.DAY, true)
|
|
10191
|
+
.withField('effective', DataType.DAY)
|
|
10157
10192
|
.withField('price', DataType.DECIMAL)
|
|
10158
10193
|
.withField('fee', DataType.DECIMAL, true)
|
|
10159
10194
|
.schema
|
|
@@ -10165,8 +10200,7 @@ module.exports = (() => {
|
|
|
10165
10200
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10166
10201
|
.withField('date', DataType.DAY)
|
|
10167
10202
|
.withField('rate', DataType.DECIMAL)
|
|
10168
|
-
.withField('
|
|
10169
|
-
.withField('effective', DataType.DAY, true)
|
|
10203
|
+
.withField('effective', DataType.DAY)
|
|
10170
10204
|
.withField('price', DataType.DECIMAL)
|
|
10171
10205
|
.withField('fee', DataType.DECIMAL, true)
|
|
10172
10206
|
.schema
|
|
@@ -10178,8 +10212,7 @@ module.exports = (() => {
|
|
|
10178
10212
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10179
10213
|
.withField('date', DataType.DAY)
|
|
10180
10214
|
.withField('rate', DataType.DECIMAL)
|
|
10181
|
-
.withField('
|
|
10182
|
-
.withField('effective', DataType.DAY, true)
|
|
10215
|
+
.withField('effective', DataType.DAY)
|
|
10183
10216
|
.withField('fee', DataType.DECIMAL, true)
|
|
10184
10217
|
.schema
|
|
10185
10218
|
);
|
|
@@ -10190,8 +10223,8 @@ module.exports = (() => {
|
|
|
10190
10223
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
10191
10224
|
.withField('date', DataType.DAY)
|
|
10192
10225
|
.withField('rate', DataType.DECIMAL)
|
|
10193
|
-
.withField('
|
|
10194
|
-
.withField('
|
|
10226
|
+
.withField('effective', DataType.DAY)
|
|
10227
|
+
.withField('price', DataType.DECIMAL)
|
|
10195
10228
|
.withField('fee', DataType.DECIMAL, true)
|
|
10196
10229
|
.schema
|
|
10197
10230
|
);
|
|
@@ -10203,7 +10236,7 @@ module.exports = (() => {
|
|
|
10203
10236
|
.withField('date', DataType.DAY)
|
|
10204
10237
|
.withField('numerator', DataType.DECIMAL)
|
|
10205
10238
|
.withField('denominator', DataType.DECIMAL)
|
|
10206
|
-
.withField('effective', DataType.DAY
|
|
10239
|
+
.withField('effective', DataType.DAY)
|
|
10207
10240
|
.withField('fee', DataType.DECIMAL, true)
|
|
10208
10241
|
.schema
|
|
10209
10242
|
);
|
|
@@ -9,6 +9,8 @@ const PortfolioSchema = require('@barchart/portfolio-api-common/lib/serializatio
|
|
|
9
9
|
PositionSummarySchema = require('@barchart/portfolio-api-common/lib/serialization/PositionSummarySchema'),
|
|
10
10
|
TransactionSchema = require('@barchart/portfolio-api-common/lib/serialization/TransactionSchema');
|
|
11
11
|
|
|
12
|
+
const PositionSummaryFrame = require('@barchart/portfolio-api-common/lib/data/PositionSummaryFrame');
|
|
13
|
+
|
|
12
14
|
const EndpointBuilder = require('@barchart/common-js/api/http/builders/EndpointBuilder'),
|
|
13
15
|
Gateway = require('@barchart/common-js/api/http/Gateway'),
|
|
14
16
|
FailureReason = require('@barchart/common-js/api/failures/FailureReason'),
|
|
@@ -138,11 +140,10 @@ module.exports = (() => {
|
|
|
138
140
|
})
|
|
139
141
|
.withQueryBuilder((qb) => {
|
|
140
142
|
qb.withVariableParameter('frame', 'frame', 'frame', true)
|
|
141
|
-
.withVariableParameter('
|
|
142
|
-
.withVariableParameter('end', 'end', 'end', true);
|
|
143
|
+
.withVariableParameter('periods', 'periods', 'periods', true);
|
|
143
144
|
})
|
|
144
|
-
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
145
145
|
.withRequestInterceptor(requestInterceptorToUse)
|
|
146
|
+
.withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
|
|
146
147
|
.withResponseInterceptor(responseInterceptorForPositionSummaryDeserialization)
|
|
147
148
|
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
148
149
|
.endpoint;
|
|
@@ -366,25 +367,43 @@ module.exports = (() => {
|
|
|
366
367
|
* @public
|
|
367
368
|
* @param {String=} portfolio
|
|
368
369
|
* @param {String=} position
|
|
370
|
+
* @param {PositionSummaryFrame=|String=} frame
|
|
371
|
+
* @param {Number=} periods
|
|
369
372
|
* @returns {Promise.<Position[]>}
|
|
370
373
|
*/
|
|
371
|
-
readPositionSummaries(
|
|
374
|
+
readPositionSummaries(portfolio, position, frame, periods) {
|
|
372
375
|
return Promise.resolve()
|
|
373
376
|
.then(() => {
|
|
374
377
|
checkStart.call(this);
|
|
375
378
|
|
|
376
|
-
assert.
|
|
377
|
-
assert.argumentIsOptional(
|
|
378
|
-
|
|
379
|
+
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
380
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
381
|
+
|
|
382
|
+
if (!is.string(frame)) {
|
|
383
|
+
assert.argumentIsOptional(frame, 'frame', PositionSummaryFrame, 'PositionSummaryFrame');
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
assert.argumentIsOptional(periods, 'periods', Number);
|
|
379
387
|
|
|
380
388
|
const query = {
|
|
381
|
-
portfolio:
|
|
382
|
-
position:
|
|
383
|
-
frame: data.frame,
|
|
384
|
-
start: data.start,
|
|
385
|
-
end: data.end
|
|
389
|
+
portfolio: portfolio || '*',
|
|
390
|
+
position: position || '*'
|
|
386
391
|
};
|
|
387
392
|
|
|
393
|
+
if (frame) {
|
|
394
|
+
if (is.string(frame)) {
|
|
395
|
+
query.frame = frame;
|
|
396
|
+
} else {
|
|
397
|
+
query.frame = frame.code;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (periods) {
|
|
402
|
+
query.periods = periods;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
console.log(query);
|
|
406
|
+
|
|
388
407
|
return Gateway.invoke(this._readPositionSummariesEndpoint, query);
|
|
389
408
|
});
|
|
390
409
|
}
|
|
@@ -583,7 +602,7 @@ module.exports = (() => {
|
|
|
583
602
|
try {
|
|
584
603
|
return JSON.parse(response.data, PortfolioSchema.CLIENT.schema.getReviver());
|
|
585
604
|
} catch (e) {
|
|
586
|
-
console.log(e);
|
|
605
|
+
console.log('Error deserializing positions', e);
|
|
587
606
|
}
|
|
588
607
|
});
|
|
589
608
|
|
|
@@ -595,7 +614,7 @@ module.exports = (() => {
|
|
|
595
614
|
try {
|
|
596
615
|
return JSON.parse(response.data, PositionSummarySchema.CLIENT.schema.getReviver());
|
|
597
616
|
} catch (e) {
|
|
598
|
-
console.log(e);
|
|
617
|
+
console.log('Error deserializing position summaries', e);
|
|
599
618
|
}
|
|
600
619
|
});
|
|
601
620
|
|
package/lib/index.js
CHANGED