How to get Bitcoin price on your Pi

in #raspberrypi8 years ago (edited)

Hey guys, today I just wanted to share a neat piece of code that allows you to retrieve the price of Bitcoin, Steem and SBD on your Raspberry Pi. You could of course add any other cryptocurrency of your liking, but this code will display those 3 as they are my favorites.

I set up this Pi yesterday and gave it as a gift to my good friend and partner @albertogm, now he doesn't have to check coinmarketcap every 5 minutes!

If you want to create your own Crypto Price Board, all you have to do is get yourself a Sensehat for your Pi and copy this Python code:

from sense_hat import SenseHat
sense = SenseHat()
from urllib.request import urlopen
import json
import time

while True:
  try:
    url = urlopen('https://poloniex.com/public?command=returnTicker').read()
    result = json.loads(url)
    SBD = result['BTC_SBD']['last']
    BTC = result['USDT_BTC']['last']
    Steem = result['BTC_STEEM']['last']
    SBD_USD = float(SBD) * float(BTC)
    STEEMUSD = float(Steem) * float(BTC)
    sense.show_message("BTC " + '{0:.0f}'.format(BTC), text_colour=[255, 215, 0])
    sense.show_message("STEEM " + '{0:.2f}'.format(STEEMUSD), text_colour=[7, 24, 138])
    sense.show_message("SBD " + '{0:.2f}'.format(SBD_USD), text_colour=[4, 112, 22])
    time.sleep(3)
  except:
    sense.show_message("failed to retrieve feed")
    time.sleep(3)

You should also add a cron job so that your script runs at starts, you can follow this guide that does just that: http://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/

Enjoy!

Sort:  

I really need to learn even the simple coding as well , I’ll take a look . How’s the mining going ?

Python is the easiest language to learn in my opinion, is quite fun..

Still preparing the container, will post about it soon..

I hope things are well on your end!

I’ll look forward to it . My brothers still creating more trying to find a place to put them. Has them in different houses right now and sometimes it’s too much load and heat

Great stuff. I need somethink like that, since I also watch coinmarketcap a lot lately.

That is what it means to be a passionate guy :)) I just wonder, is this really practical, since you will have to watch every letter one by one in a row, or is it more interesting because it just keep you focused?

hehe you just have to wait a bit..

excellent post...thanks for sharing a blog........

I have been interested in Pi but didn't know what to use it for, but this is brilliant!!

Wow great way of mining

Awesome work thanks for sharing the code here this is very useful : )

Thanks for sharing i will done upvote..A very good post @ chitty

great one post..
carry on...

Coin Marketplace

STEEM 0.08
TRX 0.29
JST 0.035
BTC 103917.07
ETH 3426.26
USDT 1.00
SBD 0.53