| | |
| | | """ |
| | | import time |
| | | |
| | | from l2.l2_data_util import L2DataUtil |
| | | from log_module import async_log_util |
| | | from log_module.log import hx_logger_trade_debug, logger_real_place_order_position |
| | | |
| | |
| | | |
| | | |
| | | # 下单 |
| | | def place_order(code, price, volume, exec_index): |
| | | def place_order(code, price, volume, data): |
| | | async_log_util.info(logger_real_place_order_position, |
| | | f"下单:code-{code} price-{price} volume-{volume} exec-index-{exec_index}") |
| | | _place_order_info_dict[code] = (price, volume, exec_index, time.time()) |
| | | f"下单:code-{code} price-{price} volume-{volume} exec-index-{data['index']}") |
| | | _place_order_info_dict[code] = (price, volume, data, time.time()) |
| | | |
| | | |
| | | # 获取下单信息 |
| | |
| | | return None |
| | | price = order_info[0] |
| | | volume = order_info[1] |
| | | exec_index = order_info[2] |
| | | exec_data = order_info[2] |
| | | # 获取量 |
| | | is_sz = code.startswith("00") |
| | | # 提交到交易所的时间预估 |
| | | min_space_time_ms = 10 if is_sz else 40 |
| | | for d in datas: |
| | | if d["val"]["num"] != volume // 100: |
| | | continue |
| | | if abs(float(price) - float(d["val"]["price"])) >= 0.01: |
| | | continue |
| | | # 不可能比下单执行位置还早 |
| | | if d["index"] <= exec_index: |
| | | if d["index"] <= exec_data["index"]: |
| | | continue |
| | | # 时间差不能小于预估下单用时 |
| | | if L2DataUtil.time_sub_as_ms(d['val'], exec_data['val']) < min_space_time_ms: |
| | | continue |
| | | # 获取到了下单位置 |
| | | async_log_util.info(hx_logger_trade_debug, f"真实下单位置:{code}-{d['index']}") |
| | |
| | | cls.__TradePointManager.delete_buy_cancel_point(code) |
| | | l2_log.debug(code, "delete_buy_cancel_point") |
| | | # 直接下单 |
| | | ordered = cls.__buy(code, capture_time, total_datas[new_buy_exec_index], new_buy_exec_index, is_first_code) |
| | | ordered = cls.__buy(code, capture_time, total_datas[-1], total_datas[-1]["index"], is_first_code) |
| | | |
| | | # 数据是否处理完毕 |
| | | if new_buy_exec_index < compute_end_index: |
| | |
| | | |
| | | |
| | | # 通过量下单,返回(代码,账号ID,订单号) |
| | | def order_volume(code, price, count, last_data_index, order_ref=None): |
| | | def order_volume(code, price, count, last_data, order_ref=None): |
| | | async_log_util.info(logger_trade, f"{code} trade_huaxin.order_volume 开始") |
| | | try: |
| | | price = round(float(price), 2) |
| | | if code.find("00") != 0 and code.find("60") != 0: |
| | | raise Exception("只支持00开头与60开头的代码下单") |
| | | # 保存下单信息 |
| | | huaxin.huaxin_delegate_postion_manager.place_order(code, price, count, last_data_index) |
| | | huaxin.huaxin_delegate_postion_manager.place_order(code, price, count, last_data) |
| | | if not constant.TRADE_ENABLE: |
| | | return |
| | | result = None |
| | |
| | | elif constant.TRADE_WAY == constant.TRADE_WAY_HUAXIN: |
| | | order_ref = huaxin_util.create_order_ref() |
| | | TradeOrderIdManager().add_order_ref(code, order_ref) |
| | | trade_huaxin.order_volume(code, price, count, last_data_index, order_ref=order_ref) |
| | | trade_huaxin.order_volume(code, price, count, last_data, order_ref=order_ref) |
| | | else: |
| | | guiTrade.buy(code, price) |
| | | __place_order_success(code, capture_timestamp, last_data, last_data_index) |