| | |
| | | # 守护30s以外的数据 |
| | | if time_space <= constant.S_CANCEL_EXPIRE_TIME: |
| | | return False, None |
| | | l2_log.cancel_debug(code, "H级是否需要撤单,数据范围:{}-{} ", start_index, end_index) |
| | | # 获取成交进度 |
| | | origin_progress_index, latest_progress_index = self.__get_traded_progress_cache(code) |
| | | if latest_progress_index is None: |
| | | latest_progress_index = -1 |
| | | # 监听的数据 |
| | | watch_indexs_dict = {} |
| | | if start_index >= 1956: |
| | | print("进入测试") |
| | | # 初始化为1防止分母为0 |
| | | total_nums = 1 |
| | | if origin_progress_index is not None: |
| | |
| | | |
| | | processed_index, cancel_num = self.__get_compute_data_cache(code) |
| | | |
| | | l2_log.cancel_debug(code, "H级是否需要撤单,数据范围:{}-{} ", start_index, end_index) |
| | | |
| | | # 获取下单次数 |
| | | cancel_rate_threshold = self.__hCancelParamsManager.get_cancel_rate(volume_index) |
| | | process_index = start_index |
| | |
| | | val = data["val"] |
| | | if L2DataUtil.is_limit_up_price_buy_cancel(val): |
| | | # 查询买入位置 |
| | | l2_log.cancel_debug(code,"查询买入位置开始:{}",i) |
| | | buy_index = l2_data_source_util.L2DataSourceUtils.get_buy_index_with_cancel_data(code, data, |
| | | local_today_num_operate_map) |
| | | l2_log.cancel_debug(code, "查询买入位置结束:{}",i) |
| | | if buy_index is not None and buy_index in watch_indexs_dict: |
| | | has_watch_canceled = True |
| | | cancel_num += data["re"] * val["num"] |
| | |
| | | def get_buy_index_with_cancel_data(cls, code, cancel_data, local_today_num_operate_map): |
| | | key = "{}-{}-{}".format(cancel_data["val"]["num"], "1", cancel_data["val"]["price"]) |
| | | cancel_datas = local_today_num_operate_map.get(key) |
| | | try: |
| | | cancel_datas.sort(key=lambda t: t["index"]) |
| | | except Exception as e: |
| | | print("测试") |
| | | for item in cancel_datas: |
| | | # 提前做计算 |
| | | cls.__get_buy_index_with_cancel_data(code, item, local_today_num_operate_map) |
| | | if cancel_datas: |
| | | try: |
| | | cancel_datas.sort(key=lambda t: t["index"]) |
| | | except Exception as e: |
| | | print("测试") |
| | | for item in cancel_datas: |
| | | # 提前做计算 |
| | | cls.__get_buy_index_with_cancel_data(code, item, local_today_num_operate_map) |
| | | |
| | | return cls.__get_buy_index_with_cancel_data(code, cancel_data, local_today_num_operate_map) |
| | | |
| | |
| | | RedisUtils.realse(redis) |
| | | |
| | | |
| | | __CodesTradeStateManager = CodesTradeStateManager() |
| | | |
| | | |
| | | # 开始交易 |
| | | def start_buy(code, capture_timestamp, last_data, last_data_index): |
| | | # @dask.delayed |
| | |
| | | |
| | | # @dask.delayed |
| | | def is_state_right(code): |
| | | trade_state = CodesTradeStateManager().get_trade_state_cache(code) |
| | | trade_state = __CodesTradeStateManager.get_trade_state_cache(code) |
| | | if trade_state != TRADE_STATE_NOT_TRADE and trade_state != TRADE_STATE_BUY_CANCEL_SUCCESS and trade_state != TRADE_STATE_BUY_CANCEL_ING: |
| | | return Exception("代码处于不可交易状态"), trade_state |
| | | return None, trade_state |
| | |
| | | |
| | | print("开始买入") |
| | | logger_trade.info("{}开始买入".format(code)) |
| | | CodesTradeStateManager().set_trade_state(code, TRADE_STATE_BUY_PLACE_ORDER) |
| | | __CodesTradeStateManager.set_trade_state(code, TRADE_STATE_BUY_PLACE_ORDER) |
| | | # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "买入判断时间", force=True) |
| | | __buy(code, price, trade_state, capture_timestamp, last_data, last_data_index) |
| | | # l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "异步买入时间", force=True) |
| | |
| | | def __place_order_success(code, capture_timestamp, last_data, last_data_index): |
| | | # 买入结束点 |
| | | use_time = round(time.time() * 1000) - capture_timestamp |
| | | logger_trade.info("{}-从截图到下单成功总费时:{}".format(code, use_time)) |
| | | # 下单成功,加入固定代码库 |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_THS: |
| | | l2_data_manager.add_to_l2_fixed_codes(code) |