Skip to content

Commit

Permalink
Updated bug fix (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisleekr authored Mar 17, 2021
1 parent cde560b commit e7d8304
Show file tree
Hide file tree
Showing 16 changed files with 777 additions and 500 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![GitHub package.json version](https://img.shields.io/github/package-json/v/chrisleekr/binance-trading-bot)](https://github.com/chrisleekr/binance-trading-bot/releases)
[![Build](https://github.com/chrisleekr/binance-trading-bot/workflows/main/badge.svg)](https://github.com/chrisleekr/binance-trading-bot/actions?query=workflow%3Amain)
[![CodeCov](https://codecov.io/gh/chrisleekr/binance-trading-bot/branch/master/graph/badge.svg)](https://codecov.io/gh/chrisleekr/binance-trading-bot)
[![Docker pull](https://img.shields.io/docker/pulls/chrisleekr/binance-trading-bot)](https://hub.docker.com/repository/docker/chrisleekr/binance-trading-bot)
[![MIT License](https://img.shields.io/github/license/chrisleekr/binance-trading-bot)](https://github.com/chrisleekr/binance-trading-bot/blob/master/LICENSE)

> Automated Binance trading bot with trailing buy/sell strategy
Expand Down Expand Up @@ -197,6 +198,7 @@ React.js based frontend communicating via Web Socket:
- Manage global/symbol settings
- Delete caches that are not monitored
- Link to public URL
- Support Add to Home Screen

## Environment Parameters

Expand Down Expand Up @@ -254,11 +256,11 @@ Or use the frontend to adjust configurations after launching the application.

| Frontend Mobile | Setting |
| ------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
| ![Frontend Mobile](https://user-images.githubusercontent.com/5715919/111026709-d79b0900-843f-11eb-8655-e23199d98237.png) | ![Setting](https://user-images.githubusercontent.com/5715919/111027223-f2bb4800-8442-11eb-9f5d-95f77298f4c0.png) |
| ![Frontend Mobile](https://user-images.githubusercontent.com/5715919/111430413-72e8f280-874e-11eb-9870-6603282fde8e.png) | ![Setting](https://user-images.githubusercontent.com/5715919/111027223-f2bb4800-8442-11eb-9f5d-95f77298f4c0.png) |

| Frontend Desktop |
| ------------------------------------------------------------------------------------------------------------------------- |
| ![Frontend Desktop](https://user-images.githubusercontent.com/5715919/111020919-3bf8a100-841d-11eb-8009-9f7c07054572.png) |
| ![Frontend Desktop](https://user-images.githubusercontent.com/5715919/111430212-28677600-874e-11eb-9314-1d617e25fd06.png) |

### Sample Trade

Expand All @@ -270,7 +272,7 @@ Or use the frontend to adjust configurations after launching the application.

| Trade History | PNL Analysis |
| ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| ![Trade History](https://user-images.githubusercontent.com/5715919/111020672-c0e2bb00-841b-11eb-9b51-584325c8ef68.png) | ![Profit & Loss](https://user-images.githubusercontent.com/5715919/111020784-6eee6500-841c-11eb-8f7b-4d9e3718f5bc.png) |
| ![Trade History](https://user-images.githubusercontent.com/5715919/111430291-4503ae00-874e-11eb-9e68-aefa4bca19b2.png) | ![Profit & Loss](https://user-images.githubusercontent.com/5715919/111430313-4df47f80-874e-11eb-9f3d-e85cf3027d74.png) |

## Changes & Todo

Expand All @@ -294,7 +296,7 @@ Or use the frontend to adjust configurations after launching the application.
- [x] Support other FIAT symbols such as BUSD, AUD
- [x] Allow entering more decimals for the last buy price
- [x] Override buy/sell configuration per symbol
- [x] Support PWA for frontend - now support "Add to Home screen"
- [x] Support PWA for frontend - **now support "Add to Home screen"**
- [x] Enable/Disable symbols trading, but continue to monitor
- [x] Add max-size for logging
- [x] Execute chaseStopLossLimitOrder on every process
Expand All @@ -303,8 +305,8 @@ Or use the frontend to adjust configurations after launching the application.
- [x] Apply chase-stop-loss-limit order for buy signal as well
- [x] Added more candle periods - 1m, 3m and 5m
- [x] Allow to disable local tunnel
- [ ] Override the lowest value in the frontend
- [ ] Allow browser notification
- [x] Fix the bug with handling open orders
- [ ] Allow browser notification in the frontend
- [ ] Secure frontend with the password

## Acknowledgments
Expand Down
65 changes: 36 additions & 29 deletions app/jobs/__tests__/trailingTrade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('trailingTrade', () => {
let mockGetNextSymbol;
let mockGetExchangeSymbols;
let mockGetSymbolConfiguration;
let mockGetSymbolInfo;
let mockGetAccountInfo;
let mockGetIndicators;
let mockGetOpenOrders;
Expand Down Expand Up @@ -52,34 +53,42 @@ describe('trailingTrade', () => {
global: 'value'
}
};
mockGetGlobalConfiguration = jest.fn().mockResolvedValueOnce(data);
mockGetGlobalConfiguration = jest.fn().mockResolvedValue(data);

data = {
...data,
symbol: 'BTCUSDT'
};
mockGetNextSymbol = jest.fn().mockResolvedValueOnce(data);
mockGetNextSymbol = jest.fn().mockResolvedValue(data);

data = {
...data
};
mockGetExchangeSymbols = jest.fn().mockResolvedValueOnce(data);
mockGetExchangeSymbols = jest.fn().mockResolvedValue(data);

data = {
...data,
symbolConfiguration: {
symbol: 'value'
}
};
mockGetSymbolConfiguration = jest.fn().mockResolvedValueOnce(data);
mockGetSymbolConfiguration = jest.fn().mockResolvedValue(data);

data = {
...data,
symbolInfo: {
symbol: 'value'
}
};
mockGetSymbolInfo = jest.fn().mockResolvedValue(data);

data = {
...data,
accountInfo: {
account: 'value'
}
};
mockGetAccountInfo = jest.fn().mockResolvedValueOnce(data);
mockGetAccountInfo = jest.fn().mockResolvedValue(data);

data = {
...data,
Expand All @@ -91,52 +100,50 @@ describe('trailingTrade', () => {
},
quoteAssetBalance: {
quoteAsset: 'value'
},
symbolInfo: {
symbol: 'value'
}
};
mockGetIndicators = jest.fn().mockResolvedValueOnce(data);
mockGetIndicators = jest.fn().mockResolvedValue(data);

data = {
...data,
openOrders: {
order: 'value'
}
};
mockGetOpenOrders = jest.fn().mockResolvedValueOnce(data);
mockGetOpenOrders = jest.fn().mockResolvedValue(data);

mockHandleOpenOrders = jest.fn().mockResolvedValueOnce(data);
mockHandleOpenOrders = jest.fn().mockResolvedValue(data);

data = {
...data,
action: 'value'
};
mockDetermineAction = jest.fn().mockResolvedValueOnce(data);
mockDetermineAction = jest.fn().mockResolvedValue(data);

data = {
...data,
buy: {
buy: 'value'
}
};
mockPlaceBuyOrder = jest.fn().mockResolvedValueOnce(data);
mockPlaceBuyOrder = jest.fn().mockResolvedValue(data);

data = {
...data,
sell: {
sell: 'value'
}
};
mockPlaceSellOrder = jest.fn().mockResolvedValueOnce(data);
mockRemoveLastBuyPrice = jest.fn().mockResolvedValueOnce(data);
mockSaveDataToCache = jest.fn().mockResolvedValueOnce(data);
mockPlaceSellOrder = jest.fn().mockResolvedValue(data);
mockRemoveLastBuyPrice = jest.fn().mockResolvedValue(data);
mockSaveDataToCache = jest.fn().mockResolvedValue(data);

jest.mock('../trailingTrade/steps', () => ({
getGlobalConfiguration: mockGetGlobalConfiguration,
getNextSymbol: mockGetNextSymbol,
getExchangeSymbols: mockGetExchangeSymbols,
getSymbolConfiguration: mockGetSymbolConfiguration,
getSymbolInfo: mockGetSymbolInfo,
getAccountInfo: mockGetAccountInfo,
getIndicators: mockGetIndicators,
getOpenOrders: mockGetOpenOrders,
Expand Down Expand Up @@ -203,19 +210,19 @@ describe('trailingTrade', () => {
...data,
symbol: 'BTCUSDT'
};
mockGetGlobalConfiguration = jest.fn().mockResolvedValueOnce(data);
mockGetNextSymbol = jest.fn().mockResolvedValueOnce(data);
mockGetExchangeSymbols = jest.fn().mockResolvedValueOnce(data);
mockGetSymbolConfiguration = jest.fn().mockResolvedValueOnce(data);
mockGetAccountInfo = jest.fn().mockResolvedValueOnce(data);
mockGetIndicators = jest.fn().mockResolvedValueOnce(data);
mockGetOpenOrders = jest.fn().mockResolvedValueOnce(data);
mockHandleOpenOrders = jest.fn().mockResolvedValueOnce(data);
mockDetermineAction = jest.fn().mockResolvedValueOnce(data);
mockPlaceBuyOrder = jest.fn().mockResolvedValueOnce(data);
mockPlaceSellOrder = jest.fn().mockResolvedValueOnce(data);
mockRemoveLastBuyPrice = jest.fn().mockResolvedValueOnce(data);
mockSaveDataToCache = jest.fn().mockResolvedValueOnce(data);
mockGetGlobalConfiguration = jest.fn().mockResolvedValue(data);
mockGetNextSymbol = jest.fn().mockResolvedValue(data);
mockGetExchangeSymbols = jest.fn().mockResolvedValue(data);
mockGetSymbolConfiguration = jest.fn().mockResolvedValue(data);
mockGetAccountInfo = jest.fn().mockResolvedValue(data);
mockGetIndicators = jest.fn().mockResolvedValue(data);
mockGetOpenOrders = jest.fn().mockResolvedValue(data);
mockHandleOpenOrders = jest.fn().mockResolvedValue(data);
mockDetermineAction = jest.fn().mockResolvedValue(data);
mockPlaceBuyOrder = jest.fn().mockResolvedValue(data);
mockPlaceSellOrder = jest.fn().mockResolvedValue(data);
mockRemoveLastBuyPrice = jest.fn().mockResolvedValue(data);
mockSaveDataToCache = jest.fn().mockResolvedValue(data);

jest.mock('../trailingTrade/steps', () => ({
getGlobalConfiguration: mockGetGlobalConfiguration,
Expand Down
10 changes: 10 additions & 0 deletions app/jobs/trailingTrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
getNextSymbol,
getExchangeSymbols,
getSymbolConfiguration,
getSymbolInfo,
getAccountInfo,
getIndicators,
getOpenOrders,
Expand All @@ -22,6 +23,7 @@ const execute = async logger => {
symbol: null,
symbolConfiguration: {},
accountInfo: {},
refreshAccountInfo: true,
indicators: {},
symbolInfo: {},
openOrders: [],
Expand All @@ -43,6 +45,10 @@ const execute = async logger => {
stepName: 'get-symbol-configuration',
stepFunc: getSymbolConfiguration
},
{
stepName: 'get-symbol-info',
stepFunc: getSymbolInfo
},
{
stepName: 'get-account-info',
stepFunc: getAccountInfo
Expand All @@ -59,6 +65,10 @@ const execute = async logger => {
stepName: 'handle-open-orders',
stepFunc: handleOpenOrders
},
{
stepName: 'get-account-info',
stepFunc: getAccountInfo
},
{
stepName: 'determine-action',
stepFunc: determineAction
Expand Down
1 change: 1 addition & 0 deletions app/jobs/trailingTrade/__tests__/steps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('steps.js', () => {
getGlobalConfiguration: expect.any(Function),
getExchangeSymbols: expect.any(Function),
getSymbolConfiguration: expect.any(Function),
getSymbolInfo: expect.any(Function),
getAccountInfo: expect.any(Function),
getOpenOrders: expect.any(Function),
getIndicators: expect.any(Function),
Expand Down
Loading

0 comments on commit e7d8304

Please sign in to comment.