Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exceeding max open trades #462

Merged
merged 21 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fea6d39
fix: exceeding max open trades
uhliksk Aug 8, 2022
6dfc0d0
Merge branch 'chrisleekr:master' into fix/exceeding-max-open-trades
uhliksk Aug 10, 2022
2f39816
Merge branch 'chrisleekr:master' into fix/exceeding-max-open-trades
uhliksk Aug 14, 2022
1fe9e72
fix: queue symbols to check max. open trades
uhliksk Aug 14, 2022
0f92374
fix: replace map with forEach
uhliksk Aug 14, 2022
a17331c
refactor: move cancelOrder to common
habibalkhabbaz Aug 14, 2022
0f285e6
Merge branch 'chrisleekr:master' into fix/exceeding-max-open-trades
uhliksk Aug 14, 2022
6d3bdef
fix: check if open orders exceeding the max open trades
habibalkhabbaz Aug 14, 2022
4157d8a
Merge branch 'fix/exceeding-max-open-trades' of https://github.com/uh…
habibalkhabbaz Aug 14, 2022
53f11e3
fix: missed husky
habibalkhabbaz Aug 14, 2022
5c488b3
fix: ensure-grid-trade-order-executed
habibalkhabbaz Aug 14, 2022
4c1cc08
fix: check open orders
habibalkhabbaz Aug 14, 2022
7672ba4
chore: lint
habibalkhabbaz Aug 14, 2022
5c4fbc2
fix: minor change
habibalkhabbaz Aug 14, 2022
d964d22
fix: clear open orders after cancellation
habibalkhabbaz Aug 14, 2022
6c8467f
test: handle-open-orders
habibalkhabbaz Aug 14, 2022
d7bb220
fix: clean open orders when order cancellation is successfull
uhliksk Aug 14, 2022
b7b47ab
refactor: updated handle open orders
chrisleekr Aug 15, 2022
12bbd3a
refactor: updated handle open orders
chrisleekr Aug 15, 2022
0acf1e6
chore: added comments
chrisleekr Aug 15, 2022
b492360
docs: updated CHANGELOG.md
chrisleekr Aug 15, 2022
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
129 changes: 127 additions & 2 deletions app/__tests__/server-binance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ describe('server-binance', () => {
.mockResolvedValue(
JSON.stringify(require('./fixtures/exchange-symbols.json'))
),
hset: jest.fn().mockResolvedValue(true)
hset: jest.fn().mockResolvedValue(true),
hgetall: jest.fn()
};
mockMongo = {
deleteAll: jest.fn().mockResolvedValue(true)
};
mockQueue = {
init: jest.fn().mockResolvedValue(true)
init: jest.fn().mockResolvedValue(true),
executeFor: jest.fn().mockResolvedValue(true)
};
mockSlack = {
sendMessage: jest.fn().mockResolvedValue(true)
Expand Down Expand Up @@ -356,6 +358,129 @@ describe('server-binance', () => {
);
});
});

describe('received data in check-open-orders 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 === 'check-open-orders') {
cb('message', 'data');
}
});
});

describe('when open orders empty', () => {
beforeEach(async () => {
mockCache.hgetall = jest.fn().mockResolvedValue(null);

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

it('does not trigger queue.executeFor', () => {
expect(mockQueue.executeFor).not.toHaveBeenCalled();
});
});

describe('when open orders not empty', () => {
beforeEach(async () => {
mockCache.hgetall = jest.fn().mockResolvedValue({
BTCUSDT: [{ orderId: 1, symbol: 'BTCUSDT' }]
});

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

it('triggers queue.executeFor', () => {
expect(mockQueue.executeFor).toHaveBeenCalledWith(logger, 'BTCUSDT');
});
});
});
});

describe('when the bot is running test mode', () => {
Expand Down
Loading