@barchart/portfolio-api-common 1.30.0 → 1.31.0
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.
|
@@ -57,6 +57,14 @@ module.exports = (() => {
|
|
|
57
57
|
return Decimal.ONE;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
function calculateForCrypto(instrument, basis, quantity) {
|
|
61
|
+
if (basis === null || quantity === null || quantity.getIsZero()) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return basis.divide(quantity).opposite();
|
|
66
|
+
}
|
|
67
|
+
|
|
60
68
|
function calculateForEquity(instrument, basis, quantity) {
|
|
61
69
|
if (basis === null || quantity === null || quantity.getIsZero()) {
|
|
62
70
|
return null;
|
|
@@ -116,6 +124,7 @@ module.exports = (() => {
|
|
|
116
124
|
const calculators = new Map();
|
|
117
125
|
|
|
118
126
|
calculators.set(InstrumentType.CASH, calculateForCash);
|
|
127
|
+
calculators.set(InstrumentType.CRYPTO, calculateForCrypto);
|
|
119
128
|
calculators.set(InstrumentType.EQUITY, calculateForEquity);
|
|
120
129
|
calculators.set(InstrumentType.EQUITY_OPTION, calculateForEquityOption);
|
|
121
130
|
calculators.set(InstrumentType.FUND, calculateForFund);
|
|
@@ -53,6 +53,10 @@ module.exports = (() => {
|
|
|
53
53
|
return new Decimal(quantity);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
function calculateForCrypto(instrument, price, quantity) {
|
|
57
|
+
return price.multiply(quantity);
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
function calculateForEquity(instrument, price, quantity) {
|
|
57
61
|
return price.multiply(quantity);
|
|
58
62
|
}
|
|
@@ -88,6 +92,7 @@ module.exports = (() => {
|
|
|
88
92
|
const calculators = new Map();
|
|
89
93
|
|
|
90
94
|
calculators.set(InstrumentType.CASH, calculateForCash);
|
|
95
|
+
calculators.set(InstrumentType.CRYPTO, calculateForCrypto);
|
|
91
96
|
calculators.set(InstrumentType.EQUITY, calculateForEquity);
|
|
92
97
|
calculators.set(InstrumentType.EQUITY_OPTION, calculateForEquityOption);
|
|
93
98
|
calculators.set(InstrumentType.FUND, calculateForFund);
|
|
@@ -221,6 +221,17 @@ module.exports = (() => {
|
|
|
221
221
|
return cash;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Crypto Tokens.
|
|
226
|
+
*
|
|
227
|
+
* @public
|
|
228
|
+
* @static
|
|
229
|
+
* @returns {InstrumentType}
|
|
230
|
+
*/
|
|
231
|
+
static get CRYPTO() {
|
|
232
|
+
return crypto;
|
|
233
|
+
}
|
|
234
|
+
|
|
224
235
|
/**
|
|
225
236
|
* An equity issue.
|
|
226
237
|
*
|
|
@@ -325,12 +336,14 @@ module.exports = (() => {
|
|
|
325
336
|
return InstrumentType.EQUITY;
|
|
326
337
|
} else if (code === 34) {
|
|
327
338
|
return InstrumentType.EQUITY_OPTION;
|
|
328
|
-
} else if (code === 5 || code
|
|
339
|
+
} else if (code === 5 || code === 15) {
|
|
329
340
|
return InstrumentType.FUND;
|
|
330
341
|
} else if (code === 2) {
|
|
331
342
|
return InstrumentType.FUTURE;
|
|
332
343
|
} else if (code === 12) {
|
|
333
344
|
return InstrumentType.FUTURE_OPTION;
|
|
345
|
+
} else if (code === 999) {
|
|
346
|
+
return InstrumentType.CRYPTO;
|
|
334
347
|
} else {
|
|
335
348
|
throw new Error(`Unable to determine InstrumentType for [ ${code} ]`);
|
|
336
349
|
}
|
|
@@ -342,6 +355,7 @@ module.exports = (() => {
|
|
|
342
355
|
}
|
|
343
356
|
|
|
344
357
|
const cash = new InstrumentType('CASH', 'cash', 'Cash', true, false, false, true, false, false, true, false, false, false, instrument => `BARCHART-${instrument.type.code}-${instrument.currency.code}`);
|
|
358
|
+
const crypto = new InstrumentType('CRYPTO', 'crypto', 'Crypto', false, false, true, false, true, false, true, false, false, true, instrument => `BARCHART-CRYPTO-${instrument.name.toUpperCase()}`);
|
|
345
359
|
const equity = new InstrumentType('EQUITY', 'equity', 'Equities', false, true, true, false, true, true, true, true, true, true, instrument => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
346
360
|
const equityOption = new InstrumentType('EQUITY_OPTION', 'equity option', 'Equity Options', false, false, true, false, true, false, false, false, false, true, instrument => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
347
361
|
const fund = new InstrumentType('FUND', 'mutual fund', 'Funds', false, true, false, false, true, true, true,false, true, true, instrument => `BARCHART-${instrument.type.code}-${instrument.symbol.barchart}`);
|
|
@@ -235,6 +235,11 @@ module.exports = (() => {
|
|
|
235
235
|
validTransactionTypes[instrumentTypeCode].push({ type: transactionType, user: userInitiated, directions: directions || [ PositionDirection.LONG, PositionDirection.SHORT, PositionDirection.EVEN ] });
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
associateTypes(InstrumentType.CRYPTO, TransactionType.BUY, true, [ PositionDirection.LONG, PositionDirection.EVEN ]);
|
|
239
|
+
associateTypes(InstrumentType.CRYPTO, TransactionType.SELL, true, [ PositionDirection.LONG ]);
|
|
240
|
+
associateTypes(InstrumentType.CRYPTO, TransactionType.SELL_SHORT, true, [ PositionDirection.SHORT, PositionDirection.EVEN ]);
|
|
241
|
+
associateTypes(InstrumentType.CRYPTO, TransactionType.BUY_SHORT, true, [ PositionDirection.SHORT ]);
|
|
242
|
+
|
|
238
243
|
associateTypes(InstrumentType.EQUITY, TransactionType.BUY, true, [ PositionDirection.LONG, PositionDirection.EVEN ]);
|
|
239
244
|
associateTypes(InstrumentType.EQUITY, TransactionType.SELL, true, [ PositionDirection.LONG ]);
|
|
240
245
|
associateTypes(InstrumentType.EQUITY, TransactionType.SELL_SHORT, true, [ PositionDirection.SHORT, PositionDirection.EVEN ]);
|
|
@@ -301,6 +306,10 @@ module.exports = (() => {
|
|
|
301
306
|
validDirections[instrumentTypeCode].push(positionDirection);
|
|
302
307
|
}
|
|
303
308
|
|
|
309
|
+
associateDirections(InstrumentType.CRYPTO, PositionDirection.EVEN);
|
|
310
|
+
associateDirections(InstrumentType.CRYPTO, PositionDirection.LONG);
|
|
311
|
+
associateDirections(InstrumentType.CRYPTO, PositionDirection.SHORT);
|
|
312
|
+
|
|
304
313
|
associateDirections(InstrumentType.EQUITY, PositionDirection.EVEN);
|
|
305
314
|
associateDirections(InstrumentType.EQUITY, PositionDirection.LONG);
|
|
306
315
|
associateDirections(InstrumentType.EQUITY, PositionDirection.SHORT);
|