Easiest and simplest way to store and process data from Binance websocket

Hello Everyone,

I’m new to Binance websocket, and I usually get information like pricing and coin information from API endpoints rather than websocket.

Is there any simple way to store data that comes from Websocket that I can use or pass to other functions? I’m using python-binance to call Websocket.

I need help with this.



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 Aisling,

Yes, try that library; unfortunately, I got an error like this:
ModuleNotFoundError: No module named ‘binance.websocket’

I already install the package:
pip install binance-connector


@cevinov verify if the python version you’re using to run the file is the one you’ve installed the binance-connector.

I urge you to store your data in dict and update the dict as you receive new data. However it will be gone forever when you terminate the app.

If you still want to keep the data the easiest way to store them in a json file.

Hello Khun,

I see. Could you give me any example code to give me an idea of how to implement it myself?


In small environments with little data, you can also try using a SQLite DB, but don’t underestimate the amount of data you’ll get. Here is an example with the UNICORN Binance Websocket API: unicorn-binance-websocket-api/examples/binance_websocket_kline_1m_ohlcv_to_sqlite at master · LUCIT-Systems-and-Development/unicorn-binance-websocket-api · GitHub

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)

I hope this helps!