| | |
| | | RedisUtils.setex_async(self.__db, f"l_cancel_real_place_order_index-{code}", tool.get_expire(), index) |
| | | if buy_single_index is not None: |
| | | if code in self.__last_trade_progress_dict: |
| | | # L撤从成交进度位开始计算 |
| | | self.compute_watch_index(code, buy_single_index, |
| | | max(buy_single_index, self.__last_trade_progress_dict[code] + 1), index) |
| | | self.__last_trade_progress_dict[code], index) |
| | | else: |
| | | self.compute_watch_index(code, buy_single_index, buy_single_index, index) |
| | | |
| | |
| | | |
| | | return False, None, "" |
| | | |
| | | def place_order_success(self, code): |
| | | self.clear(code) |
| | | # B撤单 |
| | | # 剩余一个大单撤半截就撤单 |
| | | def need_cancel_for_b(self, code, start_index, end_index): |
| | | real_place_order_info = self.__real_place_order_index_dict.get(code) |
| | | if not real_place_order_info or real_place_order_info[1]: |
| | | # 没有真实下单位置 |
| | | return False, None, "没有真实下单位置" |
| | | trade_index, is_default = TradeBuyQueue().get_traded_index(code) |
| | | if trade_index is None: |
| | | return False,None, "未获取到成交进度位" |
| | | total_datas = local_today_datas.get(code) |
| | | buyno_map = local_today_buyno_map.get(code) |
| | | cancel_half_index = None |
| | | for i in range(start_index, end_index + 1): |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | if not L2DataUtil.is_limit_up_price_buy_cancel(val): |
| | | continue |
| | | orderNo = val['orderNo'] |
| | | buy_data = buyno_map.get(f"{orderNo}") |
| | | if not buy_data: |
| | | continue |
| | | # 判断大单 |
| | | if buy_data["val"]["num"] * float(buy_data["val"]["price"]) < 29900: |
| | | continue |
| | | # 判断是否撤半截 |
| | | if buy_data["val"]["num"] > val["num"]: |
| | | cancel_half_index = i |
| | | break |
| | | if cancel_half_index is None: |
| | | return False,None, "没有撤半截" |
| | | # 有大单撤半截桩 |
| | | # 计算是否还剩下大单 |
| | | total_big_num_count = 0 |
| | | for i in range(trade_index, real_place_order_info[0]): |
| | | data = total_datas[i] |
| | | val = data['val'] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | if val["num"] * float(val["price"]) < 29900: |
| | | continue |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, i, |
| | | total_datas, |
| | | local_today_canceled_buyno_map.get( |
| | | code)) |
| | | if left_count > 0: |
| | | total_big_num_count += 1 |
| | | break |
| | | if total_big_num_count == 0: |
| | | # 没有剩下大单 |
| | | return True, total_datas[cancel_half_index], f"B撤:撤单索引-{cancel_half_index}" |
| | | return False, None, "还有大单没撤单" |
| | | |
| | | def cancel_success(self, code): |
| | | self.clear(code) |
| | | |
| | | def place_order_success(self, code): |
| | | self.clear(code) |
| | | |
| | | |
| | | def cancel_success(self, code): |
| | | self.clear(code) |
| | | |
| | | |
| | | # ---------------------------------独苗撤------------------------------- |
| | |
| | | LCancelBigNumComputer, LatestCancelIndexManager, LCancelRateManager, GCancelBigNumComputer |
| | | from l2.l2_data_manager import L2DataException, OrderBeginPosInfo |
| | | from l2.l2_data_util import local_today_datas, L2DataUtil, local_today_num_operate_map, local_today_buyno_map, \ |
| | | local_latest_datas, local_today_canceled_buyno_map,local_today_sellno_map |
| | | local_latest_datas, local_today_canceled_buyno_map, local_today_sellno_map |
| | | import l2.l2_data_util |
| | | from log_module.log import logger_l2_trade_buy, logger_l2_process, logger_l2_error, logger_debug, \ |
| | | logger_l2_not_buy_reasons, logger_real_place_order_position |
| | |
| | | pass |
| | | return None, "" |
| | | |
| | | # B撤 |
| | | def b_cancel(_buy_single_index, _buy_exec_index): |
| | | try: |
| | | b_need_cancel, b_cancel_data, extra_msg = cls.__GCancelBigNumComputer.need_cancel_for_b(code, |
| | | start_index, |
| | | end_index) |
| | | if b_need_cancel and b_cancel_data: |
| | | return b_cancel_data, f"G撤({extra_msg})" |
| | | except Exception as e: |
| | | async_log_util.error(logger_l2_error, |
| | | f"B撤出错 参数:buy_single_index-{_buy_single_index} buy_exec_index-{_buy_exec_index} 错误原因:{str(e)}") |
| | | return None, "" |
| | | |
| | | if start_index < 0: |
| | | start_index = 0 |
| | | |
| | |
| | | cancel_data, cancel_msg = None, "" |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = g_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | |
| | | # 依次处理 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = l_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | # 暂时取消S撤 |
| | | # if not cancel_data: |
| | | # cancel_data, cancel_msg = s_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | # B撤 |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = b_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = h_cancel(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | 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"]) |
| | | # 撤单成功,继续计算下单 |
| | |
| | | from trade.huaxin import huaxin_trade_api |
| | | from utils import tool |
| | | from db import redis_manager_delegate as redis_manager |
| | | from l2 import l2_log, l2_data_manager, transaction_progress, l2_data_manager_new, l2_transaction_data_processor |
| | | from l2 import l2_log, l2_data_manager, transaction_progress, l2_data_manager_new, l2_transaction_data_processor, \ |
| | | cancel_buy_strategy |
| | | from l2.transaction_progress import TradeBuyQueue |
| | | from third_data import kpl_util, kpl_data_manager, block_info |
| | | from third_data.code_plate_key_manager import LimitUpCodesPlateKeyManager, CodePlateKeyBuyManager |
| | |
| | | l2.l2_data_manager_new.L2TradeDataProcessor.process_add_datas(code, total_datas[indexs[0]:indexs[1] + 1], 0, |
| | | 0) |
| | | |
| | | @unittest.skip("跳过此单元测试") |
| | | def test_s_cancel(self): |
| | | code = "603363" |
| | | l2.l2_data_util.load_l2_data(code) |
| | |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reason_codes_dict()) |
| | | # l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first(code, None) |
| | | |
| | | @unittest.skip("跳过此单元测试") |
| | | def test_add_transaction_orders(self): |
| | | code = "603359" |
| | | date = "2024-03-14" |
| | |
| | | for d in datas: |
| | | big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, d) |
| | | |
| | | def test_b_cancel(self): |
| | | code = "603032" |
| | | l2.l2_data_util.load_l2_data(code) |
| | | total_datas = l2.l2_data_util.local_today_datas.get(code) |
| | | TradeBuyQueue.get_traded_index = mock.Mock(return_value=(1000, False)) |
| | | cancel_buy_strategy.GCancelBigNumComputer().set_real_place_order_index(code, 1015, 10000, False) |
| | | cancel_buy_strategy.GCancelBigNumComputer().set_trade_progress(code, 1000, 1000) |
| | | result = cancel_buy_strategy.GCancelBigNumComputer().need_cancel_for_b(code, 1020, 1077) |
| | | print(result) |
| | | |
| | | @unittest.skip("跳过此单元测试") |
| | | def test_transaction(self): |
| | | threading.Thread(target=async_log_util.run_sync, daemon=True).start() |