March 18, 2020

E-ink cryptocurrency ticker

I like the idea of e-ink. Ultra Low power, easily readable displays. Big fan. I also follow some cryptocurrency’s. So this project is a merge of these 2 things. It’s still a work in progress, as there a few bugs I need to sort out, and I need a nice looking case. But for now it was a fun project that does the thing well and I got to learn some image manipulation in python!

the hardware

raspberry pi 3

I had a spare one of those laying around, but they are very cheap these days. Almost any version can be used here. In the next iteration I will use a pi zero, as it will be even smaller form factor as it’s around the same dimensions as the e-ink display I used

Pomodoro inkyphat 2.7” e-ink display (black and white model)

The code currently is specific to this model as I generate an image for 2.7” and utilise the inkyphat python module, however it shouldn’t be too difficult to adjust for a larger size or model

the software

  • python (3)
  • inkyphat
  • python pillow
  • mathplot lib
  • mpl-finance

the code

Hosted in gitlab you can view the entire repository here. This was build ontop of an existing eink cryptocurrency project. The main differences was that I had the black and white e-ink display so the candlestick graph was not easy to read (it was challenging to set variations of grey) so I decided to just graph it with a spark-line.

Image

I have also added a function to utilise the Binance public API rather then Kraken.

def quotes_historical_binance_ohlc(pair, since, interval='15m'):
    unix_time = since.strftime("%s")
    if interval == '1d':
      payload = {'symbol': pair,'interval': interval, 'limit': '200'}
    else:
      payload = {'symbol': pair,'interval': interval, 'limit': '200', 'startTime': int(since.strftime('%s'))*1000}
    r = requests.get('https://api.binance.com/api/v1/klines', params=payload)
    #print(r.json())

    def parse_ohlc(data):
        return [[int(l[6]/1000), float(l[1]), float(l[2]), float(l[3]), float(l[4]), float(l[5])] for l in data]

    return parse_ohlc(r.json())

There was also a sticking point about the new InkyPhat python module. The new version had all of the python image manipulation functions removed out of the module, so I had to do it directly with Pillow.

The last thing to change was adding a config to make sure that mpl could run in headless mode

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

Run this in your scheduler (cron) and you can be the cool kid in the office again.

Inky pi