From c185fccd246827ade783cfb6241a1980eecdc24a Mon Sep 17 00:00:00 2001 From: zhiyong Date: Tue, 29 Apr 2025 01:36:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20get=5Ftoday=5Fentrust=20=20=E4=B8=AD,=20?= =?UTF-8?q?=E5=B0=86order=5Ftype,=20price=5Ftype=20=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=88=90=E8=8B=B1=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/xt_trader.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/xt_trader.py b/src/xt_trader.py index 06cf7d6..86ef326 100644 --- a/src/xt_trader.py +++ b/src/xt_trader.py @@ -144,9 +144,9 @@ class XtTrader: "stock_code": o.stock_code, "order_id": o.order_id, "order_time": o.order_time, - "order_type": o.order_type, + "order_type": "buy" if o.order_type == xtconstant.STOCK_BUY else "sell", "order_volume": o.order_volume, - "price_type": o.price_type, + "price_type": self._convert_price_type(o.price_type), "price": o.price, "traded_volume": o.traded_volume, "traded_price": o.traded_price, @@ -155,7 +155,20 @@ class XtTrader: } for o in orders ] return [] - + + def _convert_price_type(self, price_type): + """Convert numeric price type to readable string""" + price_type_map = { + xtconstant.LATEST_PRICE: "latest_price", # 最新价 + xtconstant.FIX_PRICE: "limit_price", # 指定价/限价 + xtconstant.MARKET_BEST: "market_best", # 市价最优价 + xtconstant.MARKET_CANCEL: "market_cancel", # 市价即成剩撤 + xtconstant.MARKET_CANCEL_ALL: "market_cancel_all", # 市价全额成交或撤销 + xtconstant.MARKET_PEER_PRICE_FIRST: "market_peer_best", # 对手方最优价格 + xtconstant.MARKET_MINE_PRICE_FIRST: "market_mine_best", # 本方最优价格 + } + return price_type_map.get(price_type, f"unknown_{price_type}") + def buy(self, code, price, amount): order_id = self.xt_trader.order_stock( self.account, code, xtconstant.STOCK_BUY, amount, xtconstant.FIX_PRICE, price, self._strategy_name, self._remark