Skip to content

Commit 8e16442

Browse files
committed
Omit unexported instruments from datasetId lookup
1 parent 674c9bf commit 8e16442

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/instrumentinfo.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export async function findInstrumentSymbols(
6666

6767
return {
6868
exchange,
69-
symbols: instruments.map((instrument) => (selector === 'datasetId' ? (instrument.datasetId ?? instrument.id) : instrument.id))
69+
symbols:
70+
selector === 'datasetId'
71+
? instruments.flatMap((instrument) => instrument.datasetId ?? [])
72+
: instruments.map((instrument) => instrument.id)
7073
}
7174
})
7275
)
@@ -112,7 +115,7 @@ export type UnderlyingType = 'native' | 'equity' | 'commodity' | 'fixed_income'
112115
export interface InstrumentInfo {
113116
/** symbol id */
114117
id: string
115-
/** dataset symbol id, may differ from id */
118+
/** dataset symbol id, present after the symbol appears in exported dataset metadata */
116119
datasetId?: string
117120
/** exchange id */
118121
exchange: string

test/instrumentinfo.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ describe('findInstrumentSymbols', () => {
2121
jest.restoreAllMocks()
2222
})
2323

24-
test('returns dataset ids and falls back to id when datasetId is omitted', async () => {
24+
test('returns only instruments with dataset ids when datasetId selector is used', async () => {
2525
global.fetch = createFetchMock(
2626
new Response(JSON.stringify([{ id: 'btcusdt', datasetId: 'BTCUSDT' }, { id: 'ethusdt' }]), { status: 200 })
2727
)
2828
init({ endpoint: 'https://example.com/v1' })
2929

3030
await expect(findInstrumentSymbols(['binance'], { active: true }, 'datasetId')).resolves.toEqual([
31-
{ exchange: 'binance', symbols: ['BTCUSDT', 'ethusdt'] }
31+
{ exchange: 'binance', symbols: ['BTCUSDT'] }
3232
])
3333
})
3434

0 commit comments

Comments
 (0)