@barchart/portfolio-client-js 1.2.6 → 1.2.9
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 +129 -64
- package/lib/gateway/PortfolioGateway.js +106 -35
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/example/example.js
CHANGED
|
@@ -242,16 +242,20 @@ module.exports = function () {
|
|
|
242
242
|
_this._createTransactionEndpoint = EndpointBuilder.for('create-transaction', 'create transaction').withVerb(VerbType.POST).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
243
243
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withVariableParameter('position', 'position', 'position', false).withLiteralParameter('transactions', 'transactions');
|
|
244
244
|
}).withQueryBuilder(function (qb) {
|
|
245
|
-
qb.withVariableParameter('type', 'type', 'type', false, function (
|
|
246
|
-
return
|
|
245
|
+
qb.withVariableParameter('type', 'type', 'type', false, function (t) {
|
|
246
|
+
return getTransactionTypeCode(t);
|
|
247
247
|
});
|
|
248
248
|
}).withBody('transaction').withRequestInterceptor(requestInterceptorToUse).withResponseInterceptor(responseInterceptorForPositionMutateDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
249
249
|
|
|
250
|
+
_this._batchTransactionEndpoint = EndpointBuilder.for('batch-transactions', 'batch transactions').withVerb(VerbType.POST).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
251
|
+
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withLiteralParameter('multiple', 'multiple').withLiteralParameter('transactions', 'transactions');
|
|
252
|
+
}).withBody('transactions').withRequestInterceptor(requestInterceptorToUse).withResponseInterceptor(ResponseInterceptor.DATA).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
253
|
+
|
|
250
254
|
_this._editTransactionEndpoint = EndpointBuilder.for('edit-transaction', 'edit transaction').withVerb(VerbType.POST).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(function (pb) {
|
|
251
255
|
pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withVariableParameter('position', 'position', 'position', false).withLiteralParameter('transactions', 'transactions').withVariableParameter('sequence', 'sequence', 'sequence', false);
|
|
252
256
|
}).withQueryBuilder(function (qb) {
|
|
253
|
-
qb.withVariableParameter('type', 'type', 'type', false, function (
|
|
254
|
-
return
|
|
257
|
+
qb.withVariableParameter('type', 'type', 'type', false, function (t) {
|
|
258
|
+
return getTransactionTypeCode(t);
|
|
255
259
|
});
|
|
256
260
|
}).withBody('transaction').withRequestInterceptor(requestInterceptorToUse).withResponseInterceptor(responseInterceptorForPositionMutateDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
|
|
257
261
|
|
|
@@ -350,6 +354,28 @@ module.exports = function () {
|
|
|
350
354
|
});
|
|
351
355
|
}
|
|
352
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Creates a new portfolio and immediately populates it with transactions.
|
|
359
|
+
*
|
|
360
|
+
* @public
|
|
361
|
+
* @param {Object} portfolio
|
|
362
|
+
* @return {Promise.<Portfolio>}
|
|
363
|
+
*/
|
|
364
|
+
|
|
365
|
+
}, {
|
|
366
|
+
key: 'importPortfolio',
|
|
367
|
+
value: function importPortfolio(portfolio, transactions) {
|
|
368
|
+
var _this5 = this;
|
|
369
|
+
|
|
370
|
+
return Promise.resolve().then(function () {
|
|
371
|
+
checkStart.call(_this5);
|
|
372
|
+
|
|
373
|
+
return _this5.createPortfolio(portfolio).then(function (portfolio) {
|
|
374
|
+
return _this5.batchTransactions(portfolio, transactions);
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
353
379
|
/**
|
|
354
380
|
* Updates a portfolio
|
|
355
381
|
*
|
|
@@ -361,14 +387,14 @@ module.exports = function () {
|
|
|
361
387
|
}, {
|
|
362
388
|
key: 'updatePortfolio',
|
|
363
389
|
value: function updatePortfolio(portfolio) {
|
|
364
|
-
var
|
|
390
|
+
var _this6 = this;
|
|
365
391
|
|
|
366
392
|
return Promise.resolve().then(function () {
|
|
367
|
-
checkStart.call(
|
|
393
|
+
checkStart.call(_this6);
|
|
368
394
|
|
|
369
395
|
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
370
396
|
|
|
371
|
-
return Gateway.invoke(
|
|
397
|
+
return Gateway.invoke(_this6._updatePortfolioEndpoint, PortfolioSchema.UPDATE.schema.format(portfolio));
|
|
372
398
|
});
|
|
373
399
|
}
|
|
374
400
|
|
|
@@ -383,14 +409,14 @@ module.exports = function () {
|
|
|
383
409
|
}, {
|
|
384
410
|
key: 'deletePortfolio',
|
|
385
411
|
value: function deletePortfolio(portfolio) {
|
|
386
|
-
var
|
|
412
|
+
var _this7 = this;
|
|
387
413
|
|
|
388
414
|
return Promise.resolve().then(function () {
|
|
389
|
-
checkStart.call(
|
|
415
|
+
checkStart.call(_this7);
|
|
390
416
|
|
|
391
417
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
392
418
|
|
|
393
|
-
return Gateway.invoke(
|
|
419
|
+
return Gateway.invoke(_this7._deletePortfolioEndpoint, { portfolio: portfolio });
|
|
394
420
|
});
|
|
395
421
|
}
|
|
396
422
|
|
|
@@ -407,16 +433,16 @@ module.exports = function () {
|
|
|
407
433
|
}, {
|
|
408
434
|
key: 'readPositions',
|
|
409
435
|
value: function readPositions(portfolio, position, includePreviousPrice) {
|
|
410
|
-
var
|
|
436
|
+
var _this8 = this;
|
|
411
437
|
|
|
412
438
|
return Promise.resolve().then(function () {
|
|
413
|
-
checkStart.call(
|
|
439
|
+
checkStart.call(_this8);
|
|
414
440
|
|
|
415
441
|
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
416
442
|
assert.argumentIsOptional(position, 'position', String);
|
|
417
443
|
assert.argumentIsOptional(includePreviousPrice, 'includePreviousPrice', Boolean);
|
|
418
444
|
|
|
419
|
-
return Gateway.invoke(
|
|
445
|
+
return Gateway.invoke(_this8._readPositionsEndpoint, { portfolio: portfolio || '*', position: position || '*', includePreviousPrice: includePreviousPrice });
|
|
420
446
|
});
|
|
421
447
|
}
|
|
422
448
|
|
|
@@ -431,14 +457,14 @@ module.exports = function () {
|
|
|
431
457
|
}, {
|
|
432
458
|
key: 'updatePosition',
|
|
433
459
|
value: function updatePosition(position) {
|
|
434
|
-
var
|
|
460
|
+
var _this9 = this;
|
|
435
461
|
|
|
436
462
|
return Promise.resolve().then(function () {
|
|
437
|
-
checkStart.call(
|
|
463
|
+
checkStart.call(_this9);
|
|
438
464
|
|
|
439
465
|
assert.argumentIsRequired(position, 'position', Object);
|
|
440
466
|
|
|
441
|
-
return Gateway.invoke(
|
|
467
|
+
return Gateway.invoke(_this9._updatePositionEndpoint, PositionSchema.UPDATE.schema.format(position));
|
|
442
468
|
});
|
|
443
469
|
}
|
|
444
470
|
|
|
@@ -457,10 +483,10 @@ module.exports = function () {
|
|
|
457
483
|
}, {
|
|
458
484
|
key: 'readPositionSummaries',
|
|
459
485
|
value: function readPositionSummaries(portfolio, position, frames, periods, start) {
|
|
460
|
-
var
|
|
486
|
+
var _this10 = this;
|
|
461
487
|
|
|
462
488
|
return Promise.resolve().then(function () {
|
|
463
|
-
checkStart.call(
|
|
489
|
+
checkStart.call(_this10);
|
|
464
490
|
|
|
465
491
|
assert.argumentIsOptional(portfolio, 'portfolio', String);
|
|
466
492
|
assert.argumentIsOptional(position, 'position', String);
|
|
@@ -513,7 +539,7 @@ module.exports = function () {
|
|
|
513
539
|
query.start = s;
|
|
514
540
|
}
|
|
515
541
|
|
|
516
|
-
return Gateway.invoke(
|
|
542
|
+
return Gateway.invoke(_this10._readPositionSummariesEndpoint, query);
|
|
517
543
|
});
|
|
518
544
|
}
|
|
519
545
|
|
|
@@ -529,20 +555,20 @@ module.exports = function () {
|
|
|
529
555
|
}, {
|
|
530
556
|
key: 'deletePosition',
|
|
531
557
|
value: function deletePosition(portfolio, position) {
|
|
532
|
-
var
|
|
558
|
+
var _this11 = this;
|
|
533
559
|
|
|
534
560
|
return Promise.resolve().then(function () {
|
|
535
|
-
checkStart.call(
|
|
561
|
+
checkStart.call(_this11);
|
|
536
562
|
|
|
537
563
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
538
564
|
assert.argumentIsRequired(position, 'position', String);
|
|
539
565
|
|
|
540
|
-
return Gateway.invoke(
|
|
566
|
+
return Gateway.invoke(_this11._deletePositionEndpoint, { portfolio: portfolio, position: position });
|
|
541
567
|
});
|
|
542
568
|
}
|
|
543
569
|
|
|
544
570
|
/**
|
|
545
|
-
*
|
|
571
|
+
* Creates a new transaction.
|
|
546
572
|
*
|
|
547
573
|
* @public
|
|
548
574
|
* @param {Object} transaction
|
|
@@ -552,34 +578,65 @@ module.exports = function () {
|
|
|
552
578
|
}, {
|
|
553
579
|
key: 'createTransaction',
|
|
554
580
|
value: function createTransaction(transaction) {
|
|
555
|
-
var
|
|
581
|
+
var _this12 = this;
|
|
556
582
|
|
|
557
583
|
return Promise.resolve().then(function () {
|
|
558
|
-
checkStart.call(
|
|
584
|
+
checkStart.call(_this12);
|
|
559
585
|
|
|
560
586
|
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
561
587
|
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
562
588
|
assert.argumentIsOptional(transaction.position, 'transaction.position', String);
|
|
563
589
|
|
|
564
|
-
|
|
590
|
+
if (!transaction.position) {
|
|
591
|
+
transaction.position = 'new';
|
|
592
|
+
}
|
|
565
593
|
|
|
566
|
-
|
|
567
|
-
assert.argumentIsRequired(transaction.type.code, 'transaction.type.code', String);
|
|
594
|
+
var schema = getTransactionSchema(transaction);
|
|
568
595
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
596
|
+
return Gateway.invoke(_this12._createTransactionEndpoint, schema.schema.format(transaction));
|
|
597
|
+
});
|
|
598
|
+
}
|
|
572
599
|
|
|
573
|
-
|
|
574
|
-
|
|
600
|
+
/**
|
|
601
|
+
* Creates one or more new transactions.
|
|
602
|
+
*
|
|
603
|
+
* @public
|
|
604
|
+
* @param {Object} transaction
|
|
605
|
+
* @returns {Promise}
|
|
606
|
+
*/
|
|
575
607
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
608
|
+
}, {
|
|
609
|
+
key: 'batchTransactions',
|
|
610
|
+
value: function batchTransactions(portfolio, transactions) {
|
|
611
|
+
var _this13 = this;
|
|
612
|
+
|
|
613
|
+
return Promise.resolve().then(function () {
|
|
614
|
+
checkStart.call(_this13);
|
|
615
|
+
|
|
616
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
617
|
+
assert.argumentIsArray(transactions, 'transactions', Object);
|
|
579
618
|
|
|
580
|
-
var
|
|
619
|
+
var batchData = {};
|
|
581
620
|
|
|
582
|
-
|
|
621
|
+
batchData.portfolio = portfolio;
|
|
622
|
+
batchData.transactionTypes = [];
|
|
623
|
+
batchData.transactionItems = [];
|
|
624
|
+
|
|
625
|
+
transactions.forEach(function (transaction) {
|
|
626
|
+
transaction.portfolio = portfolio.portfolio;
|
|
627
|
+
|
|
628
|
+
if (!transaction.position) {
|
|
629
|
+
transaction.position = 'new';
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
var code = getTransactionTypeCode(transaction);
|
|
633
|
+
var schema = getTransactionSchema(transaction);
|
|
634
|
+
|
|
635
|
+
batchData.transactionTypes.push(code);
|
|
636
|
+
batchData.transactionItems.push(JSON.stringify(schema.schema.format(transaction)));
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
return Gateway.invoke(_this13._batchTransactionEndpoint, batchData);
|
|
583
640
|
});
|
|
584
641
|
}
|
|
585
642
|
|
|
@@ -594,31 +651,19 @@ module.exports = function () {
|
|
|
594
651
|
}, {
|
|
595
652
|
key: 'editTransaction',
|
|
596
653
|
value: function editTransaction(transaction) {
|
|
597
|
-
var
|
|
654
|
+
var _this14 = this;
|
|
598
655
|
|
|
599
656
|
return Promise.resolve().then(function () {
|
|
600
|
-
checkStart.call(
|
|
657
|
+
checkStart.call(_this14);
|
|
601
658
|
|
|
602
659
|
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
603
660
|
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
604
661
|
assert.argumentIsRequired(transaction.position, 'transaction.position', String);
|
|
605
662
|
assert.argumentIsRequired(transaction.sequence, 'transaction.sequence', Number);
|
|
606
663
|
|
|
607
|
-
var
|
|
608
|
-
|
|
609
|
-
if (is.string(transaction.type)) {
|
|
610
|
-
assert.argumentIsRequired(transaction.type.code, 'transaction.type.code', String);
|
|
611
|
-
|
|
612
|
-
code = transaction.type;
|
|
613
|
-
} else {
|
|
614
|
-
assert.argumentIsRequired(transaction.type, 'transaction.type', TransactionType, 'TransactionType');
|
|
615
|
-
|
|
616
|
-
code = transaction.type.code;
|
|
617
|
-
}
|
|
664
|
+
var schema = getTransactionSchema(transaction);
|
|
618
665
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
return Gateway.invoke(_this12._editTransactionEndpoint, schema.schema.format(transaction));
|
|
666
|
+
return Gateway.invoke(_this14._editTransactionEndpoint, schema.schema.format(transaction));
|
|
622
667
|
});
|
|
623
668
|
}
|
|
624
669
|
|
|
@@ -637,10 +682,10 @@ module.exports = function () {
|
|
|
637
682
|
}, {
|
|
638
683
|
key: 'deleteTransaction',
|
|
639
684
|
value: function deleteTransaction(portfolio, position, sequence, force, echo) {
|
|
640
|
-
var
|
|
685
|
+
var _this15 = this;
|
|
641
686
|
|
|
642
687
|
return Promise.resolve().then(function () {
|
|
643
|
-
checkStart.call(
|
|
688
|
+
checkStart.call(_this15);
|
|
644
689
|
|
|
645
690
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
646
691
|
assert.argumentIsRequired(position, 'position', String);
|
|
@@ -648,7 +693,7 @@ module.exports = function () {
|
|
|
648
693
|
assert.argumentIsOptional(force, 'force', Boolean);
|
|
649
694
|
assert.argumentIsOptional(echo, 'echo', Boolean);
|
|
650
695
|
|
|
651
|
-
return Gateway.invoke(
|
|
696
|
+
return Gateway.invoke(_this15._deleteTransactionEndpoint, { portfolio: portfolio, position: position, sequence: sequence, force: is.boolean(force) && force, echo: is.boolean(echo) && echo });
|
|
652
697
|
});
|
|
653
698
|
}
|
|
654
699
|
|
|
@@ -664,29 +709,29 @@ module.exports = function () {
|
|
|
664
709
|
}, {
|
|
665
710
|
key: 'readTransactions',
|
|
666
711
|
value: function readTransactions(portfolio, position) {
|
|
667
|
-
var
|
|
712
|
+
var _this16 = this;
|
|
668
713
|
|
|
669
714
|
return Promise.resolve().then(function () {
|
|
670
|
-
checkStart.call(
|
|
715
|
+
checkStart.call(_this16);
|
|
671
716
|
|
|
672
717
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
673
718
|
assert.argumentIsOptional(position, 'position', String);
|
|
674
719
|
|
|
675
|
-
return Gateway.invoke(
|
|
720
|
+
return Gateway.invoke(_this16._readTransactionsEndpoint, { portfolio: portfolio, position: position || '*' });
|
|
676
721
|
});
|
|
677
722
|
}
|
|
678
723
|
}, {
|
|
679
724
|
key: 'readTransactionsFormatted',
|
|
680
725
|
value: function readTransactionsFormatted(portfolio, position) {
|
|
681
|
-
var
|
|
726
|
+
var _this17 = this;
|
|
682
727
|
|
|
683
728
|
return Promise.resolve().then(function () {
|
|
684
|
-
checkStart.call(
|
|
729
|
+
checkStart.call(_this17);
|
|
685
730
|
|
|
686
731
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
687
732
|
assert.argumentIsOptional(position, 'position', String);
|
|
688
733
|
|
|
689
|
-
return Gateway.invoke(
|
|
734
|
+
return Gateway.invoke(_this17._readTransactionsReportEndpoint, { portfolio: portfolio, position: position || '*' });
|
|
690
735
|
});
|
|
691
736
|
}
|
|
692
737
|
|
|
@@ -785,6 +830,26 @@ module.exports = function () {
|
|
|
785
830
|
return PortfolioGateway;
|
|
786
831
|
}(Disposable);
|
|
787
832
|
|
|
833
|
+
function getTransactionTypeCode(transaction) {
|
|
834
|
+
var code = void 0;
|
|
835
|
+
|
|
836
|
+
if (is.string(transaction.type)) {
|
|
837
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', String);
|
|
838
|
+
|
|
839
|
+
code = transaction.type;
|
|
840
|
+
} else {
|
|
841
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', TransactionType, 'TransactionType');
|
|
842
|
+
|
|
843
|
+
code = transaction.type.code;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
return code;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
function getTransactionSchema(transaction) {
|
|
850
|
+
return TransactionSchema.forCreate(Enum.fromCode(TransactionType, getTransactionTypeCode(transaction)));
|
|
851
|
+
}
|
|
852
|
+
|
|
788
853
|
var createPortfolioRequestInterceptor = function createPortfolioRequestInterceptor(request) {
|
|
789
854
|
return FailureReason.validateSchema(PortfolioSchema.CREATE, request.data).then(function () {
|
|
790
855
|
return Promise.resolve(request);
|
|
@@ -1257,7 +1322,7 @@ module.exports = function () {
|
|
|
1257
1322
|
return {
|
|
1258
1323
|
JwtGateway: JwtGateway,
|
|
1259
1324
|
PortfolioGateway: PortfolioGateway,
|
|
1260
|
-
version: '1.2.
|
|
1325
|
+
version: '1.2.9'
|
|
1261
1326
|
};
|
|
1262
1327
|
}();
|
|
1263
1328
|
|
|
@@ -229,7 +229,7 @@ module.exports = (() => {
|
|
|
229
229
|
.withLiteralParameter('transactions', 'transactions');
|
|
230
230
|
})
|
|
231
231
|
.withQueryBuilder((qb) => {
|
|
232
|
-
qb.withVariableParameter('type', 'type', 'type', false,
|
|
232
|
+
qb.withVariableParameter('type', 'type', 'type', false, t => getTransactionTypeCode(t));
|
|
233
233
|
})
|
|
234
234
|
.withBody('transaction')
|
|
235
235
|
.withRequestInterceptor(requestInterceptorToUse)
|
|
@@ -237,6 +237,24 @@ module.exports = (() => {
|
|
|
237
237
|
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
238
238
|
.endpoint;
|
|
239
239
|
|
|
240
|
+
this._batchTransactionEndpoint = EndpointBuilder.for('batch-transactions', 'batch transactions')
|
|
241
|
+
.withVerb(VerbType.POST)
|
|
242
|
+
.withProtocol(protocolType)
|
|
243
|
+
.withHost(host)
|
|
244
|
+
.withPort(port)
|
|
245
|
+
.withPathBuilder((pb) => {
|
|
246
|
+
pb.withLiteralParameter('portfolios', 'portfolios')
|
|
247
|
+
.withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
|
|
248
|
+
.withLiteralParameter('positions', 'positions')
|
|
249
|
+
.withLiteralParameter('multiple', 'multiple')
|
|
250
|
+
.withLiteralParameter('transactions', 'transactions');
|
|
251
|
+
})
|
|
252
|
+
.withBody('transactions')
|
|
253
|
+
.withRequestInterceptor(requestInterceptorToUse)
|
|
254
|
+
.withResponseInterceptor(ResponseInterceptor.DATA)
|
|
255
|
+
.withErrorInterceptor(ErrorInterceptor.GENERAL)
|
|
256
|
+
.endpoint;
|
|
257
|
+
|
|
240
258
|
this._editTransactionEndpoint = EndpointBuilder.for('edit-transaction', 'edit transaction')
|
|
241
259
|
.withVerb(VerbType.POST)
|
|
242
260
|
.withProtocol(protocolType)
|
|
@@ -244,14 +262,14 @@ module.exports = (() => {
|
|
|
244
262
|
.withPort(port)
|
|
245
263
|
.withPathBuilder((pb) => {
|
|
246
264
|
pb.withLiteralParameter('portfolios', 'portfolios')
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
265
|
+
.withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
|
|
266
|
+
.withLiteralParameter('positions', 'positions')
|
|
267
|
+
.withVariableParameter('position', 'position', 'position', false)
|
|
268
|
+
.withLiteralParameter('transactions', 'transactions')
|
|
269
|
+
.withVariableParameter('sequence', 'sequence', 'sequence', false);
|
|
252
270
|
})
|
|
253
271
|
.withQueryBuilder((qb) => {
|
|
254
|
-
qb.withVariableParameter('type', 'type', 'type', false,
|
|
272
|
+
qb.withVariableParameter('type', 'type', 'type', false, t => getTransactionTypeCode(t));
|
|
255
273
|
})
|
|
256
274
|
.withBody('transaction')
|
|
257
275
|
.withRequestInterceptor(requestInterceptorToUse)
|
|
@@ -373,6 +391,25 @@ module.exports = (() => {
|
|
|
373
391
|
});
|
|
374
392
|
}
|
|
375
393
|
|
|
394
|
+
/**
|
|
395
|
+
* Creates a new portfolio and immediately populates it with transactions.
|
|
396
|
+
*
|
|
397
|
+
* @public
|
|
398
|
+
* @param {Object} portfolio
|
|
399
|
+
* @return {Promise.<Portfolio>}
|
|
400
|
+
*/
|
|
401
|
+
importPortfolio(portfolio, transactions) {
|
|
402
|
+
return Promise.resolve()
|
|
403
|
+
.then(() => {
|
|
404
|
+
checkStart.call(this);
|
|
405
|
+
|
|
406
|
+
return this.createPortfolio(portfolio)
|
|
407
|
+
.then((portfolio) => {
|
|
408
|
+
return this.batchTransactions(portfolio, transactions);
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
376
413
|
/**
|
|
377
414
|
* Updates a portfolio
|
|
378
415
|
*
|
|
@@ -541,7 +578,7 @@ module.exports = (() => {
|
|
|
541
578
|
}
|
|
542
579
|
|
|
543
580
|
/**
|
|
544
|
-
*
|
|
581
|
+
* Creates a new transaction.
|
|
545
582
|
*
|
|
546
583
|
* @public
|
|
547
584
|
* @param {Object} transaction
|
|
@@ -556,28 +593,55 @@ module.exports = (() => {
|
|
|
556
593
|
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
557
594
|
assert.argumentIsOptional(transaction.position, 'transaction.position', String);
|
|
558
595
|
|
|
559
|
-
let code;
|
|
560
|
-
|
|
561
|
-
if (is.string(transaction.type)) {
|
|
562
|
-
assert.argumentIsRequired(transaction.type.code, 'transaction.type.code', String);
|
|
563
|
-
|
|
564
|
-
code = transaction.type;
|
|
565
|
-
} else {
|
|
566
|
-
assert.argumentIsRequired(transaction.type, 'transaction.type', TransactionType, 'TransactionType');
|
|
567
|
-
|
|
568
|
-
code = transaction.type.code;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
596
|
if (!transaction.position) {
|
|
572
597
|
transaction.position = 'new';
|
|
573
598
|
}
|
|
574
599
|
|
|
575
|
-
const schema =
|
|
600
|
+
const schema = getTransactionSchema(transaction);
|
|
576
601
|
|
|
577
602
|
return Gateway.invoke(this._createTransactionEndpoint, schema.schema.format(transaction));
|
|
578
603
|
});
|
|
579
604
|
}
|
|
580
605
|
|
|
606
|
+
/**
|
|
607
|
+
* Creates one or more new transactions.
|
|
608
|
+
*
|
|
609
|
+
* @public
|
|
610
|
+
* @param {Object} transaction
|
|
611
|
+
* @returns {Promise}
|
|
612
|
+
*/
|
|
613
|
+
batchTransactions(portfolio, transactions) {
|
|
614
|
+
return Promise.resolve()
|
|
615
|
+
.then(() => {
|
|
616
|
+
checkStart.call(this);
|
|
617
|
+
|
|
618
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
619
|
+
assert.argumentIsArray(transactions, 'transactions', Object);
|
|
620
|
+
|
|
621
|
+
const batchData = { };
|
|
622
|
+
|
|
623
|
+
batchData.portfolio = portfolio;
|
|
624
|
+
batchData.transactionTypes = [ ];
|
|
625
|
+
batchData.transactionItems = [ ];
|
|
626
|
+
|
|
627
|
+
transactions.forEach((transaction) => {
|
|
628
|
+
transaction.portfolio = portfolio.portfolio;
|
|
629
|
+
|
|
630
|
+
if (!transaction.position) {
|
|
631
|
+
transaction.position = 'new';
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
const code = getTransactionTypeCode(transaction);
|
|
635
|
+
const schema = getTransactionSchema(transaction);
|
|
636
|
+
|
|
637
|
+
batchData.transactionTypes.push(code);
|
|
638
|
+
batchData.transactionItems.push(JSON.stringify(schema.schema.format(transaction)));
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
return Gateway.invoke(this._batchTransactionEndpoint, batchData);
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
|
|
581
645
|
/**
|
|
582
646
|
* Edits a transaction.
|
|
583
647
|
*
|
|
@@ -595,20 +659,7 @@ module.exports = (() => {
|
|
|
595
659
|
assert.argumentIsRequired(transaction.position, 'transaction.position', String);
|
|
596
660
|
assert.argumentIsRequired(transaction.sequence, 'transaction.sequence', Number);
|
|
597
661
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
if (is.string(transaction.type)) {
|
|
601
|
-
assert.argumentIsRequired(transaction.type.code, 'transaction.type.code', String);
|
|
602
|
-
|
|
603
|
-
code = transaction.type;
|
|
604
|
-
} else {
|
|
605
|
-
assert.argumentIsRequired(transaction.type, 'transaction.type', TransactionType, 'TransactionType');
|
|
606
|
-
|
|
607
|
-
code = transaction.type.code;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
const schema = TransactionSchema.forCreate(Enum.fromCode(TransactionType, code));
|
|
662
|
+
const schema = getTransactionSchema(transaction);
|
|
612
663
|
|
|
613
664
|
return Gateway.invoke(this._editTransactionEndpoint, schema.schema.format(transaction));
|
|
614
665
|
});
|
|
@@ -749,6 +800,26 @@ module.exports = (() => {
|
|
|
749
800
|
}
|
|
750
801
|
}
|
|
751
802
|
|
|
803
|
+
function getTransactionTypeCode(transaction) {
|
|
804
|
+
let code;
|
|
805
|
+
|
|
806
|
+
if (is.string(transaction.type)) {
|
|
807
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', String);
|
|
808
|
+
|
|
809
|
+
code = transaction.type;
|
|
810
|
+
} else {
|
|
811
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', TransactionType, 'TransactionType');
|
|
812
|
+
|
|
813
|
+
code = transaction.type.code;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
return code;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function getTransactionSchema(transaction) {
|
|
820
|
+
return TransactionSchema.forCreate(Enum.fromCode(TransactionType, getTransactionTypeCode(transaction)));
|
|
821
|
+
}
|
|
822
|
+
|
|
752
823
|
const createPortfolioRequestInterceptor = (request) => {
|
|
753
824
|
return FailureReason.validateSchema(PortfolioSchema.CREATE, request.data)
|
|
754
825
|
.then(() => {
|
package/lib/index.js
CHANGED