Based on what you’ve described, it seems that what you want is handling events coming from a WebSocket connection. This is usually done at the message callback level, which you define. How you pass this callback to the WebSocket depends on the library you’re using. python-binance is not the official library, so I would suggest discussing this topic with their community.
However, if you want to use the official library, you have WebSocket examples available at https://github.com/binance/binance-connector-python/blob/master/examples/websocket/spot/websocket_api/.
Hello cevinov, for your confort, you can try with this functional script I’ve made few months ago, and uploaded now without changes (csv file name has a wrong date, default pair is BTC/USDT at 15 minutes interval)