fix: 删除零成交误判逻辑 + 各种稳定性修复
- 删除: Bitget GetTradeFee 零成交检查(PlaceMarketOrder 成功即成交) - 修复: GetTradeFee 加 1s 延迟 + 查不到返回 0(用配置估算费兜底) - 修复: HL InitExchange 在 NewTrader 中提前调用,避免 szDecimals 延迟 - 修复: close_failed 30 次重试上限,超限标记 failed 并清理 - 修复: DB 恢复时校验 Legs 完整性,跳过非法记录 - 修复: checkScaleIn/checkExit nil guard 防 panic - 修复: config.go 参数调整(手续费、阈值等) - 移除: scanner.go 中 MEW/USTC 等低流动性币对 - 添加: 更详细的下单日志(szStr、amountUSD、price) - 添加: bin/ 到 .gitignore
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -59,6 +60,13 @@ func NewHyperLiquidTrade(privateKeyHex, mainAddress, apiAddress string) (*HyperL
|
||||
}, nil
|
||||
}
|
||||
|
||||
// InitExchange ensures the HL exchange is initialized (fetches metadata, szDecimals, etc.).
|
||||
// Safe to call multiple times — no-op after first initialization.
|
||||
// Must be called before GetSize or PlaceMarketOrder for accurate size formatting.
|
||||
func (h *HyperLiquidTrade) InitExchange() error {
|
||||
return h.initExchange()
|
||||
}
|
||||
|
||||
func (h *HyperLiquidTrade) initExchange() error {
|
||||
if h.exchange != nil {
|
||||
return nil
|
||||
@@ -142,9 +150,16 @@ func (h *HyperLiquidTrade) PlaceMarketOrder(coin, side, sz string) (string, erro
|
||||
isBuy := side == "buy"
|
||||
size, _ := strconv.ParseFloat(sz, 64)
|
||||
|
||||
// Find szDecimals for this coin
|
||||
decimals := 4
|
||||
if d, ok := h.szDecimals[coin]; ok {
|
||||
decimals = d
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
log.Printf("[Order] HL MarketOpen | coin=%s isBuy=%v size=%.*f szDecimals=%d slippage=0.05 px=nil", coin, isBuy, decimals, size, decimals)
|
||||
result, err := h.exchange.MarketOpen(ctx, coin, isBuy, size, nil, 0.05, nil, nil)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("market open: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user