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

When "agg_trade" is running, I can't terminate the program using Ctrl+C. Is there any solution to this? #345

Open
IronEaterBeast opened this issue Nov 18, 2024 · 4 comments

Comments

@IronEaterBeast
Copy link

from binance.websocket.spot.websocket_stream import SpotWebsocketStreamClient

def on_message(_, _message):
print(_message)

my_client = SpotWebsocketStreamClient(on_message=on_message)
my_client.agg_trade(symbol="btcusdt")

@alplabin
Copy link
Contributor

Have you considered closing the connection using the method my_client.stop() like in the example?

@IronEaterBeast
Copy link
Author

IronEaterBeast commented Nov 27, 2024

Have you considered closing the connection using the method my_client.stop() like in the example?

Yes, I know about my_client.stop(), but what I want is for the program to keep running until I manually close it, not to stop automatically after a set time. How can I make it so that I can decide whether it should close at any time after the program starts running? @alplabin

@alplabin
Copy link
Contributor

What exactly happens when you Ctrl+c? Which os are you using?

@IronEaterBeast
Copy link
Author

IronEaterBeast commented Nov 28, 2024

What exactly happens when you Ctrl+c? Which os are you using?

I run the program in the terminal of VSCode on Windows. After pressing Ctrl+c, the program continues its previous running state, constantly fetching the latest data from a remote server and printing the data on the screen. This terminal cannot respond to any other operations. @alplabin

This is my code:

import logging
import time
from binance.lib.utils import config_logging
from binance.websocket.spot.websocket_stream import SpotWebsocketStreamClient

config_logging(logging, logging.DEBUG)


def message_handler(_, message):
    logging.info(message)

my_client = SpotWebsocketStreamClient(on_message=message_handler, is_combined=True)

# Subscribe to a single symbol stream
my_client.agg_trade(symbol="bnbusdt")

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

2 participants