I use python's while Ture loop to continuously monitor the closing price. If there is a change(greater than 0), I want to print it only once and keep monitoring without exiting the loop. How do I print only once without breaking the loop(and print only once the next time I encounter a change)? Thanks!
Supplement: Currently, sleep(0.5) will be printed twice, if it is changed to sleep(1), it will be printed once, but the low frequency can not keep up with the price changes, which will lead to the price error.
def spj(): # 收盘价
if qgm() == '00': # 时间为00的时候(每分钟一次)
return jg() # 返回价格
def close(): # 收盘价
while True: # 循环执行
if spj() != None: # 如果价格不为空
break # 跳出循环
sleep(0.01) # 循环频率
return float(spj()) # 返回收盘价
while True: # 持续监视
if close() > 0: # 如果收盘价变动
print(close()) # 打印收盘价
sleep(0.5) # 监视频率
0 Answer
No answer yet
这家伙很懒,什么都没留下...