51 lines
1.2 KiB
Python
Executable File
51 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import http.client as http
|
|
import json
|
|
|
|
# curl -sS https://api.coingecko.com/api/v3/coins/list
|
|
COINS = [
|
|
# [id, symbol]
|
|
["monero", "XMR"],
|
|
["bitcoin", "BTC"],
|
|
]
|
|
CURRENCY = "usd"
|
|
FORMAT = "{coin}=${price:.0f}"
|
|
|
|
|
|
def get_btc_fees() -> str:
|
|
url = "mempool.space"
|
|
path = "/api/v1/fees/mempool-blocks"
|
|
|
|
client = http.HTTPSConnection(url)
|
|
client.request("GET", path)
|
|
|
|
# https://mempool.space/docs/api/rest#get-mempool-blocks-fees
|
|
response = json.loads(client.getresponse().read())
|
|
return f"{int(response[0]['medianFee'])} sat/vB"
|
|
|
|
|
|
def get_coins_values() -> str:
|
|
ids = ",".join([coin[0] for coin in COINS])
|
|
url = "api.coingecko.com"
|
|
path = f"/api/v3/simple/price?ids={ids}&vs_currencies={CURRENCY}"
|
|
|
|
client = http.HTTPSConnection(url)
|
|
client.request("GET", path)
|
|
|
|
# https://www.coingecko.com/api/documentation
|
|
prices = json.loads(client.getresponse().read())
|
|
|
|
return " ".join(
|
|
FORMAT.format(coin=coin[1], price=prices[coin[0]][CURRENCY])
|
|
for coin in COINS
|
|
)
|
|
|
|
|
|
def main():
|
|
print(f"{get_btc_fees()} {get_coins_values()}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|