diff --git a/main.py b/main.py index b884c16..2276523 100644 --- a/main.py +++ b/main.py @@ -275,8 +275,17 @@ class BotSpotTrade: self.logger.info("开始闪兑: %s %s → %s", amount, from_currency, to_currency) + # OKX 闪兑 pair 注册方向为 (baseCcy, quoteCcy) = (base, quote),side 对 baseCcy 描述方向 + # ccxt 默认 baseCcy=fromCode + side=sell,不匹配 OKX 注册方向时会被拒(58009) + # 用 params 覆盖请求方向,使 baseCcy 始终等于交易对的 base 货币 + convert_params = { + 'baseCcy': base_currency, + 'quoteCcy': quote_currency, + 'side': side, + } + try: - quote = self.exchange.fetchConvertQuote(from_currency, to_currency, amount) + quote = self.exchange.fetchConvertQuote(from_currency, to_currency, amount, convert_params) self.logger.info( "获取闪兑报价成功: %s %s → %s %s, 报价ID: %s", from_currency, amount, to_currency, @@ -294,7 +303,7 @@ class BotSpotTrade: try: convert_trade = self.exchange.createConvertTrade( - quote_id, from_currency, to_currency, amount + quote_id, from_currency, to_currency, amount, convert_params ) self.logger.info("创建闪兑交易成功: %s", convert_trade) except Exception as e: @@ -324,11 +333,13 @@ class BotSpotTrade: final_data = trade_detail or convert_trade + # 覆写方向后,OKX 返回的 fromAmount = baseCcy 数量(交易币),toAmount = quoteCcy 数量(计价币) + # 记录格式与现货订单一致:filled = 交易币数量,cost = 计价币数量 record_data = { "symbol": symbol, "id": trade_id, - "filled": final_data.get("toAmount") or 0.0, - "cost": final_data.get("fromAmount") or 0.0, + "filled": final_data.get("fromAmount") or 0.0, + "cost": final_data.get("toAmount") or 0.0, "side": side, "timestamp": final_data.get("timestamp") or int(time.time() * 1000), }