@barchart/portfolio-client-js 1.1.11 → 1.1.12
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 +18 -5
- package/example/example.js +241 -138
- package/example/example.shim.js +6 -2
- package/lib/gateway/PortfolioGateway.js +68 -16
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/example/example.html
CHANGED
|
@@ -49,8 +49,6 @@
|
|
|
49
49
|
.then((data) => {
|
|
50
50
|
writeConsoleText(action, true);
|
|
51
51
|
writeConsoleObject(data);
|
|
52
|
-
|
|
53
|
-
debugger;
|
|
54
52
|
}).catch((e) => {
|
|
55
53
|
writeConsoleText(action, true);
|
|
56
54
|
writeConsoleObject(e);
|
|
@@ -63,15 +61,15 @@
|
|
|
63
61
|
|
|
64
62
|
var portfolio = {
|
|
65
63
|
name: `Random ${Math.random()}`,
|
|
66
|
-
timezone:
|
|
64
|
+
timezone: Barchart.Timezones.AMERICA_NEW_YORK,
|
|
67
65
|
dates: {
|
|
68
66
|
create: Barchart.Day.getToday(),
|
|
69
67
|
cash: Barchart.Day.getToday()
|
|
70
68
|
},
|
|
71
69
|
defaults: {
|
|
72
|
-
currency:
|
|
70
|
+
currency: Barchart.Currency.CAD,
|
|
73
71
|
reinvest: true,
|
|
74
|
-
valuation:
|
|
72
|
+
valuation: Barchart.ValuationType.AVERAGE_COST
|
|
75
73
|
},
|
|
76
74
|
miscellany: {
|
|
77
75
|
testing: {
|
|
@@ -154,6 +152,20 @@
|
|
|
154
152
|
writeConsoleText(action, true);
|
|
155
153
|
writeConsoleObject(e);
|
|
156
154
|
|
|
155
|
+
that.setConsoleMode();
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
var readPositionSummaries = function() {
|
|
159
|
+
var action = 'portfolioGateway.readPositionSummaries()';
|
|
160
|
+
|
|
161
|
+
that.gateway.readPositionSummaries(that.portfolio() || null, that.position() || null)
|
|
162
|
+
.then((data) => {
|
|
163
|
+
writeConsoleText(action, true);
|
|
164
|
+
writeConsoleObject(data);
|
|
165
|
+
}).catch((e) => {
|
|
166
|
+
writeConsoleText(action, true);
|
|
167
|
+
writeConsoleObject(e);
|
|
168
|
+
|
|
157
169
|
that.setConsoleMode();
|
|
158
170
|
});
|
|
159
171
|
};
|
|
@@ -300,6 +312,7 @@
|
|
|
300
312
|
{ text: 'Update Portfolio', action: updatePortfolio },
|
|
301
313
|
{ text: 'Delete Portfolio', action: deletePortfolio },
|
|
302
314
|
{ text: 'Get Positions', action: getPositions },
|
|
315
|
+
{ text: 'Get Positions Summaries', action: readPositionSummaries },
|
|
303
316
|
{ text: 'Delete Position', action: deletePosition },
|
|
304
317
|
{ text: 'Get Transactions', action: getTransactions },
|
|
305
318
|
{ text: 'Get Transactions (Formatted)', action: getTransactionsFormatted },
|
package/example/example.js
CHANGED
|
@@ -5,9 +5,11 @@ var JwtGateway = require('@barchart/tgam-jwt-js/lib/JwtGateway');
|
|
|
5
5
|
|
|
6
6
|
var Currency = require('@barchart/common-js/lang/Currency'),
|
|
7
7
|
Day = require('@barchart/common-js/lang/Day'),
|
|
8
|
-
Decimal = require('@barchart/common-js/lang/Decimal')
|
|
8
|
+
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
9
|
+
Timezones = require('@barchart/common-js/lang/Timezones');
|
|
9
10
|
|
|
10
|
-
var TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType')
|
|
11
|
+
var TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType'),
|
|
12
|
+
ValuationType = require('@barchart/portfolio-api-common/lib/data/ValuationType');
|
|
11
13
|
|
|
12
14
|
module.exports = function () {
|
|
13
15
|
'use strict';
|
|
@@ -19,10 +21,12 @@ module.exports = function () {
|
|
|
19
21
|
window.Barchart.Currency = Currency;
|
|
20
22
|
window.Barchart.Day = Day;
|
|
21
23
|
window.Barchart.Decimal = Decimal;
|
|
24
|
+
window.Barchart.Timezones = Timezones;
|
|
22
25
|
window.Barchart.TransactionType = TransactionType;
|
|
26
|
+
window.Barchart.ValuationType = ValuationType;
|
|
23
27
|
}();
|
|
24
28
|
|
|
25
|
-
},{"@barchart/common-js/lang/Currency":28,"@barchart/common-js/lang/Day":29,"@barchart/common-js/lang/Decimal":30,"@barchart/portfolio-api-common/lib/data/TransactionType":51,"@barchart/tgam-jwt-js/lib/JwtGateway":55}],2:[function(require,module,exports){
|
|
29
|
+
},{"@barchart/common-js/lang/Currency":28,"@barchart/common-js/lang/Day":29,"@barchart/common-js/lang/Decimal":30,"@barchart/common-js/lang/Timezones":35,"@barchart/portfolio-api-common/lib/data/TransactionType":51,"@barchart/portfolio-api-common/lib/data/ValuationType":52,"@barchart/tgam-jwt-js/lib/JwtGateway":55}],2:[function(require,module,exports){
|
|
26
30
|
'use strict';
|
|
27
31
|
|
|
28
32
|
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; }; }();
|
|
@@ -114,6 +118,8 @@ var assert = require('@barchart/common-js/lang/assert'),
|
|
|
114
118
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
115
119
|
is = require('@barchart/common-js/lang/is');
|
|
116
120
|
|
|
121
|
+
var TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType');
|
|
122
|
+
|
|
117
123
|
var PortfolioSchema = require('@barchart/portfolio-api-common/lib/serialization/PortfolioSchema'),
|
|
118
124
|
TransactionSchema = require('@barchart/portfolio-api-common/lib/serialization/TransactionSchema');
|
|
119
125
|
|
|
@@ -175,7 +181,7 @@ module.exports = function () {
|
|
|
175
181
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false);
|
|
176
182
|
}).withBody('portfolio').withRequestInterceptor(RequestInterceptor.fromDelegate(updatePortfolioRequestInterceptor)).withRequestInterceptor(requestInterceptorToUse).withResponseInterceptor(responseInterceptorForPortfolioDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
177
183
|
|
|
178
|
-
_this.
|
|
184
|
+
_this._deletePortfolioEndpoint = EndpointBuilder.for('delete-portfolio', 'delete portfolios').withVerb(VerbType.DELETE).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
179
185
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false);
|
|
180
186
|
}).withRequestInterceptor(requestInterceptorToUse).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
181
187
|
|
|
@@ -183,6 +189,14 @@ module.exports = function () {
|
|
|
183
189
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withVariableParameter('position', 'position', 'position', false);
|
|
184
190
|
}).withRequestInterceptor(requestInterceptorToUse).withResponseInterceptor(responseInterceptorForPositionDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
185
191
|
|
|
192
|
+
_this._readPositionSummariesEndpoint = EndpointBuilder.for('read-position-summaries', 'read position summaries').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
193
|
+
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('summaries', 'summaries').withVariableParameter('position', 'position', 'position', false);
|
|
194
|
+
}).withQueryBuilder(function (qb) {
|
|
195
|
+
qb.withVariableParameter('frame', 'frame', 'frame', true).withVariableParameter('start', 'start', 'start', true).withVariableParameter('end', 'end', 'end', true);
|
|
196
|
+
}).withRequestInterceptor(requestInterceptorToUse)
|
|
197
|
+
// .withResponseInterceptor(responseInterceptorForPositionDeserialization)
|
|
198
|
+
.withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
199
|
+
|
|
186
200
|
_this._deletePortfoliosEndpoint = EndpointBuilder.for('delete-portfolio', 'delete portfolios').withVerb(VerbType.DELETE).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
187
201
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withVariableParameter('position', 'position', 'position', false);
|
|
188
202
|
}).withRequestInterceptor(requestInterceptorToUse).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
@@ -264,7 +278,7 @@ module.exports = function () {
|
|
|
264
278
|
* Creates a portfolio
|
|
265
279
|
*
|
|
266
280
|
* @public
|
|
267
|
-
* @param {Object
|
|
281
|
+
* @param {Object} portfolio
|
|
268
282
|
* @return {Promise.<Portfolio>}
|
|
269
283
|
*/
|
|
270
284
|
|
|
@@ -286,7 +300,7 @@ module.exports = function () {
|
|
|
286
300
|
* Updates a portfolio
|
|
287
301
|
*
|
|
288
302
|
* @public
|
|
289
|
-
* @param {
|
|
303
|
+
* @param {Object} portfolio
|
|
290
304
|
* @return {Promise.<Portfolio>}
|
|
291
305
|
*/
|
|
292
306
|
|
|
@@ -298,7 +312,7 @@ module.exports = function () {
|
|
|
298
312
|
return Promise.resolve().then(function () {
|
|
299
313
|
checkStart.call(_this5);
|
|
300
314
|
|
|
301
|
-
assert.argumentIsRequired(portfolio, 'portfolio',
|
|
315
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
302
316
|
|
|
303
317
|
return Gateway.invoke(_this5._updatePortfolioEndpoint, PortfolioSchema.UPDATE.schema.format(portfolio));
|
|
304
318
|
});
|
|
@@ -308,8 +322,7 @@ module.exports = function () {
|
|
|
308
322
|
* Updates a portfolio
|
|
309
323
|
*
|
|
310
324
|
* @public
|
|
311
|
-
* @param {String
|
|
312
|
-
* @param {Object=} portfolioDatas
|
|
325
|
+
* @param {String} portfolio - ID of the portfolio to update
|
|
313
326
|
* @return {Promise.<Portfolio>}
|
|
314
327
|
*/
|
|
315
328
|
|
|
@@ -323,7 +336,7 @@ module.exports = function () {
|
|
|
323
336
|
|
|
324
337
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
325
338
|
|
|
326
|
-
return Gateway.invoke(_this6.
|
|
339
|
+
return Gateway.invoke(_this6._deletePortfolioEndpoint, { portfolio: portfolio });
|
|
327
340
|
});
|
|
328
341
|
}
|
|
329
342
|
|
|
@@ -352,7 +365,7 @@ module.exports = function () {
|
|
|
352
365
|
}
|
|
353
366
|
|
|
354
367
|
/**
|
|
355
|
-
*
|
|
368
|
+
* Retrieves positions for a user, a user's portfolio, or a single position.
|
|
356
369
|
*
|
|
357
370
|
* @public
|
|
358
371
|
* @param {String=} portfolio
|
|
@@ -361,43 +374,77 @@ module.exports = function () {
|
|
|
361
374
|
*/
|
|
362
375
|
|
|
363
376
|
}, {
|
|
364
|
-
key: '
|
|
365
|
-
value: function
|
|
377
|
+
key: 'readPositionSummaries',
|
|
378
|
+
value: function readPositionSummaries(portfolio, position) {
|
|
366
379
|
var _this8 = this;
|
|
367
380
|
|
|
368
381
|
return Promise.resolve().then(function () {
|
|
369
382
|
checkStart.call(_this8);
|
|
370
383
|
|
|
371
|
-
|
|
372
|
-
|
|
384
|
+
// console
|
|
385
|
+
|
|
386
|
+
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
387
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
373
388
|
|
|
374
|
-
return Gateway.invoke(_this8.
|
|
389
|
+
return Gateway.invoke(_this8._readPositionSummariesEndpoint, { portfolio: portfolio || '*', position: position || '*' });
|
|
375
390
|
});
|
|
376
391
|
}
|
|
377
392
|
|
|
378
393
|
/**
|
|
379
|
-
*
|
|
394
|
+
* Deletes a position.
|
|
380
395
|
*
|
|
381
396
|
* @public
|
|
382
397
|
* @param {String} portfolio
|
|
383
|
-
* @param {String
|
|
384
|
-
* @returns {Promise.<
|
|
398
|
+
* @param {String} position
|
|
399
|
+
* @returns {Promise.<Position[]>}
|
|
385
400
|
*/
|
|
386
401
|
|
|
387
402
|
}, {
|
|
388
|
-
key: '
|
|
389
|
-
value: function
|
|
403
|
+
key: 'deletePosition',
|
|
404
|
+
value: function deletePosition(portfolio, position) {
|
|
390
405
|
var _this9 = this;
|
|
391
406
|
|
|
392
407
|
return Promise.resolve().then(function () {
|
|
393
408
|
checkStart.call(_this9);
|
|
394
409
|
|
|
395
410
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
396
|
-
assert.
|
|
411
|
+
assert.argumentIsRequired(position, 'position', String);
|
|
412
|
+
|
|
413
|
+
return Gateway.invoke(_this9._deletePositionEndpoint, { portfolio: portfolio, position: position });
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Retrieves transactions for a portfolio, or a single position.
|
|
419
|
+
*
|
|
420
|
+
* @public
|
|
421
|
+
* @param {Object} transaction
|
|
422
|
+
* @returns {Promise.<Transaction[]>}
|
|
423
|
+
*/
|
|
424
|
+
|
|
425
|
+
}, {
|
|
426
|
+
key: 'createTransaction',
|
|
427
|
+
value: function createTransaction(transaction) {
|
|
428
|
+
var _this10 = this;
|
|
429
|
+
|
|
430
|
+
return Promise.resolve().then(function () {
|
|
431
|
+
checkStart.call(_this10);
|
|
397
432
|
|
|
398
433
|
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
434
|
+
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
435
|
+
assert.argumentIsOptional(transaction.position, 'transaction.position', String);
|
|
436
|
+
|
|
437
|
+
if (transaction.type instanceof TransactionType) {
|
|
438
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', TransactionType, 'TransactionType');
|
|
439
|
+
} else {
|
|
440
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', String);
|
|
441
|
+
}
|
|
399
442
|
|
|
400
|
-
|
|
443
|
+
if (!transaction.position) {
|
|
444
|
+
transaction.position = 'new';
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return Gateway.invoke(_this10._createTransactionEndpoint, TransactionSchema.forCreate(transaction.type));
|
|
401
448
|
});
|
|
402
449
|
}
|
|
403
450
|
|
|
@@ -414,16 +461,16 @@ module.exports = function () {
|
|
|
414
461
|
}, {
|
|
415
462
|
key: 'deleteTransaction',
|
|
416
463
|
value: function deleteTransaction(portfolio, position, transaction) {
|
|
417
|
-
var
|
|
464
|
+
var _this11 = this;
|
|
418
465
|
|
|
419
466
|
return Promise.resolve().then(function () {
|
|
420
|
-
checkStart.call(
|
|
467
|
+
checkStart.call(_this11);
|
|
421
468
|
|
|
422
469
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
423
470
|
assert.argumentIsRequired(position, 'position', String);
|
|
424
471
|
assert.argumentIsRequired(transaction, 'transaction', String);
|
|
425
472
|
|
|
426
|
-
return Gateway.invoke(
|
|
473
|
+
return Gateway.invoke(_this11._deleteTransactionsEndpoint, { portfolio: portfolio, position: position, transaction: transaction });
|
|
427
474
|
});
|
|
428
475
|
}
|
|
429
476
|
|
|
@@ -439,29 +486,29 @@ module.exports = function () {
|
|
|
439
486
|
}, {
|
|
440
487
|
key: 'readTransactions',
|
|
441
488
|
value: function readTransactions(portfolio, position) {
|
|
442
|
-
var
|
|
489
|
+
var _this12 = this;
|
|
443
490
|
|
|
444
491
|
return Promise.resolve().then(function () {
|
|
445
|
-
checkStart.call(
|
|
492
|
+
checkStart.call(_this12);
|
|
446
493
|
|
|
447
494
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
448
495
|
assert.argumentIsOptional(position, 'position', String);
|
|
449
496
|
|
|
450
|
-
return Gateway.invoke(
|
|
497
|
+
return Gateway.invoke(_this12._readTransactionsEndpoint, { portfolio: portfolio, position: position || '*' });
|
|
451
498
|
});
|
|
452
499
|
}
|
|
453
500
|
}, {
|
|
454
501
|
key: 'readTransactionsFormatted',
|
|
455
502
|
value: function readTransactionsFormatted(portfolio, position) {
|
|
456
|
-
var
|
|
503
|
+
var _this13 = this;
|
|
457
504
|
|
|
458
505
|
return Promise.resolve().then(function () {
|
|
459
|
-
checkStart.call(
|
|
506
|
+
checkStart.call(_this13);
|
|
460
507
|
|
|
461
508
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
462
509
|
assert.argumentIsOptional(position, 'position', String);
|
|
463
510
|
|
|
464
|
-
return Gateway.invoke(
|
|
511
|
+
return Gateway.invoke(_this13._readTransactionsReportEndpoint, { portfolio: portfolio, position: position || '*' });
|
|
465
512
|
});
|
|
466
513
|
}
|
|
467
514
|
|
|
@@ -611,7 +658,7 @@ module.exports = function () {
|
|
|
611
658
|
return PortfolioGateway;
|
|
612
659
|
}();
|
|
613
660
|
|
|
614
|
-
},{"./../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/serialization/PortfolioSchema":53,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":54}],4:[function(require,module,exports){
|
|
661
|
+
},{"./../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":51,"@barchart/portfolio-api-common/lib/serialization/PortfolioSchema":53,"@barchart/portfolio-api-common/lib/serialization/TransactionSchema":54}],4:[function(require,module,exports){
|
|
615
662
|
'use strict';
|
|
616
663
|
|
|
617
664
|
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; }; }();
|
|
@@ -924,7 +971,7 @@ module.exports = function () {
|
|
|
924
971
|
return {
|
|
925
972
|
JwtGateway: JwtGateway,
|
|
926
973
|
PortfolioGateway: PortfolioGateway,
|
|
927
|
-
version: '1.1.
|
|
974
|
+
version: '1.1.12'
|
|
928
975
|
};
|
|
929
976
|
}();
|
|
930
977
|
|
|
@@ -8087,9 +8134,9 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
|
8087
8134
|
|
|
8088
8135
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8089
8136
|
|
|
8090
|
-
var
|
|
8091
|
-
|
|
8092
|
-
|
|
8137
|
+
var attributes = require('./../../lang/attributes'),
|
|
8138
|
+
functions = require('./../../lang/functions'),
|
|
8139
|
+
is = require('./../../lang/is');
|
|
8093
8140
|
|
|
8094
8141
|
var LinkedList = require('./../../collections/LinkedList'),
|
|
8095
8142
|
Tree = require('./../../collections/Tree');
|
|
@@ -8125,66 +8172,54 @@ module.exports = function () {
|
|
|
8125
8172
|
}
|
|
8126
8173
|
|
|
8127
8174
|
/**
|
|
8128
|
-
*
|
|
8175
|
+
* Accepts data and returns a new object which (should) conform to
|
|
8176
|
+
* the schema.
|
|
8129
8177
|
*
|
|
8130
8178
|
* @public
|
|
8131
|
-
* @
|
|
8179
|
+
* @param {data} data
|
|
8180
|
+
* @returns {Object}
|
|
8132
8181
|
*/
|
|
8133
8182
|
|
|
8134
8183
|
|
|
8135
8184
|
_createClass(Schema, [{
|
|
8136
|
-
key: '
|
|
8185
|
+
key: 'format',
|
|
8186
|
+
value: function format(data) {
|
|
8187
|
+
var returnRef = {};
|
|
8137
8188
|
|
|
8189
|
+
this._fields.forEach(function (field) {
|
|
8190
|
+
formatField(returnRef, field, data);
|
|
8191
|
+
});
|
|
8138
8192
|
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
*/
|
|
8145
|
-
value: function validate(candidate) {
|
|
8146
|
-
var returnVal = is.object(candidate);
|
|
8193
|
+
this._components.forEach(function (component) {
|
|
8194
|
+
component.fields.forEach(function (field) {
|
|
8195
|
+
formatField(returnRef, field, data);
|
|
8196
|
+
});
|
|
8197
|
+
});
|
|
8147
8198
|
|
|
8148
|
-
return
|
|
8199
|
+
return returnRef;
|
|
8149
8200
|
}
|
|
8150
8201
|
|
|
8151
8202
|
/**
|
|
8152
|
-
*
|
|
8203
|
+
* Name of the table.
|
|
8153
8204
|
*
|
|
8154
8205
|
* @public
|
|
8155
|
-
* @returns {
|
|
8206
|
+
* @returns {String}
|
|
8156
8207
|
*/
|
|
8157
8208
|
|
|
8158
8209
|
}, {
|
|
8159
|
-
key: '
|
|
8160
|
-
value: function getSimpleReviver() {
|
|
8161
|
-
var _this = this;
|
|
8162
|
-
|
|
8163
|
-
return function (key, value) {
|
|
8164
|
-
var field = _this.fields.find(function (f) {
|
|
8165
|
-
var fieldName = array.last(f.name.split('.'));
|
|
8166
|
-
|
|
8167
|
-
return fieldName === key;
|
|
8168
|
-
});
|
|
8169
|
-
|
|
8170
|
-
if (is.object(value)) {
|
|
8171
|
-
return value;
|
|
8172
|
-
}
|
|
8210
|
+
key: 'validate',
|
|
8173
8211
|
|
|
8174
|
-
var returnVal = void 0;
|
|
8175
8212
|
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
}
|
|
8213
|
+
/**
|
|
8214
|
+
* Returns true, if an object complies with the schema.
|
|
8215
|
+
*
|
|
8216
|
+
* @public
|
|
8217
|
+
* @param {*} candidate
|
|
8218
|
+
*/
|
|
8219
|
+
value: function validate(candidate) {
|
|
8220
|
+
var returnVal = is.object(candidate);
|
|
8185
8221
|
|
|
8186
|
-
|
|
8187
|
-
};
|
|
8222
|
+
return false;
|
|
8188
8223
|
}
|
|
8189
8224
|
|
|
8190
8225
|
/**
|
|
@@ -8238,10 +8273,10 @@ module.exports = function () {
|
|
|
8238
8273
|
}, {
|
|
8239
8274
|
key: 'getReviverFactory',
|
|
8240
8275
|
value: function getReviverFactory() {
|
|
8241
|
-
var
|
|
8276
|
+
var _this = this;
|
|
8242
8277
|
|
|
8243
8278
|
return function () {
|
|
8244
|
-
return
|
|
8279
|
+
return _this.getReviver();
|
|
8245
8280
|
};
|
|
8246
8281
|
}
|
|
8247
8282
|
}, {
|
|
@@ -8305,11 +8340,11 @@ module.exports = function () {
|
|
|
8305
8340
|
function SchemaError(key, name, message) {
|
|
8306
8341
|
_classCallCheck(this, SchemaError);
|
|
8307
8342
|
|
|
8308
|
-
var
|
|
8343
|
+
var _this2 = _possibleConstructorReturn(this, (SchemaError.__proto__ || Object.getPrototypeOf(SchemaError)).call(this, message));
|
|
8309
8344
|
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
return
|
|
8345
|
+
_this2.key = key;
|
|
8346
|
+
_this2.name = name;
|
|
8347
|
+
return _this2;
|
|
8313
8348
|
}
|
|
8314
8349
|
|
|
8315
8350
|
_createClass(SchemaError, [{
|
|
@@ -8441,10 +8476,16 @@ module.exports = function () {
|
|
|
8441
8476
|
return head;
|
|
8442
8477
|
}
|
|
8443
8478
|
|
|
8479
|
+
function formatField(target, field, data) {
|
|
8480
|
+
if (attributes.has(data, field.name)) {
|
|
8481
|
+
attributes.write(target, field.name, field.dataType.convert(attributes.read(data, field.name)));
|
|
8482
|
+
}
|
|
8483
|
+
}
|
|
8484
|
+
|
|
8444
8485
|
return Schema;
|
|
8445
8486
|
}();
|
|
8446
8487
|
|
|
8447
|
-
},{"./../../collections/LinkedList":23,"./../../collections/Tree":24,"./../../lang/
|
|
8488
|
+
},{"./../../collections/LinkedList":23,"./../../collections/Tree":24,"./../../lang/attributes":38,"./../../lang/functions":39,"./../../lang/is":40,"./Component":44,"./Field":46}],48:[function(require,module,exports){
|
|
8448
8489
|
'use strict';
|
|
8449
8490
|
|
|
8450
8491
|
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; }; }();
|
|
@@ -9474,6 +9515,7 @@ module.exports = (() => {
|
|
|
9474
9515
|
|
|
9475
9516
|
},{"./../data/ValuationType":52,"@barchart/common-js/lang/Currency":28,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/Timezones":35,"@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}],54:[function(require,module,exports){
|
|
9476
9517
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
9518
|
+
is = require('@barchart/common-js/lang/is'),
|
|
9477
9519
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
9478
9520
|
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
9479
9521
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
@@ -9508,6 +9550,35 @@ module.exports = (() => {
|
|
|
9508
9550
|
return this._schema;
|
|
9509
9551
|
}
|
|
9510
9552
|
|
|
9553
|
+
/**
|
|
9554
|
+
* Returns the appropriate schema for creating a transaction of the
|
|
9555
|
+
* supplied type.
|
|
9556
|
+
*
|
|
9557
|
+
* @public
|
|
9558
|
+
* @static
|
|
9559
|
+
* @param {String|TransactionType} transactionType
|
|
9560
|
+
* @returns {TransactionSchema|null}
|
|
9561
|
+
*/
|
|
9562
|
+
static forCreate(transactionType) {
|
|
9563
|
+
let code;
|
|
9564
|
+
|
|
9565
|
+
if (transactionType instanceof TransactionType) {
|
|
9566
|
+
code = transactionType.code;
|
|
9567
|
+
} else {
|
|
9568
|
+
code = transactionType;
|
|
9569
|
+
}
|
|
9570
|
+
|
|
9571
|
+
let schema;
|
|
9572
|
+
|
|
9573
|
+
if (is.string(code)) {
|
|
9574
|
+
schema = Enum.fromCode(code);
|
|
9575
|
+
} else {
|
|
9576
|
+
schema = null;
|
|
9577
|
+
}
|
|
9578
|
+
|
|
9579
|
+
return schema;
|
|
9580
|
+
}
|
|
9581
|
+
|
|
9511
9582
|
/**
|
|
9512
9583
|
* The complete transaction schema.
|
|
9513
9584
|
*
|
|
@@ -9685,9 +9756,10 @@ module.exports = (() => {
|
|
|
9685
9756
|
.schema
|
|
9686
9757
|
);
|
|
9687
9758
|
|
|
9688
|
-
const buy = new TransactionSchema(SchemaBuilder.withName(
|
|
9759
|
+
const buy = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY.code)
|
|
9760
|
+
.withField('portfolio', DataType.STRING)
|
|
9761
|
+
.withField('position', DataType.STRING)
|
|
9689
9762
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9690
|
-
.withField('position', DataType.STRING, true)
|
|
9691
9763
|
.withField('instrument.name', DataType.STRING, true)
|
|
9692
9764
|
.withField('instrument.type', DataType.STRING, true)
|
|
9693
9765
|
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
@@ -9701,10 +9773,10 @@ module.exports = (() => {
|
|
|
9701
9773
|
.schema
|
|
9702
9774
|
);
|
|
9703
9775
|
|
|
9704
|
-
const sell = new TransactionSchema(SchemaBuilder.withName(
|
|
9776
|
+
const sell = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL.code)
|
|
9777
|
+
.withField('portfolio', DataType.STRING)
|
|
9778
|
+
.withField('position', DataType.STRING)
|
|
9705
9779
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9706
|
-
.withField('position', DataType.STRING, true)
|
|
9707
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9708
9780
|
.withField('date', DataType.DAY)
|
|
9709
9781
|
.withField('price', DataType.DECIMAL)
|
|
9710
9782
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -9712,10 +9784,10 @@ module.exports = (() => {
|
|
|
9712
9784
|
.schema
|
|
9713
9785
|
);
|
|
9714
9786
|
|
|
9715
|
-
const buyShort = new TransactionSchema(SchemaBuilder.withName(
|
|
9787
|
+
const buyShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY_SHORT.code)
|
|
9788
|
+
.withField('portfolio', DataType.STRING)
|
|
9789
|
+
.withField('position', DataType.STRING)
|
|
9716
9790
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9717
|
-
.withField('position', DataType.STRING, true)
|
|
9718
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9719
9791
|
.withField('date', DataType.DAY)
|
|
9720
9792
|
.withField('price', DataType.DECIMAL)
|
|
9721
9793
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -9723,10 +9795,15 @@ module.exports = (() => {
|
|
|
9723
9795
|
.schema
|
|
9724
9796
|
);
|
|
9725
9797
|
|
|
9726
|
-
const sellShort = new TransactionSchema(SchemaBuilder.withName(
|
|
9798
|
+
const sellShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL_SHORT.code)
|
|
9799
|
+
.withField('portfolio', DataType.STRING)
|
|
9800
|
+
.withField('position', DataType.STRING)
|
|
9727
9801
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9728
|
-
.withField('
|
|
9729
|
-
.withField('
|
|
9802
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
9803
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
9804
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
9805
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
9806
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
9730
9807
|
.withField('date', DataType.DAY)
|
|
9731
9808
|
.withField('price', DataType.DECIMAL)
|
|
9732
9809
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -9734,10 +9811,10 @@ module.exports = (() => {
|
|
|
9734
9811
|
.schema
|
|
9735
9812
|
);
|
|
9736
9813
|
|
|
9737
|
-
const dividend = new TransactionSchema(SchemaBuilder.withName(
|
|
9814
|
+
const dividend = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND.code)
|
|
9815
|
+
.withField('portfolio', DataType.STRING)
|
|
9816
|
+
.withField('position', DataType.STRING)
|
|
9738
9817
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9739
|
-
.withField('position', DataType.STRING, true)
|
|
9740
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9741
9818
|
.withField('date', DataType.DAY)
|
|
9742
9819
|
.withField('rate', DataType.DECIMAL)
|
|
9743
9820
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -9746,10 +9823,10 @@ module.exports = (() => {
|
|
|
9746
9823
|
.schema
|
|
9747
9824
|
);
|
|
9748
9825
|
|
|
9749
|
-
const dividendReinvest = new TransactionSchema(SchemaBuilder.withName(
|
|
9826
|
+
const dividendReinvest = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND_REINVEST.code)
|
|
9827
|
+
.withField('portfolio', DataType.STRING)
|
|
9828
|
+
.withField('position', DataType.STRING)
|
|
9750
9829
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9751
|
-
.withField('position', DataType.STRING, true)
|
|
9752
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9753
9830
|
.withField('date', DataType.DAY)
|
|
9754
9831
|
.withField('rate', DataType.DECIMAL)
|
|
9755
9832
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -9759,10 +9836,10 @@ module.exports = (() => {
|
|
|
9759
9836
|
.schema
|
|
9760
9837
|
);
|
|
9761
9838
|
|
|
9762
|
-
const dividendStock = new TransactionSchema(SchemaBuilder.withName(
|
|
9839
|
+
const dividendStock = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND_STOCK.code)
|
|
9840
|
+
.withField('portfolio', DataType.STRING)
|
|
9841
|
+
.withField('position', DataType.STRING)
|
|
9763
9842
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9764
|
-
.withField('position', DataType.STRING, true)
|
|
9765
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9766
9843
|
.withField('date', DataType.DAY)
|
|
9767
9844
|
.withField('rate', DataType.DECIMAL)
|
|
9768
9845
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -9772,10 +9849,10 @@ module.exports = (() => {
|
|
|
9772
9849
|
.schema
|
|
9773
9850
|
);
|
|
9774
9851
|
|
|
9775
|
-
const distributionCash = new TransactionSchema(SchemaBuilder.withName(
|
|
9852
|
+
const distributionCash = new TransactionSchema(SchemaBuilder.withName(TransactionType.DISTRIBUTION_CASH.code)
|
|
9853
|
+
.withField('portfolio', DataType.STRING)
|
|
9854
|
+
.withField('position', DataType.STRING)
|
|
9776
9855
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9777
|
-
.withField('position', DataType.STRING, true)
|
|
9778
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9779
9856
|
.withField('date', DataType.DAY)
|
|
9780
9857
|
.withField('rate', DataType.DECIMAL)
|
|
9781
9858
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -9784,10 +9861,10 @@ module.exports = (() => {
|
|
|
9784
9861
|
.schema
|
|
9785
9862
|
);
|
|
9786
9863
|
|
|
9787
|
-
const distributionFund = new TransactionSchema(SchemaBuilder.withName(
|
|
9864
|
+
const distributionFund = new TransactionSchema(SchemaBuilder.withName(TransactionType.DISTRIBUTION_FUND.code)
|
|
9865
|
+
.withField('portfolio', DataType.STRING)
|
|
9866
|
+
.withField('position', DataType.STRING)
|
|
9788
9867
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9789
|
-
.withField('position', DataType.STRING, true)
|
|
9790
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9791
9868
|
.withField('date', DataType.DAY)
|
|
9792
9869
|
.withField('rate', DataType.DECIMAL)
|
|
9793
9870
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -9796,10 +9873,10 @@ module.exports = (() => {
|
|
|
9796
9873
|
.schema
|
|
9797
9874
|
);
|
|
9798
9875
|
|
|
9799
|
-
const split = new TransactionSchema(SchemaBuilder.withName(
|
|
9876
|
+
const split = new TransactionSchema(SchemaBuilder.withName(TransactionType.SPLIT.code)
|
|
9877
|
+
.withField('portfolio', DataType.STRING)
|
|
9878
|
+
.withField('position', DataType.STRING)
|
|
9800
9879
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9801
|
-
.withField('position', DataType.STRING, true)
|
|
9802
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9803
9880
|
.withField('date', DataType.DAY)
|
|
9804
9881
|
.withField('numerator', DataType.DECIMAL)
|
|
9805
9882
|
.withField('denominator', DataType.DECIMAL)
|
|
@@ -9808,89 +9885,115 @@ module.exports = (() => {
|
|
|
9808
9885
|
.schema
|
|
9809
9886
|
);
|
|
9810
9887
|
|
|
9811
|
-
const fee = new TransactionSchema(SchemaBuilder.withName(
|
|
9888
|
+
const fee = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE.code)
|
|
9889
|
+
.withField('portfolio', DataType.STRING)
|
|
9890
|
+
.withField('position', DataType.STRING)
|
|
9812
9891
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9813
|
-
.withField('position', DataType.STRING, true)
|
|
9814
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9815
9892
|
.withField('date', DataType.DAY)
|
|
9816
9893
|
.withField('fee', DataType.DECIMAL)
|
|
9817
9894
|
.schema
|
|
9818
9895
|
);
|
|
9819
9896
|
|
|
9820
|
-
const feeUnits = new TransactionSchema(SchemaBuilder.withName(
|
|
9897
|
+
const feeUnits = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE_UNITS.code)
|
|
9898
|
+
.withField('portfolio', DataType.STRING)
|
|
9899
|
+
.withField('position', DataType.STRING)
|
|
9821
9900
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9822
|
-
.withField('position', DataType.STRING, true)
|
|
9823
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9824
9901
|
.withField('date', DataType.DAY)
|
|
9825
9902
|
.withField('fee', DataType.DECIMAL)
|
|
9826
9903
|
.withField('price', DataType.DECIMAL)
|
|
9827
9904
|
.schema
|
|
9828
9905
|
);
|
|
9829
9906
|
|
|
9830
|
-
const deposit = new TransactionSchema(SchemaBuilder.withName(
|
|
9907
|
+
const deposit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEPOSIT.code)
|
|
9908
|
+
.withField('portfolio', DataType.STRING)
|
|
9909
|
+
.withField('position', DataType.STRING)
|
|
9831
9910
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9832
|
-
.withField('
|
|
9833
|
-
.withField('
|
|
9911
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
9912
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
9913
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
9914
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
9915
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
9834
9916
|
.withField('date', DataType.DAY)
|
|
9835
9917
|
.withField('amount', DataType.DECIMAL)
|
|
9836
9918
|
.withField('fee', DataType.DECIMAL, true)
|
|
9837
9919
|
.schema
|
|
9838
9920
|
);
|
|
9839
9921
|
|
|
9840
|
-
const withdrawal = new TransactionSchema(SchemaBuilder.withName(
|
|
9922
|
+
const withdrawal = new TransactionSchema(SchemaBuilder.withName(TransactionType.WITHDRAWAL.code)
|
|
9923
|
+
.withField('portfolio', DataType.STRING)
|
|
9924
|
+
.withField('position', DataType.STRING)
|
|
9841
9925
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9842
|
-
.withField('position', DataType.STRING, true)
|
|
9843
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9844
9926
|
.withField('date', DataType.DAY)
|
|
9845
9927
|
.withField('amount', DataType.DECIMAL)
|
|
9846
9928
|
.withField('fee', DataType.DECIMAL, true)
|
|
9847
9929
|
.schema
|
|
9848
9930
|
);
|
|
9849
9931
|
|
|
9850
|
-
const debit = new TransactionSchema(SchemaBuilder.withName(
|
|
9932
|
+
const debit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEBIT.code)
|
|
9933
|
+
.withField('portfolio', DataType.STRING)
|
|
9934
|
+
.withField('position', DataType.STRING)
|
|
9851
9935
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9852
|
-
.withField('position', DataType.STRING, true)
|
|
9853
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9854
9936
|
.withField('date', DataType.DAY)
|
|
9855
9937
|
.withField('amount', DataType.DECIMAL)
|
|
9856
9938
|
.withField('fee', DataType.DECIMAL, true)
|
|
9857
9939
|
.schema
|
|
9858
9940
|
);
|
|
9859
9941
|
|
|
9860
|
-
const credit = new TransactionSchema(SchemaBuilder.withName(
|
|
9942
|
+
const credit = new TransactionSchema(SchemaBuilder.withName(TransactionType.CREDIT.code)
|
|
9943
|
+
.withField('portfolio', DataType.STRING)
|
|
9944
|
+
.withField('position', DataType.STRING)
|
|
9861
9945
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9862
|
-
.withField('position', DataType.STRING, true)
|
|
9863
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9864
9946
|
.withField('date', DataType.DAY)
|
|
9865
9947
|
.withField('amount', DataType.DECIMAL)
|
|
9866
9948
|
.withField('fee', DataType.DECIMAL, true)
|
|
9867
9949
|
.schema
|
|
9868
9950
|
);
|
|
9869
9951
|
|
|
9870
|
-
const valuation = new TransactionSchema(SchemaBuilder.withName(
|
|
9952
|
+
const valuation = new TransactionSchema(SchemaBuilder.withName(TransactionType.VALUATION.code)
|
|
9953
|
+
.withField('portfolio', DataType.STRING)
|
|
9954
|
+
.withField('position', DataType.STRING)
|
|
9871
9955
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9872
|
-
.withField('position', DataType.STRING, true)
|
|
9873
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9874
9956
|
.withField('date', DataType.DAY)
|
|
9875
9957
|
.withField('value', DataType.DECIMAL)
|
|
9876
9958
|
.withField('fee', DataType.DECIMAL, true)
|
|
9877
9959
|
.schema
|
|
9878
9960
|
);
|
|
9879
9961
|
|
|
9880
|
-
const income = new TransactionSchema(SchemaBuilder.withName(
|
|
9962
|
+
const income = new TransactionSchema(SchemaBuilder.withName(TransactionType.INCOME.code)
|
|
9963
|
+
.withField('portfolio', DataType.STRING)
|
|
9964
|
+
.withField('position', DataType.STRING)
|
|
9881
9965
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
9882
|
-
.withField('position', DataType.STRING, true)
|
|
9883
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
9884
9966
|
.withField('date', DataType.DAY)
|
|
9885
9967
|
.withField('income', DataType.DECIMAL)
|
|
9886
9968
|
.withField('fee', DataType.DECIMAL, true)
|
|
9887
9969
|
.schema
|
|
9888
9970
|
);
|
|
9889
9971
|
|
|
9972
|
+
const map = { };
|
|
9973
|
+
|
|
9974
|
+
function addSchemaToMap(type, schema) {
|
|
9975
|
+
map[type.code] = schema;
|
|
9976
|
+
}
|
|
9977
|
+
|
|
9978
|
+
addSchemaToMap(TransactionType.BUY, buy);
|
|
9979
|
+
addSchemaToMap(TransactionType.SELL, sell);
|
|
9980
|
+
addSchemaToMap(TransactionType.BUY_SHORT, buyShort);
|
|
9981
|
+
addSchemaToMap(TransactionType.SELL_SHORT, sellShort);
|
|
9982
|
+
addSchemaToMap(TransactionType.DIVIDEND, dividend);
|
|
9983
|
+
addSchemaToMap(TransactionType.DIVIDEND_STOCK, dividendStock);
|
|
9984
|
+
addSchemaToMap(TransactionType.DIVIDEND_REINVEST, dividendReinvest);
|
|
9985
|
+
addSchemaToMap(TransactionType.SPLIT, split);
|
|
9986
|
+
addSchemaToMap(TransactionType.FEE, fee);
|
|
9987
|
+
addSchemaToMap(TransactionType.FEE_UNITS, feeUnits);
|
|
9988
|
+
addSchemaToMap(TransactionType.DEPOSIT, deposit);
|
|
9989
|
+
addSchemaToMap(TransactionType.WITHDRAWAL, withdrawal);
|
|
9990
|
+
addSchemaToMap(TransactionType.VALUATION, valuation);
|
|
9991
|
+
addSchemaToMap(TransactionType.INCOME, income);
|
|
9992
|
+
|
|
9890
9993
|
return TransactionSchema;
|
|
9891
9994
|
})();
|
|
9892
9995
|
|
|
9893
|
-
},{"./../data/TransactionType":51,"@barchart/common-js/lang/Currency":28,"@barchart/common-js/lang/Enum":32,"@barchart/common-js/lang/assert":37,"@barchart/common-js/serialization/json/DataType":45,"@barchart/common-js/serialization/json/Schema":47,"@barchart/common-js/serialization/json/builders/SchemaBuilder":49}],55:[function(require,module,exports){
|
|
9996
|
+
},{"./../data/TransactionType":51,"@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}],55:[function(require,module,exports){
|
|
9894
9997
|
'use strict';
|
|
9895
9998
|
|
|
9896
9999
|
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; }; }();
|
package/example/example.shim.js
CHANGED
|
@@ -2,9 +2,11 @@ const JwtGateway = require('@barchart/tgam-jwt-js/lib/JwtGateway');
|
|
|
2
2
|
|
|
3
3
|
const Currency = require('@barchart/common-js/lang/Currency'),
|
|
4
4
|
Day = require('@barchart/common-js/lang/Day'),
|
|
5
|
-
Decimal = require('@barchart/common-js/lang/Decimal')
|
|
5
|
+
Decimal = require('@barchart/common-js/lang/Decimal'),
|
|
6
|
+
Timezones = require('@barchart/common-js/lang/Timezones');
|
|
6
7
|
|
|
7
|
-
const TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType')
|
|
8
|
+
const TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType'),
|
|
9
|
+
ValuationType = require('@barchart/portfolio-api-common/lib/data/ValuationType');
|
|
8
10
|
|
|
9
11
|
module.exports = (() => {
|
|
10
12
|
'use strict';
|
|
@@ -16,6 +18,8 @@ module.exports = (() => {
|
|
|
16
18
|
window.Barchart.Currency = Currency;
|
|
17
19
|
window.Barchart.Day = Day;
|
|
18
20
|
window.Barchart.Decimal = Decimal;
|
|
21
|
+
window.Barchart.Timezones = Timezones;
|
|
19
22
|
window.Barchart.TransactionType = TransactionType;
|
|
23
|
+
window.Barchart.ValuationType = ValuationType;
|
|
20
24
|
|
|
21
25
|
})();
|
|
@@ -3,6 +3,8 @@ const assert = require('@barchart/common-js/lang/assert'),
|
|
|
3
3
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
4
4
|
is = require('@barchart/common-js/lang/is');
|
|
5
5
|
|
|
6
|
+
const TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType');
|
|
7
|
+
|
|
6
8
|
const PortfolioSchema = require('@barchart/portfolio-api-common/lib/serialization/PortfolioSchema'),
|
|
7
9
|
TransactionSchema = require('@barchart/portfolio-api-common/lib/serialization/TransactionSchema');
|
|
8
10
|
|
|
@@ -93,7 +95,7 @@ module.exports = (() => {
|
|
|
93
95
|
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
94
96
|
.endpoint;
|
|
95
97
|
|
|
96
|
-
this.
|
|
98
|
+
this._deletePortfolioEndpoint = EndpointBuilder.for('delete-portfolio', 'delete portfolios')
|
|
97
99
|
.withVerb(VerbType.DELETE)
|
|
98
100
|
.withProtocol(protocolType)
|
|
99
101
|
.withHost(host)
|
|
@@ -122,6 +124,27 @@ module.exports = (() => {
|
|
|
122
124
|
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
123
125
|
.endpoint;
|
|
124
126
|
|
|
127
|
+
this._readPositionSummariesEndpoint = EndpointBuilder.for('read-position-summaries', 'read position summaries')
|
|
128
|
+
.withVerb(VerbType.GET)
|
|
129
|
+
.withProtocol(protocolType)
|
|
130
|
+
.withHost(host)
|
|
131
|
+
.withPort(port)
|
|
132
|
+
.withPathBuilder((pb) => {
|
|
133
|
+
pb.withLiteralParameter('portfolios', 'portfolios')
|
|
134
|
+
.withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
|
|
135
|
+
.withLiteralParameter('summaries', 'summaries')
|
|
136
|
+
.withVariableParameter('position', 'position', 'position', false);
|
|
137
|
+
})
|
|
138
|
+
.withQueryBuilder((qb) => {
|
|
139
|
+
qb.withVariableParameter('frame', 'frame', 'frame', true)
|
|
140
|
+
.withVariableParameter('start', 'start', 'start', true)
|
|
141
|
+
.withVariableParameter('end', 'end', 'end', true);
|
|
142
|
+
})
|
|
143
|
+
.withRequestInterceptor(requestInterceptorToUse)
|
|
144
|
+
// .withResponseInterceptor(responseInterceptorForPositionDeserialization)
|
|
145
|
+
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
146
|
+
.endpoint;
|
|
147
|
+
|
|
125
148
|
this._deletePortfoliosEndpoint = EndpointBuilder.for('delete-portfolio', 'delete portfolios')
|
|
126
149
|
.withVerb(VerbType.DELETE)
|
|
127
150
|
.withProtocol(protocolType)
|
|
@@ -262,7 +285,7 @@ module.exports = (() => {
|
|
|
262
285
|
* Creates a portfolio
|
|
263
286
|
*
|
|
264
287
|
* @public
|
|
265
|
-
* @param {Object
|
|
288
|
+
* @param {Object} portfolio
|
|
266
289
|
* @return {Promise.<Portfolio>}
|
|
267
290
|
*/
|
|
268
291
|
createPortfolio(portfolio) {
|
|
@@ -280,7 +303,7 @@ module.exports = (() => {
|
|
|
280
303
|
* Updates a portfolio
|
|
281
304
|
*
|
|
282
305
|
* @public
|
|
283
|
-
* @param {
|
|
306
|
+
* @param {Object} portfolio
|
|
284
307
|
* @return {Promise.<Portfolio>}
|
|
285
308
|
*/
|
|
286
309
|
updatePortfolio(portfolio) {
|
|
@@ -288,7 +311,7 @@ module.exports = (() => {
|
|
|
288
311
|
.then(() => {
|
|
289
312
|
checkStart.call(this);
|
|
290
313
|
|
|
291
|
-
assert.argumentIsRequired(portfolio, 'portfolio',
|
|
314
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
292
315
|
|
|
293
316
|
return Gateway.invoke(this._updatePortfolioEndpoint, PortfolioSchema.UPDATE.schema.format(portfolio));
|
|
294
317
|
});
|
|
@@ -298,8 +321,7 @@ module.exports = (() => {
|
|
|
298
321
|
* Updates a portfolio
|
|
299
322
|
*
|
|
300
323
|
* @public
|
|
301
|
-
* @param {String
|
|
302
|
-
* @param {Object=} portfolioDatas
|
|
324
|
+
* @param {String} portfolio - ID of the portfolio to update
|
|
303
325
|
* @return {Promise.<Portfolio>}
|
|
304
326
|
*/
|
|
305
327
|
deletePortfolio(portfolio) {
|
|
@@ -309,7 +331,7 @@ module.exports = (() => {
|
|
|
309
331
|
|
|
310
332
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
311
333
|
|
|
312
|
-
return Gateway.invoke(this.
|
|
334
|
+
return Gateway.invoke(this._deletePortfolioEndpoint, { portfolio: portfolio });
|
|
313
335
|
});
|
|
314
336
|
}
|
|
315
337
|
|
|
@@ -334,13 +356,35 @@ module.exports = (() => {
|
|
|
334
356
|
}
|
|
335
357
|
|
|
336
358
|
/**
|
|
337
|
-
*
|
|
359
|
+
* Retrieves positions for a user, a user's portfolio, or a single position.
|
|
338
360
|
*
|
|
339
361
|
* @public
|
|
340
362
|
* @param {String=} portfolio
|
|
341
363
|
* @param {String=} position
|
|
342
364
|
* @returns {Promise.<Position[]>}
|
|
343
365
|
*/
|
|
366
|
+
readPositionSummaries(portfolio, position) {
|
|
367
|
+
return Promise.resolve()
|
|
368
|
+
.then(() => {
|
|
369
|
+
checkStart.call(this);
|
|
370
|
+
|
|
371
|
+
// console
|
|
372
|
+
|
|
373
|
+
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
374
|
+
assert.argumentIsOptional(position, 'position', String);
|
|
375
|
+
|
|
376
|
+
return Gateway.invoke(this._readPositionSummariesEndpoint, { portfolio: portfolio || '*', position: position || '*' });
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Deletes a position.
|
|
382
|
+
*
|
|
383
|
+
* @public
|
|
384
|
+
* @param {String} portfolio
|
|
385
|
+
* @param {String} position
|
|
386
|
+
* @returns {Promise.<Position[]>}
|
|
387
|
+
*/
|
|
344
388
|
deletePosition(portfolio, position) {
|
|
345
389
|
return Promise.resolve()
|
|
346
390
|
.then(() => {
|
|
@@ -349,7 +393,7 @@ module.exports = (() => {
|
|
|
349
393
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
350
394
|
assert.argumentIsRequired(position, 'position', String);
|
|
351
395
|
|
|
352
|
-
return Gateway.invoke(this.
|
|
396
|
+
return Gateway.invoke(this._deletePositionEndpoint, { portfolio: portfolio, position: position });
|
|
353
397
|
});
|
|
354
398
|
}
|
|
355
399
|
|
|
@@ -357,21 +401,29 @@ module.exports = (() => {
|
|
|
357
401
|
* Retrieves transactions for a portfolio, or a single position.
|
|
358
402
|
*
|
|
359
403
|
* @public
|
|
360
|
-
* @param {
|
|
361
|
-
* @param {String=} position
|
|
404
|
+
* @param {Object} transaction
|
|
362
405
|
* @returns {Promise.<Transaction[]>}
|
|
363
406
|
*/
|
|
364
|
-
createTransaction(
|
|
407
|
+
createTransaction(transaction) {
|
|
365
408
|
return Promise.resolve()
|
|
366
409
|
.then(() => {
|
|
367
410
|
checkStart.call(this);
|
|
368
411
|
|
|
369
|
-
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
370
|
-
assert.argumentIsOptional(position, 'position', String);
|
|
371
|
-
|
|
372
412
|
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
413
|
+
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
414
|
+
assert.argumentIsOptional(transaction.position, 'transaction.position', String);
|
|
415
|
+
|
|
416
|
+
if (transaction.type instanceof TransactionType) {
|
|
417
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', TransactionType, 'TransactionType');
|
|
418
|
+
} else {
|
|
419
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', String);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (!transaction.position) {
|
|
423
|
+
transaction.position = 'new';
|
|
424
|
+
}
|
|
373
425
|
|
|
374
|
-
return Gateway.invoke(this._createTransactionEndpoint,
|
|
426
|
+
return Gateway.invoke(this._createTransactionEndpoint, TransactionSchema.forCreate(transaction.type));
|
|
375
427
|
});
|
|
376
428
|
}
|
|
377
429
|
|
package/lib/index.js
CHANGED