Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Did not trigger sell on target price #163

Closed
jl9404 opened this issue May 10, 2021 · 21 comments
Closed

Did not trigger sell on target price #163

jl9404 opened this issue May 10, 2021 · 21 comments
Labels
bug Something isn't working

Comments

@jl9404
Copy link

jl9404 commented May 10, 2021

Description

When a bot ran for ~1 day, the bot did not trigger sell on target price
but it does send the message to slack but normally there should be a binance api respond follow, but it does not show up
I am using WSL2 to host the bot, I am not sure it relates to the "bug"? I restart the WSL2 and start the bot again, everything starts working again

To Reproduce

I dont know, after ran for 1 day it happens

Expected Behaviours

It should trigger sell on target price

Screenshots

image

@jl9404 jl9404 added the bug Something isn't working label May 10, 2021
@chrisleekr
Copy link
Owner

Hmm, I can see you are using PR 77.

As you mentioned, it should've notified with the order result, but it didn't.
It means the Binance API threw an exception -
https://github.com/chrisleekr/binance-trading-bot/blob/feature-monitoring-simultaneously/app/cronjob/trailingTrade/step/place-sell-order.js#L114

If the Binance API throws an exception, it should be sent to Slack with the execution failed error - https://github.com/chrisleekr/binance-trading-bot/blob/feature-monitoring-simultaneously/app/cronjob/trailingTrade.js#L181

So didn't you get any further message after that?

@jl9404
Copy link
Author

jl9404 commented May 10, 2021

Hmm, I can see you are using PR 77.

As you mentioned, it should've notified with the order result, but it didn't.
It means the Binance API threw an exception -
https://github.com/chrisleekr/binance-trading-bot/blob/feature-monitoring-simultaneously/app/cronjob/trailingTrade/step/place-sell-order.js#L114

If the Binance API throws an exception, it should be sent to Slack with the execution failed error - https://github.com/chrisleekr/binance-trading-bot/blob/feature-monitoring-simultaneously/app/cronjob/trailingTrade.js#L181

So didn't you get any further message after that?

yep, no more further message, when it happens, it floods my slack channel

@chrisleekr
Copy link
Owner

@jl9404
Even API limit error should send the slack message. Hmm, I cannot think of another reason.
Could the docker container just die? Is it still running? Still, have the same issue?

@jl9404
Copy link
Author

jl9404 commented May 10, 2021

@jl9404
Even API limit error should send the slack message. Hmm, I cannot think of another reason.
Could the docker container just die? Is it still running? Still, have the same issue?

when it happens i tried to use my api key & secret to request binance api directly, it seems no problem and not getting blocked.
I am using docker-compose to run it tho and it is still running & restart docker doesnt help
so i guess it could be WSL2 problem, but i dont know why

@chrisleekr
Copy link
Owner

You mentioned it floods my slack channel

Is it like over 10 orders?
Could you see the timestamp in Slack?

At the current time Binance rate limits are:

1200 requests per minute
10 orders per second
100,000 orders per 24hrs

@jl9404
Copy link
Author

jl9404 commented May 10, 2021

its around 5 coins to be sold

LINKUSDT 
XLMUSDT 
LTCUSDT 
BNBUSDT 
XLMUSDT 
LTCUSDT Sell Action (15:56:00.104): STOP_LOSS_LIMIT
BNBUSDT Sell Action (15:56:00.105): STOP_LOSS_LIMIT
XLMUSDT Sell Action (15:56:00.127): STOP_LOSS_LIMIT
LINKUSDT Sell Action (15:56:05.117): STOP_LOSS_LIMIT
BNBUSDT Sell Action (15:56:06.112): STOP_LOSS_LIMIT
XLMUSDT Sell Action (15:56:06.111): STOP_LOSS_LIMIT
XLMUSDT Sell Action (15:56:12.108): STOP_LOSS_LIMIT
BNBUSDT Sell Action (15:56:12.122): STOP_LOSS_LIMIT
LTCUSDT Sell Action (15:56:12.149): STOP_LOSS_LIMIT
...

@chrisleekr
Copy link
Owner

Ok, right so 5 symbols trying to place an order actively.

#77 (comment)

If you see the above comment, I calculated API usage of the bot.
And since I have added an additional order check before removing the last buy price - https://github.com/chrisleekr/binance-trading-bot/blob/feature-monitoring-simultaneously/app/cronjob/trailingTrade/step/remove-last-buy-price.js#L129 - it might be over 1 minute API limit.

I will need to update the weight calculation, but would you be able to count how many orders were trying to make within a minute?

@jl9404
Copy link
Author

jl9404 commented May 10, 2021

LTCUSDT Sell Action (15:59:00.129): STOP_LOSS_LIMIT
BNBUSDT Sell Action (15:59:00.130): STOP_LOSS_LIMIT
XLMUSDT Sell Action (15:59:00.148): STOP_LOSS_LIMIT
LINKUSDT Sell Action (15:59:05.126): STOP_LOSS_LIMIT
BNBUSDT Sell Action (15:59:06.108): STOP_LOSS_LIMIT
XLMUSDT Sell Action (15:59:06.107): STOP_LOSS_LIMIT
BNBUSDT Sell Action (15:59:12.113): STOP_LOSS_LIMIT
XLMUSDT Sell Action (15:59:12.114): STOP_LOSS_LIMIT
LTCUSDT Sell Action (15:59:12.130): STOP_LOSS_LIMIT
LINKUSDT Sell Action (15:59:17.132): STOP_LOSS_LIMIT
BNBUSDT Sell Action (15:59:18.113): STOP_LOSS_LIMIT
XLMUSDT Sell Action (15:59:18.124): STOP_LOSS_LIMIT
LTCUSDT Sell Action (15:59:18.138): STOP_LOSS_LIMIT
LINKUSDT Sell Action (15:59:23.160): STOP_LOSS_LIMIT
XLMUSDT Sell Action (15:59:24.134): STOP_LOSS_LIMIT
LTCUSDT Sell Action (15:59:24.135): STOP_LOSS_LIMIT
BNBUSDT Sell Action (15:59:24.135): STOP_LOSS_LIMIT
LINKUSDT Sell Action (15:59:29.144): STOP_LOSS_LIMIT

