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:
@@ -81,9 +81,12 @@ func (b *BitgetTrade) PlaceMarketOrder(side, symbol, size, tradeSide string) (st
|
||||
}
|
||||
return result.Data.OrderID, nil
|
||||
}
|
||||
|
||||
// GetTradeFee queries the fills endpoint for actual fee charged.
|
||||
// Waits 1s before querying because Bitget's fills API may lag behind
|
||||
// the place-order response. Returns 0 if no fills yet (caller uses
|
||||
// estimated fee from config as fallback).
|
||||
func (b *BitgetTrade) GetTradeFee(symbol, orderID string) (feeUSD float64, err error) {
|
||||
time.Sleep(1 * time.Second)
|
||||
ts := fmt.Sprintf("%d", time.Now().UnixMilli())
|
||||
method := "GET"
|
||||
requestPath := "/api/v2/mix/order/fills?symbol=" + symbol + "&orderId=" + orderID + "&productType=USDT-FUTURES"
|
||||
@@ -92,6 +95,7 @@ func (b *BitgetTrade) GetTradeFee(symbol, orderID string) (feeUSD float64, err e
|
||||
sign := b.sign(method, requestPath, ts, "")
|
||||
url := host + requestPath
|
||||
req, _ := http.NewRequest(method, url, nil)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("ACCESS-KEY", b.APIKey)
|
||||
req.Header.Set("ACCESS-SIGN", sign)
|
||||
req.Header.Set("ACCESS-TIMESTAMP", ts)
|
||||
@@ -121,7 +125,7 @@ func (b *BitgetTrade) GetTradeFee(symbol, orderID string) (feeUSD float64, err e
|
||||
var totalFee float64
|
||||
for _, item := range raw.Data.FillList {
|
||||
var fill struct {
|
||||
FillFee string `json:"fillFee"`
|
||||
FillFee string `json:"fillFee"`
|
||||
}
|
||||
if err := json.Unmarshal(item, &fill); err != nil {
|
||||
continue
|
||||
|
||||
@@ -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