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