@barchart/portfolio-api-common 1.0.200 → 1.0.204
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/lib/api/failures/PortfolioFailureType.js +13 -0
- package/lib/processing/PositionContainer.js +15 -0
- package/lib/processing/PositionGroup.js +9 -0
- package/lib/processing/PositionItem.js +26 -0
- package/lib/serialization/TransactionSchema.js +0 -1
- package/package.json +1 -1
- package/test/SpecRunner.js +50 -0
|
@@ -12,6 +12,17 @@ module.exports = (() => {
|
|
|
12
12
|
constructor() {
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* The portfolio referenced does not exist.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
* @static
|
|
20
|
+
* @returns {FailureType}
|
|
21
|
+
*/
|
|
22
|
+
static get POSITION_CREATE_FAILED_NO_PORTFOLIO() {
|
|
23
|
+
return positionCreateFailedNoPortfolio;
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
/**
|
|
16
27
|
* The transaction would occur before an existing transaction.
|
|
17
28
|
*
|
|
@@ -60,6 +71,8 @@ module.exports = (() => {
|
|
|
60
71
|
}
|
|
61
72
|
}
|
|
62
73
|
|
|
74
|
+
const positionCreateFailedNoPortfolio = new FailureType('POSITION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to create transaction. The referenced portfolio does not exist. Has it been deleted?');
|
|
75
|
+
|
|
63
76
|
const transactionCreateFailedOutOfSequence = new FailureType('TRANSACTION_CREATE_FAILED_OUT_OF_SEQUENCE', 'Unable to create transaction, because the transaction date is out-of-sequence. In other words, it would occur before an existing transaction. Please confirm your intent to re-write transaction history (which could take some time and alter the historical results for this position).');
|
|
64
77
|
const transactionCreateFailedDirectionSwitch = new FailureType('TRANSACTION_CREATE_FAILED_DIRECTION_SWITCH', 'Unable to create transaction, because the position direction would be switched (from long to short or vice versa). Please close the position (to a zero balance) first, then enter a second transaction.');
|
|
65
78
|
const transactionCreateRewriteUnsupported = new FailureType('TRANSACTION_CREATE_REWRITE_UNSUPPORTED', 'Unable to re-write transaction history. This operation is not currently supported (but will be implemented soon).');
|
|
@@ -206,6 +206,21 @@ module.exports = (() => {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Updates the portfolio data. For example, a portfolio's name might change.
|
|
211
|
+
*
|
|
212
|
+
* @public
|
|
213
|
+
* @param {Object} portfolio
|
|
214
|
+
*/
|
|
215
|
+
updatePortfolio(portfolio) {
|
|
216
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
217
|
+
assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
|
|
218
|
+
|
|
219
|
+
this.startTransaction(() => {
|
|
220
|
+
getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(item => item.updatePortfolio(portfolio));
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
209
224
|
/**
|
|
210
225
|
* Removes an existing portfolio, and all of it's positions, from the container. This
|
|
211
226
|
* also triggers removal of the portfolio and it's positions from any applicable
|
|
@@ -463,6 +463,15 @@ module.exports = (() => {
|
|
|
463
463
|
});
|
|
464
464
|
}
|
|
465
465
|
|
|
466
|
+
this._disposeStack.push(item.registerPortfolioChangeHandler((portfolio, sender) => {
|
|
467
|
+
const descriptionSelector = this._definition.descriptionSelector;
|
|
468
|
+
|
|
469
|
+
this._description = descriptionSelector(this._items[0]);
|
|
470
|
+
|
|
471
|
+
this._dataActual.description = this._description;
|
|
472
|
+
this._dataFormat.description = this._description;
|
|
473
|
+
}));
|
|
474
|
+
|
|
466
475
|
this._disposeStack.push(quoteBinding);
|
|
467
476
|
this._disposeStack.push(newsBinding);
|
|
468
477
|
this._disposeStack.push(fundamentalBinding);
|
|
@@ -73,6 +73,7 @@ module.exports = (() => {
|
|
|
73
73
|
this._quoteChangedEvent = new Event(this);
|
|
74
74
|
this._newsExistsChangedEvent = new Event(this);
|
|
75
75
|
this._fundamentalDataChangeEvent = new Event(this);
|
|
76
|
+
this._portfolioChangedEvent = new Event(this);
|
|
76
77
|
this._positionItemDisposeEvent = new Event(this);
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -146,6 +147,19 @@ module.exports = (() => {
|
|
|
146
147
|
return this._currentQuote;
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
updatePortfolio(portfolio) {
|
|
151
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
152
|
+
assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
|
|
153
|
+
|
|
154
|
+
if (portfolio.portfolio !== this._portfolio.portfolio) {
|
|
155
|
+
throw new Error('Unable to move position into new portfolio.');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (this._portfolio !== portfolio) {
|
|
159
|
+
this._portfolioChangedEvent.fire(this._portfolio = portfolio);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
149
163
|
/**
|
|
150
164
|
* Sets the current quote -- causing position-level data (e.g. market value) to
|
|
151
165
|
* be recalculated.
|
|
@@ -241,6 +255,17 @@ module.exports = (() => {
|
|
|
241
255
|
return this._newsExistsChangedEvent.register(handler);
|
|
242
256
|
}
|
|
243
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Registers an observer changes to portfolio metadata.
|
|
260
|
+
*
|
|
261
|
+
* @public
|
|
262
|
+
* @param {Function} handler
|
|
263
|
+
* @returns {Disposable}
|
|
264
|
+
*/
|
|
265
|
+
registerPortfolioChangeHandler(handler) {
|
|
266
|
+
return this._portfolioChangedEvent.register(handler);
|
|
267
|
+
}
|
|
268
|
+
|
|
244
269
|
/**
|
|
245
270
|
* Registers an observer for object disposal.
|
|
246
271
|
*
|
|
@@ -258,6 +283,7 @@ module.exports = (() => {
|
|
|
258
283
|
this._quoteChangedEvent.clear();
|
|
259
284
|
this._newsExistsChangedEvent.clear();
|
|
260
285
|
this._fundamentalDataChangeEvent.clear();
|
|
286
|
+
this._portfolioChangedEvent.clear();
|
|
261
287
|
this._positionItemDisposeEvent.clear();
|
|
262
288
|
}
|
|
263
289
|
|
|
@@ -448,7 +448,6 @@ module.exports = (() => {
|
|
|
448
448
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
449
449
|
.withField('date', DataType.DAY)
|
|
450
450
|
.withField('value', DataType.DECIMAL)
|
|
451
|
-
.withField('fee', DataType.DECIMAL, true)
|
|
452
451
|
.withField('force', DataType.BOOLEAN, true)
|
|
453
452
|
.schema
|
|
454
453
|
);
|
package/package.json
CHANGED
package/test/SpecRunner.js
CHANGED
|
@@ -922,6 +922,21 @@ module.exports = (() => {
|
|
|
922
922
|
}
|
|
923
923
|
}
|
|
924
924
|
|
|
925
|
+
/**
|
|
926
|
+
* Updates the portfolio data. For example, a portfolio's name might change.
|
|
927
|
+
*
|
|
928
|
+
* @public
|
|
929
|
+
* @param {Object} portfolio
|
|
930
|
+
*/
|
|
931
|
+
updatePortfolio(portfolio) {
|
|
932
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
933
|
+
assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
|
|
934
|
+
|
|
935
|
+
this.startTransaction(() => {
|
|
936
|
+
getPositionItemsForPortfolio(this._items, portfolio.portfolio).forEach(item => item.updatePortfolio(portfolio));
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
|
|
925
940
|
/**
|
|
926
941
|
* Removes an existing portfolio, and all of it's positions, from the container. This
|
|
927
942
|
* also triggers removal of the portfolio and it's positions from any applicable
|
|
@@ -2042,6 +2057,15 @@ module.exports = (() => {
|
|
|
2042
2057
|
});
|
|
2043
2058
|
}
|
|
2044
2059
|
|
|
2060
|
+
this._disposeStack.push(item.registerPortfolioChangeHandler((portfolio, sender) => {
|
|
2061
|
+
const descriptionSelector = this._definition.descriptionSelector;
|
|
2062
|
+
|
|
2063
|
+
this._description = descriptionSelector(this._items[0]);
|
|
2064
|
+
|
|
2065
|
+
this._dataActual.description = this._description;
|
|
2066
|
+
this._dataFormat.description = this._description;
|
|
2067
|
+
}));
|
|
2068
|
+
|
|
2045
2069
|
this._disposeStack.push(quoteBinding);
|
|
2046
2070
|
this._disposeStack.push(newsBinding);
|
|
2047
2071
|
this._disposeStack.push(fundamentalBinding);
|
|
@@ -2411,6 +2435,7 @@ module.exports = (() => {
|
|
|
2411
2435
|
this._quoteChangedEvent = new Event(this);
|
|
2412
2436
|
this._newsExistsChangedEvent = new Event(this);
|
|
2413
2437
|
this._fundamentalDataChangeEvent = new Event(this);
|
|
2438
|
+
this._portfolioChangedEvent = new Event(this);
|
|
2414
2439
|
this._positionItemDisposeEvent = new Event(this);
|
|
2415
2440
|
}
|
|
2416
2441
|
|
|
@@ -2484,6 +2509,19 @@ module.exports = (() => {
|
|
|
2484
2509
|
return this._currentQuote;
|
|
2485
2510
|
}
|
|
2486
2511
|
|
|
2512
|
+
updatePortfolio(portfolio) {
|
|
2513
|
+
assert.argumentIsRequired(portfolio, 'portfolio', Object);
|
|
2514
|
+
assert.argumentIsRequired(portfolio.portfolio, 'portfolio.portfolio', String);
|
|
2515
|
+
|
|
2516
|
+
if (portfolio.portfolio !== this._portfolio.portfolio) {
|
|
2517
|
+
throw new Error('Unable to move position into new portfolio.');
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
if (this._portfolio !== portfolio) {
|
|
2521
|
+
this._portfolioChangedEvent.fire(this._portfolio = portfolio);
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2487
2525
|
/**
|
|
2488
2526
|
* Sets the current quote -- causing position-level data (e.g. market value) to
|
|
2489
2527
|
* be recalculated.
|
|
@@ -2579,6 +2617,17 @@ module.exports = (() => {
|
|
|
2579
2617
|
return this._newsExistsChangedEvent.register(handler);
|
|
2580
2618
|
}
|
|
2581
2619
|
|
|
2620
|
+
/**
|
|
2621
|
+
* Registers an observer changes to portfolio metadata.
|
|
2622
|
+
*
|
|
2623
|
+
* @public
|
|
2624
|
+
* @param {Function} handler
|
|
2625
|
+
* @returns {Disposable}
|
|
2626
|
+
*/
|
|
2627
|
+
registerPortfolioChangeHandler(handler) {
|
|
2628
|
+
return this._portfolioChangedEvent.register(handler);
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2582
2631
|
/**
|
|
2583
2632
|
* Registers an observer for object disposal.
|
|
2584
2633
|
*
|
|
@@ -2596,6 +2645,7 @@ module.exports = (() => {
|
|
|
2596
2645
|
this._quoteChangedEvent.clear();
|
|
2597
2646
|
this._newsExistsChangedEvent.clear();
|
|
2598
2647
|
this._fundamentalDataChangeEvent.clear();
|
|
2648
|
+
this._portfolioChangedEvent.clear();
|
|
2599
2649
|
this._positionItemDisposeEvent.clear();
|
|
2600
2650
|
}
|
|
2601
2651
|
|