docs: config docs
This commit is contained in:
parent
fdac273ed4
commit
2760df07bd
10
README.md
10
README.md
@ -1,13 +1,9 @@
|
||||
# crypto
|
||||
Get your current holding in crypto from CoinGecko in your own currency.
|
||||
Get the `value` of one+ `coin` from CoinGecko in the `currency` of your
|
||||
`choice`.
|
||||
|
||||
## How-To
|
||||
Set your coins, your currency and the format you want the output in crypto
|
||||
You can get a list of valid id with:
|
||||
```console
|
||||
$ curl https://api.coingecko.com/api/v3/coins/list
|
||||
```
|
||||
|
||||
Set the `COINS`, `CURRENCY` and `FORMAT` you want in `crypto`.
|
||||
```console
|
||||
$ ./crypto
|
||||
```
|
||||
|
9
crypto
9
crypto
@ -3,24 +3,25 @@
|
||||
import json
|
||||
import requests
|
||||
|
||||
# curl https://api.coingecko.com/api/v3/coins/list
|
||||
COINS = [
|
||||
# [id, symbol]
|
||||
["bitcoin", "BTC"],
|
||||
]
|
||||
CUR = "usd"
|
||||
FMT = "{coin}=${price:.0f}"
|
||||
CURRENCY = "usd"
|
||||
FORMAT = "{coin}=${price:.0f}"
|
||||
|
||||
|
||||
def main():
|
||||
coin_ids = ",".join([coin for coin in list(zip(*COINS))[0]])
|
||||
url = f"https://api.coingecko.com/api/v3/simple/price?ids={coin_ids}&vs_currencies={CUR}"
|
||||
url = f"https://api.coingecko.com/api/v3/simple/price?ids={coin_ids}&vs_currencies={CURRENCY}"
|
||||
|
||||
# {'bitcoin': {'usd': 69420}}
|
||||
prices = json.loads(requests.get(url).text)
|
||||
|
||||
print(
|
||||
*[
|
||||
FMT.format(coin=coin[1], price=prices[coin[0]][CUR])
|
||||
FORMAT.format(coin=coin[1], price=prices[coin[0]][CURRENCY])
|
||||
for coin in COINS
|
||||
]
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user