我正在尝试使用其他API和Binance API
我可以这样:
for coin in data:
binance_prices.update( { coin["symbol"]: coin["price"]} )
但是Poloniex API的结构不同。
我尝试过
for coin_name in data:
for coin in data[coin_name]:
print(coin)
和
for coin_name in data:
for coin in data[coin_name]:
print(coin[0])
和其他不同版本,但没有一个起作用。我不明白如何获取每种硬币的价值并将其添加到我的字典中
答案 0 :(得分:0)
在python3.x中解压key:value对:
for coin_name, coin in data.items():
print(coin_name, coin)
解压缩python2.x中的key:value对:
for coin_name, coin in data.iteritems():
print(coin_name, coin)
coin_name是关键,coin是更新的价值。
答案 1 :(得分:0)
由于链接到的数据如下所示:
data = {“ BTC_BCN”:{“ id”:7,“ last”:“ 0.00000027”,“ lowestAsk”:“ 0.00000027”,“ highestBid”:“ 0.00000026”,“ percentChange”:“ 0.00000000”,“ baseVolume“:” 15.89962938“,” quoteVolume“:” 61952376.46356154“,” isFrozen“:” 0“,” high24hr“:” 0.00000027“,” low24hr“:” 0.00000025“},” BTC_BTCD“:{” id“:12 ,“ last”:“ 0.00235724”,“ lowestAsk”:“ 0.00235205”,“ highestBid”:“ 0.00230028”,“ percentChange”:“ 0.05644243”,“ baseVolume”:“ 0.22806668”,“ quoteVolume”:“ 96.48063458”,“ isFrozen“:” 0“,” high24hr“:” 0.00252499“,” low24hr“:” 0.00222999“},” BTC_BTM“:{” id“:13,” last“:” 0.00001912“,” lowestAsk“:” 0.00001992“ ,“ highestBid”:“ 0.00001912”,“ percentChange”:“-0.03287809”,“ baseVolume”:“ 0.28352400”,“ quoteVolume”:“ 14457.54592986”,“ isFrozen”:“ 0”,“ high24hr”:“ 0.00002067”, “ low24hr”:“ 0.00001912”},“ BTC_BTS”:{“ id”:14,“ last”:“ 0.00001605”,“ lowestAsk”:“ 0.00001606”,“ highestBid”:“ 0.00001605”,“ percentChange”:“- 0.00372439“,” baseVolume“:” 10.33652166“,” quoteVolume“:” 640365.41889709“,” isFrozen“:” 0“,” high24hr“:” 0.00001636“,” low24hr“:” 0.00001578“},等等...]}
使用此循环打印名称和最后价格:
for x in data:
print "coin name {} was last sold at {}".format(x,data[x]["last"])