| | |
| | | from huaxin_client import l2_data_manager |
| | | import lev2mdapi |
| | | from huaxin_client.command_manager import L2ActionCallback |
| | | from log_module import log |
| | | from log_module import log, async_log_util |
| | | from log_module.log import logger_local_huaxin_l2_subscript, logger_system, logger_local_huaxin_l2_transaction, \ |
| | | logger_local_huaxin_g_cancel, logger_l2_codes_subscript |
| | | |
| | |
| | | if transaction_big_order_nos and pTransaction['BuyNo'] in transaction_big_order_nos: |
| | | # 正在成交的订单撤单了 |
| | | l2_data_manager.trading_order_canceled(code, pTransaction['BuyNo']) |
| | | logger_local_huaxin_g_cancel.info(f"G撤撤单:{code} - {pTransaction['BuyNo']}") |
| | | async_log_util.info(logger_local_huaxin_g_cancel, f"G撤撤单:{code} - {pTransaction['BuyNo']}") |
| | | if min_volume is None: |
| | | # 默认筛选50w |
| | | if pTransaction['TradePrice'] * pTransaction['Volume'] < 500000: |
| | |
| | | if transaction_big_order_nos and pOrderDetail['OrderNO'] in transaction_big_order_nos: |
| | | # 正在成交的订单撤单了 |
| | | l2_data_manager.trading_order_canceled(code, pOrderDetail['OrderNO']) |
| | | logger_local_huaxin_g_cancel.info(f"G撤撤单:{code} - {pOrderDetail['OrderNO']}") |
| | | async_log_util.info(logger_local_huaxin_g_cancel, f"G撤撤单:{code} - {pOrderDetail['OrderNO']}") |
| | | |
| | | min_volume, limit_up_price = self.codes_volume_and_price_dict.get(code) |
| | | if min_volume is None: |
| | |
| | | # 买 |
| | | try: |
| | | req_rid_dict[sinfo] = (client_id, request_id, sk, local_order_id) |
| | | self.__tradeSimpleApi.buy(code, volume, price, sinfo) |
| | | |
| | | threading.Thread(target=lambda: self.__tradeSimpleApi.buy(code, volume, price, sinfo), |
| | | daemon=True).start() |
| | | except Exception as e: |
| | | send_response(json.dumps({"code": 1, "msg": str(e)}), TYPE_ORDER, client_id, |
| | | request_id) |
| | |
| | | cls.unreal_buy_dict.pop(code) |
| | | |
| | | @classmethod |
| | | def set_real_place_order_index(cls, code, index,buy_single_index): |
| | | cancel_buy_strategy.set_real_place_position(code, index,buy_single_index) |
| | | def set_real_place_order_index(cls, code, index, buy_single_index): |
| | | cancel_buy_strategy.set_real_place_position(code, index, buy_single_index) |
| | | |
| | | # 处理华鑫L2数据 |
| | | @classmethod |
| | |
| | | _start_index = total_datas[-1]["index"] + 1 |
| | | datas = l2_huaxin_util.get_format_l2_datas(code, origin_datas, |
| | | gpcode_manager.get_limit_up_price(code), _start_index) |
| | | try: |
| | | # 获取下单位置 |
| | | place_order_index = huaxin_delegate_postion_manager.get_l2_place_order_position(code, datas) |
| | | if place_order_index: |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos( |
| | | code) |
| | | cls.set_real_place_order_index(code, place_order_index, buy_single_index) |
| | | async_log_util.info(logger_l2_process, "code:{} 获取到下单真实位置:{}", code, place_order_index) |
| | | except: |
| | | logger_l2_error.exception(f"{code} 处理真实下单位置出错") |
| | | |
| | | __start_time = round(t.time() * 1000) |
| | | if len(datas) > 0: |
| | | cls.process_add_datas(code, datas, 0, __start_time) |
| | |
| | | local_today_datas[code].extend(add_datas) |
| | | l2.l2_data_util.load_num_operate_map(local_today_num_operate_map, code, add_datas) |
| | | l2.l2_data_util.load_buy_no_map(local_today_buyno_map, code, add_datas) |
| | | |
| | | if constant.L2_SOURCE_TYPE == constant.L2_SOURCE_TYPE_HUAXIN: |
| | | try: |
| | | # 获取下单位置 |
| | | place_order_index = huaxin_delegate_postion_manager.get_l2_place_order_position(code, add_datas) |
| | | if place_order_index: |
| | | buy_single_index, buy_exec_index, buy_compute_index, num, count, max_num_set, buy_volume_rate = cls.__get_order_begin_pos( |
| | | code) |
| | | cls.set_real_place_order_index(code, place_order_index, buy_single_index) |
| | | async_log_util.info(logger_l2_process, "code:{} 获取到下单真实位置:{}", code, place_order_index) |
| | | except: |
| | | logger_l2_error.exception(f"{code} 处理真实下单位置出错") |
| | | # 第1条数据是否为09:30:00 |
| | | if add_datas[0]["val"]["time"] == "09:30:00": |
| | | if global_util.cuurent_prices.get(code): |
| | |
| | | |
| | | # 依次处理 |
| | | cancel_data, cancel_msg = s_cancel(buy_single_index, buy_exec_index) |
| | | # if not cancel_data: |
| | | # cancel_data, cancel_msg = h_cancel(buy_single_index, buy_exec_index) |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = l_cancel(buy_single_index, buy_exec_index) |
| | | |
| | | if not cancel_data: |
| | | cancel_data, cancel_msg = h_cancel(buy_single_index, buy_exec_index) |
| | | # l2_log.debug(code, "撤单计算结束") |
| | | # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, |
| | | # "已下单-撤单 判断是否需要撤单") |
| | |
| | | return False |
| | | finally: |
| | | pass |
| | | |
| | | |
| | | @classmethod |
| | | def cancel_buy(cls, code, msg=None, source="l2"): |
| | |
| | | hx_logger_trade_debug.info(f"获取交易数据开始:{type_}") |
| | | try: |
| | | if type_ == "delegate_list": |
| | | dataJSON = huaxin_trade_api.get_delegate_list(can_cancel=False) |
| | | dataJSON = huaxin_trade_api.get_delegate_list(can_cancel=False, timeout=10) |
| | | print("获取委托列表", dataJSON) |
| | | if dataJSON["code"] == 0: |
| | | data = dataJSON["data"] |
| | |
| | | d['orderSysID'], |
| | | d['insertTime']) |
| | | if new_place_order_index: |
| | | cancel_buy_strategy.set_real_place_position(d['securityID'], new_place_order_index) |
| | | cancel_buy_strategy.set_real_place_position(d['securityID'], |
| | | new_place_order_index) |
| | | |
| | | |
| | | elif huaxin_util.is_canceled(d["orderStatus"]) or huaxin_util.is_deal(d["orderStatus"]): |
| | | elif huaxin_util.is_canceled(d["orderStatus"]) or huaxin_util.is_deal( |
| | | d["orderStatus"]): |
| | | # 已经撤单/已经成交,需要处理临时保存的系统订单号 |
| | | TradeOrderIdManager().remove_order_id(d['securityID'], |
| | | d['accountID'], |
| | |
| | | # 获取撤销比例 |
| | | @staticmethod |
| | | def get_cancel_rate(volume_rate_index): |
| | | rates = [0.35, 0.45, 0.55, 0.65, 0.65, 0.75, 0.75, 0.75] |
| | | if volume_rate_index >= len(rates): |
| | | volume_rate_index = -1 |
| | | return rates[volume_rate_index] |
| | | # 暂时固定死 |
| | | # rates = [0.35, 0.45, 0.55, 0.65, 0.65, 0.75, 0.75, 0.75] |
| | | # if volume_rate_index >= len(rates): |
| | | # volume_rate_index = -1 |
| | | # return rates[volume_rate_index] |
| | | return 0.89 |
| | | |
| | | |
| | | class L2TradeFactorUtil: |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | export_l2_excel("002207") |
| | | export_l2_excel("600360", date="2023-09-11") |