Nomics.com Cryptocurrency Tickers

Provides price updates and 24h change for the top ten cryptocurrencies by marketcap.

Image preview of Nomics.com Cryptocurrency Tickers plugin.

nomics_bitbar.py

Edit
Open on GitHub
#!/usr/bin/env LC_ALL=en_US.UTF-8 /usr/local/bin/python

'''
    All metadata is placed here
'''
# <xbar.title>Nomics.com Cryptocurrency Tickers</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Daniel Anderson</xbar.author>
# <xbar.author.github>dtand</xbar.author.github>
# <xbar.desc>Provides price updates and 24h change for the top ten cryptocurrencies by marketcap.</xbar.desc>
# <xbar.image>https://i.ibb.co/4SD8cZs/Screen-Shot-2019-11-25-at-6-16-56-PM.png</xbar.image>
# <xbar.dependencies>python,requests</xbar.dependencies>
# <xbar.abouturl>https://nomics.com</xbar.abouturl>
import requests


## Base url for api
BASE_URL = 'https://api.nomics.com/v1'

## Tickers endpoint
ENDPOINT = 'currencies/ticker'

## FREE API key
API_KEY = '4465bf5e9801e08b9a3e04084c7ea3c3'

## Returns top ten cryptocurrencies
def get_top_ten():
    url = "{}/currencies/ticker?key={}".format(BASE_URL, API_KEY)
    response = requests.get(url)
    data = response.json()
    top_ten = []
    i = 0 
    for ticker in data:
        if i >= 10:
            break
        top_ten.append(ticker["id"])
        i = i + 1
    return top_ten

## Returns ticker for provided symbol
def get_tickers(symbols):
    params = {
        "ids": symbols
    }
    url = '{}/{}?key={}'.format(BASE_URL, ENDPOINT, API_KEY)
    response = requests.get(url, params=params)
    data = response.json()
    return data

## Pads string to certain length
def pad_string(string, length):
    padding = length - len(string)
    return string.ljust(padding)

## Returns the string specification for stdout
## for bitbar interpreter
def generate_bitbar_format(tickers):
    std_out_strings = []
    i = 1
    for ticker in tickers:
        symbol   = ticker['symbol']

        price    = round(float(ticker['price']),4)

        if price < 1.00:
            price = '${:,.4f}'.format(price)
        else:
            price = '${:,.2f}'.format(price)

        p = abs(float(ticker['1d']['price_change_pct']))
        percent  = round(p * 100, 2)
        percent  = str(percent) + "%"

        col_one = pad_string(symbol + ": " + price, 24)

        if float(ticker['1d']['price_change_pct']) >= 0:
            std_out_strings.append(col_one + "\t+" + percent + " | color=green")
        else:
            std_out_strings.append(col_one + "\t-" + percent + " | color=red")

        i = i + 1

    return std_out_strings

## Print output with bitbar formatting between new lines
def output_values(values):
    print(" Nomics.com | image=iVBORw0KGgoAAAANSUhEUgAAADYAAAA2CAYAAACMRWrdAAABk2lDQ1BJQ0MgUHJvZmlsZQAAKJF9kL1LQmEUxh+vhVFGgw0ODReyWjTMIGpLDUQwEDPIauh+qFfQ6+V6pYLGoKVBaOhj6Wtoaa7VoTUIiiKIlv6DvpaQ23m9hlbUgZfz43nPOe95H4DbFDQt3+YHCqqhJyIhfi41zzue0AU3XBjDkCCVtGA8HgPFV/4e77ewsXztY7N+3/8b3XK6JAE2nnhS0nSDeIm4f9nQGK8T9+q0FPEO46zFp4xFi6v1mmQiTHxDzEuKIBO/EnslRS8AHJvvkQsy6dyUxSpjhbHY0ptt4UK+LDX2ZD90ptXZGVZPpw8RRDGNOHiIKCOHPAz4KKuklJCg+5CRXjFYc7ioreq5rGLwQXIozUdVadjLB/wjEwDz+6ePTa14AIy/AfZKUxO3gfMNwH3f1Dz7QA95dXahCbpQl+x0uEwGeD4hm1OA6wroXChlRgPWj5whoP3RNF8GAMcWUKuY5sehadaOqPkBqKqWd41ZOL4DkmtA7BLY3QMGs/Tm4h8eddQ9avjwb03Dx0/wyngPzfkFKgAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9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EZ0nrxxndfMwJ093NQe0cukHvdM8GR6VR16CswfDYqO2A9UY7AL9drDw1pjvZjv1NhltfRJ/rmEEPAawE8aZ7dwAdpN94p4yF+oe088Ft4XiHXrIdBTMrKbagZTI/cs0sWBKkTNt86Bkh2jyf+Z1iyWRNt8Lz15kW3cK4cT38GHnSI+AhBsXI4iC832f/4LXSWr1BGB0x5VFw21IU0yv+Hwim37hI2Q16AAAAAElFTkSuQmCC")
    print("Go to nomics.com for all assets | href=https://nomics.com")
    for i,value in enumerate(values):
        print(value)
    print('Refresh | refresh=true')

## Wrapper method for generating output and printing it
def std_out(tickers):
    output_values(generate_bitbar_format(tickers))

def main():
    top_ten = get_top_ten()
    tickers = get_tickers(",".join(top_ten))
    std_out(tickers)

if __name__ == "__main__":
    main()