LUCIT-Systems-and-Development / unicorn-binance-local-depth-cache

A Python SDK by LUCIT for accessing and managing multiple local Binance order books with Python in a simple, fast, flexible, robust and fully featured way.
https://unicorn-binance-local-depth-cache.docs.lucit.tech/
Other
36 stars 11 forks source link

dictionary changed size during iteration in manager._sort_depth_cache #3

Closed foentiex closed 2 years ago

foentiex commented 2 years ago

Check this or we will delete your issue. (fill in the checkbox with an X like so: [x])

Select one:

Environment

What kind of internet connection do you have?

cable

Average system load (CPU)

70%

Hardware specification

Intel© Core™ i3-2120T CPU @ 2.60GHz × 2, 
10Gib 

Operating System? (include version)

Which endpoint do you connect?

 binance.com

Python Version Requirement

Exact Python Version?

3.8.10

Pip Version?

3.8.10

Dependencies

Run pip list > pip_list.txt and upload the file. pip_list.txt

UNICORN Binance Local Depth Cache Version?

Did you upgrade to the latest release version with `pip install unicorn-binance-local-depth-cache --upgrade`? No

unicorn-binance-local-depth-cache-0.1.0

Description of your issue

[example_depthcache.py.log](https://github.com/LUCIT-Systems-and-Development/unicorn-binance-local-depth-cache/files/8186753/example_depthcache.py.log)

Running the next file:

example_depthcache_2.py.txt

Traceback (most recent call last): File "/test/unicorn/example_depthcache.py", line 61, in print(market + f" Top 10 asks: {ubldc.get_asks(market=market)[:10]}") File "venv2/lib/python3.8/site-packages/unicorn_binance_local_depth_cache/manager.py", line 399, in get_asks return self._sort_depth_cache(self.depth_caches[market.lower()]['asks'], reverse=False) File "/venv2/lib/python3.8/site-packages/unicorn_binance_local_depth_cache/manager.py", line 321, in _sort_depth_cache new_items = [[float(price), float(quantity)] for price, quantity in items.items()] File /venv2/lib/python3.8/site-packages/unicorn_binance_local_depth_cache/manager.py", line 321, in new_items = [[float(price), float(quantity)] for price, quantity in items.items()] RuntimeError: dictionary changed size during iteration

foentiex commented 2 years ago

The same bug occurs in the version 0.2.0

Traceback (most recent call last): File "/test/unicorn/example_depthcache.py", line 26, in print(market + f" Top 10 bids: {ubldc.get_bids(market=market)[:10]}") File "/venv/lib/python3.9/site-packages/unicorn_binance_local_depth_cache/manager.py", line 434, in get_bids return self._sort_depth_cache(self.depth_caches[market.lower()]['bids'], reverse=True) File "venv/lib/python3.9/site-packages/unicorn_binance_local_depth_cache/manager.py", line 351, in _sort_depth_cache new_items = [[float(price), float(quantity)] for price, quantity in items.items()] File "/venv/lib/python3.9/site-packages/unicorn_binance_local_depth_cache/manager.py", line 351, in new_items = [[float(price), float(quantity)] for price, quantity in items.items()] RuntimeError: dictionary changed size during iteration

oliver-zehentleitner commented 2 years ago

Thanks for reporting it.

I added threading locks to avoid concurrent access to asks and bids which changes in a very high frequency.

https://github.com/LUCIT-Systems-and-Development/unicorn-binance-local-depth-cache/releases/tag/0.3.0.