| | |
| | | __sell_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=10) |
| | | __process_l1_data_thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=10) |
| | | __current_price_dict = {} |
| | | current_buy1_dict = {} |
| | | |
| | | @classmethod |
| | | def __sell(cls, datas): |
| | |
| | | # 格式 (代码,现价,涨幅,量,更新时间,买1价格,买1量) |
| | | price = d[1] |
| | | cls.__current_price_dict[code] = price |
| | | cls.current_buy1_dict[code] = (d[5], d[6]) |
| | | |
| | | # 获取L1现价 |
| | | @classmethod |
| | |
| | | except Exception as e1: |
| | | logging.exception(e1) |
| | | |
| | | # 撤长期没有成交的单 |
| | | def __cancel_not_deal_order(self, code, order_ref, timeout=2): |
| | | time.sleep(timeout) |
| | | # 撤买单 |
| | | huaxin_trade_api.cancel_order(1, code, "", orderRef = order_ref) |
| | | |
| | | # 交易 |
| | | def OnTrade(self, client_id, request_id, data): |
| | | try: |
| | |
| | | else: |
| | | raise e |
| | | else: |
| | | result = huaxin_trade_api.order(direction, code, volume, price, price_type=price_type, sinfo=sinfo, |
| | | blocking=True, request_id=request_id) |
| | | if not price: |
| | | # 没有传入价格,以最新价买入 |
| | | current_price = TradeServerProcessor.get_l1_current_price(code) |
| | | if not current_price: |
| | | raise Exception("尚未获取到现价") |
| | | # 获取买1金额 |
| | | price = round(float(current_price), 2) |
| | | buy1_info = TradeServerProcessor.current_buy1_dict.get(code) |
| | | if buy1_info and buy1_info[0] * buy1_info[1] > 50 * 10000: |
| | | # 如果买1在50w以上就加一档 |
| | | price += 0.01 |
| | | order_ref = huaxin_util.create_order_ref() |
| | | result = huaxin_trade_api.order(direction, code, volume, price, price_type=price_type, |
| | | sinfo=sinfo, order_ref=order_ref, |
| | | blocking=True, request_id=request_id) |
| | | # 2s内没成交就撤单 |
| | | self.__cancel_sell_thread_pool.submit(self.__cancel_not_deal_order, code, order_ref) |
| | | else: |
| | | result = huaxin_trade_api.order(direction, code, volume, price, price_type=price_type, |
| | | sinfo=sinfo, |
| | | blocking=True, request_id=request_id) |
| | | self.send_response({"code": 0, "data": result}, client_id, request_id) |
| | | elif trade_type == outside_api_command_manager.TRADE_TYPE_CANCEL_ORDER: |
| | | print("手动撤单:", data) |
| | |
| | | fdata["total"] = d["prePosition"] |
| | | fdata["available"] = d["availablePosition"] |
| | | fdata["cost_price"] = round(float(d["historyPosPrice"]), 2) |
| | | # 有现价就获取现价 |
| | | current_price = TradeServerProcessor.get_l1_current_price(code) |
| | | if current_price: |
| | | fdata["cost_price"] = current_price |
| | | |
| | | deal_order_system_id_infos = {} |
| | | # 获取已经卖的单数 |
| | | deal_list = self.__DealRecordManager.list_sell_by_code_cache(code) |
| | |
| | | |
| | | fdata["sell_orders"] = [k[0] for k in deal_list] |
| | | break |
| | | # 有现价就获取现价 |
| | | current_price = TradeServerProcessor.get_l1_current_price(code) |
| | | if current_price: |
| | | fdata["cost_price"] = current_price |
| | | |
| | | async_log_util.info(logger_trade_position_api_request, f"{fdata}") |
| | | result = {"code": 0, "data": fdata} |
| | | self.send_response(result, client_id, request_id) |