| | |
| | | from third_data.kpl_data_manager import KPLDataManager |
| | | from third_data.kpl_limit_up_data_manager import CodeLimitUpSequenceManager |
| | | from third_data.kpl_util import KPLDataType |
| | | from trade import trade_manager, l2_trade_util, trade_data_manager |
| | | from trade import trade_manager, l2_trade_util, trade_data_manager, trade_constant |
| | | import l2_data_util as l2_data_util_old |
| | | |
| | | from trade.huaxin import huaxin_trade_api, huaxin_trade_data_update, \ |
| | |
| | | msg_list.append(f"撤卖单数量:{sell_count}") |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | can_cancel = l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动撤单") |
| | | can_cancel = l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动撤单", cancel_type=trade_constant.CANCEL_TYPE_HUMAN) |
| | | if not can_cancel: |
| | | msg_list.append(f"无法撤买单") |
| | | else: |
| | |
| | | if operate == outside_api_command_manager.OPERRATE_SET: |
| | | # 先手动撤单 |
| | | try: |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动拉黑") |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动拉黑", cancel_type=trade_constant.CANCEL_TYPE_HUMAN) |
| | | except Exception as e: |
| | | logger_debug.exception(e) |
| | | l2_trade_util.forbidden_trade(code, msg="手动加入 trade_server") |
| | |
| | | def cancel_order(code_): |
| | | try: |
| | | l2.l2_data_util.load_l2_data(code_, True) |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code_, "手动撤销") |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code_, "手动撤销", cancel_type= trade_constant.CANCEL_TYPE_HUMAN) |
| | | showinfo("提示", "撤单成功") |
| | | except Exception as e: |
| | | showwarning("提示", "撤单成功异常" + str(e)) |
| | |
| | | try: |
| | | cancel_result = cancel_buy_strategy.FCancelBigNumComputer().need_cancel_for_deal_fast(code) |
| | | if cancel_result[0]: |
| | | L2TradeDataProcessor.cancel_buy(code, f"F撤:{cancel_result[1]}") |
| | | L2TradeDataProcessor.cancel_buy(code, f"F撤:{cancel_result[1]}", cancel_type=trade_constant.CANCEL_TYPE_F) |
| | | else: |
| | | l2_log.f_cancel_debug(code, f"获取真实成交位的F撤未生效:{cancel_result[1]}") |
| | | except Exception as e: |
| | |
| | | # 默认量为0.2 |
| | | if order_begin_pos.buy_volume_rate is None: |
| | | order_begin_pos.buy_volume_rate = 0.2 |
| | | cancel_data, cancel_msg = None, "" |
| | | cancel_data, cancel_msg, cancel_type = None, "", None |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = g_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | cancel_type = trade_constant.CANCEL_TYPE_G |
| | | # 依次处理 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = l_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | cancel_type = trade_constant.CANCEL_TYPE_L |
| | | # B撤 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = b_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | cancel_type = trade_constant.CANCEL_TYPE_G |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = h_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | cancel_type = trade_constant.CANCEL_TYPE_H |
| | | # J撤 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = j_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | cancel_type = trade_constant.CANCEL_TYPE_J |
| | | |
| | | if cancel_data and not DCancelBigNumComputer().has_auto_cancel_rules(code): |
| | | l2_log.debug(code, "触发撤单,撤单位置:{} ,撤单原因:{}", cancel_data["index"], cancel_msg) |
| | | # 撤单 |
| | | cls.cancel_buy(code, cancel_msg, cancel_index=cancel_data["index"]) |
| | | cls.cancel_buy(code, cancel_msg, cancel_index=cancel_data["index"], cancel_type=cancel_type) |
| | | # 撤单成功,继续计算下单 |
| | | cls.__process_not_order(code, cancel_data["index"] + 1, end_index, capture_time, is_first_code) |
| | | else: |
| | |
| | | pass |
| | | |
| | | @classmethod |
| | | def cancel_buy(cls, code, msg=None, source="l2", cancel_index=None): |
| | | def cancel_buy(cls, code, msg=None, source="l2", cancel_index=None, cancel_type=None): |
| | | # 是否是交易队列触发 |
| | | order_begin_pos = cls.__get_order_begin_pos( |
| | | code) |
| | | # 激进下单只有L撤能撤单 |
| | | if order_begin_pos and order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL and cancel_type not in {trade_constant.CANCEL_TYPE_L,trade_constant.CANCEL_TYPE_L_UP, trade_constant.CANCEL_TYPE_L_DOWN}: |
| | | return False |
| | | |
| | | total_datas = local_today_datas.get(code) |
| | | if not total_datas: |
| | | return False |
| | |
| | | from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager, BigOrderDealManager |
| | | from log_module import async_log_util |
| | | from log_module.log import hx_logger_l2_debug, logger_l2_trade_buy_queue, logger_debug, hx_logger_l2_upload |
| | | from trade import current_price_process_manager |
| | | from trade import current_price_process_manager, trade_constant |
| | | import concurrent.futures |
| | | |
| | | from utils import tool |
| | |
| | | need_cancel, cancel_msg = SCancelBigNumComputer().set_big_sell_order_info_for_cancel(code, |
| | | big_sell_order_info, |
| | | order_begin_pos) |
| | | cancel_type = None |
| | | if need_cancel: |
| | | cancel_msg = f"S撤:{cancel_msg}" |
| | | cancel_type = trade_constant.CANCEL_TYPE_S |
| | | if not need_cancel: |
| | | need_cancel, cancel_msg = FCancelBigNumComputer().need_cancel_for_p(code, |
| | | order_begin_pos) |
| | | cancel_type = trade_constant.CANCEL_TYPE_F |
| | | # 判断时间是否与本地时间相差5s以上 |
| | | if tool.trade_time_sub(tool.get_now_time_str(), l2_huaxin_util.convert_time(datas[-1][3])) > 10: |
| | | now_seconds = int(tool.get_now_time_str().replace(":", "")) |
| | | if now_seconds < int("093200"): # or int("130000") <= now_seconds < int("130200"): |
| | | need_cancel, cancel_msg = True, f"成交时间与本地时间相差10S以上,{l2_huaxin_util.convert_time(datas[-1][3])}" |
| | | cancel_type = trade_constant.CANCEL_TYPE_L2_DELAY |
| | | if need_cancel: |
| | | L2TradeDataProcessor.cancel_buy(code, cancel_msg) |
| | | L2TradeDataProcessor.cancel_buy(code, cancel_msg, cancel_type=cancel_type) |
| | | |
| | | # GCancelBigNumComputer().set_big_sell_order_info(code, big_sell_order_info) |
| | | use_time_list.append(("处理卖单相关撤数据", time.time() - _start_time)) |
| | |
| | | total_datas) |
| | | cancel_result = FCancelBigNumComputer().need_cancel_for_deal_fast(code, buy_progress_index) |
| | | if cancel_result[0]: |
| | | L2TradeDataProcessor.cancel_buy(code, f"F撤:{cancel_result[1]}") |
| | | L2TradeDataProcessor.cancel_buy(code, f"F撤:{cancel_result[1]}", |
| | | cancel_type=trade_constant.CANCEL_TYPE_F) |
| | | if not cancel_result[0]: |
| | | try: |
| | | cancel_result = NBCancelBigNumComputer().need_cancel(code, buy_progress_index) |
| | | if cancel_result[0]: |
| | | L2TradeDataProcessor.cancel_buy(code, f"大市值无大单撤:{cancel_result[1]}") |
| | | L2TradeDataProcessor.cancel_buy(code, f"大市值无大单撤:{cancel_result[1]}", |
| | | cancel_type=trade_constant.CANCEL_TYPE_NB) |
| | | except: |
| | | pass |
| | | |
| | |
| | | try: |
| | | cancel_result = FCancelBigNumComputer().need_cancel_for_w(code) |
| | | if cancel_result[0]: |
| | | L2TradeDataProcessor.cancel_buy(code, f"W撤:{cancel_result[1]}") |
| | | L2TradeDataProcessor.cancel_buy(code, f"W撤:{cancel_result[1]}", cancel_type=trade_constant.CANCEL_TYPE_W) |
| | | except: |
| | | pass |
| | | |
| | |
| | | state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code) |
| | | if state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or state == trade_constant.TRADE_STATE_BUY_DELEGATED or state == trade_constant.TRADE_STATE_BUY_CANCEL_ING: |
| | | try: |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动撤销") |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动撤销", cancel_type=trade_constant.CANCEL_TYPE_HUMAN) |
| | | return_str = json.dumps({"code": 0}) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | |
| | | need_cancel, rule_id = DCancelBigNumComputer().need_cancel(code, buy_1_volume) |
| | | if need_cancel: |
| | | try: |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, f"盯封单撤:{time_str}-{buy_1_volume}") |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, f"盯封单撤:{time_str}-{buy_1_volume}", cancel_type=trade_constant.CANCEL_TYPE_D) |
| | | finally: |
| | | TradeRuleManager().excuted(rule_id) |
| | | except Exception as e: |
| | |
| | | state = trade_manager.CodesTradeStateManager().get_trade_state(code) |
| | | if state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or state == trade_constant.TRADE_STATE_BUY_DELEGATED or state == trade_constant.TRADE_STATE_BUY_CANCEL_ING: |
| | | try: |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动撤销") |
| | | l2_data_manager_new.L2TradeDataProcessor.cancel_buy(code, "手动撤销", cancel_type=trade_constant.CANCEL_TYPE_HUMAN) |
| | | return_str = json.dumps({"code": 0}) |
| | | except Exception as e: |
| | | return_str = json.dumps({"code": 2, "msg": str(e)}) |
| | |
| | | TRADE_STATE_BUY_CANCEL_SUCCESS = 14 |
| | | # 买成功 |
| | | TRADE_STATE_BUY_SUCCESS = 12 |
| | | |
| | | |
| | | # 人工撤单 |
| | | CANCEL_TYPE_HUMAN = 20 |
| | | # F撤 |
| | | CANCEL_TYPE_F = 1 |
| | | # H撤 |
| | | CANCEL_TYPE_H = 2 |
| | | |
| | | CANCEL_TYPE_L = 3 |
| | | |
| | | # L前 |
| | | CANCEL_TYPE_L_UP = 31 |
| | | # L后 |
| | | CANCEL_TYPE_L_DOWN = 32 |
| | | # G撤单 |
| | | CANCEL_TYPE_G = 5 |
| | | # S撤 |
| | | CANCEL_TYPE_S = 6 |
| | | # S快 |
| | | CANCEL_TYPE_S_FAST = 61 |
| | | # S慢 |
| | | CANCEL_TYPE_S_SLOW = 62 |
| | | |
| | | # J撤 |
| | | CANCEL_TYPE_J = 7 |
| | | |
| | | # L2延迟 |
| | | CANCEL_TYPE_L2_DELAY = 8 |
| | | |
| | | # 大市值无大单 |
| | | CANCEL_TYPE_NB = 9 |
| | | |
| | | # W撤 |
| | | CANCEL_TYPE_W = 10 |
| | | |
| | | # D撤 |
| | | CANCEL_TYPE_D = 11 |