Created
September 2, 2021 21:24
-
-
Save billyjacoby/c1c0159b4cce356ab47cafcdc5f7fae4 to your computer and use it in GitHub Desktop.
An xbar plugin to track the price of SOL using Binance's API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding=utf-8 | |
# <xbar.title>Binance Price Ticker</xbar.title> | |
# <xbar.version>v1.0</xbar.version> | |
# <xbar.author>Gabriel Age</xbar.author> | |
# <xbar.author.github>agezao</xbar.author.github> | |
# <xbar.desc>Displays Binance's ticker price for configured coin pairs</xbar.desc> | |
# <xbar.image>https://i.imgur.com/zJsoTl8.jpg</xbar.image> | |
# <xbar.dependencies>python</xbar.dependencies> | |
import json | |
from urllib import urlopen | |
# List here the symbols you want to keep track: | |
coin_symbols = ['SOLUSDT'] | |
# To get a list of available symbols check all the "symbol" attributes here: | |
# https://api.binance.com/api/v1/ticker/24hr | |
for coin_symbol in coin_symbols: | |
url = "https://api.binance.com/api/v1/ticker/24hr?symbol={}".format( | |
coin_symbol) | |
payload = urlopen(url) | |
data = json.load(payload) | |
last_price = float(data['lastPrice']) | |
price_variation = float(data['priceChangePercent']) | |
print('{} - {} : {}%'.format("SOL", | |
last_price, price_variation)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simply place this in your Xbar plugins folder to view the price of SOL updated every 6 seconds!