CyberPunkMetalHead / Binance-volatility-trading-bot

This is a fully functioning Binance trading bot that measures the volatility of every coin on Binance and places trades with the highest gaining coins If you like this project consider donating though the Brave browser to allow me to continuously improve the script.
MIT License
3.42k stars 779 forks source link

List index out of range for orders[coin] #1

Closed 343N closed 3 years ago

343N commented 3 years ago

When update_portfolio is called, I very often get a list index out of range error and the program crashes.

  File "app.py", line 286, in <module>
    update_porfolio(orders, last_price, volume)
  File "app.py", line 228, in update_porfolio
    'symbol': orders[coin][0]['symbol'],
IndexError: list index out of range

Using my debugger, it looks like some currencies that the bot tries to buy are in the orders dict, but some don't end up going in there and are just empty.

image

I'm guessing it's an issue where the client is retrieving orders too quickly before they place on Binance's end?

andrewsauter-nbcuni commented 3 years ago

Not the original coder and I'm not familiar with Python, but in NodeJs there's this concept of async/await for things like this. I did a quick google and I think this might be similar: https://docs.python.org/3/library/asyncio-task.html

343N commented 3 years ago

For now, I just put a 100 millisecond time.sleep before it gets all orders from the binance client, it seems to have fixed it, though it's just a workaround for now.

edit: Nevermind, I still got the issue, I may have just gotten lucky before, or 100 milliseconds wasn't enough. changed it to 500ms. it could be a completely different issue though, i'm not too familiar with how python-binance works on the backend

CyberPunkMetalHead commented 3 years ago

I haven't been able to replicate your issue, but I did push a new commit. Can you verify that your issue is gone?

atmar commented 3 years ago

I have the same issue all the time in live aswell. Tried changing all requests to await using async functions from binance library, but same result. It's a big problem because it creates the orders, crashes before it puts it in the JSON and the orders are stuck in limbo until you manually sell them back to USDT on binance

LewisLebentz commented 3 years ago

I have the same issue all the time in live aswell. Tried changing all requests to await using async functions from binance library, but same result. It's a big problem because it creates the orders, crashes before it puts it in the JSON and the orders are stuck in limbo until you manually sell them back to USDT on binance

What could the problem be then? Did you change it to await client.create_order? Surely that means it can't finish before it populates the orders dict? I'm having the same problem. I'll try using await and/or a sleep to see if that fixes things for me.

It's getting pretty difficult to test as the market isn't going up right now...

CyberPunkMetalHead commented 3 years ago

The last commit should now fix this issue :)