A Python Script for Live Bitcoin Price Ticker

Hi Everyone!

I've seen that people in this group have been interested in scripting and building simple things to interact with the cryptocurrency markets.

To help everyone out, I wrote up a brief script which will connect to the websocket for any major exchange and start streaming price data from the exchange.

It's so easy to do anyone could do it. All you need is Python and the ability to copy and paste code. Let's quickly walk through how we can get started.

Install Library

We will need to install the following library.

pip install shrimpy-python 

Script

Once the library has finished installing, you can run this simple script to begin streaming live Bitcoin ticker data.

# import the Shrimpy library for free crypto exchange websockets import shrimpy # create the Shrimpy websocket client client = shrimpy.ShrimpyWsClient() # define the handler to manage the output stream def handler(msg): # multiple trades can be returned in each message, so take the last one ticker = msg['content'][len(msg['content']) - 1]['price'] print(ticker) # construct the subscription object subscribe_data = { "type": "subscribe", "exchange": "binance", "pair": "btc-usdt", "channel": "trade" } # connect to the Shrimpy websocket and subscribe client.connect() client.subscribe(subscribe_data, handler) # disconnect from the websocket once data collection is complete client.disconnect() 

That's it! Let me know if you have any questions. You can find the documentation for these APIs here. I also wrote up a few example articles to provide more information:

Script for Cryptocurrency Price Charts

Script for Bitcoin Price Live Ticker



Submitted September 22, 2019 at 02:03AM by ShrimpyApp https://ift.tt/2M9Acj0

Comments

Popular posts from this blog

Coinmarketcap are listing BCH sites as BTC

15 years of BTC Power Law