fix(convert): 修正 OKX 闪兑方向覆盖和字段映射
- 新增 convert_params 覆盖 ccxt 默认请求方向,baseCcy=base货币,side=bot买卖方向 - 修复 record_data 字段映射:filled=fromAmount(baseCcy数量),cost=toAmount(quoteCcy数量) - 保留 fetchConvertTrade 空壳回退逻辑 - 解决 USDT→OKB 闪兑报 58009 'Crypto pair not exist' 的问题
This commit is contained in:
1 file changed
+15
-4
@@ -275,8 +275,17 @@ class BotSpotTrade:
|
|||||||
|
|
||||||
self.logger.info("开始闪兑: %s %s → %s", amount, from_currency, to_currency)
|
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:
|
try:
|
||||||
quote = self.exchange.fetchConvertQuote(from_currency, to_currency, amount)
|
quote = self.exchange.fetchConvertQuote(from_currency, to_currency, amount, convert_params)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
"获取闪兑报价成功: %s %s → %s %s, 报价ID: %s",
|
"获取闪兑报价成功: %s %s → %s %s, 报价ID: %s",
|
||||||
from_currency, amount, to_currency,
|
from_currency, amount, to_currency,
|
||||||
@@ -294,7 +303,7 @@ class BotSpotTrade:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
convert_trade = self.exchange.createConvertTrade(
|
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)
|
self.logger.info("创建闪兑交易成功: %s", convert_trade)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -324,11 +333,13 @@ class BotSpotTrade:
|
|||||||
|
|
||||||
final_data = trade_detail or convert_trade
|
final_data = trade_detail or convert_trade
|
||||||
|
|
||||||
|
# 覆写方向后,OKX 返回的 fromAmount = baseCcy 数量(交易币),toAmount = quoteCcy 数量(计价币)
|
||||||
|
# 记录格式与现货订单一致:filled = 交易币数量,cost = 计价币数量
|
||||||
record_data = {
|
record_data = {
|
||||||
"symbol": symbol,
|
"symbol": symbol,
|
||||||
"id": trade_id,
|
"id": trade_id,
|
||||||
"filled": final_data.get("toAmount") or 0.0,
|
"filled": final_data.get("fromAmount") or 0.0,
|
||||||
"cost": final_data.get("fromAmount") or 0.0,
|
"cost": final_data.get("toAmount") or 0.0,
|
||||||
"side": side,
|
"side": side,
|
||||||
"timestamp": final_data.get("timestamp") or int(time.time() * 1000),
|
"timestamp": final_data.get("timestamp") or int(time.time() * 1000),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user