Introducing Python websockets and asyncio with a worked example
A quick beginner’s tutorial into Python websockets with a Deribit cryptocurrency example.
In this note, we’re going to run through some basics on running Python websockets, along with an example where we use websockets to receive live cryptocurrency data from one the largest Bitcoin futures trading platform Deribit.
Firstly, you need to install websockets.
Installing Python websockets
Installing websockets:
pip install websockets
Websockets requires Python 3.6.1 or greater. Perhaps you can create a new virtual environment and install websockets into this environment. This way, you don’t mess around with your base environment.
conda create --name myNewEnv python=3.7
conda install -n myNewEnv websockets
In the code above, we’ve created an new Python virtual environment called “myNewEnv” in which we install Python version 3.7. We have also installed websockets into this version.
What is websockets?
Websockets is a standard protocol for two way data transfer between a client and a server. Websockets does not run over HTTP, it has a separate implementation on top of TCP. This is the…