首页 > 解决方案 > 使用 HTTP 请求进行过滤

问题描述

我目前正在使用 XT.com API(加密货币兑换)。我想在这个交易所获得加密货币的最新价格。到目前为止,以下是我的代码:

ticker = api.get_ticker(dict(market='btc_usdt'))
#XTPrice = ticker['price']
print(ticker) 

运行这段代码给了我这个:

Please wait a moment...retry now... times is 1
(True, {'high': 50494.6, 'low': 47993.99, 'rate': 0.0267, 'price': 50174.41, 'moneyVol': 40012402.49752388, 'coinVol': 809.706147, 'ask': 50173.88, 'bid': 50172.19, 'askVol': 0.147934, 'bidVol': 0.052413, 'depthTime': 1629726830489}, <Response [200]>)

我想只保留“价格”部分。我试图添加代码:

XTPrice = ticker['price']
print(XTPrice)

但这会导致错误。

任何人都可以为我提供任何帮助吗?

标签: pythonapirest

解决方案


ticker[1]['price']

Epsi95 提供的代码


推荐阅读