fix bug
This commit is contained in:
@@ -7,7 +7,7 @@ class AccountMixin:
|
||||
account_type: str
|
||||
|
||||
def _positions(self, path: str) -> tuple[list[str], list[PositionItem]]:
|
||||
payload = self._post(path, {"account": self.account_type}) or {}
|
||||
payload = self._post_json(path, {"account": self.account_type}) or {}
|
||||
raw = payload.get("data", payload) if isinstance(payload, dict) else payload
|
||||
if isinstance(raw, list):
|
||||
positions = [PositionItem.from_trade_detail(item) for item in raw]
|
||||
@@ -18,21 +18,21 @@ class AccountMixin:
|
||||
def holding(self): return self._positions("/api/holding")
|
||||
|
||||
def assets(self) -> Assets:
|
||||
payload = self._post("/api/v2/assets", {"account": self.account_type}) or {}
|
||||
payload = self._post_json("/api/v2/assets", {"account": self.account_type}) or {}
|
||||
data = payload.get("data", payload) if isinstance(payload, dict) else {}
|
||||
return Assets.from_dict(data)
|
||||
|
||||
def total_money(self) -> float: return float(self._post("/api/money/total", {"account": self.account_type}).get("total_money", 0))
|
||||
def available_money(self) -> float: return float(self._post("/api/money/available", {"account": self.account_type}).get("available_money", 0))
|
||||
def total_money(self) -> float: return float(self._post_json("/api/money/total", {"account": self.account_type}).get("total_money", 0))
|
||||
def available_money(self) -> float: return float(self._post_json("/api/money/available", {"account": self.account_type}).get("available_money", 0))
|
||||
def buy(self, stock: str, price: float, volume: int, pr_type: int = 0): return self._order("/api/order/buy", stock, price, volume, pr_type)
|
||||
def sell(self, stock: str, price: float, volume: int, pr_type: int = 0): return self._order("/api/order/sell", stock, price, volume, pr_type)
|
||||
|
||||
def _order(self, path, stock, price, volume, pr_type):
|
||||
body = {"stock": stock, "price": price, "volume": volume}
|
||||
if pr_type: body["prType"] = pr_type
|
||||
return self._post(path, body)
|
||||
return self._post_json(path, body)
|
||||
|
||||
def order_status_list(self): return self._post("/api/order/status", {"account": self.account_type}).get("orders", [])
|
||||
def cancel_all(self): return self._post("/api/order/cancel_all", {"account": self.account_type})
|
||||
def cancel_by_rule(self, stock: str, volume: int): return self._post("/api/order/cancel_order", {"stock": stock, "volume": volume, "account": self.account_type})
|
||||
def deals(self): return self._post("/api/order/deal", {"account": self.account_type}).get("deals", [])
|
||||
def order_status_list(self): return self._post_json("/api/order/status", {"account": self.account_type}).get("orders", [])
|
||||
def cancel_all(self): return self._post_json("/api/order/cancel_all", {"account": self.account_type})
|
||||
def cancel_by_rule(self, stock: str, volume: int): return self._post_json("/api/order/cancel_order", {"stock": stock, "volume": volume, "account": self.account_type})
|
||||
def deals(self): return self._post_json("/api/order/deal", {"account": self.account_type}).get("deals", [])
|
||||
|
||||
Reference in New Issue
Block a user