Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/feeds/binance/binance-feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class BinanceFeed extends BaseDataFeed {
}

protected async fetchTickerImpl(symbol: string): Promise<Ticker> {
const cached = this.latestTickers.get(symbol);
const cached = this.latestTickers.get(symbol.toUpperCase());
if (cached) return cached;

await this.ensureConnected();
Expand Down Expand Up @@ -130,7 +130,7 @@ export class BinanceFeed extends BaseDataFeed {
}

protected watchTickerImpl(symbol: string, callback: (ticker: Ticker) => void): () => void {
const sub: Subscription = { symbol, callback };
const sub: Subscription = { symbol: symbol.toUpperCase(), callback };
this.subscriptions.push(sub);
this.ensureConnected().catch((err: unknown) => {
logger.error('[BinanceFeed] initial connect failed in watchTickerImpl', {
Expand Down
59 changes: 58 additions & 1 deletion core/test/unit/dataFeeds.core.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { ExchangeNotAvailable, NotSupported } from '../../src/errors';
import { BinanceFeed } from '../../src/feeds/binance';
import { ChainlinkFeed } from '../../src/feeds/chainlink/chainlink-feed';
import { Ticker } from '../../src/feeds/types';

class TestBinanceFeed extends BinanceFeed {
subscribe(symbol: string, callback: (ticker: Ticker) => void) {
return this.watchTickerImpl(symbol, callback);
}
setCachedTicker(ticker: Ticker) {
(this as any).latestTickers.set(ticker.symbol, ticker);
}
}

describe('Data feed backend errors', () => {
test('Binance fetchTicker names the missing relay URL setting', async () => {
Expand All @@ -22,6 +32,53 @@ describe('Data feed backend errors', () => {
} satisfies Partial<NotSupported>);
});

test('Binance watchTicker normalizes symbol case', async () => {
const feed = new TestBinanceFeed({ wsUrl: '', apiKey: '' });
const callback = jest.fn<(ticker: Ticker) => void>();

feed.subscribe('btc/usdt', callback);

const subscriptions = (feed as any).subscriptions;

expect(subscriptions[0].symbol).toBe('BTC/USDT');

await feed.close();
});

test('Binance fetchTicker normalizes symbol case', async () => {
const feed = new TestBinanceFeed({ wsUrl: '', apiKey: '' });
const ticker = {
symbol: 'BTC/USDT',
info: {},
timestamp: undefined,
datetime: undefined,
high: undefined,
low: undefined,
bid: undefined,
bidVolume: undefined,
ask: undefined,
askVolume: undefined,
vwap: undefined,
open: undefined,
close: 50000,
last: 50000,
previousClose: undefined,
change: undefined,
percentage: undefined,
average: undefined,
quoteVolume: undefined,
baseVolume: undefined,
indexPrice: undefined,
markPrice: undefined,
} satisfies Ticker;

feed.setCachedTicker(ticker);

await expect(feed.fetchTicker('btc/usdt')).resolves.toBe(ticker);

await feed.close();
});

test('Chainlink oracle calls name the missing REST API URL setting', async () => {
const feed = new ChainlinkFeed({ baseUrl: '', apiKey: '', wsUrl: '' });

Expand All @@ -40,4 +97,4 @@ describe('Data feed backend errors', () => {
status: 501,
} satisfies Partial<NotSupported>);
});
});
});