@sebspark/tradeinsight 3.0.6 → 3.0.8
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/dist/index.d.mts +83 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/{index.js → index.mjs} +59 -67
- package/dist/index.mjs.map +1 -0
- package/package.json +4 -5
- package/dist/index.d.ts +0 -69
- package/dist/index.js.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//#region src/generated/tickerMessage.d.ts
|
|
2
|
+
interface InstrumentPrice {
|
|
3
|
+
ask: null | number;
|
|
4
|
+
bid: null | number;
|
|
5
|
+
last: null | number;
|
|
6
|
+
lastInSek: null | number;
|
|
7
|
+
}
|
|
8
|
+
interface Ticker {
|
|
9
|
+
id: string;
|
|
10
|
+
mic: string;
|
|
11
|
+
isin: string;
|
|
12
|
+
ticker: string;
|
|
13
|
+
currencyCode: string;
|
|
14
|
+
price: InstrumentPrice;
|
|
15
|
+
}
|
|
16
|
+
interface TickerMessage {
|
|
17
|
+
tickers: Ticker[];
|
|
18
|
+
}
|
|
19
|
+
declare const CloudSchema: {
|
|
20
|
+
schemaId: string;
|
|
21
|
+
avroDefinition: string;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/instruments/createId.d.ts
|
|
25
|
+
declare const createStockId: ({
|
|
26
|
+
isin,
|
|
27
|
+
mic,
|
|
28
|
+
currency
|
|
29
|
+
}: {
|
|
30
|
+
isin: string;
|
|
31
|
+
currency: string;
|
|
32
|
+
mic: string;
|
|
33
|
+
}) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Create an ID for a FOREX instrument, i.e. a currency relationship.
|
|
36
|
+
* The structure matches a currency pair:
|
|
37
|
+
*
|
|
38
|
+
* Base currency / quote currency = Exchange rate
|
|
39
|
+
*
|
|
40
|
+
* @see https://en.wikipedia.org/wiki/Currency_pair
|
|
41
|
+
* @example
|
|
42
|
+
* EUR/USD = 1.45
|
|
43
|
+
* This means a person would need 1.45 US dollars to purchase one Euro.
|
|
44
|
+
*/
|
|
45
|
+
declare const createForexId: ({
|
|
46
|
+
quoteCurrency,
|
|
47
|
+
baseCurrency
|
|
48
|
+
}: {
|
|
49
|
+
baseCurrency: string;
|
|
50
|
+
quoteCurrency: string;
|
|
51
|
+
}) => string;
|
|
52
|
+
declare const createIndexId: ({
|
|
53
|
+
ticker
|
|
54
|
+
}: {
|
|
55
|
+
ticker: string;
|
|
56
|
+
}) => string;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/instruments/parseId.d.ts
|
|
59
|
+
type StockId = {
|
|
60
|
+
type: 'STOCK';
|
|
61
|
+
isin: string;
|
|
62
|
+
mic: string;
|
|
63
|
+
currency: string;
|
|
64
|
+
};
|
|
65
|
+
type ForexId = {
|
|
66
|
+
type: 'FOREX';
|
|
67
|
+
baseCurrency: string;
|
|
68
|
+
quoteCurrency: string;
|
|
69
|
+
};
|
|
70
|
+
type IndexId = {
|
|
71
|
+
type: 'INDEX';
|
|
72
|
+
ticker: string;
|
|
73
|
+
};
|
|
74
|
+
declare const parseId: (id: string) => StockId | ForexId | IndexId;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/pubsub/main.d.ts
|
|
77
|
+
declare const TickersTopic = "tradeinsight.tickers";
|
|
78
|
+
type TickersPubSubChannels = {
|
|
79
|
+
[TickersTopic]: TickerMessage;
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
export { CloudSchema, InstrumentPrice, Ticker, TickerMessage, TickersPubSubChannels, TickersTopic, createForexId, createIndexId, createStockId, parseId };
|
|
83
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/generated/tickerMessage.ts","../src/instruments/createId.ts","../src/instruments/parseId.ts","../src/pubsub/main.ts"],"sourcesContent":[],"mappings":";UAAiB,eAAA;EAAA,GA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
|
|
2
|
+
const CloudSchema = {
|
|
3
|
+
schemaId: "ticker-v1",
|
|
4
|
+
avroDefinition: `{
|
|
5
5
|
"type": "record",
|
|
6
6
|
"name": "TickerMessage",
|
|
7
7
|
"namespace": "com.financial.api",
|
|
@@ -84,69 +84,61 @@ var CloudSchema = {
|
|
|
84
84
|
`
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/instruments/createId.ts
|
|
89
|
+
const createStockId = ({ isin, mic, currency }) => `STOCK-${isin}_${mic}_${currency}`.toUpperCase();
|
|
90
|
+
/**
|
|
91
|
+
* Create an ID for a FOREX instrument, i.e. a currency relationship.
|
|
92
|
+
* The structure matches a currency pair:
|
|
93
|
+
*
|
|
94
|
+
* Base currency / quote currency = Exchange rate
|
|
95
|
+
*
|
|
96
|
+
* @see https://en.wikipedia.org/wiki/Currency_pair
|
|
97
|
+
* @example
|
|
98
|
+
* EUR/USD = 1.45
|
|
99
|
+
* This means a person would need 1.45 US dollars to purchase one Euro.
|
|
100
|
+
*/
|
|
101
|
+
const createForexId = ({ quoteCurrency, baseCurrency }) => `FOREX-${baseCurrency}_${quoteCurrency}`.toUpperCase();
|
|
102
|
+
const createIndexId = ({ ticker }) => `INDEX-${ticker}`.toUpperCase();
|
|
98
103
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (!first) {
|
|
132
|
-
throw new Error("Missing ticker");
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
type,
|
|
136
|
-
ticker: first
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
throw new Error("Invalid type");
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/instruments/parseId.ts
|
|
106
|
+
const parseId = (id) => {
|
|
107
|
+
const [type, ...rest] = id.split("-");
|
|
108
|
+
const [first, second, third] = rest.join().split("_");
|
|
109
|
+
if (type === "STOCK") {
|
|
110
|
+
if (!second) throw new Error("Missing MIC");
|
|
111
|
+
if (!third) throw new Error("Missing currency");
|
|
112
|
+
return {
|
|
113
|
+
type,
|
|
114
|
+
isin: first,
|
|
115
|
+
mic: second,
|
|
116
|
+
currency: third
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (type === "FOREX") {
|
|
120
|
+
if (!first) throw new Error("Missing baseCurrency");
|
|
121
|
+
if (!second) throw new Error("Missing quoteCurrency");
|
|
122
|
+
return {
|
|
123
|
+
type,
|
|
124
|
+
baseCurrency: first,
|
|
125
|
+
quoteCurrency: second
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (type === "INDEX") {
|
|
129
|
+
if (!first) throw new Error("Missing ticker");
|
|
130
|
+
return {
|
|
131
|
+
type,
|
|
132
|
+
ticker: first
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
throw new Error("Invalid type");
|
|
140
136
|
};
|
|
141
137
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
createStockId,
|
|
150
|
-
parseId
|
|
151
|
-
};
|
|
152
|
-
//# sourceMappingURL=index.js.map
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/pubsub/main.ts
|
|
140
|
+
const TickersTopic = "tradeinsight.tickers";
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
export { CloudSchema, TickersTopic, createForexId, createIndexId, createStockId, parseId };
|
|
144
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/generated/tickerMessage.ts","../src/instruments/createId.ts","../src/instruments/parseId.ts","../src/pubsub/main.ts"],"sourcesContent":["export interface InstrumentPrice {\n ask: null | number\n bid: null | number\n last: null | number\n lastInSek: null | number\n}\n\nexport interface Ticker {\n id: string\n mic: string\n isin: string\n ticker: string\n currencyCode: string\n price: InstrumentPrice\n}\n\nexport interface TickerMessage {\n tickers: Ticker[]\n}\n\nexport const CloudSchema = {\n schemaId: 'ticker-v1',\n\n avroDefinition: `{\n \"type\": \"record\",\n \"name\": \"TickerMessage\",\n \"namespace\": \"com.financial.api\",\n \"doc\": \"Real-time update containing the latest pricing details of financial instruments.\",\n \"fields\": [\n {\n \"name\": \"tickers\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"record\",\n \"name\": \"Ticker\",\n \"doc\": \"A real-time update containing the latest pricing details of a financial instrument.\",\n \"fields\": [\n {\n \"name\": \"id\",\n \"type\": \"string\",\n \"doc\": \"Unique identifier of the instrument. Consists of type followed by the least common denominators making it unique. Example: STOCK-SE0000148884;XSTO;SEK\"\n },\n {\n \"name\": \"mic\",\n \"type\": \"string\",\n \"doc\": \"The Market Identifier Code (MIC), specifying the financial market where the instrument is listed.\"\n },\n {\n \"name\": \"isin\",\n \"type\": \"string\",\n \"doc\": \"International Securities Identification Number (ISIN) uniquely identifying the financial instrument.\"\n },\n {\n \"name\": \"ticker\",\n \"type\": \"string\",\n \"doc\": \"The stock market symbol or abbreviation used to identify the financial instrument on the exchange.\"\n },\n {\n \"name\": \"currencyCode\",\n \"type\": \"string\",\n \"doc\": \"The code representing the currency in which the instrument's price is denominated.\"\n },\n {\n \"name\": \"price\",\n \"type\": {\n \"type\": \"record\",\n \"name\": \"InstrumentPrice\",\n \"doc\": \"A representation of the current pricing details for a financial instrument.\",\n \"fields\": [\n {\n \"name\": \"ask\",\n \"type\": [\"null\", \"double\"],\n \"doc\": \"The current ask price. If no ask price is available, this can be null.\",\n \"default\": null\n },\n {\n \"name\": \"bid\",\n \"type\": [\"null\", \"double\"],\n \"doc\": \"The current bid price. If no bid price is available, this can be null.\",\n \"default\": null\n },\n {\n \"name\": \"last\",\n \"type\": [\"null\", \"double\"],\n \"doc\": \"The last traded price. If there hasn't been any recent trade, this can be null.\",\n \"default\": null\n },\n {\n \"name\": \"lastInSek\",\n \"type\": [\"null\", \"double\"],\n \"doc\": \"The last traded price in SEK. If there hasn't been any recent trade, this can be null.\",\n \"default\": null\n }\n ]\n }\n }\n ]\n }\n }\n }\n ]\n}\n`,\n}\n","export const createStockId = ({\n isin,\n mic,\n currency,\n}: {\n isin: string\n currency: string\n mic: string\n}) => `STOCK-${isin}_${mic}_${currency}`.toUpperCase()\n\n/**\n * Create an ID for a FOREX instrument, i.e. a currency relationship.\n * The structure matches a currency pair:\n *\n * Base currency / quote currency = Exchange rate\n *\n * @see https://en.wikipedia.org/wiki/Currency_pair\n * @example\n * EUR/USD = 1.45\n * This means a person would need 1.45 US dollars to purchase one Euro.\n */\nexport const createForexId = ({\n quoteCurrency,\n baseCurrency,\n}: {\n baseCurrency: string\n quoteCurrency: string\n}) => `FOREX-${baseCurrency}_${quoteCurrency}`.toUpperCase()\n\nexport const createIndexId = ({ ticker }: { ticker: string }) =>\n `INDEX-${ticker}`.toUpperCase()\n","type StockId = {\n type: 'STOCK'\n isin: string\n mic: string\n currency: string\n}\n\ntype ForexId = {\n type: 'FOREX'\n baseCurrency: string\n quoteCurrency: string\n}\n\ntype IndexId = {\n type: 'INDEX'\n ticker: string\n}\n\nexport const parseId = (id: string): StockId | ForexId | IndexId => {\n const [type, ...rest] = id.split('-')\n const [first, second, third] = rest.join().split('_')\n\n if (type === 'STOCK') {\n if (!second) {\n throw new Error('Missing MIC')\n }\n\n if (!third) {\n throw new Error('Missing currency')\n }\n\n return {\n type,\n isin: first,\n mic: second,\n currency: third,\n }\n }\n\n if (type === 'FOREX') {\n if (!first) {\n throw new Error('Missing baseCurrency')\n }\n\n if (!second) {\n throw new Error('Missing quoteCurrency')\n }\n\n return {\n type,\n baseCurrency: first,\n quoteCurrency: second,\n }\n }\n\n if (type === 'INDEX') {\n if (!first) {\n throw new Error('Missing ticker')\n }\n\n return {\n type,\n ticker: first,\n }\n }\n\n throw new Error('Invalid type')\n}\n","import type { TickerMessage } from '../generated/tickerMessage'\n\nexport const TickersTopic = 'tradeinsight.tickers'\nexport type TickersPubSubChannels = {\n [TickersTopic]: TickerMessage\n}\n"],"mappings":";AAoBA,MAAa,cAAc;CACzB,UAAU;CAEV,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiFjB;;;;ACxGD,MAAa,iBAAiB,EAC5B,MACA,KACA,eAKI,SAAS,KAAK,GAAG,IAAI,GAAG,WAAW,aAAa;;;;;;;;;;;;AAatD,MAAa,iBAAiB,EAC5B,eACA,mBAII,SAAS,aAAa,GAAG,gBAAgB,aAAa;AAE5D,MAAa,iBAAiB,EAAE,aAC9B,SAAS,SAAS,aAAa;;;;ACZjC,MAAa,WAAW,OAA4C;CAClE,MAAM,CAAC,MAAM,GAAG,QAAQ,GAAG,MAAM,IAAI;CACrC,MAAM,CAAC,OAAO,QAAQ,SAAS,KAAK,MAAM,CAAC,MAAM,IAAI;AAErD,KAAI,SAAS,SAAS;AACpB,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,cAAc;AAGhC,MAAI,CAAC,MACH,OAAM,IAAI,MAAM,mBAAmB;AAGrC,SAAO;GACL;GACA,MAAM;GACN,KAAK;GACL,UAAU;GACX;;AAGH,KAAI,SAAS,SAAS;AACpB,MAAI,CAAC,MACH,OAAM,IAAI,MAAM,uBAAuB;AAGzC,MAAI,CAAC,OACH,OAAM,IAAI,MAAM,wBAAwB;AAG1C,SAAO;GACL;GACA,cAAc;GACd,eAAe;GAChB;;AAGH,KAAI,SAAS,SAAS;AACpB,MAAI,CAAC,MACH,OAAM,IAAI,MAAM,iBAAiB;AAGnC,SAAO;GACL;GACA,QAAQ;GACT;;AAGH,OAAM,IAAI,MAAM,eAAe;;;;;AChEjC,MAAa,eAAe"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/tradeinsight",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.8",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"import": "./dist/index.
|
|
10
|
-
"react-native": "./dist/index.
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"react-native": "./dist/index.mjs"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "
|
|
17
|
+
"build": "spark-build src/index.ts",
|
|
18
18
|
"depcheck": "depcheck",
|
|
19
19
|
"dev": "tsc --watch --noEmit",
|
|
20
20
|
"generate:avro": "ts-node ./scripts/avro-to-ts.ts",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"@sebspark/tsconfig": "*",
|
|
27
27
|
"avro-typescript": "1.3.0",
|
|
28
28
|
"ts-node": "10.9.2",
|
|
29
|
-
"tsdown": "0.16.6",
|
|
30
29
|
"vitest": "4.0.6"
|
|
31
30
|
}
|
|
32
31
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
interface InstrumentPrice {
|
|
2
|
-
ask: null | number;
|
|
3
|
-
bid: null | number;
|
|
4
|
-
last: null | number;
|
|
5
|
-
lastInSek: null | number;
|
|
6
|
-
}
|
|
7
|
-
interface Ticker {
|
|
8
|
-
id: string;
|
|
9
|
-
mic: string;
|
|
10
|
-
isin: string;
|
|
11
|
-
ticker: string;
|
|
12
|
-
currencyCode: string;
|
|
13
|
-
price: InstrumentPrice;
|
|
14
|
-
}
|
|
15
|
-
interface TickerMessage {
|
|
16
|
-
tickers: Ticker[];
|
|
17
|
-
}
|
|
18
|
-
declare const CloudSchema: {
|
|
19
|
-
schemaId: string;
|
|
20
|
-
avroDefinition: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
declare const createStockId: ({ isin, mic, currency, }: {
|
|
24
|
-
isin: string;
|
|
25
|
-
currency: string;
|
|
26
|
-
mic: string;
|
|
27
|
-
}) => string;
|
|
28
|
-
/**
|
|
29
|
-
* Create an ID for a FOREX instrument, i.e. a currency relationship.
|
|
30
|
-
* The structure matches a currency pair:
|
|
31
|
-
*
|
|
32
|
-
* Base currency / quote currency = Exchange rate
|
|
33
|
-
*
|
|
34
|
-
* @see https://en.wikipedia.org/wiki/Currency_pair
|
|
35
|
-
* @example
|
|
36
|
-
* EUR/USD = 1.45
|
|
37
|
-
* This means a person would need 1.45 US dollars to purchase one Euro.
|
|
38
|
-
*/
|
|
39
|
-
declare const createForexId: ({ quoteCurrency, baseCurrency, }: {
|
|
40
|
-
baseCurrency: string;
|
|
41
|
-
quoteCurrency: string;
|
|
42
|
-
}) => string;
|
|
43
|
-
declare const createIndexId: ({ ticker }: {
|
|
44
|
-
ticker: string;
|
|
45
|
-
}) => string;
|
|
46
|
-
|
|
47
|
-
type StockId = {
|
|
48
|
-
type: 'STOCK';
|
|
49
|
-
isin: string;
|
|
50
|
-
mic: string;
|
|
51
|
-
currency: string;
|
|
52
|
-
};
|
|
53
|
-
type ForexId = {
|
|
54
|
-
type: 'FOREX';
|
|
55
|
-
baseCurrency: string;
|
|
56
|
-
quoteCurrency: string;
|
|
57
|
-
};
|
|
58
|
-
type IndexId = {
|
|
59
|
-
type: 'INDEX';
|
|
60
|
-
ticker: string;
|
|
61
|
-
};
|
|
62
|
-
declare const parseId: (id: string) => StockId | ForexId | IndexId;
|
|
63
|
-
|
|
64
|
-
declare const TickersTopic = "tradeinsight.tickers";
|
|
65
|
-
type TickersPubSubChannels = {
|
|
66
|
-
[TickersTopic]: TickerMessage;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export { CloudSchema, type InstrumentPrice, type Ticker, type TickerMessage, type TickersPubSubChannels, TickersTopic, createForexId, createIndexId, createStockId, parseId };
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generated/tickerMessage.ts","../src/instruments/createId.ts","../src/instruments/parseId.ts","../src/pubsub/main.ts"],"sourcesContent":["export interface InstrumentPrice {\n ask: null | number\n bid: null | number\n last: null | number\n lastInSek: null | number\n}\n\nexport interface Ticker {\n id: string\n mic: string\n isin: string\n ticker: string\n currencyCode: string\n price: InstrumentPrice\n}\n\nexport interface TickerMessage {\n tickers: Ticker[]\n}\n\nexport const CloudSchema = {\n schemaId: 'ticker-v1',\n\n avroDefinition: `{\n \"type\": \"record\",\n \"name\": \"TickerMessage\",\n \"namespace\": \"com.financial.api\",\n \"doc\": \"Real-time update containing the latest pricing details of financial instruments.\",\n \"fields\": [\n {\n \"name\": \"tickers\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"record\",\n \"name\": \"Ticker\",\n \"doc\": \"A real-time update containing the latest pricing details of a financial instrument.\",\n \"fields\": [\n {\n \"name\": \"id\",\n \"type\": \"string\",\n \"doc\": \"Unique identifier of the instrument. Consists of type followed by the least common denominators making it unique. Example: STOCK-SE0000148884;XSTO;SEK\"\n },\n {\n \"name\": \"mic\",\n \"type\": \"string\",\n \"doc\": \"The Market Identifier Code (MIC), specifying the financial market where the instrument is listed.\"\n },\n {\n \"name\": \"isin\",\n \"type\": \"string\",\n \"doc\": \"International Securities Identification Number (ISIN) uniquely identifying the financial instrument.\"\n },\n {\n \"name\": \"ticker\",\n \"type\": \"string\",\n \"doc\": \"The stock market symbol or abbreviation used to identify the financial instrument on the exchange.\"\n },\n {\n \"name\": \"currencyCode\",\n \"type\": \"string\",\n \"doc\": \"The code representing the currency in which the instrument's price is denominated.\"\n },\n {\n \"name\": \"price\",\n \"type\": {\n \"type\": \"record\",\n \"name\": \"InstrumentPrice\",\n \"doc\": \"A representation of the current pricing details for a financial instrument.\",\n \"fields\": [\n {\n \"name\": \"ask\",\n \"type\": [\"null\", \"double\"],\n \"doc\": \"The current ask price. If no ask price is available, this can be null.\",\n \"default\": null\n },\n {\n \"name\": \"bid\",\n \"type\": [\"null\", \"double\"],\n \"doc\": \"The current bid price. If no bid price is available, this can be null.\",\n \"default\": null\n },\n {\n \"name\": \"last\",\n \"type\": [\"null\", \"double\"],\n \"doc\": \"The last traded price. If there hasn't been any recent trade, this can be null.\",\n \"default\": null\n },\n {\n \"name\": \"lastInSek\",\n \"type\": [\"null\", \"double\"],\n \"doc\": \"The last traded price in SEK. If there hasn't been any recent trade, this can be null.\",\n \"default\": null\n }\n ]\n }\n }\n ]\n }\n }\n }\n ]\n}\n`,\n}\n","export const createStockId = ({\n isin,\n mic,\n currency,\n}: {\n isin: string\n currency: string\n mic: string\n}) => `STOCK-${isin}_${mic}_${currency}`.toUpperCase()\n\n/**\n * Create an ID for a FOREX instrument, i.e. a currency relationship.\n * The structure matches a currency pair:\n *\n * Base currency / quote currency = Exchange rate\n *\n * @see https://en.wikipedia.org/wiki/Currency_pair\n * @example\n * EUR/USD = 1.45\n * This means a person would need 1.45 US dollars to purchase one Euro.\n */\nexport const createForexId = ({\n quoteCurrency,\n baseCurrency,\n}: {\n baseCurrency: string\n quoteCurrency: string\n}) => `FOREX-${baseCurrency}_${quoteCurrency}`.toUpperCase()\n\nexport const createIndexId = ({ ticker }: { ticker: string }) =>\n `INDEX-${ticker}`.toUpperCase()\n","type StockId = {\n type: 'STOCK'\n isin: string\n mic: string\n currency: string\n}\n\ntype ForexId = {\n type: 'FOREX'\n baseCurrency: string\n quoteCurrency: string\n}\n\ntype IndexId = {\n type: 'INDEX'\n ticker: string\n}\n\nexport const parseId = (id: string): StockId | ForexId | IndexId => {\n const [type, ...rest] = id.split('-')\n const [first, second, third] = rest.join().split('_')\n\n if (type === 'STOCK') {\n if (!second) {\n throw new Error('Missing MIC')\n }\n\n if (!third) {\n throw new Error('Missing currency')\n }\n\n return {\n type,\n isin: first,\n mic: second,\n currency: third,\n }\n }\n\n if (type === 'FOREX') {\n if (!first) {\n throw new Error('Missing baseCurrency')\n }\n\n if (!second) {\n throw new Error('Missing quoteCurrency')\n }\n\n return {\n type,\n baseCurrency: first,\n quoteCurrency: second,\n }\n }\n\n if (type === 'INDEX') {\n if (!first) {\n throw new Error('Missing ticker')\n }\n\n return {\n type,\n ticker: first,\n }\n }\n\n throw new Error('Invalid type')\n}\n","import type { TickerMessage } from '../generated/tickerMessage'\n\nexport const TickersTopic = 'tradeinsight.tickers'\nexport type TickersPubSubChannels = {\n [TickersTopic]: TickerMessage\n}\n"],"mappings":";AAoBO,IAAM,cAAc;AAAA,EACzB,UAAU;AAAA,EAEV,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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