@sebspark/tradeinsight 0.1.1 → 0.3.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
@@ -1,3 +1,25 @@
1
+ interface InstrumentPrice {
2
+ ask: null | number;
3
+ bid: null | number;
4
+ last: null | number;
5
+ lastInSek: null | number;
6
+ }
7
+ interface StockTicker {
8
+ id: string;
9
+ mic: string;
10
+ isin: string;
11
+ ticker: string;
12
+ currencyCode: string;
13
+ price: InstrumentPrice;
14
+ }
15
+ interface StockTickerMessage {
16
+ tickers: StockTicker[];
17
+ }
18
+ declare const CloudSchema: {
19
+ schemaId: string;
20
+ avroDefinition: string;
21
+ };
22
+
1
23
  declare const createStockId: ({ isin, mic, currency, }: {
2
24
  isin: string;
3
25
  currency: string;
@@ -8,4 +30,18 @@ declare const createForexId: ({ fromCurrency, toCurrency, }: {
8
30
  fromCurrency: string;
9
31
  }) => string;
10
32
 
11
- export { createForexId, createStockId };
33
+ declare const parseId: (id: string) => {
34
+ type: "STOCK" | "FOREX";
35
+ isin?: string;
36
+ mic?: string;
37
+ currency?: string;
38
+ fromCurrency?: string;
39
+ toCurrency?: string;
40
+ };
41
+
42
+ declare const StockTickerTopic = "tradeinsight.stockticker";
43
+ type StockTickerPubSubChannels = {
44
+ [StockTickerTopic]: StockTickerMessage;
45
+ };
46
+
47
+ export { CloudSchema, type InstrumentPrice, type StockTicker, type StockTickerMessage, type StockTickerPubSubChannels, StockTickerTopic, createForexId, createStockId, parseId };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,25 @@
1
+ interface InstrumentPrice {
2
+ ask: null | number;
3
+ bid: null | number;
4
+ last: null | number;
5
+ lastInSek: null | number;
6
+ }
7
+ interface StockTicker {
8
+ id: string;
9
+ mic: string;
10
+ isin: string;
11
+ ticker: string;
12
+ currencyCode: string;
13
+ price: InstrumentPrice;
14
+ }
15
+ interface StockTickerMessage {
16
+ tickers: StockTicker[];
17
+ }
18
+ declare const CloudSchema: {
19
+ schemaId: string;
20
+ avroDefinition: string;
21
+ };
22
+
1
23
  declare const createStockId: ({ isin, mic, currency, }: {
2
24
  isin: string;
3
25
  currency: string;
@@ -8,4 +30,18 @@ declare const createForexId: ({ fromCurrency, toCurrency, }: {
8
30
  fromCurrency: string;
9
31
  }) => string;
10
32
 
11
- export { createForexId, createStockId };
33
+ declare const parseId: (id: string) => {
34
+ type: "STOCK" | "FOREX";
35
+ isin?: string;
36
+ mic?: string;
37
+ currency?: string;
38
+ fromCurrency?: string;
39
+ toCurrency?: string;
40
+ };
41
+
42
+ declare const StockTickerTopic = "tradeinsight.stockticker";
43
+ type StockTickerPubSubChannels = {
44
+ [StockTickerTopic]: StockTickerMessage;
45
+ };
46
+
47
+ export { CloudSchema, type InstrumentPrice, type StockTicker, type StockTickerMessage, type StockTickerPubSubChannels, StockTickerTopic, createForexId, createStockId, parseId };
package/dist/index.js CHANGED
@@ -20,12 +20,101 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ CloudSchema: () => CloudSchema,
24
+ StockTickerTopic: () => StockTickerTopic,
23
25
  createForexId: () => createForexId,
24
- createStockId: () => createStockId
26
+ createStockId: () => createStockId,
27
+ parseId: () => parseId
25
28
  });
26
29
  module.exports = __toCommonJS(index_exports);
27
30
 
28
- // src/createId.ts
31
+ // src/generated/stockticker.ts
32
+ var CloudSchema = {
33
+ schemaId: "stockticker-v1",
34
+ avroDefinition: `{
35
+ "type": "record",
36
+ "name": "StockTickerMessage",
37
+ "namespace": "com.financial.api",
38
+ "doc": "Real-time update containing the latest pricing details of financial instruments.",
39
+ "fields": [
40
+ {
41
+ "name": "tickers",
42
+ "type": {
43
+ "type": "array",
44
+ "items": {
45
+ "type": "record",
46
+ "name": "StockTicker",
47
+ "doc": "A real-time update containing the latest pricing details of a financial instrument.",
48
+ "fields": [
49
+ {
50
+ "name": "id",
51
+ "type": "string",
52
+ "doc": "Unique identifier of the instrument, consists of TYPE, ISIN, MIC, and Currency Code. Format: TYPE-ISIN;MIC;CurrencyCode"
53
+ },
54
+ {
55
+ "name": "mic",
56
+ "type": "string",
57
+ "doc": "The Market Identifier Code (MIC), specifying the financial market where the instrument is listed."
58
+ },
59
+ {
60
+ "name": "isin",
61
+ "type": "string",
62
+ "doc": "International Securities Identification Number (ISIN) uniquely identifying the financial instrument."
63
+ },
64
+ {
65
+ "name": "ticker",
66
+ "type": "string",
67
+ "doc": "The stock market symbol or abbreviation used to identify the financial instrument on the exchange."
68
+ },
69
+ {
70
+ "name": "currencyCode",
71
+ "type": "string",
72
+ "doc": "The code representing the currency in which the instrument's price is denominated."
73
+ },
74
+ {
75
+ "name": "price",
76
+ "type": {
77
+ "type": "record",
78
+ "name": "InstrumentPrice",
79
+ "doc": "A representation of the current pricing details for a financial instrument.",
80
+ "fields": [
81
+ {
82
+ "name": "ask",
83
+ "type": ["null", "double"],
84
+ "doc": "The current ask price. If no ask price is available, this can be null.",
85
+ "default": null
86
+ },
87
+ {
88
+ "name": "bid",
89
+ "type": ["null", "double"],
90
+ "doc": "The current bid price. If no bid price is available, this can be null.",
91
+ "default": null
92
+ },
93
+ {
94
+ "name": "last",
95
+ "type": ["null", "double"],
96
+ "doc": "The last traded price. If there hasn't been any recent trade, this can be null.",
97
+ "default": null
98
+ },
99
+ {
100
+ "name": "lastInSek",
101
+ "type": ["null", "double"],
102
+ "doc": "The last traded price in SEK. If there hasn't been any recent trade, this can be null.",
103
+ "default": null
104
+ }
105
+ ]
106
+ }
107
+ }
108
+ ]
109
+ }
110
+ }
111
+ }
112
+ ]
113
+ }
114
+ `
115
+ };
116
+
117
+ // src/instruments/createId.ts
29
118
  var createStockId = ({
30
119
  isin,
31
120
  mic,
@@ -35,8 +124,48 @@ var createForexId = ({
35
124
  fromCurrency,
36
125
  toCurrency
37
126
  }) => `FOREX-${toCurrency};${fromCurrency}`.toUpperCase();
127
+
128
+ // src/instruments/parseId.ts
129
+ var parseId = (id) => {
130
+ const [type, ...rest] = id.split("-");
131
+ const [first, second, third] = rest.join("-").split(";");
132
+ if (type === "STOCK") {
133
+ if (!second) {
134
+ throw new Error("Missing MIC");
135
+ }
136
+ if (!third) {
137
+ throw new Error("Missing currency");
138
+ }
139
+ return {
140
+ type,
141
+ isin: first,
142
+ mic: second,
143
+ currency: third
144
+ };
145
+ }
146
+ if (type === "FOREX") {
147
+ if (!first) {
148
+ throw new Error("Missing fromCurrency");
149
+ }
150
+ if (!second) {
151
+ throw new Error("Missing toCurrency");
152
+ }
153
+ return {
154
+ type,
155
+ fromCurrency: first,
156
+ toCurrency: second
157
+ };
158
+ }
159
+ throw new Error("Invalid type");
160
+ };
161
+
162
+ // src/pubsub/main.ts
163
+ var StockTickerTopic = "tradeinsight.stockticker";
38
164
  // Annotate the CommonJS export names for ESM import in node:
39
165
  0 && (module.exports = {
166
+ CloudSchema,
167
+ StockTickerTopic,
40
168
  createForexId,
41
- createStockId
169
+ createStockId,
170
+ parseId
42
171
  });
package/dist/index.mjs CHANGED
@@ -1,4 +1,90 @@
1
- // src/createId.ts
1
+ // src/generated/stockticker.ts
2
+ var CloudSchema = {
3
+ schemaId: "stockticker-v1",
4
+ avroDefinition: `{
5
+ "type": "record",
6
+ "name": "StockTickerMessage",
7
+ "namespace": "com.financial.api",
8
+ "doc": "Real-time update containing the latest pricing details of financial instruments.",
9
+ "fields": [
10
+ {
11
+ "name": "tickers",
12
+ "type": {
13
+ "type": "array",
14
+ "items": {
15
+ "type": "record",
16
+ "name": "StockTicker",
17
+ "doc": "A real-time update containing the latest pricing details of a financial instrument.",
18
+ "fields": [
19
+ {
20
+ "name": "id",
21
+ "type": "string",
22
+ "doc": "Unique identifier of the instrument, consists of TYPE, ISIN, MIC, and Currency Code. Format: TYPE-ISIN;MIC;CurrencyCode"
23
+ },
24
+ {
25
+ "name": "mic",
26
+ "type": "string",
27
+ "doc": "The Market Identifier Code (MIC), specifying the financial market where the instrument is listed."
28
+ },
29
+ {
30
+ "name": "isin",
31
+ "type": "string",
32
+ "doc": "International Securities Identification Number (ISIN) uniquely identifying the financial instrument."
33
+ },
34
+ {
35
+ "name": "ticker",
36
+ "type": "string",
37
+ "doc": "The stock market symbol or abbreviation used to identify the financial instrument on the exchange."
38
+ },
39
+ {
40
+ "name": "currencyCode",
41
+ "type": "string",
42
+ "doc": "The code representing the currency in which the instrument's price is denominated."
43
+ },
44
+ {
45
+ "name": "price",
46
+ "type": {
47
+ "type": "record",
48
+ "name": "InstrumentPrice",
49
+ "doc": "A representation of the current pricing details for a financial instrument.",
50
+ "fields": [
51
+ {
52
+ "name": "ask",
53
+ "type": ["null", "double"],
54
+ "doc": "The current ask price. If no ask price is available, this can be null.",
55
+ "default": null
56
+ },
57
+ {
58
+ "name": "bid",
59
+ "type": ["null", "double"],
60
+ "doc": "The current bid price. If no bid price is available, this can be null.",
61
+ "default": null
62
+ },
63
+ {
64
+ "name": "last",
65
+ "type": ["null", "double"],
66
+ "doc": "The last traded price. If there hasn't been any recent trade, this can be null.",
67
+ "default": null
68
+ },
69
+ {
70
+ "name": "lastInSek",
71
+ "type": ["null", "double"],
72
+ "doc": "The last traded price in SEK. If there hasn't been any recent trade, this can be null.",
73
+ "default": null
74
+ }
75
+ ]
76
+ }
77
+ }
78
+ ]
79
+ }
80
+ }
81
+ }
82
+ ]
83
+ }
84
+ `
85
+ };
86
+
87
+ // src/instruments/createId.ts
2
88
  var createStockId = ({
3
89
  isin,
4
90
  mic,
@@ -8,7 +94,47 @@ var createForexId = ({
8
94
  fromCurrency,
9
95
  toCurrency
10
96
  }) => `FOREX-${toCurrency};${fromCurrency}`.toUpperCase();
97
+
98
+ // src/instruments/parseId.ts
99
+ var parseId = (id) => {
100
+ const [type, ...rest] = id.split("-");
101
+ const [first, second, third] = rest.join("-").split(";");
102
+ if (type === "STOCK") {
103
+ if (!second) {
104
+ throw new Error("Missing MIC");
105
+ }
106
+ if (!third) {
107
+ throw new Error("Missing currency");
108
+ }
109
+ return {
110
+ type,
111
+ isin: first,
112
+ mic: second,
113
+ currency: third
114
+ };
115
+ }
116
+ if (type === "FOREX") {
117
+ if (!first) {
118
+ throw new Error("Missing fromCurrency");
119
+ }
120
+ if (!second) {
121
+ throw new Error("Missing toCurrency");
122
+ }
123
+ return {
124
+ type,
125
+ fromCurrency: first,
126
+ toCurrency: second
127
+ };
128
+ }
129
+ throw new Error("Invalid type");
130
+ };
131
+
132
+ // src/pubsub/main.ts
133
+ var StockTickerTopic = "tradeinsight.stockticker";
11
134
  export {
135
+ CloudSchema,
136
+ StockTickerTopic,
12
137
  createForexId,
13
- createStockId
138
+ createStockId,
139
+ parseId
14
140
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/tradeinsight",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -11,11 +11,14 @@
11
11
  "scripts": {
12
12
  "build": "tsup-node src/index.ts --format esm,cjs --dts",
13
13
  "dev": "tsc --watch --noEmit",
14
+ "generate:avro": "ts-node ./scripts/avro-to-ts.ts",
14
15
  "lint": "biome check .",
15
16
  "test": "vitest run --passWithNoTests --coverage",
16
17
  "typecheck": "vitest --typecheck.only --passWithNoTests"
17
18
  },
18
19
  "devDependencies": {
20
+ "avro-typescript": "1.3.0",
21
+ "ts-node": "10.9.2",
19
22
  "tsconfig": "*"
20
23
  }
21
24
  }