feat: optimized sbar, gammastep asia, wpdef
This commit is contained in:
parent
f48e958d44
commit
395119a0fe
19 changed files with 159 additions and 157 deletions
|
@ -4,46 +4,30 @@ import http.client as http
|
|||
import json
|
||||
|
||||
# curl -sS https://api.coingecko.com/api/v3/coins/list
|
||||
COINS = [
|
||||
# [id, symbol]
|
||||
["monero", "XMR"],
|
||||
["bitcoin", "BTC"],
|
||||
]
|
||||
COINS = ["monero", "bitcoin"]
|
||||
CURRENCY = "usd"
|
||||
FORMAT = "{coin}=${price:.0f}"
|
||||
|
||||
|
||||
def get_btc_fees() -> str:
|
||||
url = "mempool.space"
|
||||
path = "/api/v1/fees/mempool-blocks"
|
||||
|
||||
client = http.HTTPSConnection(url, timeout=10)
|
||||
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, timeout=10)
|
||||
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
|
||||
)
|
||||
FORMAT = "{symbol}=${price:.0f} {trend:+.1f}%"
|
||||
|
||||
|
||||
# https://docs.coingecko.com/v3.0.1/reference/coins-id
|
||||
def main():
|
||||
print(f"{get_btc_fees()} {get_coins_values()}")
|
||||
path = "/api/v3/coins/{id}?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false"
|
||||
client = http.HTTPSConnection("api.coingecko.com", timeout=10)
|
||||
strings = []
|
||||
|
||||
for c in COINS:
|
||||
client.request("GET", path.format(id=c))
|
||||
j = json.loads(client.getresponse().read())
|
||||
|
||||
strings.append(
|
||||
FORMAT.format(
|
||||
symbol=j["symbol"].upper(),
|
||||
price=j["market_data"]["current_price"][CURRENCY],
|
||||
trend=j["market_data"]["price_change_percentage_24h"],
|
||||
)
|
||||
)
|
||||
|
||||
print(" - ".join(strings))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue