指令单方式多进程实现止盈止损的Python流程

理财品牌 2025-10-24543 admin
指令单方式多进程实现止盈止损的Python流程
"""A股疯牛,节前给大家发了不小的红包。趁着放假着手写个止盈止损的小程序,预设运行条件为miniQMT,在指令单中指定stock_code,stock_price,stock_quantity,实现无盯盘模式的买入和卖出操作。环境下调试通过。创建日期:2024/10/2主要功能:通过csv文件的指令单,向程序输入股票代码、止盈/止损单价、数量,以多进程通过程序方式下达买卖订单。订单部分后续。作者声明:仅供用于学习和研究,欢迎交流和探讨。转载请须注明出处。"""importosimporttimeimportdatetimeimportpandasaspdimportmultiprocessingimportloggingfromxtquantimportxtdatafromcoloramaimportFore,init股票代码eq:600150._price=stock_price止盈/止损的数量_pl_status=False退出循环以防止进程崩溃classStopPLManager:def__init__(self,file_path_):_path=file_path_csv文件的最后修改时间_processes={}检查并打印当前进程状态_market_closed():当前csv文件的修改时间_file_changed(current_modified_time):更新最后修改时间_orders_from_file()定时检测csv文件并处理defcheck_process_status(self):"""检查并打印当前进程状态"""(f"现有进程:{_processes}")defis_market_closed(self):"""检查市场是否关闭"""dt=()设置目标时间()=target_time读取止盈/止损订单:去重处理_orders(unique_orders)没有订单,停止所有进程defprocess_orders(self,unique_orders):终止所有进程检查现有进程表,对指令单中已不存在的股票代码,需要终止其进程current_stock_codes=set(unique_orders['stock_code'].values)forstock_codeinlist(_()):ifstock_codenotincurrent_stock_codes:指定止盈/止损指令单CSV文件路径,文件格式stock_code,stock_price,stock_quantitymanager=StopPLManager(file_path)()

Copyright © 2002-2030 金宝理财网理财品牌排行-理财产品怎么买合适-金宝理财网 sitemap.xml