@sebspark/tradeinsight 3.0.9 → 3.0.11

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.cjs ADDED
@@ -0,0 +1,159 @@
1
+
2
+ //#region src/generated/tickerMessage.ts
3
+ const CloudSchema = {
4
+ schemaId: "ticker-v1",
5
+ avroDefinition: `{
6
+ "type": "record",
7
+ "name": "TickerMessage",
8
+ "namespace": "com.financial.api",
9
+ "doc": "Real-time update containing the latest pricing details of financial instruments.",
10
+ "fields": [
11
+ {
12
+ "name": "tickers",
13
+ "type": {
14
+ "type": "array",
15
+ "items": {
16
+ "type": "record",
17
+ "name": "Ticker",
18
+ "doc": "A real-time update containing the latest pricing details of a financial instrument.",
19
+ "fields": [
20
+ {
21
+ "name": "id",
22
+ "type": "string",
23
+ "doc": "Unique identifier of the instrument. Consists of type followed by the least common denominators making it unique. Example: STOCK-SE0000148884;XSTO;SEK"
24
+ },
25
+ {
26
+ "name": "mic",
27
+ "type": "string",
28
+ "doc": "The Market Identifier Code (MIC), specifying the financial market where the instrument is listed."
29
+ },
30
+ {
31
+ "name": "isin",
32
+ "type": "string",
33
+ "doc": "International Securities Identification Number (ISIN) uniquely identifying the financial instrument."
34
+ },
35
+ {
36
+ "name": "ticker",
37
+ "type": "string",
38
+ "doc": "The stock market symbol or abbreviation used to identify the financial instrument on the exchange."
39
+ },
40
+ {
41
+ "name": "currencyCode",
42
+ "type": "string",
43
+ "doc": "The code representing the currency in which the instrument's price is denominated."
44
+ },
45
+ {
46
+ "name": "price",
47
+ "type": {
48
+ "type": "record",
49
+ "name": "InstrumentPrice",
50
+ "doc": "A representation of the current pricing details for a financial instrument.",
51
+ "fields": [
52
+ {
53
+ "name": "ask",
54
+ "type": ["null", "double"],
55
+ "doc": "The current ask price. If no ask price is available, this can be null.",
56
+ "default": null
57
+ },
58
+ {
59
+ "name": "bid",
60
+ "type": ["null", "double"],
61
+ "doc": "The current bid price. If no bid price is available, this can be null.",
62
+ "default": null
63
+ },
64
+ {
65
+ "name": "last",
66
+ "type": ["null", "double"],
67
+ "doc": "The last traded price. If there hasn't been any recent trade, this can be null.",
68
+ "default": null
69
+ },
70
+ {
71
+ "name": "lastInSek",
72
+ "type": ["null", "double"],
73
+ "doc": "The last traded price in SEK. If there hasn't been any recent trade, this can be null.",
74
+ "default": null
75
+ }
76
+ ]
77
+ }
78
+ }
79
+ ]
80
+ }
81
+ }
82
+ }
83
+ ]
84
+ }
85
+ `
86
+ };
87
+
88
+ //#endregion
89
+ //#region src/instruments/createId.ts
90
+ const createStockId = ({ isin, mic, currency }) => `STOCK-${isin}_${mic}_${currency}`.toUpperCase();
91
+ /**
92
+ * Create an ID for a FOREX instrument, i.e. a currency relationship.
93
+ * The structure matches a currency pair:
94
+ *
95
+ * Base currency / quote currency = Exchange rate
96
+ *
97
+ * @see https://en.wikipedia.org/wiki/Currency_pair
98
+ * @example
99
+ * EUR/USD = 1.45
100
+ * This means a person would need 1.45 US dollars to purchase one Euro.
101
+ */
102
+ const createForexId = ({ quoteCurrency, baseCurrency }) => `FOREX-${baseCurrency}_${quoteCurrency}`.toUpperCase();
103
+ const createIndexId = ({ ticker }) => `INDEX-${ticker}`.toUpperCase();
104
+ const createFundId = ({ isin }) => `FUND-${isin}`.toUpperCase();
105
+
106
+ //#endregion
107
+ //#region src/instruments/parseId.ts
108
+ const parseId = (id) => {
109
+ const [type, ...rest] = id.split("-");
110
+ const [first, second, third] = rest.join().split("_");
111
+ if (type === "STOCK") {
112
+ if (!second) throw new Error("Missing MIC");
113
+ if (!third) throw new Error("Missing currency");
114
+ return {
115
+ type,
116
+ isin: first,
117
+ mic: second,
118
+ currency: third
119
+ };
120
+ }
121
+ if (type === "FOREX") {
122
+ if (!first) throw new Error("Missing baseCurrency");
123
+ if (!second) throw new Error("Missing quoteCurrency");
124
+ return {
125
+ type,
126
+ baseCurrency: first,
127
+ quoteCurrency: second
128
+ };
129
+ }
130
+ if (type === "INDEX") {
131
+ if (!first) throw new Error("Missing ticker");
132
+ return {
133
+ type,
134
+ ticker: first
135
+ };
136
+ }
137
+ if (type === "FUND") {
138
+ if (!first) throw new Error("Missing isin");
139
+ return {
140
+ type,
141
+ isin: first
142
+ };
143
+ }
144
+ throw new Error("Invalid type");
145
+ };
146
+
147
+ //#endregion
148
+ //#region src/pubsub/main.ts
149
+ const TickersTopic = "tradeinsight.tickers";
150
+
151
+ //#endregion
152
+ exports.CloudSchema = CloudSchema;
153
+ exports.TickersTopic = TickersTopic;
154
+ exports.createForexId = createForexId;
155
+ exports.createFundId = createFundId;
156
+ exports.createIndexId = createIndexId;
157
+ exports.createStockId = createStockId;
158
+ exports.parseId = parseId;
159
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","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\nexport const createFundId = ({ isin }: { isin: string }) =>\n `FUND-${isin}`.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\ntype FundId = {\n type: 'FUND'\n isin: string\n}\n\ntype TradeInsightId = StockId | ForexId | IndexId | FundId\n\nexport const parseId = (id: string): TradeInsightId => {\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 if (type === 'FUND') {\n if (!first) {\n throw new Error('Missing isin')\n }\n\n return {\n type,\n isin: 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;AAEjC,MAAa,gBAAgB,EAAE,WAC7B,QAAQ,OAAO,aAAa;;;;ACR9B,MAAa,WAAW,OAA+B;CACrD,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,KAAI,SAAS,QAAQ;AACnB,MAAI,CAAC,MACH,OAAM,IAAI,MAAM,eAAe;AAGjC,SAAO;GACL;GACA,MAAM;GACP;;AAGH,OAAM,IAAI,MAAM,eAAe;;;;;AClFjC,MAAa,eAAe"}
@@ -0,0 +1,93 @@
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
+ declare const createFundId: ({
58
+ isin
59
+ }: {
60
+ isin: string;
61
+ }) => string;
62
+ //#endregion
63
+ //#region src/instruments/parseId.d.ts
64
+ type StockId = {
65
+ type: 'STOCK';
66
+ isin: string;
67
+ mic: string;
68
+ currency: string;
69
+ };
70
+ type ForexId = {
71
+ type: 'FOREX';
72
+ baseCurrency: string;
73
+ quoteCurrency: string;
74
+ };
75
+ type IndexId = {
76
+ type: 'INDEX';
77
+ ticker: string;
78
+ };
79
+ type FundId = {
80
+ type: 'FUND';
81
+ isin: string;
82
+ };
83
+ type TradeInsightId = StockId | ForexId | IndexId | FundId;
84
+ declare const parseId: (id: string) => TradeInsightId;
85
+ //#endregion
86
+ //#region src/pubsub/main.d.ts
87
+ declare const TickersTopic = "tradeinsight.tickers";
88
+ type TickersPubSubChannels = {
89
+ [TickersTopic]: TickerMessage;
90
+ };
91
+ //#endregion
92
+ export { CloudSchema, InstrumentPrice, Ticker, TickerMessage, TickersPubSubChannels, TickersTopic, createForexId, createFundId, createIndexId, createStockId, parseId };
93
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/generated/tickerMessage.ts","../src/instruments/createId.ts","../src/instruments/parseId.ts","../src/pubsub/main.ts"],"sourcesContent":[],"mappings":";UAAiB,eAAA;EAAA,GAAA,EAAA,IAAA,GAAA,MAAe;EAOf,GAAA,EAAA,IAAM,GAAA,MAAA;EASN,IAAA,EAAA,IAAA,GAAA,MAAa;EAIjB,SAAA,EAAA,IAoFZ,GAAA,MAAA;;UAjGgB,MAAA;;ECPJ,GAAA,EAAA,MAAA;EAAiB,IAAA,EAAA,MAAA;EAAA,MAAA,EAAA,MAAA;EAAA,YAAA,EAAA,MAAA;EAAA,KAAA,EDarB,eCbqB;AAqB9B;AAQa,UDbI,aAAA,CCaa;EAGjB,OAAA,EDfF,MCgBmB,EAAA;;cDbjB;;EEpBR,cAAO,EAAA,MAAA;AAAA,CAAA;;;cDAC;;;;ADoBb;EApBiB,IAAA,EAAA,MAAA;EAOA,QAAA,EAAM,MAAA;EASN,GAAA,EAAA,MAAA;AAIjB,CAAA,EAAA,GAAa,MAAA;;;;ACpBb;;;;;AAqBA;AAQA;AAGA;cAXa;;;;;;MCrBR,MAAA;AAOA,cDsBQ,aCtBD,EAAA,CAAA;EAAA;AAMA,CANA,EAAA;EAMP,MAAA,EAAA,MAAO;AAAA,CAAA,EAAA,GAKP,MAAA;AAKA,cDSQ,YCTM,EAAA,CAAA;EAAA;CAAA,EAAA;EAAG,IAAA,EAAA,MAAA;CAAU,EAAA,GAAA,MAAA;;;KAvB3B,OAAA;EFAY,IAAA,EAAA,OAAA;EAOA,IAAA,EAAA,MAAM;EASN,GAAA,EAAA,MAAA;EAIJ,QAAA,EAAA,MAoFZ;;KEjGI,OAAA;;EDPQ,YAAA,EAAA,MAQyC;EARxB,aAAA,EAAA,MAAA;CAAA;KCazB,OAAA,GDbyB;EAAA,IAAA,EAAA,OAAA;EAqBjB,MAAA,EAAA,MAAA;AAQb,CAAA;AAGA,KCdK,MAAA,GDcQ;;;;KCTR,cAAA,GAAiB,OAvBV,GAuBoB,OAvBpB,GAuB8B,OAvB9B,GAuBwC,MAvBxC;AAOP,cAkBQ,OAlBD,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,GAkByB,cAlBzB;;;AFPK,cGEJ,YAAA,GHFmB,sBAAA;AAOf,KGJL,qBAAA,GHUH;EAGQ,CGZd,YAAA,CHYc,EGZC,aHaP;AAGX,CAAA"}
package/dist/index.d.mts CHANGED
@@ -54,6 +54,11 @@ declare const createIndexId: ({
54
54
  }: {
55
55
  ticker: string;
56
56
  }) => string;
57
+ declare const createFundId: ({
58
+ isin
59
+ }: {
60
+ isin: string;
61
+ }) => string;
57
62
  //#endregion
58
63
  //#region src/instruments/parseId.d.ts
59
64
  type StockId = {
@@ -71,7 +76,12 @@ type IndexId = {
71
76
  type: 'INDEX';
72
77
  ticker: string;
73
78
  };
74
- declare const parseId: (id: string) => StockId | ForexId | IndexId;
79
+ type FundId = {
80
+ type: 'FUND';
81
+ isin: string;
82
+ };
83
+ type TradeInsightId = StockId | ForexId | IndexId | FundId;
84
+ declare const parseId: (id: string) => TradeInsightId;
75
85
  //#endregion
76
86
  //#region src/pubsub/main.d.ts
77
87
  declare const TickersTopic = "tradeinsight.tickers";
@@ -79,5 +89,5 @@ type TickersPubSubChannels = {
79
89
  [TickersTopic]: TickerMessage;
80
90
  };
81
91
  //#endregion
82
- export { CloudSchema, InstrumentPrice, Ticker, TickerMessage, TickersPubSubChannels, TickersTopic, createForexId, createIndexId, createStockId, parseId };
92
+ export { CloudSchema, InstrumentPrice, Ticker, TickerMessage, TickersPubSubChannels, TickersTopic, createForexId, createFundId, createIndexId, createStockId, parseId };
83
93
  //# sourceMappingURL=index.d.mts.map
@@ -1 +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":[],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cAkBQ,OAlBD,EAAA,CAAA,EAAA,EAAA,MAAA,EAAA,GAkByB,cAlBzB;;;AFPK,cGEJ,YAAA,GHFmB,sBAAA;AAOf,KGJL,qBAAA,GHUH;EAGQ,CGZd,YAAA,CHYc,EGZC,aHaP;AAGX,CAAA"}
package/dist/index.mjs CHANGED
@@ -100,6 +100,7 @@ const createStockId = ({ isin, mic, currency }) => `STOCK-${isin}_${mic}_${curre
100
100
  */
101
101
  const createForexId = ({ quoteCurrency, baseCurrency }) => `FOREX-${baseCurrency}_${quoteCurrency}`.toUpperCase();
102
102
  const createIndexId = ({ ticker }) => `INDEX-${ticker}`.toUpperCase();
103
+ const createFundId = ({ isin }) => `FUND-${isin}`.toUpperCase();
103
104
 
104
105
  //#endregion
105
106
  //#region src/instruments/parseId.ts
@@ -132,6 +133,13 @@ const parseId = (id) => {
132
133
  ticker: first
133
134
  };
134
135
  }
136
+ if (type === "FUND") {
137
+ if (!first) throw new Error("Missing isin");
138
+ return {
139
+ type,
140
+ isin: first
141
+ };
142
+ }
135
143
  throw new Error("Invalid type");
136
144
  };
137
145
 
@@ -140,5 +148,5 @@ const parseId = (id) => {
140
148
  const TickersTopic = "tradeinsight.tickers";
141
149
 
142
150
  //#endregion
143
- export { CloudSchema, TickersTopic, createForexId, createIndexId, createStockId, parseId };
151
+ export { CloudSchema, TickersTopic, createForexId, createFundId, createIndexId, createStockId, parseId };
144
152
  //# sourceMappingURL=index.mjs.map
@@ -1 +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"}
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\nexport const createFundId = ({ isin }: { isin: string }) =>\n `FUND-${isin}`.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\ntype FundId = {\n type: 'FUND'\n isin: string\n}\n\ntype TradeInsightId = StockId | ForexId | IndexId | FundId\n\nexport const parseId = (id: string): TradeInsightId => {\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 if (type === 'FUND') {\n if (!first) {\n throw new Error('Missing isin')\n }\n\n return {\n type,\n isin: 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;AAEjC,MAAa,gBAAgB,EAAE,WAC7B,QAAQ,OAAO,aAAa;;;;ACR9B,MAAa,WAAW,OAA+B;CACrD,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,KAAI,SAAS,QAAQ;AACnB,MAAI,CAAC,MACH,OAAM,IAAI,MAAM,eAAe;AAGjC,SAAO;GACL;GACA,MAAM;GACP;;AAGH,OAAM,IAAI,MAAM,eAAe;;;;;AClFjC,MAAa,eAAe"}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@sebspark/tradeinsight",
3
- "version": "3.0.9",
3
+ "version": "3.0.11",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "types": "./dist/index.d.ts",
8
+ "types": "./dist/index.d.mts",
9
9
  "import": "./dist/index.mjs",
10
- "react-native": "./dist/index.js"
10
+ "react-native": "./dist/index.cjs"
11
11
  }
12
12
  },
13
13
  "files": [
14
14
  "dist"
15
15
  ],
16
16
  "scripts": {
17
- "build": "spark-build src/index.ts",
17
+ "build": "spark-build src/index.ts --format esm --format cjs",
18
18
  "depcheck": "depcheck",
19
19
  "dev": "tsc --watch --noEmit",
20
20
  "generate:avro": "ts-node ./scripts/avro-to-ts.ts",