@sebspark/tradeinsight 5.0.2 → 6.0.1
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 +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -13,13 +13,13 @@ const currency = 'SEK'
|
|
|
13
13
|
const id = createStockId({ isin, mic, currency })
|
|
14
14
|
|
|
15
15
|
console.log(id)
|
|
16
|
-
//
|
|
16
|
+
// STO_SE0000108656_SEK_XSTO
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
### Parse ID
|
|
20
20
|
|
|
21
21
|
```javascript
|
|
22
|
-
const { type,
|
|
23
|
-
console.log(type,
|
|
22
|
+
const { type, baseCurrency, quoteCurrency } = parseId('FXS_USD_EUR')
|
|
23
|
+
console.log(type, baseCurrency, quoteCurrency)
|
|
24
24
|
// FOREX, USD, EUR
|
|
25
25
|
```
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/generated/tickerMessage.ts","../src/instruments/types.ts","../src/instruments/createId.ts","../src/instruments/parseId.ts","../src/pubsub/main.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/generated/tickerMessage.ts","../src/instruments/types.ts","../src/instruments/createId.ts","../src/instruments/parseId.ts","../src/pubsub/main.ts"],"mappings":";UAAiB,eAAA;EACf,GAAA;EACA,GAAA;EACA,IAAA;EACA,SAAA;AAAA;AAAA,UAGe,MAAA;EACf,EAAA;EACA,GAAA;EACA,IAAA;EACA,MAAA;EACA,YAAA;EACA,KAAA,EAAO,eAAA;AAAA;AAAA,UAGQ,aAAA;EACf,OAAA,EAAS,MAAA;AAAA;AAAA,cAGE,WAAA;EAoFZ,QAAA;EAAA,cAAA;AAAA;;;cCxGY,KAAA;EAAA;;;;;;;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,YAAA;EAAgB,IAAA;EAAA;AAAA,GAAoB,IAAA,CAAK,MAAA;AAAA,cAGzC,aAAA;EAAiB,MAAA;EAAA;AAAA,GAAsB,IAAA,CAAK,OAAA;AAAA,cAG5C,aAAA;EAAiB,aAAA;EAAA;AAAA,GAG3B,IAAA,CAAK,OAAA;AAAA,cAGK,aAAA;EAAiB,IAAA;EAAA,GAAA;EAAA;AAAA,GAAyB,IAAA,CAAK,OAAA;;;cCpC/C,OAAA,GAAW,EAAA,aAAa,cAAA;;;cCZxB,YAAA;AAAA,KACD,qBAAA;EAAA,CACT,YAAA,GAAe,aAAA;AAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -83,7 +83,6 @@ const CloudSchema = {
|
|
|
83
83
|
}
|
|
84
84
|
`
|
|
85
85
|
};
|
|
86
|
-
|
|
87
86
|
//#endregion
|
|
88
87
|
//#region src/instruments/types.ts
|
|
89
88
|
const types = {
|
|
@@ -97,7 +96,6 @@ const types = {
|
|
|
97
96
|
IDX: "IDX",
|
|
98
97
|
STO: "STO"
|
|
99
98
|
};
|
|
100
|
-
|
|
101
99
|
//#endregion
|
|
102
100
|
//#region src/instruments/createId.ts
|
|
103
101
|
const createBondExchangeId = ({ isin, mic, currency }) => `${types.BNE}_${isin}_${mic}_${currency}`.toUpperCase();
|
|
@@ -108,8 +106,7 @@ const createETPId = ({ mic, isin, currency }) => `${types.ETP}_${isin}_${mic}_${
|
|
|
108
106
|
const createFundId = ({ isin, currency }) => `${types.FND}_${isin}_${currency}`.toUpperCase();
|
|
109
107
|
const createIndexId = ({ ticker, currency }) => `${types.IDX}_${ticker}_${currency}`.toUpperCase();
|
|
110
108
|
const createForexId = ({ quoteCurrency, baseCurrency }) => `${types.FXS}_${baseCurrency}_${quoteCurrency}`.toUpperCase();
|
|
111
|
-
const createStockId = ({ isin, mic, currency }) => `${types.STO}_${isin}_${
|
|
112
|
-
|
|
109
|
+
const createStockId = ({ isin, mic, currency }) => `${types.STO}_${isin}_${currency}_${mic}`.toUpperCase();
|
|
113
110
|
//#endregion
|
|
114
111
|
//#region src/instruments/parseId.ts
|
|
115
112
|
const parseId = (id) => {
|
|
@@ -193,22 +190,21 @@ const parseId = (id) => {
|
|
|
193
190
|
};
|
|
194
191
|
case "STO":
|
|
195
192
|
if (!first) throw new Error("Missing isin");
|
|
196
|
-
if (!second) throw new Error("Missing
|
|
197
|
-
if (!third) throw new Error("Missing
|
|
193
|
+
if (!second) throw new Error("Missing currency");
|
|
194
|
+
if (!third) throw new Error("Missing mic");
|
|
198
195
|
return {
|
|
199
196
|
type: "STO",
|
|
200
197
|
isin: first,
|
|
201
|
-
mic:
|
|
202
|
-
currency:
|
|
198
|
+
mic: third,
|
|
199
|
+
currency: second
|
|
203
200
|
};
|
|
204
201
|
default: throw new Error("Invalid type");
|
|
205
202
|
}
|
|
206
203
|
};
|
|
207
|
-
|
|
208
204
|
//#endregion
|
|
209
205
|
//#region src/pubsub/main.ts
|
|
210
206
|
const TickersTopic = "tradeinsight.tickers";
|
|
211
|
-
|
|
212
207
|
//#endregion
|
|
213
208
|
export { CloudSchema, TickersTopic, createBondExchangeId, createBondOTCId, createDerivativeId, createETFId, createETPId, createForexId, createFundId, createIndexId, createStockId, parseId, types };
|
|
209
|
+
|
|
214
210
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/generated/tickerMessage.ts","../src/instruments/types.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 types = {\n BNE: 'BNE',\n BND: 'BND',\n DER: 'DER',\n ETF: 'ETF',\n ETP: 'ETP',\n FXS: 'FXS',\n FND: 'FND',\n IDX: 'IDX',\n STO: 'STO',\n} as const\n\nexport type BondExchangeId = {\n type: (typeof types)['BNE']\n isin: string\n mic: string\n currency: string\n}\n\nexport type BondOTCId = {\n type: (typeof types)['BND']\n isin: string\n currency: string\n}\n\nexport type DerivativeId = {\n type: (typeof types)['DER']\n ticker: string\n mic: string\n currency: string\n strike: string\n expiry: string\n}\n\nexport type ETFId = {\n type: (typeof types)['ETF']\n isin: string\n mic: string\n currency: string\n}\n\nexport type ETPId = {\n type: (typeof types)['ETP']\n isin: string\n mic: string\n currency: string\n}\n\nexport type ForexId = {\n type: (typeof types)['FXS']\n baseCurrency: string\n quoteCurrency: string\n}\n\nexport type FundId = {\n type: (typeof types)['FND']\n isin: string\n currency: string\n}\n\nexport type IndexId = {\n type: (typeof types)['IDX']\n ticker: string\n currency: string\n}\n\nexport type StockId = {\n type: (typeof types)['STO']\n isin: string\n mic: string\n currency: string\n}\n\nexport type TradeInsightId =\n | BondExchangeId\n | BondOTCId\n | DerivativeId\n | ETFId\n | ETPId\n | ForexId\n | FundId\n | IndexId\n | StockId\n","import {\n type BondExchangeId,\n type BondOTCId,\n type DerivativeId,\n type ETFId,\n type ETPId,\n type ForexId,\n type FundId,\n type IndexId,\n type StockId,\n types,\n} from './types'\n\nexport const createBondExchangeId = ({\n isin,\n mic,\n currency,\n}: Omit<BondExchangeId, 'type'>) =>\n `${types.BNE}_${isin}_${mic}_${currency}`.toUpperCase()\n\nexport const createBondOTCId = ({ isin, currency }: Omit<BondOTCId, 'type'>) =>\n `${types.BND}_${isin}_${currency}`.toUpperCase()\n\nexport const createDerivativeId = ({\n ticker,\n mic,\n currency,\n strike,\n expiry,\n}: Omit<DerivativeId, 'type'>) =>\n `${types.DER}_${ticker}_${mic}_${currency}_${strike}_${expiry}`.toUpperCase()\n\nexport const createETFId = ({ mic, isin, currency }: Omit<ETFId, 'type'>) =>\n `${types.ETF}_${isin}_${mic}_${currency}`.toUpperCase()\n\nexport const createETPId = ({ mic, isin, currency }: Omit<ETPId, 'type'>) =>\n `${types.ETP}_${isin}_${mic}_${currency}`.toUpperCase()\n\nexport const createFundId = ({ isin, currency }: Omit<FundId, 'type'>) =>\n `${types.FND}_${isin}_${currency}`.toUpperCase()\n\nexport const createIndexId = ({ ticker, currency }: Omit<IndexId, 'type'>) =>\n `${types.IDX}_${ticker}_${currency}`.toUpperCase()\n\nexport const createForexId = ({\n quoteCurrency,\n baseCurrency,\n}: Omit<ForexId, 'type'>) =>\n `${types.FXS}_${baseCurrency}_${quoteCurrency}`.toUpperCase()\n\nexport const createStockId = ({ isin, mic, currency }: Omit<StockId, 'type'>) =>\n `${types.STO}_${isin}_${mic}_${currency}`.toUpperCase()\n","import type {\n BondExchangeId,\n BondOTCId,\n DerivativeId,\n ETFId,\n ETPId,\n ForexId,\n FundId,\n IndexId,\n StockId,\n TradeInsightId,\n types,\n} from './types'\n\nexport const parseId = (id: string): TradeInsightId => {\n const [initial, first, second, third, fourth, fifth] = id.split('_')\n const type = initial as keyof typeof types\n\n switch (type) {\n case 'BNE':\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing mic')\n }\n if (!third) {\n throw new Error('Missing currency')\n }\n return {\n type: 'BNE',\n isin: first,\n mic: second,\n currency: third,\n } satisfies BondExchangeId as BondExchangeId\n\n case 'BND':\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing currency')\n }\n return {\n type: 'BND',\n isin: first,\n currency: second,\n } satisfies BondOTCId as BondOTCId\n\n case 'DER': {\n if (!first) {\n throw new Error('Missing ticker')\n }\n if (!second) {\n throw new Error('Missing mic')\n }\n if (!third) {\n throw new Error('Missing currency')\n }\n if (!fourth) {\n throw new Error('Missing strike')\n }\n if (!fifth) {\n throw new Error('Missing expiry')\n }\n return {\n type: 'DER',\n ticker: first,\n mic: second,\n currency: third,\n strike: fourth,\n expiry: fifth,\n } satisfies DerivativeId as DerivativeId\n }\n\n case 'ETF': {\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing mic')\n }\n if (!third) {\n throw new Error('Missing currency')\n }\n return {\n type: 'ETF',\n isin: first,\n mic: second,\n currency: third,\n } satisfies ETFId as ETFId\n }\n\n case 'ETP': {\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing mic')\n }\n if (!third) {\n throw new Error('Missing currency')\n }\n return {\n type: 'ETP',\n isin: first,\n mic: second,\n currency: third,\n } satisfies ETPId as ETPId\n }\n\n case 'FXS': {\n if (!first) {\n throw new Error('Missing baseCurrency')\n }\n if (!second) {\n throw new Error('Missing quoteCurrency')\n }\n return {\n type: 'FXS',\n baseCurrency: first,\n quoteCurrency: second,\n } satisfies ForexId as ForexId\n }\n\n case 'FND': {\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing currency')\n }\n return {\n type: 'FND',\n isin: first,\n currency: second,\n } satisfies FundId as FundId\n }\n\n case 'IDX': {\n if (!first) {\n throw new Error('Missing ticker')\n }\n if (!second) {\n throw new Error('Missing currency')\n }\n return {\n type: 'IDX',\n ticker: first,\n currency: second,\n } satisfies IndexId as IndexId\n }\n\n case 'STO': {\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing mic')\n }\n if (!third) {\n throw new Error('Missing currency')\n }\n return {\n type: 'STO',\n isin: first,\n mic: second,\n currency: third,\n } satisfies StockId as StockId\n }\n\n default:\n throw new Error('Invalid type')\n }\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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AwB;AAE1C,UAAO;IACL,MAAM;IACN,cAAc;IACd,eAAe;IAChB;EAGH,KAAK;AACH,OAAI,CAAC,MACH,OAAM,IAAI,MAAM,eAAe;AAEjC,OAAI,CAAC,OACH,OAAM,IAAI,MAAM,mBAAmB;AAErC,UAAO;IACL,MAAM;IACN,MAAM;IACN,UAAU;IACX;EAGH,KAAK;AACH,OAAI,CAAC,MACH,OAAM,IAAI,MAAM,iBAAiB;AAEnC,OAAI,CAAC,OACH,OAAM,IAAI,MAAM,mBAAmB;AAErC,UAAO;IACL,MAAM;IACN,QAAQ;IACR,UAAU;IACX;EAGH,KAAK;AACH,OAAI,CAAC,MACH,OAAM,IAAI,MAAM,eAAe;AAEjC,OAAI,CAAC,OACH,OAAM,IAAI,MAAM,cAAc;AAEhC,OAAI,CAAC,MACH,OAAM,IAAI,MAAM,mBAAmB;AAErC,UAAO;IACL,MAAM;IACN,MAAM;IACN,KAAK;IACL,UAAU;IACX;EAGH,QACE,OAAM,IAAI,MAAM,eAAe;;;;;;AC1KrC,MAAa,eAAe"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/generated/tickerMessage.ts","../src/instruments/types.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 types = {\n BNE: 'BNE',\n BND: 'BND',\n DER: 'DER',\n ETF: 'ETF',\n ETP: 'ETP',\n FXS: 'FXS',\n FND: 'FND',\n IDX: 'IDX',\n STO: 'STO',\n} as const\n\nexport type BondExchangeId = {\n type: (typeof types)['BNE']\n isin: string\n mic: string\n currency: string\n}\n\nexport type BondOTCId = {\n type: (typeof types)['BND']\n isin: string\n currency: string\n}\n\nexport type DerivativeId = {\n type: (typeof types)['DER']\n ticker: string\n mic: string\n currency: string\n strike: string\n expiry: string\n}\n\nexport type ETFId = {\n type: (typeof types)['ETF']\n isin: string\n mic: string\n currency: string\n}\n\nexport type ETPId = {\n type: (typeof types)['ETP']\n isin: string\n mic: string\n currency: string\n}\n\nexport type ForexId = {\n type: (typeof types)['FXS']\n baseCurrency: string\n quoteCurrency: string\n}\n\nexport type FundId = {\n type: (typeof types)['FND']\n isin: string\n currency: string\n}\n\nexport type IndexId = {\n type: (typeof types)['IDX']\n ticker: string\n currency: string\n}\n\nexport type StockId = {\n type: (typeof types)['STO']\n isin: string\n mic: string\n currency: string\n}\n\nexport type TradeInsightId =\n | BondExchangeId\n | BondOTCId\n | DerivativeId\n | ETFId\n | ETPId\n | ForexId\n | FundId\n | IndexId\n | StockId\n","import {\n type BondExchangeId,\n type BondOTCId,\n type DerivativeId,\n type ETFId,\n type ETPId,\n type ForexId,\n type FundId,\n type IndexId,\n type StockId,\n types,\n} from './types'\n\nexport const createBondExchangeId = ({\n isin,\n mic,\n currency,\n}: Omit<BondExchangeId, 'type'>) =>\n `${types.BNE}_${isin}_${mic}_${currency}`.toUpperCase()\n\nexport const createBondOTCId = ({ isin, currency }: Omit<BondOTCId, 'type'>) =>\n `${types.BND}_${isin}_${currency}`.toUpperCase()\n\nexport const createDerivativeId = ({\n ticker,\n mic,\n currency,\n strike,\n expiry,\n}: Omit<DerivativeId, 'type'>) =>\n `${types.DER}_${ticker}_${mic}_${currency}_${strike}_${expiry}`.toUpperCase()\n\nexport const createETFId = ({ mic, isin, currency }: Omit<ETFId, 'type'>) =>\n `${types.ETF}_${isin}_${mic}_${currency}`.toUpperCase()\n\nexport const createETPId = ({ mic, isin, currency }: Omit<ETPId, 'type'>) =>\n `${types.ETP}_${isin}_${mic}_${currency}`.toUpperCase()\n\nexport const createFundId = ({ isin, currency }: Omit<FundId, 'type'>) =>\n `${types.FND}_${isin}_${currency}`.toUpperCase()\n\nexport const createIndexId = ({ ticker, currency }: Omit<IndexId, 'type'>) =>\n `${types.IDX}_${ticker}_${currency}`.toUpperCase()\n\nexport const createForexId = ({\n quoteCurrency,\n baseCurrency,\n}: Omit<ForexId, 'type'>) =>\n `${types.FXS}_${baseCurrency}_${quoteCurrency}`.toUpperCase()\n\nexport const createStockId = ({ isin, mic, currency }: Omit<StockId, 'type'>) =>\n `${types.STO}_${isin}_${currency}_${mic}`.toUpperCase()\n","import type {\n BondExchangeId,\n BondOTCId,\n DerivativeId,\n ETFId,\n ETPId,\n ForexId,\n FundId,\n IndexId,\n StockId,\n TradeInsightId,\n types,\n} from './types'\n\nexport const parseId = (id: string): TradeInsightId => {\n const [initial, first, second, third, fourth, fifth] = id.split('_')\n const type = initial as keyof typeof types\n\n switch (type) {\n case 'BNE':\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing mic')\n }\n if (!third) {\n throw new Error('Missing currency')\n }\n return {\n type: 'BNE',\n isin: first,\n mic: second,\n currency: third,\n } satisfies BondExchangeId as BondExchangeId\n\n case 'BND':\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing currency')\n }\n return {\n type: 'BND',\n isin: first,\n currency: second,\n } satisfies BondOTCId as BondOTCId\n\n case 'DER': {\n if (!first) {\n throw new Error('Missing ticker')\n }\n if (!second) {\n throw new Error('Missing mic')\n }\n if (!third) {\n throw new Error('Missing currency')\n }\n if (!fourth) {\n throw new Error('Missing strike')\n }\n if (!fifth) {\n throw new Error('Missing expiry')\n }\n return {\n type: 'DER',\n ticker: first,\n mic: second,\n currency: third,\n strike: fourth,\n expiry: fifth,\n } satisfies DerivativeId as DerivativeId\n }\n\n case 'ETF': {\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing mic')\n }\n if (!third) {\n throw new Error('Missing currency')\n }\n return {\n type: 'ETF',\n isin: first,\n mic: second,\n currency: third,\n } satisfies ETFId as ETFId\n }\n\n case 'ETP': {\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing mic')\n }\n if (!third) {\n throw new Error('Missing currency')\n }\n return {\n type: 'ETP',\n isin: first,\n mic: second,\n currency: third,\n } satisfies ETPId as ETPId\n }\n\n case 'FXS': {\n if (!first) {\n throw new Error('Missing baseCurrency')\n }\n if (!second) {\n throw new Error('Missing quoteCurrency')\n }\n return {\n type: 'FXS',\n baseCurrency: first,\n quoteCurrency: second,\n } satisfies ForexId as ForexId\n }\n\n case 'FND': {\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing currency')\n }\n return {\n type: 'FND',\n isin: first,\n currency: second,\n } satisfies FundId as FundId\n }\n\n case 'IDX': {\n if (!first) {\n throw new Error('Missing ticker')\n }\n if (!second) {\n throw new Error('Missing currency')\n }\n return {\n type: 'IDX',\n ticker: first,\n currency: second,\n } satisfies IndexId as IndexId\n }\n\n case 'STO': {\n if (!first) {\n throw new Error('Missing isin')\n }\n if (!second) {\n throw new Error('Missing currency')\n }\n if (!third) {\n throw new Error('Missing mic')\n }\n return {\n type: 'STO',\n isin: first,\n mic: third,\n currency: second,\n } satisfies StockId as StockId\n }\n\n default:\n throw new Error('Invalid type')\n }\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,QAAQ;CACnB,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACN;;;ACGD,MAAa,wBAAwB,E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IACN,UAAU;IACX;EAGH,KAAK;AACH,OAAI,CAAC,MACH,OAAM,IAAI,MAAM,iBAAiB;AAEnC,OAAI,CAAC,OACH,OAAM,IAAI,MAAM,mBAAmB;AAErC,UAAO;IACL,MAAM;IACN,QAAQ;IACR,UAAU;IACX;EAGH,KAAK;AACH,OAAI,CAAC,MACH,OAAM,IAAI,MAAM,eAAe;AAEjC,OAAI,CAAC,OACH,OAAM,IAAI,MAAM,mBAAmB;AAErC,OAAI,CAAC,MACH,OAAM,IAAI,MAAM,cAAc;AAEhC,UAAO;IACL,MAAM;IACN,MAAM;IACN,KAAK;IACL,UAAU;IACX;EAGH,QACE,OAAM,IAAI,MAAM,eAAe;;;;;AC1KrC,MAAa,eAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/tradeinsight",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -23,9 +23,11 @@
|
|
|
23
23
|
"typecheck": "vitest --typecheck.only --passWithNoTests"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@sebspark/tsconfig": "3.0.5",
|
|
27
26
|
"avro-typescript": "1.3.0",
|
|
28
|
-
"ts-node": "10.9.2"
|
|
29
|
-
|
|
27
|
+
"ts-node": "10.9.2"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/seb-oss/Spark-packages.git"
|
|
30
32
|
}
|
|
31
33
|
}
|