18 orders

@chrisleekr
Copy link
Owner

@jl9404 Let me redo the calculation.
Just a quick confirm, is it operating ok now?

@jl9404
Copy link
Author

jl9404 commented May 10, 2021

@jl9404 Let me redo the calculation.
Just a quick confirm, is it operating ok now?

yeah, after i restart the WSL2 it starts to sell, but the weird point is restarting docker doesnt help 🤔

@chrisleekr
Copy link
Owner

I still suspect API limit. I mean you restarted docker and then a few mins later, you restarted WSL2 right?

@jl9404
Copy link
Author

jl9404 commented May 10, 2021

I still suspect API limit. I mean you restarted docker and then a few mins later, you restarted WSL2 right?

i tried docker restart binance-bot first, it doesnt work, and then just wsl --shutdown to reboot the wsl 🙈

@chrisleekr
Copy link
Owner

That is odd.

Let's start a bit by bit. Let me stop my bot and calculate API weights. And make sure it was not that.

@chrisleekr
Copy link
Owner

It's definitely API limt. Odd that was not reported to Slack.

Binance has changed weight for accountInfo to 11 weights from 5 weights.

Trailing Trade Indicator - single coin per second
  - get symbol configuration: N/A
  - get account info: 11 weights
  - get indicators for the symbol: 1 weight
  - get open orders for the symbol: 3 weights
  
Total weight: 15 weight * 60 seconds = 900 weights

Trailing Trade - all coins per second
  - get symbol configuration: N/A
  - get symbol info:N/A assumming all information cached
  - ensure order placed: N/A
  - get balances: N/A assumming all information cached
  - get open orders: N/A
  - get indicators: N/A
  - handle open orders: assumming there are open orders
      - cancel order: 1 weight
      - get open orders: 3 weights assumming cancelling is failed due to high volume
      - get account info: 11 weights
  - get balances: N/A
  - determine actions: N/A
  - place buy order: N/A because all orders were sell
  - place sell order: 
      - place order: 1 weight
      - get open orders: 3 weights
      - get account info: 11 weights
  - place sell stop loss order: N/A
  - get balances: N/A
  - remove last buy price: N/A assumming cache worked correclty
  - save data to cache: N/A

Total weight: 30 weight * 18 orders = 540 weight

Estimated API weight usage: 1440

I will need to check the used weight and put the bot on hold the bot until API weight is cleared.

@jl9404
Copy link
Author

jl9404 commented May 10, 2021

thanks!

@chrisleekr
Copy link
Owner

It will take some time because I need to refactor some code. I wanna say try not to use aggressive configuration for now, but 🤷 it's up to you!

@jl9404
Copy link
Author

jl9404 commented May 12, 2021

hmm, still having the issue after pulling the #77

Used Weight (1m): 106

and those sellable symbols are locked 🤔

Update 1: it seems a clock sync issue, but it wont send error to slack

Error: Timestamp for this request is outside of the recvWindow

https://github.com/chrisleekr/binance-trading-bot/blob/feature-monitoring-simultaneously/app/cronjob/trailingTrade.js#L173

@chrisleekr
Copy link
Owner

Oh oh, nice catch on error.

Error: Timestamp for this request is outside of the recvWindow

That can cause when the response is not received within the expected time or your machine time is not synced

Refer this ccxt/ccxt#936 (comment)

Try with syncing the time first.

@jl9404
Copy link
Author

jl9404 commented May 12, 2021

Oh oh, nice catch on error.

Error: Timestamp for this request is outside of the recvWindow

That can cause when the response is not received within the expected time or your machine time is not synced

Refer this ccxt/ccxt#936 (comment)

Try with syncing the time first.

yep, it works fine after i sync the clock
but should we stop trading if there are recurring errors like this?
since it wont send to slack, so it will be a bit hard to debug

@chrisleekr
Copy link
Owner

chrisleekr commented May 12, 2021

@jl9404

Ahhhh good to hear.

Actually, now I understand why you didn't receive the following message because I excluded that error!
That explains a lot.

but should we stop trading if there are recurring errors like this?

Not actually, I found the error is happening based on your network situation.
I exclude it because it happens too often and works well after.
It will spam your slack if include that error.

Very good. So this was a time sync issue again.

Would you mind putting your steps to Wiki, please? https://github.com/chrisleekr/binance-trading-bot/wiki/Troubleshooting

And close the issue :)

chrisleekr added a commit that referenced this issue May 21, 2021
…ements (#77)

- Updated frontend to display version - #59
- Support monitoring multiple coins simultaneously - #77
- Added docker-stack.yml for the Portainer - @hipposen
- Fixed precision issues for some FIAT - #90
- Improved frontend & settings UI - #93 #85
- Support all symbols - #104
- Added stop loss feature - #99
- Stabilised Local Tunnel, cronjob and Binance WebSocket
- Prevented to place new order when the API limit reached - #163
- Added NPM task for building docker image on Windows by @garyng - #175

Co-authored-by: GaryNg <garyng.zhongbo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants