mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-04 19:41:02 +08:00
Merge pull request #467 from zhouyongyou/fix/binance-multi-assets-api-error
fix: 智能处理币安多资产模式和统一账户API错误
This commit is contained in:
@@ -866,6 +866,21 @@ func (t *AsterTrader) SetMarginMode(symbol string, isCrossMargin bool) error {
|
||||
log.Printf(" ✓ %s 仓位模式已是 %s 或有持仓无法更改", symbol, marginType)
|
||||
return nil
|
||||
}
|
||||
// 检测多资产模式(错误码 -4168)
|
||||
if strings.Contains(err.Error(), "Multi-Assets mode") ||
|
||||
strings.Contains(err.Error(), "-4168") ||
|
||||
strings.Contains(err.Error(), "4168") {
|
||||
log.Printf(" ⚠️ %s 检测到多资产模式,强制使用全仓模式", symbol)
|
||||
log.Printf(" 💡 提示:如需使用逐仓模式,请在交易所关闭多资产模式")
|
||||
return nil
|
||||
}
|
||||
// 检测统一账户 API
|
||||
if strings.Contains(err.Error(), "unified") ||
|
||||
strings.Contains(err.Error(), "portfolio") ||
|
||||
strings.Contains(err.Error(), "Portfolio") {
|
||||
log.Printf(" ❌ %s 检测到统一账户 API,无法进行合约交易", symbol)
|
||||
return fmt.Errorf("请使用「现货与合约交易」API 权限,不要使用「统一账户 API」")
|
||||
}
|
||||
log.Printf(" ⚠️ 设置仓位模式失败: %v", err)
|
||||
// 不返回错误,让交易继续
|
||||
return nil
|
||||
|
||||
@@ -193,6 +193,17 @@ func (t *FuturesTrader) SetMarginMode(symbol string, isCrossMargin bool) error {
|
||||
log.Printf(" ⚠️ %s 有持仓,无法更改仓位模式,继续使用当前模式", symbol)
|
||||
return nil
|
||||
}
|
||||
// 检测多资产模式(错误码 -4168)
|
||||
if contains(err.Error(), "Multi-Assets mode") || contains(err.Error(), "-4168") || contains(err.Error(), "4168") {
|
||||
log.Printf(" ⚠️ %s 检测到多资产模式,强制使用全仓模式", symbol)
|
||||
log.Printf(" 💡 提示:如需使用逐仓模式,请在币安关闭多资产模式")
|
||||
return nil
|
||||
}
|
||||
// 检测统一账户 API(Portfolio Margin)
|
||||
if contains(err.Error(), "unified") || contains(err.Error(), "portfolio") || contains(err.Error(), "Portfolio") {
|
||||
log.Printf(" ❌ %s 检测到统一账户 API,无法进行合约交易", symbol)
|
||||
return fmt.Errorf("请使用「现货与合约交易」API 权限,不要使用「统一账户 API」")
|
||||
}
|
||||
log.Printf(" ⚠️ 设置仓位模式失败: %v", err)
|
||||
// 不返回错误,让交易继续
|
||||
return nil
|
||||
|
||||
@@ -1530,14 +1530,18 @@ function ExchangeConfigModal({
|
||||
onClose: () => void
|
||||
language: Language
|
||||
}) {
|
||||
const [selectedExchangeId, setSelectedExchangeId] = useState(
|
||||
editingExchangeId || ''
|
||||
)
|
||||
const [apiKey, setApiKey] = useState('')
|
||||
const [secretKey, setSecretKey] = useState('')
|
||||
const [passphrase, setPassphrase] = useState('')
|
||||
const [testnet, setTestnet] = useState(false)
|
||||
const [showGuide, setShowGuide] = useState(false)
|
||||
const [selectedExchangeId, setSelectedExchangeId] = useState(editingExchangeId || '');
|
||||
const [apiKey, setApiKey] = useState('');
|
||||
const [secretKey, setSecretKey] = useState('');
|
||||
const [passphrase, setPassphrase] = useState('');
|
||||
const [testnet, setTestnet] = useState(false);
|
||||
const [showGuide, setShowGuide] = useState(false);
|
||||
|
||||
// 币安配置指南展开状态
|
||||
const [showBinanceGuide, setShowBinanceGuide] = useState(false);
|
||||
|
||||
// Hyperliquid 特定字段
|
||||
const [hyperliquidWalletAddr, setHyperliquidWalletAddr] = useState('');
|
||||
|
||||
// Aster 特定字段
|
||||
const [asterUser, setAsterUser] = useState('')
|
||||
@@ -1708,32 +1712,104 @@ function ExchangeConfigModal({
|
||||
{selectedExchange && (
|
||||
<>
|
||||
{/* Binance 和其他 CEX 交易所的字段 */}
|
||||
{(selectedExchange.id === 'binance' ||
|
||||
selectedExchange.type === 'cex') &&
|
||||
selectedExchange.id !== 'hyperliquid' &&
|
||||
selectedExchange.id !== 'aster' && (
|
||||
<>
|
||||
<div>
|
||||
<label
|
||||
className="block text-sm font-semibold mb-2"
|
||||
style={{ color: '#EAECEF' }}
|
||||
>
|
||||
{t('apiKey', language)}
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
value={apiKey}
|
||||
onChange={(e) => setApiKey(e.target.value)}
|
||||
placeholder={t('enterAPIKey', language)}
|
||||
className="w-full px-3 py-2 rounded"
|
||||
style={{
|
||||
background: '#0B0E11',
|
||||
border: '1px solid #2B3139',
|
||||
color: '#EAECEF',
|
||||
}}
|
||||
required
|
||||
/>
|
||||
{(selectedExchange.id === 'binance' || selectedExchange.type === 'cex') && selectedExchange.id !== 'hyperliquid' && selectedExchange.id !== 'aster' && (
|
||||
<>
|
||||
{/* 币安用户配置提示 (D1 方案) */}
|
||||
{selectedExchange.id === 'binance' && (
|
||||
<div
|
||||
className="mb-4 p-3 rounded cursor-pointer transition-colors"
|
||||
style={{
|
||||
background: '#1a3a52',
|
||||
border: '1px solid #2b5278',
|
||||
}}
|
||||
onClick={() => setShowBinanceGuide(!showBinanceGuide)}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span style={{ color: '#58a6ff' }}>ℹ️</span>
|
||||
<span className="text-sm font-medium" style={{ color: '#EAECEF' }}>
|
||||
<strong>币安用户必读:</strong>
|
||||
使用「现货与合约交易」API,不要用「统一账户 API」
|
||||
</span>
|
||||
</div>
|
||||
<span style={{ color: '#8b949e' }}>
|
||||
{showBinanceGuide ? '▲' : '▼'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 展开的详细说明 */}
|
||||
{showBinanceGuide && (
|
||||
<div
|
||||
className="mt-3 pt-3"
|
||||
style={{
|
||||
borderTop: '1px solid #2b5278',
|
||||
fontSize: '0.875rem',
|
||||
color: '#c9d1d9'
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<p className="mb-2" style={{ color: '#8b949e' }}>
|
||||
<strong>原因:</strong>统一账户 API 权限结构不同,会导致订单提交失败
|
||||
</p>
|
||||
|
||||
<p className="font-semibold mb-1" style={{ color: '#EAECEF' }}>
|
||||
正确配置步骤:
|
||||
</p>
|
||||
<ol className="list-decimal list-inside space-y-1 mb-3" style={{ paddingLeft: '0.5rem' }}>
|
||||
<li>登录币安 → 个人中心 → <strong>API 管理</strong></li>
|
||||
<li>创建 API → 选择「<strong>系统生成的 API 密钥</strong>」</li>
|
||||
<li>勾选「<strong>现货与合约交易</strong>」(<span style={{ color: '#f85149' }}>不选统一账户</span>)</li>
|
||||
<li>IP 限制选「<strong>无限制</strong>」或添加服务器 IP</li>
|
||||
</ol>
|
||||
|
||||
<p className="mb-2 p-2 rounded" style={{ background: '#3d2a00', border: '1px solid #9e6a03' }}>
|
||||
💡 <strong>多资产模式用户注意:</strong>
|
||||
如果您开启了多资产模式,将强制使用全仓模式。建议关闭多资产模式以支持逐仓交易。
|
||||
</p>
|
||||
|
||||
<a
|
||||
href="https://www.binance.com/zh-CN/support/faq/how-to-create-api-keys-on-binance-360002502072"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-block text-sm hover:underline"
|
||||
style={{ color: '#58a6ff' }}
|
||||
>
|
||||
📖 查看币安官方教程 ↗
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-semibold mb-2" style={{ color: '#EAECEF' }}>
|
||||
{t('apiKey', language)}
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
value={apiKey}
|
||||
onChange={(e) => setApiKey(e.target.value)}
|
||||
placeholder={t('enterAPIKey', language)}
|
||||
className="w-full px-3 py-2 rounded"
|
||||
style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF' }}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-semibold mb-2" style={{ color: '#EAECEF' }}>
|
||||
{t('secretKey', language)}
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
value={secretKey}
|
||||
onChange={(e) => setSecretKey(e.target.value)}
|
||||
placeholder={t('enterSecretKey', language)}
|
||||
className="w-full px-3 py-2 rounded"
|
||||
style={{ background: '#0B0E11', border: '1px solid #2B3139', color: '#EAECEF' }}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label
|
||||
|
||||
Reference in New Issue
Block a user