@barchart/portfolio-api-common 1.31.0 → 1.32.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.
@@ -27,6 +27,7 @@ module.exports = (() => {
27
27
 
28
28
  const REQUIRED_CURRENCIES = [
29
29
  Currency.CAD,
30
+ Currency.CHF,
30
31
  Currency.EUR,
31
32
  Currency.HKD,
32
33
  Currency.JPY,
@@ -14,6 +14,11 @@ module.exports = (() => {
14
14
 
15
15
  const DEFAULT_MAXIMUM_WAIT_BEFORE_TIMEOUT_IN_MILLISECONDS = 3 * 1000;
16
16
 
17
+ const regex = { };
18
+
19
+ regex.crypto = { };
20
+ regex.crypto.token = /^(.*) - (USD)$/i;
21
+
17
22
  /**
18
23
  * A utility that downloads instrument metadata (i.e. instrument "profile" data).
19
24
  *
@@ -37,28 +42,37 @@ module.exports = (() => {
37
42
  * @returns {Promise<Object>}
38
43
  */
39
44
  async getInstrument(symbol) {
40
- return Promise.resolve()
41
- .then(() => {
42
- assert.argumentIsRequired(symbol, 'symbol', String);
43
-
44
- return promise.timeout(Gateway.invoke(instrumentLookupEndpoint, { symbol }), this._waitInMilliseconds, 'instrument lookup')
45
- .catch((e) => {
46
- let message;
47
-
48
- if (is.string(e) && e === 'timeout') {
49
- message = `Instrument lookup for [ ${symbol} ] failed due to timed out`;
50
- } else {
51
- message = `Instrument lookup for [ ${symbol} ] failed due to an unspecified error`;
52
- }
53
-
54
- return Promise.reject(message);
55
- }).then((result) => {
56
- if (result.instrument === null) {
57
- return Promise.reject(`Instrument lookup for [ ${symbol} ] failed, the instrument does not exist`);
58
- }
59
-
60
- return result;
61
- });
45
+ assert.argumentIsRequired(symbol, 'symbol', String);
46
+
47
+ return promise.timeout(Gateway.invoke(instrumentLookupEndpoint, { symbol }), this._waitInMilliseconds, 'instrument lookup')
48
+ .catch((e) => {
49
+ let message;
50
+
51
+ if (is.string(e) && e === 'timeout') {
52
+ message = `Instrument lookup for [ ${symbol} ] failed due to timed out`;
53
+ } else {
54
+ message = `Instrument lookup for [ ${symbol} ] failed due to an unspecified error`;
55
+ }
56
+
57
+ return Promise.reject(message);
58
+ }).then((result) => {
59
+ if (result.instrument === null) {
60
+ return Promise.reject(`Instrument lookup for [ ${symbol} ] failed, the instrument does not exist`);
61
+ }
62
+
63
+ const instrument = result.instrument;
64
+
65
+ if (instrument.symbolType === 18) {
66
+ const match = instrument.name.match(regex.crypto.token) || null;
67
+
68
+ if (match !== null) {
69
+ instrument.name = match[1];
70
+ instrument.currency = 'USD';
71
+ instrument.symbolType = 999;
72
+ }
73
+ }
74
+
75
+ return result;
62
76
  });
63
77
  }
64
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.31.0",
3
+ "version": "1.32.0",
4
4
  "description": "Common JavaScript code used by Barchart's Portfolio Service",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -15,7 +15,7 @@
15
15
  "url": "git+ssh://git@github.com/barchart/portfolio-api-common.git"
16
16
  },
17
17
  "dependencies": {
18
- "@barchart/common-js": "^4.27.0",
18
+ "@barchart/common-js": "^4.43.0",
19
19
  "@barchart/marketdata-api-js": "^6.2.1",
20
20
  "uuid": "^8.3.2"
21
21
  },