| 
					阅读:6925回复:0
				 限定时间平仓
					from datetime import datetime
 # 参数设置 CLOSE_TIME = "14:50" # 设置平仓时间(根据具体品种调整) async def on_bar(quote): # 转换行情时间为可读格式 current_time = datetime.fromtimestamp(quote.datetime // 1000000000).strftime('%H:%M') # 收盘平仓逻辑 if current_time >= CLOSE_TIME: if api.get_position(symbol).pos != 0: print(f"[{current_time}] 执行收盘平仓") await api.target_position(symbol=symbol, volume=0) # 在main函数中启动策略 async def main(): symbol = "SHFE.au1912" api = TqApi() quote = api.get_quote(symbol) api.create_task(on_bar(quote)) | |
| 
 | 
 
							
 
				



 
							