Skip to content

Commit

Permalink
feat: update auto trigger and trading view widget (chrisleekr#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisleekr authored Sep 26, 2021
1 parent 244734f commit 7f58b8f
Show file tree
Hide file tree
Showing 55 changed files with 2,003 additions and 1,188 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ RELEASENOTES text eol=lf

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
*.eot text eol=crlf
*.ttf text eol=crlf


# Denote all files that are truly binary and should not be modified.
*.acorn binary
Expand All @@ -39,3 +42,8 @@ RELEASENOTES text eol=lf
*.exe binary
*.jar binary
*.phar binary
*.eot binary
*.otf binary
*.ttf binary
*.woff binary
*.woff2 binary
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [Unreleased]

- Enhanced auto-trigger buy feature - [#316](https://github.com/chrisleekr/binance-trading-bot/issues/316)
- Added TradingView Technical Analysis - [#327](https://github.com/chrisleekr/binance-trading-bot/issues/327)

## [0.0.79] - 2021-09-19

- Clear exchange/symbol info cache in the Redis periodically - [#284](https://github.com/chrisleekr/binance-trading-bot/issues/284)
Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = grunt => {
'./public/dist/js/SymbolSettingIconGridSell.min.js',
'./public/dist/js/SymbolSettingIcon.min.js',
'./public/dist/js/CoinWrapperSymbol.min.js',
'./public/dist/js/CoinWrapperTradingView.min.js',
'./public/dist/js/CoinWrapper.min.js',
'./public/dist/js/DustTransferIcon.min.js',
'./public/dist/js/ManualTradeIcon.min.js',
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ Please refer
[CHANGELOG.md](https://github.com/chrisleekr/binance-trading-bot/blob/master/CHANGELOG.md)
to view the past changes.

- [ ] Enhance auto-trigger buy feature - [#316](https://github.com/chrisleekr/binance-trading-bot/issues/316)
- [ ] Allow to execute stop-loss before buy action - [#299](https://github.com/chrisleekr/binance-trading-bot/issues/299)
- [ ] Improve sell strategy with conditional stop price percentage based on the profit percentage - [#94](https://github.com/chrisleekr/binance-trading-bot/issues/94)
- [ ] Add sudden drop buy strategy - [#67](https://github.com/chrisleekr/binance-trading-bot/issues/67)
Expand Down
8 changes: 4 additions & 4 deletions app/cronjob/trailingTrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ const execute = async logger => {
stepName: 'get-symbol-info',
stepFunc: getSymbolInfo
},
{
stepName: 'get-override-action',
stepFunc: getOverrideAction
},
{
stepName: 'ensure-manual-order',
stepFunc: ensureManualOrder
Expand All @@ -116,6 +112,10 @@ const execute = async logger => {
stepName: 'get-indicators',
stepFunc: getIndicators
},
{
stepName: 'get-override-action',
stepFunc: getOverrideAction
},
{
stepName: 'handle-open-orders',
stepFunc: handleOpenOrders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,113 +60,6 @@ describe('ensure-grid-trade-order-executed.js', () => {
mockSaveGridTradeOrder = jest.fn().mockResolvedValue(true);
});

describe('when action is already determined', () => {
beforeEach(async () => {
jest.mock('../../../trailingTradeHelper/common', () => ({
calculateLastBuyPrice: mockCalculateLastBuyPrice,
getAPILimit: mockGetAPILimit,
isExceedAPILimit: mockIsExceedAPILimit,
disableAction: mockDisableAction,
saveOrderStats: mockSaveOrderStats
}));

jest.mock('../../../trailingTradeHelper/configuration', () => ({
saveSymbolGridTrade: mockSaveSymbolGridTrade
}));

jest.mock('../../../trailingTradeHelper/order', () => ({
getGridTradeOrder: mockGetGridTradeOrder,
deleteGridTradeOrder: mockDeleteGridTradeOrder,
saveGridTradeOrder: mockSaveGridTradeOrder
}));

const step = require('../ensure-grid-trade-order-executed');

rawData = {
symbol: 'BTCUSDT',
action: 'buy',
featureToggle: { notifyOrderExecute: true, notifyDebug: true },
symbolConfiguration: {
symbols: ['BTCUSDT', 'BNBUSDT'],
buy: {
gridTrade: [
{
triggerPercentage: 1,
stopPercentage: 1.025,
limitPercentage: 1.026,
maxPurchaseAmount: 10,
executed: false,
executedOrder: null
},
{
triggerPercentage: 0.8,
stopPercentage: 1.025,
limitPercentage: 1.026,
maxPurchaseAmount: 10,
executed: false,
executedOrder: null
}
]
},
sell: {
gridTrade: [
{
triggerPercentage: 1.03,
stopPercentage: 0.985,
limitPercentage: 0.984,
quantityPercentage: 0.8,
executed: false,
executedOrder: null
},
{
triggerPercentage: 1.05,
stopPercentage: 0.975,
limitPercentage: 0.974,
quantityPercentage: 1,
executed: false,
executedOrder: null
}
]
},
system: {
checkOrderExecutePeriod: 10,
temporaryDisableActionAfterConfirmingOrder: 20
}
}
};

result = await step.execute(loggerMock, rawData);
});

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

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

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

it('does not trigger binance.client.getOrder', () => {
expect(binanceMock.client.getOrder).not.toHaveBeenCalled();
});

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

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

it('returns epxected result', () => {
expect(result).toStrictEqual(rawData);
});
});

describe('when api limit is exceed', () => {
beforeEach(async () => {
mockIsExceedAPILimit = jest.fn().mockReturnValue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('ensure-manual-order.js', () => {

let mockCalculateLastBuyPrice;
let mockGetAPILimit;
let mockIsExceedAPILimit;

let mockGetSymbolGridTrade;
let mockSaveSymbolGridTrade;
Expand Down Expand Up @@ -40,6 +41,13 @@ describe('ensure-manual-order.js', () => {

mockCalculateLastBuyPrice = jest.fn().mockResolvedValue(true);
mockGetAPILimit = jest.fn().mockResolvedValue(10);
mockIsExceedAPILimit = jest.fn().mockReturnValue(false);

jest.mock('../../../trailingTradeHelper/common', () => ({
calculateLastBuyPrice: mockCalculateLastBuyPrice,
getAPILimit: mockGetAPILimit,
isExceedAPILimit: mockIsExceedAPILimit
}));

mockGetSymbolGridTrade = jest.fn().mockResolvedValue({
buy: [
Expand All @@ -56,13 +64,79 @@ describe('ensure-manual-order.js', () => {
mockSaveManualOrder = jest.fn().mockResolvedValue(true);
});

describe('when manual buy order is not available', () => {
describe('when api limit exceeded', () => {
beforeEach(async () => {
mockIsExceedAPILimit = jest.fn().mockReturnValue(true);

jest.mock('../../../trailingTradeHelper/common', () => ({
calculateLastBuyPrice: mockCalculateLastBuyPrice,
getAPILimit: mockGetAPILimit
getAPILimit: mockGetAPILimit,
isExceedAPILimit: mockIsExceedAPILimit
}));

jest.mock('../../../trailingTradeHelper/configuration', () => ({
getSymbolGridTrade: mockGetSymbolGridTrade,
saveSymbolGridTrade: mockSaveSymbolGridTrade
}));

jest.mock('../../../trailingTradeHelper/order', () => ({
getManualOrders: mockGetManualOrders,
deleteManualOrder: mockDeleteManualOrder,
saveManualOrder: mockSaveManualOrder
}));

const step = require('../ensure-manual-order');

rawData = {
symbol: 'BTCUSDT',
isLocked: false,
featureToggle: { notifyDebug: true },
symbolConfiguration: {
system: {
checkManualOrderPeriod: 10
}
}
};

result = await step.execute(loggerMock, rawData);
});

it('does not trigger binance.client.getOrder', () => {
expect(binanceMock.client.getOrder).not.toHaveBeenCalled();
});

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

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

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

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

it('returns expected result', () => {
expect(result).toStrictEqual({
symbol: 'BTCUSDT',
isLocked: false,
featureToggle: { notifyDebug: true },
symbolConfiguration: {
system: {
checkManualOrderPeriod: 10
}
}
});
});
});

describe('when manual buy order is not available', () => {
beforeEach(async () => {
jest.mock('../../../trailingTradeHelper/configuration', () => ({
getSymbolGridTrade: mockGetSymbolGridTrade,
saveSymbolGridTrade: mockSaveSymbolGridTrade
Expand Down Expand Up @@ -213,11 +287,6 @@ describe('ensure-manual-order.js', () => {
].forEach(testData => {
describe(`${testData.desc}`, () => {
beforeEach(async () => {
jest.mock('../../../trailingTradeHelper/common', () => ({
calculateLastBuyPrice: mockCalculateLastBuyPrice,
getAPILimit: mockGetAPILimit
}));

jest.mock('../../../trailingTradeHelper/configuration', () => ({
getSymbolGridTrade: mockGetSymbolGridTrade,
saveSymbolGridTrade: mockSaveSymbolGridTrade
Expand Down Expand Up @@ -407,11 +476,6 @@ describe('ensure-manual-order.js', () => {
].forEach(testData => {
describe(`${testData.desc}`, () => {
beforeEach(async () => {
jest.mock('../../../trailingTradeHelper/common', () => ({
calculateLastBuyPrice: mockCalculateLastBuyPrice,
getAPILimit: mockGetAPILimit
}));

mockGetManualOrders = jest
.fn()
.mockResolvedValue(testData.cacheResults);
Expand Down
Loading

0 comments on commit 7f58b8f

Please sign in to comment.