| | |
| | | cls.__front_id = front_id |
| | | |
| | | # sinfo char(32) |
| | | def buy(self, code, count, price, sinfo, order_ref, need_shadedow_order = True): |
| | | def buy(self, code, count, price, sinfo, order_ref, shadow_price = None): |
| | | if not ENABLE_ORDER: |
| | | return |
| | | if sinfo in self.__buy_sinfo_set: |
| | |
| | | ret = api.ReqOrderInsert(req_field, self.req_id) |
| | | if ret != 0: |
| | | raise Exception('ReqOrderInsert fail, ret[%d]' % ret) |
| | | |
| | | if queue_trade_w_l2_r is not None: |
| | | queue_trade_w_l2_r.put_nowait( |
| | | json.dumps({"type": "listen_volume", "data": {"code": code, |
| | |
| | | 'utf-8')) |
| | | async_log_util.info(logger_trade, f"{code}华鑫本地真实下单结束") |
| | | # --------------------------------影子订单-------------------------------- |
| | | if need_shadedow_order: |
| | | if shadow_price: |
| | | if order_ref: |
| | | # 下一个影子订单 |
| | | shadow_order_ref = order_ref + 1 |
| | | shadow_sinfo = f"s_b_{order_ref}" |
| | | shadow_price = tool.get_buy_min_price(price) |
| | | req_field.LimitPrice = shadow_price |
| | | req_field.SInfo = shadow_sinfo |
| | | req_field.OrderRef = shadow_order_ref |
| | |
| | | price = data["price"] |
| | | sinfo = data["sinfo"] |
| | | order_ref = data.get("order_ref") |
| | | shadow_price = data.get("shadow_price") |
| | | |
| | | if direction == 1: |
| | | async_log_util.info(logger_trade, f"{code}华鑫本地开始下单") |
| | |
| | | req_rid_dict[sinfo] = (client_id, request_id, sk, order_ref) |
| | | # threading.Thread(target=lambda: self.__tradeSimpleApi.buy(code, volume, price, sinfo, order_ref), |
| | | # daemon=True).start() |
| | | self.trade_thread_pool.submit(self.__tradeSimpleApi.buy, code, volume, price, sinfo, order_ref) |
| | | self.trade_thread_pool.submit(self.__tradeSimpleApi.buy, code, volume, price, sinfo, order_ref, shadow_price) |
| | | |
| | | async_log_util.info(logger_trade, f"{code}华鑫本地下单线程结束") |
| | | except Exception as e: |
| | |
| | | |
| | | |
| | | # 下单 |
| | | def place_order(code, price, volume, data, order_ref): |
| | | def place_order(code, price, volume, data, order_ref, shadow_price): |
| | | async_log_util.info(logger_real_place_order_position, |
| | | f"下单:code-{code} price-{price} volume-{volume} exec-index-{data['index']} order_ref-{order_ref}") |
| | | _place_order_info_dict[code] = (price, volume, data, time.time(), order_ref) |
| | | f"下单:code-{code} price-{price} shadow_price-{shadow_price} volume-{volume} exec-index-{data['index']} order_ref-{order_ref}") |
| | | _place_order_info_dict[code] = (price, volume, data, time.time(), order_ref, shadow_price) |
| | | |
| | | |
| | | # 获取下单信息 |
| | |
| | | volume = order_info[1] |
| | | exec_data = order_info[2] |
| | | order_ref = order_info[4] |
| | | shadow_price = order_info[5] |
| | | # 获取量 |
| | | is_sz = code.startswith("00") |
| | | # 提交到交易所的时间预估 |
| | |
| | | # 判断影子订单位置 |
| | | if val["num"] != huaxin_client_constant.SHADOW_ORDER_VOLUME // 100: |
| | | continue |
| | | if abs(tool.get_buy_min_price(limit_up_price) - float(val["price"])) >= 0.01: |
| | | if abs(shadow_price - float(val["price"])) >= 0.01: |
| | | continue |
| | | if d["index"] <= exec_data["index"]: |
| | | continue |
| | |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | getCodeJingXuanBlocks("002316") |
| | | print(getLimitUpInfo()) |
| | |
| | | # 获取涨停价 |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | if limit_up_price and volume == huaxin_client_constant.SHADOW_ORDER_VOLUME: |
| | | shadow_price = tool.get_buy_min_price(float(limit_up_price)) |
| | | if abs(float(limitPrice) - float(shadow_price)) < 0.01: |
| | | if abs(float(limitPrice) - float(limit_up_price)) >= 0.01: |
| | | is_shadow_order = True |
| | | |
| | | order = HuaxinOrderEntity(code, orderStatus, orderRef, accountID, orderSysID, |
| | |
| | | if not is_shadow_order: |
| | | # 订单相关回调 |
| | | # 重新请求委托列表与资金 |
| | | huaxin_trade_data_update.add_delegate_list("来自交易管道") |
| | | # huaxin_trade_data_update.add_delegate_list("来自交易管道") |
| | | huaxin_trade_data_update.add_deal_list() |
| | | huaxin_trade_data_update.add_money_list() |
| | | # print("响应结果:", data_json['data']) |
| | |
| | | # price:价格(如果是卖时不传价格就按照5挡价卖) |
| | | # blocking是否阻塞进程 |
| | | def order(direction, code, volume, price, price_type=2, blocking=False, sinfo=None, request_id=None, |
| | | order_ref=None): |
| | | order_ref=None, shadow_price=None): |
| | | timestamp = round(time.time() * 1000) |
| | | if not sinfo: |
| | | sinfo = f"b_{code}_{timestamp}" |
| | |
| | | "order_ref": order_ref, |
| | | "volume": volume, |
| | | "price_type": price_type, |
| | | "price": price, "sinfo": sinfo}, request_id=request_id, blocking=blocking, |
| | | "price": price, "shadow_price": shadow_price, "sinfo": sinfo}, request_id=request_id, |
| | | blocking=blocking, |
| | | is_pipe=is_pipe_channel_normal()) |
| | | try: |
| | | if blocking: |
| | |
| | | try: |
| | | limit_up_data_str = kpl_api.getLimitUpInfo() |
| | | limit_up_datas = json.loads(limit_up_data_str) |
| | | limit_up_datas = limit_up_datas["list"] |
| | | for d in limit_up_datas: |
| | | code = d[0] |
| | | if code in codes: |
| | |
| | | is_shadow_order = False |
| | | limit_up_price = gpcode_manager.get_limit_up_price_cache(code) |
| | | if limit_up_price and volume == huaxin_client_constant.SHADOW_ORDER_VOLUME: |
| | | shadow_price = tool.get_buy_min_price(float(limit_up_price)) |
| | | if abs(float(limitPrice) - float(shadow_price)) < 0.01: |
| | | |
| | | if abs(float(limitPrice) - float(limit_up_price)) >= 0.01: |
| | | is_shadow_order = True |
| | | if is_shadow_order: |
| | | continue |
| | |
| | | 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, order_ref) |
| | | shadow_price = tool.get_shadow_price(price) |
| | | huaxin.huaxin_delegate_postion_manager.place_order(code, price, count, last_data, order_ref, |
| | | shadow_price=shadow_price) |
| | | if not constant.TRADE_ENABLE: |
| | | return |
| | | result = None |
| | | blocking = False |
| | | try: |
| | | async_log_util.info(logger_trade, f"{code}下单开始") |
| | | result = huaxin_trade_api.order(1, code, count, price, blocking=blocking, order_ref=order_ref) |
| | | result = huaxin_trade_api.order(1, code, count, price, blocking=blocking, order_ref=order_ref, |
| | | shadow_price=shadow_price) |
| | | async_log_util.info(logger_trade, f"{code}下单结束") |
| | | except Exception as e: |
| | | if str(e).find("超时") >= 0: |
| | |
| | | return max(price1, price2) |
| | | |
| | | |
| | | # 获取买入价格笼子的最低价 |
| | | def get_shadow_price(price): |
| | | fprice = round((100 - random.randint(2, 10)) * price / 100, 2) |
| | | if price - 0.1 < fprice: |
| | | fprice = price - 0.1 |
| | | return round(fprice, 2) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | print(get_buy_min_price(20)) |
| | | print(get_shadow_price(20)) |
| | | print(get_shadow_price(20)) |
| | | print(get_shadow_price(20)) |
| | | # print(trade_time_sub("11:29:59", 5)) |
| | | # print(trade_time_sub("10:29:59", 10)) |
| | | # print(trade_time_add_second("13:29:59", 60)) |
| | |
| | | except: |
| | | pass |
| | | return None |
| | | |