@barchart/portfolio-api-common 1.0.25 → 1.0.26
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const assert = require('@barchart/common-js/lang/assert'),
|
|
2
|
+
is = require('@barchart/common-js/lang/is'),
|
|
2
3
|
Currency = require('@barchart/common-js/lang/Currency'),
|
|
3
4
|
DataType = require('@barchart/common-js/serialization/json/DataType'),
|
|
4
5
|
Enum = require('@barchart/common-js/lang/Enum'),
|
|
@@ -33,6 +34,35 @@ module.exports = (() => {
|
|
|
33
34
|
return this._schema;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Returns the appropriate schema for creating a transaction of the
|
|
39
|
+
* supplied type.
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
* @static
|
|
43
|
+
* @param {String|TransactionType} transactionType
|
|
44
|
+
* @returns {TransactionSchema|null}
|
|
45
|
+
*/
|
|
46
|
+
static forCreate(transactionType) {
|
|
47
|
+
let code;
|
|
48
|
+
|
|
49
|
+
if (transactionType instanceof TransactionType) {
|
|
50
|
+
code = transactionType.code;
|
|
51
|
+
} else {
|
|
52
|
+
code = transactionType;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let schema;
|
|
56
|
+
|
|
57
|
+
if (is.string(code)) {
|
|
58
|
+
schema = Enum.fromCode(code);
|
|
59
|
+
} else {
|
|
60
|
+
schema = null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return schema;
|
|
64
|
+
}
|
|
65
|
+
|
|
36
66
|
/**
|
|
37
67
|
* The complete transaction schema.
|
|
38
68
|
*
|
|
@@ -210,9 +240,10 @@ module.exports = (() => {
|
|
|
210
240
|
.schema
|
|
211
241
|
);
|
|
212
242
|
|
|
213
|
-
const buy = new TransactionSchema(SchemaBuilder.withName(
|
|
243
|
+
const buy = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY.code)
|
|
244
|
+
.withField('portfolio', DataType.STRING)
|
|
245
|
+
.withField('position', DataType.STRING)
|
|
214
246
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
215
|
-
.withField('position', DataType.STRING, true)
|
|
216
247
|
.withField('instrument.name', DataType.STRING, true)
|
|
217
248
|
.withField('instrument.type', DataType.STRING, true)
|
|
218
249
|
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
@@ -226,10 +257,10 @@ module.exports = (() => {
|
|
|
226
257
|
.schema
|
|
227
258
|
);
|
|
228
259
|
|
|
229
|
-
const sell = new TransactionSchema(SchemaBuilder.withName(
|
|
260
|
+
const sell = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL.code)
|
|
261
|
+
.withField('portfolio', DataType.STRING)
|
|
262
|
+
.withField('position', DataType.STRING)
|
|
230
263
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
231
|
-
.withField('position', DataType.STRING, true)
|
|
232
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
233
264
|
.withField('date', DataType.DAY)
|
|
234
265
|
.withField('price', DataType.DECIMAL)
|
|
235
266
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -237,10 +268,10 @@ module.exports = (() => {
|
|
|
237
268
|
.schema
|
|
238
269
|
);
|
|
239
270
|
|
|
240
|
-
const buyShort = new TransactionSchema(SchemaBuilder.withName(
|
|
271
|
+
const buyShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.BUY_SHORT.code)
|
|
272
|
+
.withField('portfolio', DataType.STRING)
|
|
273
|
+
.withField('position', DataType.STRING)
|
|
241
274
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
242
|
-
.withField('position', DataType.STRING, true)
|
|
243
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
244
275
|
.withField('date', DataType.DAY)
|
|
245
276
|
.withField('price', DataType.DECIMAL)
|
|
246
277
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -248,10 +279,15 @@ module.exports = (() => {
|
|
|
248
279
|
.schema
|
|
249
280
|
);
|
|
250
281
|
|
|
251
|
-
const sellShort = new TransactionSchema(SchemaBuilder.withName(
|
|
282
|
+
const sellShort = new TransactionSchema(SchemaBuilder.withName(TransactionType.SELL_SHORT.code)
|
|
283
|
+
.withField('portfolio', DataType.STRING)
|
|
284
|
+
.withField('position', DataType.STRING)
|
|
252
285
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
253
|
-
.withField('
|
|
254
|
-
.withField('
|
|
286
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
287
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
288
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
289
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
290
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
255
291
|
.withField('date', DataType.DAY)
|
|
256
292
|
.withField('price', DataType.DECIMAL)
|
|
257
293
|
.withField('quantity', DataType.DECIMAL)
|
|
@@ -259,10 +295,10 @@ module.exports = (() => {
|
|
|
259
295
|
.schema
|
|
260
296
|
);
|
|
261
297
|
|
|
262
|
-
const dividend = new TransactionSchema(SchemaBuilder.withName(
|
|
298
|
+
const dividend = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND.code)
|
|
299
|
+
.withField('portfolio', DataType.STRING)
|
|
300
|
+
.withField('position', DataType.STRING)
|
|
263
301
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
264
|
-
.withField('position', DataType.STRING, true)
|
|
265
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
266
302
|
.withField('date', DataType.DAY)
|
|
267
303
|
.withField('rate', DataType.DECIMAL)
|
|
268
304
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -271,10 +307,10 @@ module.exports = (() => {
|
|
|
271
307
|
.schema
|
|
272
308
|
);
|
|
273
309
|
|
|
274
|
-
const dividendReinvest = new TransactionSchema(SchemaBuilder.withName(
|
|
310
|
+
const dividendReinvest = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND_REINVEST.code)
|
|
311
|
+
.withField('portfolio', DataType.STRING)
|
|
312
|
+
.withField('position', DataType.STRING)
|
|
275
313
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
276
|
-
.withField('position', DataType.STRING, true)
|
|
277
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
278
314
|
.withField('date', DataType.DAY)
|
|
279
315
|
.withField('rate', DataType.DECIMAL)
|
|
280
316
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -284,10 +320,10 @@ module.exports = (() => {
|
|
|
284
320
|
.schema
|
|
285
321
|
);
|
|
286
322
|
|
|
287
|
-
const dividendStock = new TransactionSchema(SchemaBuilder.withName(
|
|
323
|
+
const dividendStock = new TransactionSchema(SchemaBuilder.withName(TransactionType.DIVIDEND_STOCK.code)
|
|
324
|
+
.withField('portfolio', DataType.STRING)
|
|
325
|
+
.withField('position', DataType.STRING)
|
|
288
326
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
289
|
-
.withField('position', DataType.STRING, true)
|
|
290
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
291
327
|
.withField('date', DataType.DAY)
|
|
292
328
|
.withField('rate', DataType.DECIMAL)
|
|
293
329
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -297,10 +333,10 @@ module.exports = (() => {
|
|
|
297
333
|
.schema
|
|
298
334
|
);
|
|
299
335
|
|
|
300
|
-
const distributionCash = new TransactionSchema(SchemaBuilder.withName(
|
|
336
|
+
const distributionCash = new TransactionSchema(SchemaBuilder.withName(TransactionType.DISTRIBUTION_CASH.code)
|
|
337
|
+
.withField('portfolio', DataType.STRING)
|
|
338
|
+
.withField('position', DataType.STRING)
|
|
301
339
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
302
|
-
.withField('position', DataType.STRING, true)
|
|
303
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
304
340
|
.withField('date', DataType.DAY)
|
|
305
341
|
.withField('rate', DataType.DECIMAL)
|
|
306
342
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -309,10 +345,10 @@ module.exports = (() => {
|
|
|
309
345
|
.schema
|
|
310
346
|
);
|
|
311
347
|
|
|
312
|
-
const distributionFund = new TransactionSchema(SchemaBuilder.withName(
|
|
348
|
+
const distributionFund = new TransactionSchema(SchemaBuilder.withName(TransactionType.DISTRIBUTION_FUND.code)
|
|
349
|
+
.withField('portfolio', DataType.STRING)
|
|
350
|
+
.withField('position', DataType.STRING)
|
|
313
351
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
314
|
-
.withField('position', DataType.STRING, true)
|
|
315
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
316
352
|
.withField('date', DataType.DAY)
|
|
317
353
|
.withField('rate', DataType.DECIMAL)
|
|
318
354
|
.withField('open', DataType.DECIMAL, true)
|
|
@@ -321,10 +357,10 @@ module.exports = (() => {
|
|
|
321
357
|
.schema
|
|
322
358
|
);
|
|
323
359
|
|
|
324
|
-
const split = new TransactionSchema(SchemaBuilder.withName(
|
|
360
|
+
const split = new TransactionSchema(SchemaBuilder.withName(TransactionType.SPLIT.code)
|
|
361
|
+
.withField('portfolio', DataType.STRING)
|
|
362
|
+
.withField('position', DataType.STRING)
|
|
325
363
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
326
|
-
.withField('position', DataType.STRING, true)
|
|
327
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
328
364
|
.withField('date', DataType.DAY)
|
|
329
365
|
.withField('numerator', DataType.DECIMAL)
|
|
330
366
|
.withField('denominator', DataType.DECIMAL)
|
|
@@ -333,84 +369,110 @@ module.exports = (() => {
|
|
|
333
369
|
.schema
|
|
334
370
|
);
|
|
335
371
|
|
|
336
|
-
const fee = new TransactionSchema(SchemaBuilder.withName(
|
|
372
|
+
const fee = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE.code)
|
|
373
|
+
.withField('portfolio', DataType.STRING)
|
|
374
|
+
.withField('position', DataType.STRING)
|
|
337
375
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
338
|
-
.withField('position', DataType.STRING, true)
|
|
339
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
340
376
|
.withField('date', DataType.DAY)
|
|
341
377
|
.withField('fee', DataType.DECIMAL)
|
|
342
378
|
.schema
|
|
343
379
|
);
|
|
344
380
|
|
|
345
|
-
const feeUnits = new TransactionSchema(SchemaBuilder.withName(
|
|
381
|
+
const feeUnits = new TransactionSchema(SchemaBuilder.withName(TransactionType.FEE_UNITS.code)
|
|
382
|
+
.withField('portfolio', DataType.STRING)
|
|
383
|
+
.withField('position', DataType.STRING)
|
|
346
384
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
347
|
-
.withField('position', DataType.STRING, true)
|
|
348
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
349
385
|
.withField('date', DataType.DAY)
|
|
350
386
|
.withField('fee', DataType.DECIMAL)
|
|
351
387
|
.withField('price', DataType.DECIMAL)
|
|
352
388
|
.schema
|
|
353
389
|
);
|
|
354
390
|
|
|
355
|
-
const deposit = new TransactionSchema(SchemaBuilder.withName(
|
|
391
|
+
const deposit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEPOSIT.code)
|
|
392
|
+
.withField('portfolio', DataType.STRING)
|
|
393
|
+
.withField('position', DataType.STRING)
|
|
356
394
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
357
|
-
.withField('
|
|
358
|
-
.withField('
|
|
395
|
+
.withField('instrument.name', DataType.STRING, true)
|
|
396
|
+
.withField('instrument.type', DataType.STRING, true)
|
|
397
|
+
.withField('instrument.currency', DataType.forEnum(Currency, 'Currency'), true)
|
|
398
|
+
.withField('instrument.symbol.barchart', DataType.STRING, true)
|
|
399
|
+
.withField('instrument.symbol.display', DataType.STRING, true)
|
|
359
400
|
.withField('date', DataType.DAY)
|
|
360
401
|
.withField('amount', DataType.DECIMAL)
|
|
361
402
|
.withField('fee', DataType.DECIMAL, true)
|
|
362
403
|
.schema
|
|
363
404
|
);
|
|
364
405
|
|
|
365
|
-
const withdrawal = new TransactionSchema(SchemaBuilder.withName(
|
|
406
|
+
const withdrawal = new TransactionSchema(SchemaBuilder.withName(TransactionType.WITHDRAWAL.code)
|
|
407
|
+
.withField('portfolio', DataType.STRING)
|
|
408
|
+
.withField('position', DataType.STRING)
|
|
366
409
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
367
|
-
.withField('position', DataType.STRING, true)
|
|
368
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
369
410
|
.withField('date', DataType.DAY)
|
|
370
411
|
.withField('amount', DataType.DECIMAL)
|
|
371
412
|
.withField('fee', DataType.DECIMAL, true)
|
|
372
413
|
.schema
|
|
373
414
|
);
|
|
374
415
|
|
|
375
|
-
const debit = new TransactionSchema(SchemaBuilder.withName(
|
|
416
|
+
const debit = new TransactionSchema(SchemaBuilder.withName(TransactionType.DEBIT.code)
|
|
417
|
+
.withField('portfolio', DataType.STRING)
|
|
418
|
+
.withField('position', DataType.STRING)
|
|
376
419
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
377
|
-
.withField('position', DataType.STRING, true)
|
|
378
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
379
420
|
.withField('date', DataType.DAY)
|
|
380
421
|
.withField('amount', DataType.DECIMAL)
|
|
381
422
|
.withField('fee', DataType.DECIMAL, true)
|
|
382
423
|
.schema
|
|
383
424
|
);
|
|
384
425
|
|
|
385
|
-
const credit = new TransactionSchema(SchemaBuilder.withName(
|
|
426
|
+
const credit = new TransactionSchema(SchemaBuilder.withName(TransactionType.CREDIT.code)
|
|
427
|
+
.withField('portfolio', DataType.STRING)
|
|
428
|
+
.withField('position', DataType.STRING)
|
|
386
429
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
387
|
-
.withField('position', DataType.STRING, true)
|
|
388
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
389
430
|
.withField('date', DataType.DAY)
|
|
390
431
|
.withField('amount', DataType.DECIMAL)
|
|
391
432
|
.withField('fee', DataType.DECIMAL, true)
|
|
392
433
|
.schema
|
|
393
434
|
);
|
|
394
435
|
|
|
395
|
-
const valuation = new TransactionSchema(SchemaBuilder.withName(
|
|
436
|
+
const valuation = new TransactionSchema(SchemaBuilder.withName(TransactionType.VALUATION.code)
|
|
437
|
+
.withField('portfolio', DataType.STRING)
|
|
438
|
+
.withField('position', DataType.STRING)
|
|
396
439
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
397
|
-
.withField('position', DataType.STRING, true)
|
|
398
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
399
440
|
.withField('date', DataType.DAY)
|
|
400
441
|
.withField('value', DataType.DECIMAL)
|
|
401
442
|
.withField('fee', DataType.DECIMAL, true)
|
|
402
443
|
.schema
|
|
403
444
|
);
|
|
404
445
|
|
|
405
|
-
const income = new TransactionSchema(SchemaBuilder.withName(
|
|
446
|
+
const income = new TransactionSchema(SchemaBuilder.withName(TransactionType.INCOME.code)
|
|
447
|
+
.withField('portfolio', DataType.STRING)
|
|
448
|
+
.withField('position', DataType.STRING)
|
|
406
449
|
.withField('type', DataType.forEnum(TransactionType, 'TransactionType'))
|
|
407
|
-
.withField('position', DataType.STRING, true)
|
|
408
|
-
.withField('currency', DataType.forEnum(Currency, 'Currency'))
|
|
409
450
|
.withField('date', DataType.DAY)
|
|
410
451
|
.withField('income', DataType.DECIMAL)
|
|
411
452
|
.withField('fee', DataType.DECIMAL, true)
|
|
412
453
|
.schema
|
|
413
454
|
);
|
|
414
455
|
|
|
456
|
+
const map = { };
|
|
457
|
+
|
|
458
|
+
function addSchemaToMap(type, schema) {
|
|
459
|
+
map[type.code] = schema;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
addSchemaToMap(TransactionType.BUY, buy);
|
|
463
|
+
addSchemaToMap(TransactionType.SELL, sell);
|
|
464
|
+
addSchemaToMap(TransactionType.BUY_SHORT, buyShort);
|
|
465
|
+
addSchemaToMap(TransactionType.SELL_SHORT, sellShort);
|
|
466
|
+
addSchemaToMap(TransactionType.DIVIDEND, dividend);
|
|
467
|
+
addSchemaToMap(TransactionType.DIVIDEND_STOCK, dividendStock);
|
|
468
|
+
addSchemaToMap(TransactionType.DIVIDEND_REINVEST, dividendReinvest);
|
|
469
|
+
addSchemaToMap(TransactionType.SPLIT, split);
|
|
470
|
+
addSchemaToMap(TransactionType.FEE, fee);
|
|
471
|
+
addSchemaToMap(TransactionType.FEE_UNITS, feeUnits);
|
|
472
|
+
addSchemaToMap(TransactionType.DEPOSIT, deposit);
|
|
473
|
+
addSchemaToMap(TransactionType.WITHDRAWAL, withdrawal);
|
|
474
|
+
addSchemaToMap(TransactionType.VALUATION, valuation);
|
|
475
|
+
addSchemaToMap(TransactionType.INCOME, income);
|
|
476
|
+
|
|
415
477
|
return TransactionSchema;
|
|
416
478
|
})();
|