Skip to content

Commit 4c71a18

Browse files
committed
fix: throw errors for non-existing orderbooks across all exchanges
Closes #66
1 parent d5a820e commit 4c71a18

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

core/src/exchanges/baozi/normalizer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MarketFetchParams } from '../../BaseExchange';
22
import { UnifiedMarket, UnifiedEvent, PriceCandle, OrderBook, Trade, Position, Balance } from '../../types';
3+
import { NotFound } from '../../errors';
34
import { IExchangeNormalizer } from '../interfaces';
45
import {
56
LAMPORTS_PER_SOL,
@@ -88,12 +89,12 @@ export class BaoziNormalizer implements IExchangeNormalizer<BaoziRawMarket, Baoz
8889

8990
normalizeOrderBook(raw: BaoziRawMarket | null, outcomeId: string): OrderBook {
9091
if (!raw) {
91-
throw new Error(`Market not found for outcome: ${outcomeId}`);
92+
throw new NotFound(`Market not found for outcome: ${outcomeId}`, 'Baozi');
9293
}
9394

9495
const market = this.normalizeMarket(raw);
9596
if (!market) {
96-
throw new Error(`Could not parse market for outcome: ${outcomeId}`);
97+
throw new NotFound(`Could not parse market for outcome: ${outcomeId}`, 'Baozi');
9798
}
9899

99100
const outcome = market.outcomes.find(o => o.outcomeId === outcomeId);

core/src/exchanges/kalshi/fetcher.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MarketFilterParams, EventFetchParams, OHLCVParams, TradesParams, MyTradesParams } from '../../BaseExchange';
22
import { IExchangeFetcher, FetcherContext } from '../interfaces';
33
import { kalshiErrorMapper } from './errors';
4+
import { NotFound } from '../../errors';
45
import { validateIdFormat } from '../../utils/validation';
56
import { mapIntervalToKalshi } from './utils';
67

@@ -253,6 +254,10 @@ export class KalshiFetcher implements IExchangeFetcher<KalshiRawEvent, KalshiRaw
253254
validateIdFormat(id, 'OrderBook');
254255
const ticker = id.replace(/-NO$/, '');
255256
const data = await this.ctx.callApi('GetMarketOrderbook', { ticker });
257+
const book = data.orderbook_fp;
258+
if (!book || (!book.yes_dollars?.length && !book.no_dollars?.length)) {
259+
throw new NotFound(`Order book not found: ${id}`, 'Kalshi');
260+
}
256261
return data;
257262
}
258263

core/src/exchanges/limitless/fetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export class LimitlessFetcher implements IExchangeFetcher<LimitlessRawMarket, Li
170170
timestamp: data.timestamp,
171171
};
172172
} catch (error: any) {
173-
return { bids: [], asks: [] };
173+
throw limitlessErrorMapper.mapError(error);
174174
}
175175
}
176176

0 commit comments

Comments
 (0)