mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
Revert "feat: 添加 OKX 交易所支持 (#1150)"
This reverts commit 174f59b90721572dcdd03a9527fa86a48395018c.
This commit is contained in:
+8
-35
@@ -152,8 +152,6 @@ func (d *Database) createTables() error {
|
||||
lighter_wallet_addr TEXT DEFAULT '',
|
||||
lighter_private_key TEXT DEFAULT '',
|
||||
lighter_api_key_private_key TEXT DEFAULT '',
|
||||
-- OKX 特定字段
|
||||
okx_passphrase TEXT DEFAULT '',
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
@@ -364,7 +362,6 @@ func (d *Database) createTables() error {
|
||||
`ALTER TABLE exchanges ADD COLUMN lighter_wallet_addr TEXT DEFAULT ''`,
|
||||
`ALTER TABLE exchanges ADD COLUMN lighter_private_key TEXT DEFAULT ''`,
|
||||
`ALTER TABLE exchanges ADD COLUMN lighter_api_key_private_key TEXT DEFAULT ''`,
|
||||
`ALTER TABLE exchanges ADD COLUMN okx_passphrase TEXT DEFAULT ''`,
|
||||
`ALTER TABLE traders ADD COLUMN custom_prompt TEXT DEFAULT ''`,
|
||||
`ALTER TABLE traders ADD COLUMN override_base_prompt BOOLEAN DEFAULT 0`,
|
||||
`ALTER TABLE traders ADD COLUMN is_cross_margin BOOLEAN DEFAULT 1`, // 默认为全仓模式
|
||||
@@ -492,7 +489,6 @@ func (d *Database) initDefaultData() error {
|
||||
}{
|
||||
{"binance", "Binance Futures", "binance"},
|
||||
{"bybit", "Bybit Futures", "bybit"},
|
||||
{"okx", "OKX Futures", "okx"},
|
||||
{"hyperliquid", "Hyperliquid", "hyperliquid"},
|
||||
{"aster", "Aster DEX", "aster"},
|
||||
{"lighter", "LIGHTER DEX", "lighter"},
|
||||
@@ -752,10 +748,8 @@ type ExchangeConfig struct {
|
||||
LighterWalletAddr string `json:"lighterWalletAddr"` // Ethereum 钱包地址 (L1)
|
||||
LighterPrivateKey string `json:"lighterPrivateKey"` // L1私钥(用于识别账户)
|
||||
LighterAPIKeyPrivateKey string `json:"lighterAPIKeyPrivateKey"` // API Key私钥(40字节,用于签名交易)
|
||||
// OKX 特定字段
|
||||
OKXPassphrase string `json:"okxPassphrase"` // OKX API Passphrase
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TraderRecord 交易员配置(数据库实体)
|
||||
@@ -1146,16 +1140,7 @@ func (d *Database) GetExchanges(userID string) ([]*ExchangeConfig, error) {
|
||||
COALESCE(aster_private_key, '') as aster_private_key,
|
||||
COALESCE(lighter_wallet_addr, '') as lighter_wallet_addr,
|
||||
COALESCE(lighter_private_key, '') as lighter_private_key,
|
||||
COALESCE(lighter_api_key_private_key, '') as lighter_api_key_private_key,
|
||||
COALESCE(okx_passphrase, '') as okx_passphrase,
|
||||
COALESCE(lighter_api_key_private_key, '') as lighter_api_key_private_key,
|
||||
COALESCE(okx_passphrase, '') as okx_passphrase,
|
||||
COALESCE(lighter_api_key_private_key, '') as lighter_api_key_private_key,
|
||||
COALESCE(okx_passphrase, '') as okx_passphrase,
|
||||
COALESCE(lighter_api_key_private_key, '') as lighter_api_key_private_key,
|
||||
COALESCE(okx_passphrase, '') as okx_passphrase,
|
||||
COALESCE(lighter_api_key_private_key, '') as lighter_api_key_private_key,
|
||||
COALESCE(okx_passphrase, '') as okx_passphrase,
|
||||
COALESCE(lighter_api_key_private_key, '') as lighter_api_key_private_key,
|
||||
created_at, updated_at
|
||||
FROM exchanges WHERE user_id = ? ORDER BY id
|
||||
`, userID)
|
||||
@@ -1176,7 +1161,6 @@ func (d *Database) GetExchanges(userID string) ([]*ExchangeConfig, error) {
|
||||
&exchange.AsterSigner, &exchange.AsterPrivateKey,
|
||||
&exchange.LighterWalletAddr, &exchange.LighterPrivateKey,
|
||||
&exchange.LighterAPIKeyPrivateKey,
|
||||
&exchange.OKXPassphrase,
|
||||
&createdAt, &updatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -1193,7 +1177,6 @@ func (d *Database) GetExchanges(userID string) ([]*ExchangeConfig, error) {
|
||||
exchange.AsterPrivateKey = d.decryptSensitiveData(exchange.AsterPrivateKey)
|
||||
exchange.LighterPrivateKey = d.decryptSensitiveData(exchange.LighterPrivateKey)
|
||||
exchange.LighterAPIKeyPrivateKey = d.decryptSensitiveData(exchange.LighterAPIKeyPrivateKey)
|
||||
exchange.OKXPassphrase = d.decryptSensitiveData(exchange.OKXPassphrase)
|
||||
|
||||
exchanges = append(exchanges, &exchange)
|
||||
}
|
||||
@@ -1202,8 +1185,8 @@ func (d *Database) GetExchanges(userID string) ([]*ExchangeConfig, error) {
|
||||
}
|
||||
|
||||
// UpdateExchange 更新交易所配置,如果不存在则创建用户特定配置
|
||||
// 🔒 安全特性:空值不会覆盖现有的敏感字段(api_key, secret_key, aster_private_key, lighter_private_key, okx_passphrase)
|
||||
func (d *Database) UpdateExchange(userID, id string, enabled bool, apiKey, secretKey string, testnet bool, hyperliquidWalletAddr, asterUser, asterSigner, asterPrivateKey, lighterWalletAddr, lighterPrivateKey, okxPassphrase string) error {
|
||||
// 🔒 安全特性:空值不会覆盖现有的敏感字段(api_key, secret_key, aster_private_key, lighter_private_key)
|
||||
func (d *Database) UpdateExchange(userID, id string, enabled bool, apiKey, secretKey string, testnet bool, hyperliquidWalletAddr, asterUser, asterSigner, asterPrivateKey, lighterWalletAddr, lighterPrivateKey string) error {
|
||||
log.Printf("🔧 UpdateExchange: userID=%s, id=%s, enabled=%v", userID, id, enabled)
|
||||
|
||||
// 构建动态 UPDATE SET 子句
|
||||
@@ -1244,12 +1227,6 @@ func (d *Database) UpdateExchange(userID, id string, enabled bool, apiKey, secre
|
||||
args = append(args, encryptedLighterPrivateKey)
|
||||
}
|
||||
|
||||
if okxPassphrase != "" {
|
||||
encryptedOKXPassphrase := d.encryptSensitiveData(okxPassphrase)
|
||||
setClauses = append(setClauses, "okx_passphrase = ?")
|
||||
args = append(args, encryptedOKXPassphrase)
|
||||
}
|
||||
|
||||
// WHERE 条件
|
||||
args = append(args, id, userID)
|
||||
|
||||
@@ -1290,9 +1267,6 @@ func (d *Database) UpdateExchange(userID, id string, enabled bool, apiKey, secre
|
||||
} else if id == "hyperliquid" {
|
||||
name = "Hyperliquid"
|
||||
typ = "dex"
|
||||
} else if id == "okx" {
|
||||
name = "OKX Futures"
|
||||
typ = "cex"
|
||||
} else if id == "aster" {
|
||||
name = "Aster DEX"
|
||||
typ = "dex"
|
||||
@@ -1311,15 +1285,14 @@ func (d *Database) UpdateExchange(userID, id string, enabled bool, apiKey, secre
|
||||
encryptedSecretKey := d.encryptSensitiveData(secretKey)
|
||||
encryptedAsterPrivateKey := d.encryptSensitiveData(asterPrivateKey)
|
||||
encryptedLighterPrivateKey := d.encryptSensitiveData(lighterPrivateKey)
|
||||
encryptedOKXPassphrase := d.encryptSensitiveData(okxPassphrase)
|
||||
|
||||
// 创建用户特定的配置,使用原始的交易所ID
|
||||
_, err = d.db.Exec(`
|
||||
INSERT INTO exchanges (id, user_id, name, type, enabled, api_key, secret_key, testnet,
|
||||
hyperliquid_wallet_addr, aster_user, aster_signer, aster_private_key,
|
||||
lighter_wallet_addr, lighter_private_key, okx_passphrase, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))
|
||||
`, id, userID, name, typ, enabled, encryptedAPIKey, encryptedSecretKey, testnet, hyperliquidWalletAddr, asterUser, asterSigner, encryptedAsterPrivateKey, lighterWalletAddr, encryptedLighterPrivateKey, encryptedOKXPassphrase)
|
||||
lighter_wallet_addr, lighter_private_key, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), datetime('now'))
|
||||
`, id, userID, name, typ, enabled, encryptedAPIKey, encryptedSecretKey, testnet, hyperliquidWalletAddr, asterUser, asterSigner, encryptedAsterPrivateKey, lighterWalletAddr, encryptedLighterPrivateKey)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("❌ UpdateExchange: 创建记录失败: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user