获取所有加密货币的价格



我正在尝试制作一个加密晴雨表。我有一小段代码,用于获取每个符号的美元价格。现在我想把它们加起来,得到这些硬币的总数(每种硬币的价格)。我有实时价格,但我不知道怎么把它们加起来。我还想知道1、4、8和24小时前每个符号的价格……

In the end it should look like this  :
Current             1Hour                ...  24Hours
BTCUSDT $49343.34   BTCUSDT $49133.12         BTCUSDT $48763.34
...                 ...                       ..
ETHUSDT $2123.84    ETHUSDT $2087.53          ETHUSDT $1987.23
sum : $6255422.23   Sum : $6249983m92         Sum : 6187291.51
下面是我的代码:
import requests
import json
import datetime
import time
api_request = requests.get('https://api.binance.com/api/v3/ticker/price')
api = json.loads(api_request.content)
for x in api:
print(x['symbol'], "${0:.4f}".format(float(x['price'])))
# THE PART WHERE I GOT DIFFERENT TIMES
while True:
dt = datetime
cur_time = (dt.datetime.now().strftime('%d-%m %H:%M'))
one_hour = (dt.datetime.now() - dt.timedelta(hours=1)).strftime('%d-%m %H:%M')
four_hours = (dt.datetime.now() - dt.timedelta(hours=4)).strftime('%d-%m %H:%M')
eight_hours = (dt.datetime.now() - dt.timedelta(hours=8)).strftime('%d-%m %H:%M')
one_day = (dt.datetime.now() - dt.timedelta(hours=24)).strftime('%d-%m %H:%M')
print(cur_time)
print(one_hour)
print(four_hours)
print(eight_hours)
print(one_day)
time.sleep(60)

有一个API库可以获取几乎所有加密货币的价格

import cryptocompare
def crypto_price('BTC'):
coin_acronym = str(acronyms['BTC'])
price_crypto = cryptocompare.get_price(coin_acronym, currency='USD', full=True).get('RAW').get(coin_acronym).get(
'USD').get(
'PRICE')
return price_crypto

最新更新