Skip to content

Commit

Permalink
fix: incorrect symbol in reset-symbol-websockets (chrisleekr#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
habibalkhabbaz authored Aug 17, 2022
1 parent 165d110 commit a370a49
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
106 changes: 105 additions & 1 deletion app/__tests__/server-binance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe('server-binance', () => {
});
});

describe('received data in check-open-orders channel', () => {
describe('when data received in check-open-orders channel', () => {
beforeEach(async () => {
config.get = jest.fn(key => {
switch (key) {
Expand Down Expand Up @@ -481,6 +481,110 @@ describe('server-binance', () => {
});
});
});

describe('when data received in reset-symbol-websockets channel', () => {
beforeEach(async () => {
config.get = jest.fn(key => {
switch (key) {
case 'mode':
return 'live';
default:
return `value-${key}`;
}
});

mockLockSymbol = jest.fn().mockResolvedValue(true);
mockUnlockSymbol = jest.fn().mockResolvedValue(true);

mockSetupUserWebsocket = jest.fn().mockResolvedValue(true);

mockSyncCandles = jest.fn().mockResolvedValue(true);
mockSetupCandlesWebsocket = jest.fn().mockResolvedValue(true);
mockGetWebsocketCandlesClean = jest
.fn()
.mockImplementation(() => ({ '1h': () => true }));

mockSyncATHCandles = jest.fn().mockResolvedValue(true);
mockSetupATHCandlesWebsocket = jest.fn().mockResolvedValue(true);

mockGetWebsocketATHCandlesClean = jest
.fn()
.mockImplementation(() => ({ '1d': () => true, '30m': () => true }));

mockSetupTickersWebsocket = jest.fn().mockResolvedValue(true);
mockRefreshTickersClean = jest.fn().mockResolvedValue(true);
mockGetWebsocketTickersClean = jest.fn().mockImplementation(() => ({
BTCUSDT: () => true,
BNBUSDT: () => true
}));

mockSyncOpenOrders = jest.fn().mockResolvedValue(true);
mockSyncDatabaseOrders = jest.fn().mockResolvedValue(true);

mockGetGlobalConfiguration = jest.fn().mockResolvedValue({
symbols: ['BTCUSDT', 'BNBUSDT']
});

mockGetAccountInfoFromAPI = jest.fn().mockResolvedValue({
account: 'info'
});

mockCacheExchangeSymbols = jest.fn().mockResolvedValue(true);

jest.mock('../cronjob/trailingTradeHelper/configuration', () => ({
getGlobalConfiguration: mockGetGlobalConfiguration
}));

jest.mock('../cronjob/trailingTradeHelper/common', () => ({
getAccountInfoFromAPI: mockGetAccountInfoFromAPI,
lockSymbol: mockLockSymbol,
unlockSymbol: mockUnlockSymbol,
cacheExchangeSymbols: mockCacheExchangeSymbols
}));

jest.mock('../binance/user', () => ({
setupUserWebsocket: mockSetupUserWebsocket
}));

jest.mock('../binance/orders', () => ({
syncOpenOrders: mockSyncOpenOrders,
syncDatabaseOrders: mockSyncDatabaseOrders
}));

jest.mock('../binance/candles', () => ({
syncCandles: mockSyncCandles,
setupCandlesWebsocket: mockSetupCandlesWebsocket,
getWebsocketCandlesClean: mockGetWebsocketCandlesClean
}));

jest.mock('../binance/ath-candles', () => ({
syncATHCandles: mockSyncATHCandles,
setupATHCandlesWebsocket: mockSetupATHCandlesWebsocket,
getWebsocketATHCandlesClean: mockGetWebsocketATHCandlesClean
}));

jest.mock('../binance/tickers', () => ({
setupTickersWebsocket: mockSetupTickersWebsocket,
refreshTickersClean: mockRefreshTickersClean,
getWebsocketTickersClean: mockGetWebsocketTickersClean
}));

mockPubSub.subscribe = jest.fn().mockImplementation((key, cb) => {
if (key === 'reset-symbol-websockets') {
cb('message', 'BTCUSDT');
}
});

const { runBinance } = require('../server-binance');
await runBinance(logger);
});

it('triggers setupTickersWebsocket', () => {
expect(mockSetupTickersWebsocket).toHaveBeenCalledWith(logger, [
'BTCUSDT'
]);
});
});
});

describe('when the bot is running test mode', () => {
Expand Down
2 changes: 1 addition & 1 deletion app/server-binance.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const setupBinance = async logger => {
PubSub.subscribe('reset-symbol-websockets', async (message, data) => {
logger.info(`Message: ${message}, Data: ${data}`);

const symbol = message;
const symbol = data;

PubSub.publish('frontend-notification', {
type: 'info',
Expand Down

0 comments on commit a370a49

Please sign in to comment.