gnome applet to track crypto prices

June 13, 2022 (2y ago)

gnome applet to track crypto prices

13 June 2021

add more FOMO to your life by constantly showing crypto prices as an applet. Wrote a small gnome applet to keep track of prices :)


Building applet

from gi.repository import Gtk as gtk
from gi.repository import AppIndicator3 as appindicator
import signal
from threading import Thread

APPINDICATOR_ID = "my-crypto-tracker"

def main():
    indicator = appindicator.Indicator.new(
        APPINDICATOR_ID,
        os.path.abspath("crypto.svg"),
        appindicator.IndicatorCategory.SYSTEM_SERVICES,
    )
    indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
    indicator.set_menu(build_menu())
    gtk.main()

def build_menu():
    menu = gtk.Menu()
    item_quit = gtk.MenuItem("Quit")
    menu.append(item_quit)
    menu.show_all()
    return menu

def quit(source):
    notify.uninit()
    gtk.main_quit()

if __name__ == "__main__":
    signal.signal(signal.SIGINT, signal.SIG_DFL)

API to track crypto prices

I usually use bitbns as the source

CRYPTO_PRICE_ENDPOINT = "https://bitbns.com/order/getTickerWithVolume/"
def fetch_prices(coin_symbol):
    response = requests.get(CRYPTO_PRICE_ENDPOINT)
    response_to_json = response.json()
    coin_price = response_to_json[coin_symbol]["last_traded_price"]
    return coin_price

Update ticker to the applet

use indicator.set_label(your_thread) to keep updating the ticker

Lock Thread