@barchart/portfolio-client-js 1.2.6 → 1.2.7
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 +128 -64
- package/lib/gateway/PortfolioGateway.js +100 -30
- 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,64 @@ 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;
|
|
579
612
|
|
|
580
|
-
|
|
613
|
+
return Promise.resolve().then(function () {
|
|
614
|
+
checkStart.call(_this13);
|
|
615
|
+
|
|
616
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
617
|
+
assert.argumentIsArray(transactions, 'transactions', Object);
|
|
618
|
+
|
|
619
|
+
var batchData = transactions.reduce(function (data, transaction) {
|
|
620
|
+
transaction.portfolio = portfolio.portfolio;
|
|
621
|
+
|
|
622
|
+
if (!transaction.position) {
|
|
623
|
+
transaction.position = 'new';
|
|
624
|
+
}
|
|
581
625
|
|
|
582
|
-
|
|
626
|
+
var code = getTransactionTypeCode(transaction);
|
|
627
|
+
var schema = getTransactionSchema(transaction);
|
|
628
|
+
|
|
629
|
+
data.types.push(code);
|
|
630
|
+
data.transactions.push(JSON.stringify(schema.schema.format(transaction)));
|
|
631
|
+
|
|
632
|
+
return data;
|
|
633
|
+
}, {
|
|
634
|
+
types: [],
|
|
635
|
+
transactions: []
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
return Gateway.invoke(_this13._batchTransactionEndpoint, batchData);
|
|
583
639
|
});
|
|
584
640
|
}
|
|
585
641
|
|
|
@@ -594,31 +650,19 @@ module.exports = function () {
|
|
|
594
650
|
}, {
|
|
595
651
|
key: 'editTransaction',
|
|
596
652
|
value: function editTransaction(transaction) {
|
|
597
|
-
var
|
|
653
|
+
var _this14 = this;
|
|
598
654
|
|
|
599
655
|
return Promise.resolve().then(function () {
|
|
600
|
-
checkStart.call(
|
|
656
|
+
checkStart.call(_this14);
|
|
601
657
|
|
|
602
658
|
assert.argumentIsRequired(transaction, 'transaction', Object);
|
|
603
659
|
assert.argumentIsRequired(transaction.portfolio, 'transaction.portfolio', String);
|
|
604
660
|
assert.argumentIsRequired(transaction.position, 'transaction.position', String);
|
|
605
661
|
assert.argumentIsRequired(transaction.sequence, 'transaction.sequence', Number);
|
|
606
662
|
|
|
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
|
-
}
|
|
663
|
+
var schema = getTransactionSchema(transaction);
|
|
618
664
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
return Gateway.invoke(_this12._editTransactionEndpoint, schema.schema.format(transaction));
|
|
665
|
+
return Gateway.invoke(_this14._editTransactionEndpoint, schema.schema.format(transaction));
|
|
622
666
|
});
|
|
623
667
|
}
|
|
624
668
|
|
|
@@ -637,10 +681,10 @@ module.exports = function () {
|
|
|
637
681
|
}, {
|
|
638
682
|
key: 'deleteTransaction',
|
|
639
683
|
value: function deleteTransaction(portfolio, position, sequence, force, echo) {
|
|
640
|
-
var
|
|
684
|
+
var _this15 = this;
|
|
641
685
|
|
|
642
686
|
return Promise.resolve().then(function () {
|
|
643
|
-
checkStart.call(
|
|
687
|
+
checkStart.call(_this15);
|
|
644
688
|
|
|
645
689
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
646
690
|
assert.argumentIsRequired(position, 'position', String);
|
|
@@ -648,7 +692,7 @@ module.exports = function () {
|
|
|
648
692
|
assert.argumentIsOptional(force, 'force', Boolean);
|
|
649
693
|
assert.argumentIsOptional(echo, 'echo', Boolean);
|
|
650
694
|
|
|
651
|
-
return Gateway.invoke(
|
|
695
|
+
return Gateway.invoke(_this15._deleteTransactionEndpoint, { portfolio: portfolio, position: position, sequence: sequence, force: is.boolean(force) && force, echo: is.boolean(echo) && echo });
|
|
652
696
|
});
|
|
653
697
|
}
|
|
654
698
|
|
|
@@ -664,29 +708,29 @@ module.exports = function () {
|
|
|
664
708
|
}, {
|
|
665
709
|
key: 'readTransactions',
|
|
666
710
|
value: function readTransactions(portfolio, position) {
|
|
667
|
-
var
|
|
711
|
+
var _this16 = this;
|
|
668
712
|
|
|
669
713
|
return Promise.resolve().then(function () {
|
|
670
|
-
checkStart.call(
|
|
714
|
+
checkStart.call(_this16);
|
|
671
715
|
|
|
672
716
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
673
717
|
assert.argumentIsOptional(position, 'position', String);
|
|
674
718
|
|
|
675
|
-
return Gateway.invoke(
|
|
719
|
+
return Gateway.invoke(_this16._readTransactionsEndpoint, { portfolio: portfolio, position: position || '*' });
|
|
676
720
|
});
|
|
677
721
|
}
|
|
678
722
|
}, {
|
|
679
723
|
key: 'readTransactionsFormatted',
|
|
680
724
|
value: function readTransactionsFormatted(portfolio, position) {
|
|
681
|
-
var
|
|
725
|
+
var _this17 = this;
|
|
682
726
|
|
|
683
727
|
return Promise.resolve().then(function () {
|
|
684
|
-
checkStart.call(
|
|
728
|
+
checkStart.call(_this17);
|
|
685
729
|
|
|
686
730
|
assert.argumentIsRequired(portfolio, 'portfolio', String);
|
|
687
731
|
assert.argumentIsOptional(position, 'position', String);
|
|
688
732
|
|
|
689
|
-
return Gateway.invoke(
|
|
733
|
+
return Gateway.invoke(_this17._readTransactionsReportEndpoint, { portfolio: portfolio, position: position || '*' });
|
|
690
734
|
});
|
|
691
735
|
}
|
|
692
736
|
|
|
@@ -785,6 +829,26 @@ module.exports = function () {
|
|
|
785
829
|
return PortfolioGateway;
|
|
786
830
|
}(Disposable);
|
|
787
831
|
|
|
832
|
+
function getTransactionTypeCode(transaction) {
|
|
833
|
+
var code = void 0;
|
|
834
|
+
|
|
835
|
+
if (is.string(transaction.type)) {
|
|
836
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', String);
|
|
837
|
+
|
|
838
|
+
code = transaction.type;
|
|
839
|
+
} else {
|
|
840
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', TransactionType, 'TransactionType');
|
|
841
|
+
|
|
842
|
+
code = transaction.type.code;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
return code;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
function getTransactionSchema(transaction) {
|
|
849
|
+
return TransactionSchema.forCreate(Enum.fromCode(TransactionType, getTransactionTypeCode(transaction)));
|
|
850
|
+
}
|
|
851
|
+
|
|
788
852
|
var createPortfolioRequestInterceptor = function createPortfolioRequestInterceptor(request) {
|
|
789
853
|
return FailureReason.validateSchema(PortfolioSchema.CREATE, request.data).then(function () {
|
|
790
854
|
return Promise.resolve(request);
|
|
@@ -1257,7 +1321,7 @@ module.exports = function () {
|
|
|
1257
1321
|
return {
|
|
1258
1322
|
JwtGateway: JwtGateway,
|
|
1259
1323
|
PortfolioGateway: PortfolioGateway,
|
|
1260
|
-
version: '1.2.
|
|
1324
|
+
version: '1.2.7'
|
|
1261
1325
|
};
|
|
1262
1326
|
}();
|
|
1263
1327
|
|
|
@@ -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)
|
|
@@ -251,7 +269,7 @@ module.exports = (() => {
|
|
|
251
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,54 @@ 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 = transactions.reduce((data, transaction) => {
|
|
622
|
+
transaction.portfolio = portfolio.portfolio;
|
|
623
|
+
|
|
624
|
+
if (!transaction.position) {
|
|
625
|
+
transaction.position = 'new';
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
const code = getTransactionTypeCode(transaction);
|
|
629
|
+
const schema = getTransactionSchema(transaction);
|
|
630
|
+
|
|
631
|
+
data.types.push(code);
|
|
632
|
+
data.transactions.push(JSON.stringify(schema.schema.format(transaction)));
|
|
633
|
+
|
|
634
|
+
return data;
|
|
635
|
+
}, {
|
|
636
|
+
types: [ ],
|
|
637
|
+
transactions: [ ]
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
return Gateway.invoke(this._batchTransactionEndpoint, batchData);
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
|
|
581
644
|
/**
|
|
582
645
|
* Edits a transaction.
|
|
583
646
|
*
|
|
@@ -595,20 +658,7 @@ module.exports = (() => {
|
|
|
595
658
|
assert.argumentIsRequired(transaction.position, 'transaction.position', String);
|
|
596
659
|
assert.argumentIsRequired(transaction.sequence, 'transaction.sequence', Number);
|
|
597
660
|
|
|
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));
|
|
661
|
+
const schema = getTransactionSchema(transaction);
|
|
612
662
|
|
|
613
663
|
return Gateway.invoke(this._editTransactionEndpoint, schema.schema.format(transaction));
|
|
614
664
|
});
|
|
@@ -749,6 +799,26 @@ module.exports = (() => {
|
|
|
749
799
|
}
|
|
750
800
|
}
|
|
751
801
|
|
|
802
|
+
function getTransactionTypeCode(transaction) {
|
|
803
|
+
let code;
|
|
804
|
+
|
|
805
|
+
if (is.string(transaction.type)) {
|
|
806
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', String);
|
|
807
|
+
|
|
808
|
+
code = transaction.type;
|
|
809
|
+
} else {
|
|
810
|
+
assert.argumentIsRequired(transaction.type, 'transaction.type', TransactionType, 'TransactionType');
|
|
811
|
+
|
|
812
|
+
code = transaction.type.code;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
return code;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
function getTransactionSchema(transaction) {
|
|
819
|
+
return TransactionSchema.forCreate(Enum.fromCode(TransactionType, getTransactionTypeCode(transaction)));
|
|
820
|
+
}
|
|
821
|
+
|
|
752
822
|
const createPortfolioRequestInterceptor = (request) => {
|
|
753
823
|
return FailureReason.validateSchema(PortfolioSchema.CREATE, request.data)
|
|
754
824
|
.then(() => {
|
package/lib/index.js
CHANGED