Skip to content

Commit

Permalink
fix: order status update (chrisleekr#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisleekr authored Aug 10, 2022
1 parent 8160e25 commit a2cd38e
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 181 deletions.
8 changes: 8 additions & 0 deletions app/__tests__/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,12 @@ describe('server', () => {
it('triggers runBinance', () => {
expect(mockRunBinance).toHaveBeenCalled();
});

it('triggers runCronjob', () => {
expect(mockRunCronJob).toHaveBeenCalled();
});

it('triggers runFrontend', () => {
expect(mockRunFrontend).toHaveBeenCalled();
});
});
32 changes: 32 additions & 0 deletions app/binance/__tests__/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('user.js', () => {
let mockUpdateGridTradeLastOrder;
let mockGetManualOrder;
let mockSaveManualOrder;
let mockExecuteTrailingTrade;

let mockUserClean;

Expand Down Expand Up @@ -137,6 +138,14 @@ describe('user.js', () => {
});

describe('when executionReport event received', () => {
beforeEach(() => {
mockExecuteTrailingTrade = jest.fn().mockResolvedValue(true);

jest.mock('../../cronjob', () => ({
executeTrailingTrade: mockExecuteTrailingTrade
}));
});

describe('when last order not found', () => {
beforeEach(async () => {
mockUserClean = jest.fn().mockResolvedValue(true);
Expand Down Expand Up @@ -225,10 +234,15 @@ describe('user.js', () => {
expect(mockUpdateGridTradeLastOrder).not.toHaveBeenCalled();
});

it('does not trigger executeTrailingTrade', () => {
expect(mockExecuteTrailingTrade).not.toHaveBeenCalled();
});

it('does not trigger userClean', () => {
expect(mockUserClean).not.toHaveBeenCalled();
});
});

describe('when last order found', () => {
beforeEach(async () => {
mockUserClean = jest.fn().mockResolvedValue(true);
Expand Down Expand Up @@ -336,6 +350,13 @@ describe('user.js', () => {
);
});

it('triggers executeTrailingTrade', () => {
expect(mockExecuteTrailingTrade).toHaveBeenCalledWith(
loggerMock,
'ETHUSDT'
);
});

it('does not trigger userClean', () => {
expect(mockUserClean).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -429,6 +450,10 @@ describe('user.js', () => {
expect(mockSaveManualOrder).not.toHaveBeenCalled();
});

it('does not trigger executeTrailingTrade', () => {
expect(mockExecuteTrailingTrade).not.toHaveBeenCalled();
});

it('does not trigger userClean', () => {
expect(mockUserClean).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -540,6 +565,13 @@ describe('user.js', () => {
);
});

it('triggers executeTrailingTrade', () => {
expect(mockExecuteTrailingTrade).toHaveBeenCalledWith(
loggerMock,
'ETHUSDT'
);
});

it('does not trigger userClean', () => {
expect(mockUserClean).not.toHaveBeenCalled();
});
Expand Down
19 changes: 18 additions & 1 deletion app/binance/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
getManualOrder,
saveManualOrder
} = require('../cronjob/trailingTradeHelper/order');
const { executeTrailingTrade } = require('../cronjob');

let userClean;

Expand Down Expand Up @@ -51,7 +52,10 @@ const setupUserWebsocket = async logger => {
totalQuoteTradeQuantity,
totalTradeQuantity
} = evt;
logger.info({ evt }, 'Received new report');
logger.info(
{ symbol, evt, saveLog: true },
`There is a new update in order. ${orderId} - ${side} - ${orderStatus}`
);

const checkLastOrder = async () => {
const lastOrder = await getGridTradeLastOrder(
Expand All @@ -74,6 +78,12 @@ const setupUserWebsocket = async logger => {
isWorking: isOrderWorking,
updateTime: eventTime
});
logger.info(
{ symbol, lastOrder, saveLog: true },
'The last order has been updated.'
);

executeTrailingTrade(logger, symbol);
}
};

Expand All @@ -96,6 +106,13 @@ const setupUserWebsocket = async logger => {
isWorking: isOrderWorking,
updateTime: eventTime
});

logger.info(
{ symbol, manualOrder, saveLog: true },
'The manual order has been updated.'
);

executeTrailingTrade(logger, symbol);
}
};

Expand Down
Loading

0 comments on commit a2cd38e

Please sign in to comment.