@sebspark/tradeinsight 0.1.1 → 0.2.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.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # `@sebspark/tradeinsight`
2
2
 
3
- Trade Insight client library with helps
3
+ Trade Insight client library with helpers for instrument IDs.
package/dist/index.d.mts CHANGED
@@ -8,4 +8,13 @@ declare const createForexId: ({ fromCurrency, toCurrency, }: {
8
8
  fromCurrency: string;
9
9
  }) => string;
10
10
 
11
- export { createForexId, createStockId };
11
+ declare const parseId: (id: string) => {
12
+ type: "STOCK" | "FOREX";
13
+ isin?: string;
14
+ mic?: string;
15
+ currency?: string;
16
+ fromCurrency?: string;
17
+ toCurrency?: string;
18
+ };
19
+
20
+ export { createForexId, createStockId, parseId };
package/dist/index.d.ts CHANGED
@@ -8,4 +8,13 @@ declare const createForexId: ({ fromCurrency, toCurrency, }: {
8
8
  fromCurrency: string;
9
9
  }) => string;
10
10
 
11
- export { createForexId, createStockId };
11
+ declare const parseId: (id: string) => {
12
+ type: "STOCK" | "FOREX";
13
+ isin?: string;
14
+ mic?: string;
15
+ currency?: string;
16
+ fromCurrency?: string;
17
+ toCurrency?: string;
18
+ };
19
+
20
+ export { createForexId, createStockId, parseId };
package/dist/index.js CHANGED
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  createForexId: () => createForexId,
24
- createStockId: () => createStockId
24
+ createStockId: () => createStockId,
25
+ parseId: () => parseId
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
27
28
 
@@ -35,8 +36,43 @@ var createForexId = ({
35
36
  fromCurrency,
36
37
  toCurrency
37
38
  }) => `FOREX-${toCurrency};${fromCurrency}`.toUpperCase();
39
+
40
+ // src/parseId.ts
41
+ var parseId = (id) => {
42
+ const [type, ...rest] = id.split("-");
43
+ const [first, second, third] = rest.join("-").split(";");
44
+ if (type === "STOCK") {
45
+ if (!second) {
46
+ throw new Error("Missing MIC");
47
+ }
48
+ if (!third) {
49
+ throw new Error("Missing currency");
50
+ }
51
+ return {
52
+ type,
53
+ isin: first,
54
+ mic: second,
55
+ currency: third
56
+ };
57
+ }
58
+ if (type === "FOREX") {
59
+ if (!first) {
60
+ throw new Error("Missing fromCurrency");
61
+ }
62
+ if (!second) {
63
+ throw new Error("Missing toCurrency");
64
+ }
65
+ return {
66
+ type,
67
+ fromCurrency: first,
68
+ toCurrency: second
69
+ };
70
+ }
71
+ throw new Error("Invalid type");
72
+ };
38
73
  // Annotate the CommonJS export names for ESM import in node:
39
74
  0 && (module.exports = {
40
75
  createForexId,
41
- createStockId
76
+ createStockId,
77
+ parseId
42
78
  });
package/dist/index.mjs CHANGED
@@ -8,7 +8,42 @@ var createForexId = ({
8
8
  fromCurrency,
9
9
  toCurrency
10
10
  }) => `FOREX-${toCurrency};${fromCurrency}`.toUpperCase();
11
+
12
+ // src/parseId.ts
13
+ var parseId = (id) => {
14
+ const [type, ...rest] = id.split("-");
15
+ const [first, second, third] = rest.join("-").split(";");
16
+ if (type === "STOCK") {
17
+ if (!second) {
18
+ throw new Error("Missing MIC");
19
+ }
20
+ if (!third) {
21
+ throw new Error("Missing currency");
22
+ }
23
+ return {
24
+ type,
25
+ isin: first,
26
+ mic: second,
27
+ currency: third
28
+ };
29
+ }
30
+ if (type === "FOREX") {
31
+ if (!first) {
32
+ throw new Error("Missing fromCurrency");
33
+ }
34
+ if (!second) {
35
+ throw new Error("Missing toCurrency");
36
+ }
37
+ return {
38
+ type,
39
+ fromCurrency: first,
40
+ toCurrency: second
41
+ };
42
+ }
43
+ throw new Error("Invalid type");
44
+ };
11
45
  export {
12
46
  createForexId,
13
- createStockId
47
+ createStockId,
48
+ parseId
14
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/tradeinsight",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",