Getting started
With all the craze around crypto coins I thought it would be a fun project to pull live prices from Binance.us. To first get started head over to https://www.binance.us/ to get signed up, from there hover over your user account and select API management. Give a name for your api project then copy and paste your api key and api secret to a text file, you only can view your secret once so make sure you save it in a good place.
The Code
First you need to pip install python-binance, from there
from binance.websockets import BinanceSocketManager
from binance.client import Client
client = Client(api_key, api_secret)
Pass in your key and secret however you would like, then create the manager like so
bm = BinanceSocketManager(client)
# start any sockets here, i.e a trade socket
conn_key = bm.start_trade_socket('DOGEUSDT', process_message)
# then start the socket manager
bm.start()
Almost there now all we need to do is create a callback to process the data
def process_message(msg):
print("Current Price: {}".format(msg['p']))
Now we can see the live price for Doge
Read more here docs
Top comments (1)
Cannot import this in new version