| | |
| | | from huaxin_client import socket_util |
| | | from huaxin_client.client_network import SendResponseSkManager |
| | | from log_module import async_log_util |
| | | from log_module.log import logger_local_huaxin_trade_debug, logger_trade |
| | | from log_module.log import logger_local_huaxin_trade_debug, logger_trade, logger_local_huaxin_contact_debug |
| | | |
| | | MSG_TYPE_HEART = "heart" |
| | | # 命令信息 |
| | |
| | | |
| | | @classmethod |
| | | def process_command(cls, _type, client_id, result_json, sk=None): |
| | | async_log_util.info(logger_local_huaxin_contact_debug, f"process_command: {result_json}") |
| | | # 查看是否是设置L2的代码 |
| | | if _type == CLIENT_TYPE_CMD_L2: |
| | | cls.pipe_l2.send( |
| | |
| | | elif _type == "test": |
| | | cls.action_callback.OnTest(client_id, request_id, data, sk) |
| | | except Exception as e: |
| | | logger_local_huaxin_trade_debug.debug(f"process_command出错:{result_json}") |
| | | logging.exception(e) |
| | | logging.error(result_json) |
| | | async_log_util.error(logger_local_huaxin_contact_debug, f"process_command出错: {result_json}") |
| | | # logging.exception(e) |
| | | # logging.error(result_json) |
| | | |
| | | @classmethod |
| | | def run_process_command(cls, queue_strategy_trade: multiprocessing.Queue): |
| | |
| | | val = queue_strategy_trade.get() |
| | | if val: |
| | | _type = val["type"] |
| | | async_log_util.info(logger_local_huaxin_contact_debug, f"接受到信息: {_type}") |
| | | cls.process_command_thread_pool.submit(lambda: cls.process_command(_type, None, val)) |
| | | except Exception as e: |
| | | async_log_util.exception(logger_local_huaxin_trade_debug, e) |
| | |
| | | return False, True, f"股价大于{constant.MAX_CODE_PRICE}块" |
| | | |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN: |
| | | total_data = local_today_datas.get(code) |
| | | trade_price = current_price_process_manager.get_trade_price(code) |
| | | if trade_price is None: |
| | | return False, True, f"尚未获取到当前成交价" |
| | | if float(limit_up_price) - float(trade_price) > 0.00001: |
| | | return False, False, f"当前成交价({trade_price})尚未在0档及以内" |
| | | |
| | | # 计算信号起始位置到当前的手数 |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos(code) |
| | | num_operate_map = local_today_num_operate_map.get(code) |
| | | total_num = 0 |
| | | for i in range(buy_single_index, total_data[-1]["index"] + 1): |
| | | data = total_data[i] |
| | | val = data["val"] |
| | | if not L2DataUtil.is_limit_up_price_buy(val): |
| | | continue |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count(code, |
| | | data["index"], |
| | | total_data, |
| | | num_operate_map) |
| | | total_num += left_count * val["num"] |
| | | m_base_val = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code) |
| | | thresh_hold_num = m_base_val//(float(gpcode_manager.get_limit_up_price(code))*100) |
| | | if total_num < thresh_hold_num * 2: |
| | | return False, False, f"当前成交价({trade_price})尚未在0档及以内 且 纯买额({total_num})小于2倍M值({thresh_hold_num*2})" |
| | | # 判断成交进度是否距离我们的位置很近 |
| | | total_data = local_today_datas.get(code) |
| | | trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code) |
| | | if False and not is_default and trade_index: |
| | | not_cancel_num = 0 |
| | |
| | | if not sinfo: |
| | | sinfo = f"cb_{code}_{round(time.time() * 1000)}_{random.randint(0, 10000)}" |
| | | order_action_ref = huaxin_util.create_order_ref() |
| | | if not request_id: |
| | | request_id = __get_request_id(ClientSocketManager.CLIENT_TYPE_TRADE) |
| | | # 执行2次撤单,防止没有撤到 |
| | | for i in range(2): |
| | | request_id = __request(ClientSocketManager.CLIENT_TYPE_TRADE, |
| | | {"type": ClientSocketManager.CLIENT_TYPE_TRADE, "trade_type": 2, |
| | | "direction": direction, |
| | |
| | | |
| | | from code_attribute import big_money_num_manager, limit_up_time_manager, global_data_loader, gpcode_manager |
| | | import constant |
| | | from trade import trade_manager |
| | | from utils import global_util, tool |
| | | |
| | | |
| | |
| | | self.now_time = now_time |
| | | self.buy_rank = self.get_buy_rank() |
| | | |
| | | # 是否是初次下单 |
| | | @classmethod |
| | | def is_first_place_order(cls, code): |
| | | return trade_manager.CodesTradeStateManager().get_trade_state_cache(code) == trade_manager.TRADE_STATE_NOT_TRADE |
| | | |
| | | # 设置分数 |
| | | def set_score(self, score): |
| | | score_ranks = [constant.BUY_SCORE_RANK_3, constant.BUY_SCORE_RANK_2, constant.BUY_SCORE_RANK_1, |
| | |
| | | volume_rate_index = self.volume_rate_index |
| | | if self.volume_rate_index >= len(ts): |
| | | volume_rate_index = -1 |
| | | # 首次下单必须同1s |
| | | if self.is_first_place_order(self.code): |
| | | return 1 |
| | | return ts[volume_rate_index] |
| | | |
| | | # 获取需要的大单个数 |
| | |
| | | volume_rate_index = self.volume_rate_index |
| | | if self.volume_rate_index >= len(counts): |
| | | volume_rate_index = -1 |
| | | # 第一次下单必须为2个 |
| | | if self.is_first_place_order(self.code): |
| | | return 2 |
| | | return counts[volume_rate_index] |
| | | |
| | | # 获取安全笔数影响比例 |
| | |
| | | # 获取m值 |
| | | def get_m_val(self): |
| | | base_m = self.get_base_m_val(self.code) |
| | | if self.is_first_place_order(self.code): |
| | | base_m = int(base_m * 1.5) |
| | | rate = self.get_m_val_rate(self.volume_rate_index) |
| | | m = round(base_m * (1 + rate)) |
| | | return m, "" |