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

Lagging issue on other threads when using start_depth_socket #1318

Open
pazooki opened this issue Apr 28, 2023 · 0 comments
Open

Lagging issue on other threads when using start_depth_socket #1318

pazooki opened this issue Apr 28, 2023 · 0 comments

Comments

@pazooki
Copy link

pazooki commented Apr 28, 2023

Describe the bug
When starting a new thread; twm.start_depth_socket it blocks long enough that I get lagging issue on twm.start_aggtrade_socket and the price data becomes out of date. I've timed strategy.update_depth and reduced it to just setting an instance variable to store the data coming into twm.start_depth_socket but the problem still persists. I have also tried to use ThreadedDepthCacheManager and that had the same problem of causing a lag on other threads.

To Reproduce
Code snippet to reproduce the behavior:

BTCUSDT = 'BTCUSDT'

def main(strategy, is_testing):
    config = TESTNET_CONFIG if is_testing else CONFIG

    twm = ThreadedWebsocketManager(api_key=config['API_KEY'], api_secret=config['API_SECRET'], testnet=is_testing)
    # dcm = ThreadedDepthCacheManager(api_key=config['API_KEY'], api_secret=config['API_SECRET'], testnet=is_testing)
    # dcm.start()
    twm.start()
    twm.start_depth_socket(callback=strategy.update_depth, symbol=BTCUSDT, depth=10, interval=1)
    twm.start_aggtrade_socket(strategy.next, symbol=BTCUSDT)
    twm.start_user_socket(strategy.update_balance)
    # dcm.join()
    twm.join()

Expected behavior
No lagging on other threads when I use twm.start_*

Environment (please complete the following information):

  • Python version: 3.11.3
  • Virtual Env: virtualenv
  • OS: Fedora 38
  • python-binance version: 1.0.17

Logs or Additional context

I am sharing the strategy object among twm.start_depth_socket and twm.start_aggtrade_socket and twm.start_user_socket however there is no conflict or race condition since they each update their own variables without updating variables belonging to other threads. The problem I'm seeing is that the price that I receive in start_aggtrade_socket is lagged behind and outdated and when I watch and compare it to the Binance Client price.
I tried it only on TESTNET

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant