Skip to content

Commit

Permalink
Updated fixes (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisleekr authored Mar 18, 2021
1 parent 2a81c7a commit 64f93eb
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 120 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +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)
[![Docker pull](https://img.shields.io/docker/pulls/chrisleekr/binance-trading-bot)](https://hub.docker.com/r/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 @@ -306,6 +306,8 @@ Or use the frontend to adjust configurations after launching the application.
- [x] Added more candle periods - 1m, 3m and 5m
- [x] Allow to disable local tunnel
- [x] Fix the bug with handling open orders
- [x] Fix the bug with limit step in the frontend
- [x] Updated the frontend to display buy open orders with the buy signal
- [ ] Allow browser notification in the frontend
- [ ] Secure frontend with the password

Expand All @@ -314,3 +316,4 @@ Or use the frontend to adjust configurations after launching the application.
- [@d0x2f](https://github.com/d0x2f)
- [@Maxoos](https://github.com/Maxoos)
- [@OOtta](https://github.com/OOtta)
- [@thamlth](https://github.com/thamlth)
112 changes: 57 additions & 55 deletions app/jobs/trailingTrade/step/__tests__/get-indicators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('get-indicators.js', () => {
candles: { interval: '1h', limit: 50 },
buy: {
triggerPercentage: 1.01,
limitPercentage: 1.011
limitPercentage: 1.021
},
sell: {
triggerPercentage: 0.99,
limitPercentage: 0.98
triggerPercentage: 1.06,
limitPercentage: 0.979
}
},
baseAssetBalance: { total: 0.1 },
Expand All @@ -57,9 +57,10 @@ describe('get-indicators.js', () => {
symbol: 'BTCUSDT',
symbolConfiguration: {
candles: { interval: '1h', limit: 50 },
buy: { triggerPercentage: 1.01, limitPercentage: 1.011 },
sell: { triggerPercentage: 0.99, limitPercentage: 0.98 }
buy: { triggerPercentage: 1.01, limitPercentage: 1.021 },
sell: { triggerPercentage: 1.06, limitPercentage: 0.979 }
},
baseAssetBalance: { total: 0.1, estimatedValue: 1555.509 },
openOrders: [],
indicators: {
lowestPrice: 8893.03,
Expand All @@ -77,13 +78,9 @@ describe('get-indicators.js', () => {
quoteAssetVolume: '59899003.79417636'
}
},
baseAssetBalance: {
total: 0.1,
estimatedValue: 1555.509
},
buy: {
currentPrice: 15555.09,
limitPrice: 15726.195989999998,
limitPrice: 15881.746889999999,
lowestPrice: 8893.03,
triggerPrice: 8981.9603,
difference: 73.18146017634923,
Expand All @@ -93,7 +90,7 @@ describe('get-indicators.js', () => {
},
sell: {
currentPrice: 15555.09,
limitPrice: 15243.9882,
limitPrice: 15228.43311,
lastBuyPrice: null,
triggerPrice: null,
difference: null,
Expand Down Expand Up @@ -123,11 +120,11 @@ describe('get-indicators.js', () => {
candles: { interval: '1h', limit: 50 },
buy: {
triggerPercentage: 1.01,
limitPercentage: 1.011
limitPercentage: 1.021
},
sell: {
triggerPercentage: 0.99,
limitPercentage: 0.98
triggerPercentage: 1.06,
limitPercentage: 0.979
}
},
baseAssetBalance: { total: 0.1 },
Expand Down Expand Up @@ -180,8 +177,8 @@ describe('get-indicators.js', () => {
symbol: 'BTCUSDT',
symbolConfiguration: {
candles: { interval: '1h', limit: 50 },
buy: { triggerPercentage: 1.01, limitPercentage: 1.011 },
sell: { triggerPercentage: 0.99, limitPercentage: 0.98 }
buy: { triggerPercentage: 1.01, limitPercentage: 1.021 },
sell: { triggerPercentage: 1.06, limitPercentage: 0.979 }
},
baseAssetBalance: { total: 0.1, estimatedValue: 1555.509 },
openOrders: [
Expand All @@ -206,9 +203,10 @@ describe('get-indicators.js', () => {
stopPrice: '16100.000',
time: 1615465601162,
currentPrice: 15555.09,
limitPrice: 15726.195989999998,
limitPercentage: 1.011,
difference: 2.3769512362538103,
limitPrice: 15881.746889999999,
limitPercentage: 1.021,
differenceToExecute: -3.5030976998525976,
differenceToCancel: -1.37423868741684,
updatedAt: expect.any(Object)
},
{
Expand All @@ -221,9 +219,10 @@ describe('get-indicators.js', () => {
stopPrice: '15900.000',
time: 1615465601162,
currentPrice: 15555.09,
limitPrice: 15243.9882,
limitPercentage: 0.98,
difference: -4.303413197341621,
limitPrice: 15228.43311,
limitPercentage: 0.979,
differenceToExecute: -2.2173449333947826,
differenceToCancel: -4.40995396669539,
minimumProfit: 35,
minimumProfitPercentage: 43.75,
updatedAt: expect.any(Object)
Expand All @@ -247,7 +246,7 @@ describe('get-indicators.js', () => {
},
buy: {
currentPrice: 15555.09,
limitPrice: 15726.195989999998,
limitPrice: 15881.746889999999,
lowestPrice: 8893.03,
triggerPrice: 8981.9603,
difference: 73.18146017634923,
Expand All @@ -273,9 +272,10 @@ describe('get-indicators.js', () => {
stopPrice: '16100.000',
time: 1615465601162,
currentPrice: 15555.09,
limitPrice: 15726.195989999998,
limitPercentage: 1.011,
difference: 2.3769512362538103,
limitPrice: 15881.746889999999,
limitPercentage: 1.021,
differenceToExecute: -3.5030976998525976,
differenceToCancel: -1.37423868741684,
updatedAt: expect.any(Object)
}
],
Expand All @@ -284,10 +284,10 @@ describe('get-indicators.js', () => {
},
sell: {
currentPrice: 15555.09,
limitPrice: 15243.9882,
limitPrice: 15228.43311,
lastBuyPrice: 9000,
triggerPrice: 8910,
difference: 42.71971425430519,
triggerPrice: 9540,
difference: 38.669593039963125,
currentProfit: 655.509,
currentProfitPercentage: 42.14112550939918,
openOrders: [
Expand All @@ -301,9 +301,10 @@ describe('get-indicators.js', () => {
stopPrice: '15900.000',
time: 1615465601162,
currentPrice: 15555.09,
limitPrice: 15243.9882,
limitPercentage: 0.98,
difference: -4.303413197341621,
limitPrice: 15228.43311,
limitPercentage: 0.979,
differenceToExecute: -2.2173449333947826,
differenceToCancel: -4.40995396669539,
minimumProfit: 35,
minimumProfitPercentage: 43.75,
updatedAt: expect.any(Object)
Expand All @@ -330,11 +331,11 @@ describe('get-indicators.js', () => {
candles: { interval: '1h', limit: 50 },
buy: {
triggerPercentage: 1.01,
limitPercentage: 1.011
limitPercentage: 1.021
},
sell: {
triggerPercentage: 0.99,
limitPercentage: 0.98
triggerPercentage: 1.06,
limitPercentage: 0.979
}
},
baseAssetBalance: {
Expand Down Expand Up @@ -381,13 +382,10 @@ describe('get-indicators.js', () => {
symbol: 'BTCUSDT',
symbolConfiguration: {
candles: { interval: '1h', limit: 50 },
buy: { triggerPercentage: 1.01, limitPercentage: 1.011 },
sell: { triggerPercentage: 0.99, limitPercentage: 0.98 }
},
baseAssetBalance: {
total: 0.1,
estimatedValue: 1555.509
buy: { triggerPercentage: 1.01, limitPercentage: 1.021 },
sell: { triggerPercentage: 1.06, limitPercentage: 0.979 }
},
baseAssetBalance: { total: 0.1, estimatedValue: 1555.509 },
openOrders: [
{
orderId: 1,
Expand All @@ -410,9 +408,10 @@ describe('get-indicators.js', () => {
stopPrice: '16100.000',
time: 1615465601162,
currentPrice: 15555.09,
limitPrice: 15726.195989999998,
limitPercentage: 1.011,
difference: 2.3769512362538103,
limitPrice: 15881.746889999999,
limitPercentage: 1.021,
differenceToExecute: -3.5030976998525976,
differenceToCancel: -1.37423868741684,
updatedAt: expect.any(Object)
},
{
Expand All @@ -425,9 +424,10 @@ describe('get-indicators.js', () => {
stopPrice: '15900.000',
time: 1615465601162,
currentPrice: 15555.09,
limitPrice: 15243.9882,
limitPercentage: 0.98,
difference: -4.303413197341621,
limitPrice: 15228.43311,
limitPercentage: 0.979,
differenceToExecute: -2.2173449333947826,
differenceToCancel: -4.40995396669539,
minimumProfit: null,
minimumProfitPercentage: null,
updatedAt: expect.any(Object)
Expand All @@ -451,7 +451,7 @@ describe('get-indicators.js', () => {
},
buy: {
currentPrice: 15555.09,
limitPrice: 15726.195989999998,
limitPrice: 15881.746889999999,
lowestPrice: 8893.03,
triggerPrice: 8981.9603,
difference: 73.18146017634923,
Expand All @@ -477,9 +477,10 @@ describe('get-indicators.js', () => {
stopPrice: '16100.000',
time: 1615465601162,
currentPrice: 15555.09,
limitPrice: 15726.195989999998,
limitPercentage: 1.011,
difference: 2.3769512362538103,
limitPrice: 15881.746889999999,
limitPercentage: 1.021,
differenceToExecute: -3.5030976998525976,
differenceToCancel: -1.37423868741684,
updatedAt: expect.any(Object)
}
],
Expand All @@ -488,7 +489,7 @@ describe('get-indicators.js', () => {
},
sell: {
currentPrice: 15555.09,
limitPrice: 15243.9882,
limitPrice: 15228.43311,
lastBuyPrice: null,
triggerPrice: null,
difference: null,
Expand All @@ -505,9 +506,10 @@ describe('get-indicators.js', () => {
stopPrice: '15900.000',
time: 1615465601162,
currentPrice: 15555.09,
limitPrice: 15243.9882,
limitPercentage: 0.98,
difference: -4.303413197341621,
limitPrice: 15228.43311,
limitPercentage: 0.979,
differenceToExecute: -2.2173449333947826,
differenceToCancel: -4.40995396669539,
minimumProfit: null,
minimumProfitPercentage: null,
updatedAt: expect.any(Object)
Expand Down
11 changes: 8 additions & 3 deletions app/jobs/trailingTrade/step/get-indicators.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ const execute = async (logger, rawData) => {
if (order.side.toLowerCase() === 'buy') {
newOrder.limitPrice = buyLimitPrice;
newOrder.limitPercentage = buyLimitPercentage;
newOrder.difference =
(1 - parseFloat(order.stopPrice / buyLimitPrice)) * -100;
newOrder.differenceToExecute =
(1 - parseFloat(order.stopPrice / currentPrice)) * 100;

newOrder.differenceToCancel =
(1 - parseFloat(order.stopPrice / buyLimitPrice)) * 100;
}

if (order.side.toLowerCase() === 'sell') {
newOrder.limitPrice = sellLimitPrice;
newOrder.limitPercentage = sellLimitPercentage;
newOrder.difference =
newOrder.differenceToExecute =
(1 - parseFloat(order.stopPrice / currentPrice)) * 100;
newOrder.differenceToCancel =
(1 - parseFloat(order.stopPrice / sellLimitPrice)) * 100;

newOrder.minimumProfit = null;
Expand Down
29 changes: 20 additions & 9 deletions public/js/CoinWrapperBuyOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ class CoinWrapperBuyOrders extends React.Component {
''
)}
<div className='coin-info-column coin-info-column-price divider'></div>
<div className='coin-info-column coin-info-column-price'>
<span className='coin-info-label'>Current price:</span>
<HightlightChange className='coin-info-value'>
{openOrder.currentPrice.toFixed(precision)}
</HightlightChange>
</div>

{openOrder.limitPrice ? (
<div className='coin-info-column coin-info-column-order'>
<span className='coin-info-label'>Current limit Price:</span>
Expand All @@ -89,11 +84,27 @@ class CoinWrapperBuyOrders extends React.Component {
) : (
''
)}
{openOrder.difference ? (
{openOrder.differenceToCancel ? (
<div className='coin-info-column coin-info-column-order'>
<span className='coin-info-label'>Difference to cancel:</span>
<HightlightChange className='coin-info-value'>
{openOrder.differenceToCancel.toFixed(2)}%
</HightlightChange>
</div>
) : (
''
)}
<div className='coin-info-column coin-info-column-price'>
<span className='coin-info-label'>Current price:</span>
<HightlightChange className='coin-info-value'>
{openOrder.currentPrice.toFixed(precision)}
</HightlightChange>
</div>
{openOrder.differenceToExecute ? (
<div className='coin-info-column coin-info-column-order'>
<span className='coin-info-label'>Difference to buy:</span>
<span className='coin-info-label'>Difference to execute:</span>
<HightlightChange className='coin-info-value'>
{openOrder.difference.toFixed(2)}%
{openOrder.differenceToExecute.toFixed(2)}%
</HightlightChange>
</div>
) : (
Expand Down
7 changes: 1 addition & 6 deletions public/js/CoinWrapperBuySignal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class CoinWrapperBuySignal extends React.Component {
}
} = this.props;

if (buy.openOrders.length > 0) {
return '';
}

const precision = tickSize.indexOf(1) - 1;

return (
Expand Down Expand Up @@ -97,9 +93,8 @@ class CoinWrapperBuySignal extends React.Component {
''
)}
{buy.processMessage ? (
<div>
<div className='d-flex flex-column flex-grow-1'>
<div className='coin-info-column coin-info-column-price divider'></div>

<div className='coin-info-column coin-info-column-message'>
<HightlightChange className='coin-info-message'>
{buy.processMessage}
Expand Down
Loading

0 comments on commit 64f93eb

Please sign in to comment.