请教各位,我想在while中跟踪订单变化,循环之前保存当时时间time1,while开始后当订单状态在2秒后(time.time()-time1>2)的状态还是pending就return 0,如果是ORDER_STATE_CLOSED,那就return 1,返回完成。
但是在实盘测试中,发现程序会进入无限循环不会停下来,最后一条信息就是“订单已下”
代码附下,请大大帮忙释疑
order_result =exchange.Sell(fee,size)
Log('订单已下')
if order_result==None:
return 0
if order_result!=None:
time1=time.time()
while True:
order_status=exchange.GetOrder(order_result).Status
if order_status==None and time.time()-time1>2:
Log('订单状态获取失败')
return 0
if order_status!=None:
if time.time()-time1>2 and (order_status==ORDER_STATE_CANCELED or order_status==ORDER_STATE_PENDING):
Log("订单挂单或被取消")
return 0
if order_status==ORDER_STATE_CLOSED:
Log("订单完成")
return 1
Inventors quantify - small dreamsSee the code below. What's up? order_result = exchange.Sell ((fee, size) # Subscribe Log (('Order has been placed') if order_result==None: # not returned Order ID return is 0. if order_result!=None: # Submission was successful time1=time.time() # record Second level Timestamp while True: #circular judgment order_status=exchange.GetOrder ((order_result).Status # reads the status of the order if order_status==None and time.time() -time1>2: # and after placing the order, loop read Judge the time before the order status comparison, detect if it is more than 2 seconds Log (('order status failed to be obtained') # return is 0. If order_status!=None: # Obtained status Successfully if time.time() -time1>2 and (order_status==ORDER_STATE_CANCELED or order_status==ORDER_STATE_PENDING): # The order is to be hung or canceled after 2 seconds Log (("Orders are pending or canceled") return is 0. if order_status ==ORDER_STATE_CLOSED: # The order has been completed Log (("Order completed") return one What's up? The logic should be fine. The problem may be that the order data that GetOrder returns may contain other states, such as an unknown state, which is the exchange where you operate. It is recommended to add Log (order_status) after order_status=exchange.GetOrder (order_result).
Inventors quantify - small dreamsThe exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange, the exchange.
hunter1015The editor made a mistake when posting, the code determined that the variables were consistent. The real disk was tested many times, it was stuck in GetOrder and could not come out, no error will be reported, no LOG will be returned.
Inventors quantify - small dreamsIs your code misspelled, this ID should be undefined, only this appears in the code. This is a list of all the different ways Dn-filebox.qbox.me/d89332ffbe84fa2cdcac442649edb35f4f61a3cc.png is credited in the database.
hunter1015I've been testing it a couple of times these past two days and found that the exchange.GetOrder () statement didn't come back at all after it was triggered, or that once I entered the statement, the program stuck dead inside and didn't come out, resulting in all the printed content I set up not being printed out. def main (: I'm not sure what you mean. time1=time.time ((() Log ((' record time is 'time1) depth = _C (exchange.GetDepth); Orders_buy1=depth.Bids[0].Price orders_buy2=depth.Bids[1].Price Orders_buy3=depth.Bids[2].Price Orders_sell1=depth.Asks[0].Price orders_sell2=depth.Asks[1].Price orders_sell3=depth.Asks[2].Price What do you think? account=exchange.GetAccount (()) What do you think? Sell (orders_buy 1*0.999, 0.1); # place an order time1=time.time() # recording the completed time string If sell_order_id==None: Log (('order number is empty') if sell_order_id!=None: # if the order number is successfully obtained order_back_message_last=None # record the last time The order's return message content is being queried (initialized as None) What do you think? while True: # enters the while loop, tracks order information with GetOrder order_back_message=exchange.GetOrder ((order_result) The message returned by #GetOrder ((all)) Log (('query order returned content is', order_back_message) # brainless output order returned content What do you think? if order_back_message!=order_back_message_last: # if this order information is not the same as the last one, Log output and update order_back_message_last Log (('query order returned content is 'order_back_message') I'm not sure what you mean by that. What do you think? What do you think? order_status=order_back_message.Status# command returns extract Status from data structure (no need to see it from now on, because it didn't go through) Order_status=exchange.GetOrder ((sell_order_id).Status This is a list of all the different ways Order_status is credited in the database. Log ((order_status) is not available. If order_status==None and time.time() -time1>2: Log (('order status failed to be obtained') break If order_status!=None: If order_status == ORDER_STATE_CLOSED: If order_status is closed, then order_status is closed. Log (('Hedging - Success') break #return True elif time.time (() -time1>2 and (order_status ==ORDER_STATE_CANCELED or order_status ==ORDER_STATE_PENDING): Log (('Hedging - Failed') break #return False I'm not sure what you mean. #Log (('xunhuan')) is the name of the blog. #PD_SHORTLog (('current time=',time.time(), 'initial time=',time1)
Inventors quantify - small dreamsIn fact, some exchanges have a standard status in various non-BotVS documents, BotVS is defined as an unknown status, you can see the specific value of the status after the order_status=exchange.GetOrder. It is possible to see what the specific order status is, and then judge the question (what causes the death cycle).
hunter1015@ChiloChiloDream.ChiloDream, I'm at gateIO, this problem was discovered a few days ago, and I wrote a simple code to retest the results and I feel no problem. This is a list of all the different ways Dn-filebox.qbox.me/97f571e4222ee9c61bd6e3cb203af319b11a8c72.png is credited in the database.