我需要通過間隔從網站獲取信息。我寫了兩個循環到對方。不知何故,第二個條件,而循環不起作用,並使其成爲一個無限循環。雖然價值觀似乎相同。他們甚至計算。我究竟做錯了什麼?不條件不能在python for循環中工作
import requests
import time
buy = 0.0
sell = 0.0
tidnew = 0
counter = -1
main_api = 'https://api.bitfinex.com/v1'
trades = '/trades/'
etc = 'ETCUSD'
getorders = main_api+trades+etc
json_orderget = requests.get(getorders).json()
json_orderline = json_orderget[0]
tid = json_orderline["tid"]
if json_orderline["type"] == 'buy':
buy = float(json_orderline["amount"])
else:
sell = float(json_orderline["amount"])
time.sleep(1)
while True:
print("first while loop")
json_orderget = requests.get(getorders).json()
json_orderline = json_orderget[0]
tidnew = json_orderline["tid"]
int(tidnew)
counter += 1
tid = int(tid)
tidnew = int(tidnew)
if tid == tidnew:
print("Tid's are equal.")
while tid != tidnew:
print("Second while loop")
json_orderline = json_orderget[counter]
price = json_orderline["price"]
tidnew = json_orderline["tid"]
if json_orderline["type"] == 'buy':
buy += float(json_orderline["amount"])
else:
sell += float(json_orderline["amount"])
print("New price is: " + str(price))
print("New tid is: " + str(tid))
print("Buy volume is: " + str(buy))
print("Sell volume is: " + str(sell))
counter += 1
tid = tidnew
print("tid is: " + str(tid))
tid = int(tid)
counter = -1
time.sleep(1)
你怎麼能指望什麼,但一個無限循環,如果你寫的'而TRUE'永不'break'循環?你認爲那裏的停車條件是什麼? –
* int(tidnew)*是無用的語句,當結果是無處分配的。 – guidot