23
main.py
23
main.py
@@ -160,6 +160,26 @@ class MexcSpotTrade:
|
|||||||
self.csv_file = f"output/{config_file_name}.csv"
|
self.csv_file = f"output/{config_file_name}.csv"
|
||||||
self.symbol_mapping = symbol_mapping
|
self.symbol_mapping = symbol_mapping
|
||||||
|
|
||||||
|
def _api_get_balance(self) -> str:
|
||||||
|
"""
|
||||||
|
获取账户余额
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
账户余额字典或None(如果失败)
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
logger.info("查询账户余额")
|
||||||
|
account_info = self.trader.get_account_info()
|
||||||
|
account_info_balance = account_info.get("balances", [])
|
||||||
|
balances = ""
|
||||||
|
for item in account_info_balance:
|
||||||
|
balances += f"{item['available']} {item['asset']} "
|
||||||
|
logger.info("获取账户余额成功")
|
||||||
|
return balances
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("查询账户信息失败: %s", str(e))
|
||||||
|
return f"ERROR: {str(e)}"
|
||||||
|
|
||||||
def _api_get_order(self, symbol: str, order_id: str) -> Optional[Dict[str, Any]]:
|
def _api_get_order(self, symbol: str, order_id: str) -> Optional[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
查询订单状态
|
查询订单状态
|
||||||
@@ -251,6 +271,7 @@ class MexcSpotTrade:
|
|||||||
executed_qty = order_data["executedQty"]
|
executed_qty = order_data["executedQty"]
|
||||||
cummulative_quote_qty = order_data["cummulativeQuoteQty"]
|
cummulative_quote_qty = order_data["cummulativeQuoteQty"]
|
||||||
side = order_data["side"]
|
side = order_data["side"]
|
||||||
|
balances = self._api_get_balance()
|
||||||
|
|
||||||
# 确定交易类型显示
|
# 确定交易类型显示
|
||||||
trade_type = "买入" if side == "BUY" else "卖出"
|
trade_type = "买入" if side == "BUY" else "卖出"
|
||||||
@@ -268,6 +289,7 @@ class MexcSpotTrade:
|
|||||||
"资金账户",
|
"资金账户",
|
||||||
"CEX",
|
"CEX",
|
||||||
f"MEXC API - Order ID: {order_id}",
|
f"MEXC API - Order ID: {order_id}",
|
||||||
|
balances
|
||||||
]
|
]
|
||||||
|
|
||||||
# 检查文件是否存在
|
# 检查文件是否存在
|
||||||
@@ -292,6 +314,7 @@ class MexcSpotTrade:
|
|||||||
"现金账户",
|
"现金账户",
|
||||||
"目标账户",
|
"目标账户",
|
||||||
"备注",
|
"备注",
|
||||||
|
"balances"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
|
Reference in New Issue
Block a user