Skip to content

Commit

Permalink
fix: queue symbols to check max. open trades
Browse files Browse the repository at this point in the history
  • Loading branch information
uhliksk committed Aug 14, 2022
1 parent 2f39816 commit 1fe9e72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('ensure-grid-trade-order-executed.js', () => {
let mockGetGridTradeLastOrder;
let mockDeleteGridTradeOrder;

let mockQueue;

describe('execute', () => {
beforeEach(async () => {
jest.clearAllMocks().resetModules();
Expand All @@ -31,6 +33,12 @@ describe('ensure-grid-trade-order-executed.js', () => {
jest.requireActual('moment')(nextCheck || '2020-01-02T00:00:00+00:00')
);

mockQueue = {
executeFor: jest.fn().mockResolvedValue(true)
};

jest.mock('../../../trailingTradeHelper/queue', () => mockQueue);

const { slack, logger, PubSub } = require('../../../../helpers');

slackMock = slack;
Expand Down Expand Up @@ -488,6 +496,10 @@ describe('ensure-grid-trade-order-executed.js', () => {
);
});

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

it('triggers saveOrderStats', () => {
expect(mockSaveOrderStats).toHaveBeenCalledWith(loggerMock, [
'BTCUSDT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
deleteGridTradeOrder,
getGridTradeLastOrder
} = require('../../trailingTradeHelper/order');
const queue = require('../../trailingTradeHelper/queue');

/**
* Remove last order from cache
Expand Down Expand Up @@ -254,6 +255,13 @@ const execute = async (logger, rawData) => {
},
temporaryDisableActionAfterConfirmingOrder
);

// Queue other symbols to check if max. open trade is reached
symbols.map(async symbolToQueue => {
if (symbolToQueue !== symbol) {
queue.executeFor(logger, symbolToQueue);
}
});
} else if (removeStatuses.includes(lastBuyOrder.status)) {
logger.info(
{
Expand Down

0 comments on commit 1fe9e72

Please sign in to comment.