When a Simple Ticker Becomes a New Project
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
Do you ever run out of ideas? xD
I actually do, but only occasionally 😅
Thanks for finding, and fixing, another "hole" in our ecosystem - funnily enough this one is not even "our problem", binance being disallowed by the US SEC is an issue that I think a lot of US citizens face.
!PAKX
!PIMP
!PIZZA
View or trade
PAKX
tokens.Use !PAKX command if you hold enough balance to call for a @pakx vote on worthy posts! More details available on PAKX Blog.
Even looking past that issue, I think blocking price checks via the API is just petty.
$PIZZA slices delivered:
@ecoinstant(1/20) tipped @thecrazygm
Come get MOONed!
Congratulations @thecrazygm! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out our last posts:
Don't you love rabbit holes? I think that it's badass that, because you couldn't get one crypto ticker to work as you wanted, you just made a better one yourself. Brilliant. 😁 🙏 💚 ✨ 🤙
I do love rabbit holes, when they don't get me severely sidetracked from what I was aiming for in the first place. But this time I do think I was better off at the end.
I feel you on that one, and that's always my hope as well. Indeed, it would seem so, which is excellent. 😁 🙏 💚 ✨ 🤙