Hey everyone,
I recently wanted to add the current HIVE price to my Qtile bar, which I thought would be a simple task. Qtile has a built-in CryptoTicker
widget, so I figured I would just add it to my configuration and be done.
I was wrong. This small task sent me down a mini rabbit hole that ended with me writing my own custom widget.
The Problem with Region-Locking
According to the Qtile documentation, my options for data sources were Coinbase or Binance. HIVE isn't on Coinbase, so I configured the widget to use Binance. All I got was a "No network" error. I knew HIVE was on Binance, so what was going on?
A quick manual API call with curl
gave me the answer:
It turns out that Binance's region restrictions apply to their API as well, which, wow, talk about petty. Since I'm in the US, the API was completely inaccessible to me.
From a Quick Fix to a Full Widget
My first thought was to just build a quick, single-purpose widget using the CoinGecko API, which I know works reliably for me.
# A simple widget to get just the HIVE price
def parse_hive_price(response):
try:
price = float(response["hive"]["usd"])
return f"HIVE: ${price:.2f}"
except (KeyError, TypeError, ValueError):
return "HIVE: Error"
class HivePrice(GenPollUrl):
def __init__(self, **config):
super().__init__(
url="https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd",
json=True,
parse=parse_hive_price,
**config,
)
This worked fine, but then it hit me: why would I use the default CryptoTicker
to get the price of BTC or ETH from one service, and my own separate widget to get the price of HIVE from another? It made more sense to build one widget that could do it all using a single, reliable data source.
So, I created a fully-functional CoinGeckoTicker
widget. It mimics the interface of the original CryptoTicker
but uses the CoinGecko API for all its requests.
The Result
Now, instead of fighting with region-locked APIs, I have a flexible and reliable ticker that can pull the price for any crypto I want, all from one place.
You can find the full code and installation instructions on GitHub:
Now, I know what you might be thinking:
"What's a Qtile?!"
🤣 It's a niche Tiling Window Manager written in Python for Linux, and yes, I am that much of a nerd. But for those of us who use it, having tools that just work without fighting arbitrary restrictions is a huge win.
As always,
Michael Garcia a.k.a. TheCrazyGM