feat: actual exchange fees for entry orders

- BitgetTrade: added GetTradeFee() queries /mix/order/fills
- HyperLiquidTrade: added GetTradeFee() parses MarketOpen response
- trader.placeOrder() now returns (errMsg, actualFeeUSD)
- executeEntry uses actual fee from exchange, falls back to estimate
This commit is contained in:
jackyu66git
2026-05-04 18:35:33 +08:00
parent 0b2bfd0b02
commit 6baae85eaa
3 changed files with 132 additions and 28 deletions
+28
View File
@@ -83,6 +83,7 @@ func (h *HyperLiquidTrade) IsConfigured() bool {
return h.configured
}
// PlaceMarketOrder places a market order and returns the raw JSON response.
func (h *HyperLiquidTrade) PlaceMarketOrder(coin, side, sz string) (string, error) {
if !h.configured {
return "", fmt.Errorf("HL not configured")
@@ -120,6 +121,33 @@ func (h *HyperLiquidTrade) PlaceMarketOrder(coin, side, sz string) (string, erro
return string(respJSON), nil
}
// GetTradeFee parses the MarketOpen JSON response to extract filled size and
// estimates the actual fee from the exchange taker rate.
func (h *HyperLiquidTrade) GetTradeFee(orderResponseJSON string, takerFeePct float64) (feeUSD float64, err error) {
var resp struct {
Statuses []struct {
Filled *struct {
TotalSz string `json:"totalSz"`
AvgPx string `json:"avgPx"`
} `json:"filled,omitempty"`
Error *string `json:"error,omitempty"`
} `json:"statuses"`
}
if err := json.Unmarshal([]byte(orderResponseJSON), &resp); err != nil {
return 0, fmt.Errorf("parse order response: %w", err)
}
for _, st := range resp.Statuses {
if st.Filled != nil {
sz, _ := strconv.ParseFloat(st.Filled.TotalSz, 64)
px, _ := strconv.ParseFloat(st.Filled.AvgPx, 64)
if sz > 0 && px > 0 {
return sz * px * takerFeePct / 100, nil
}
}
}
return 0, fmt.Errorf("no filled status in response")
}
func (h *HyperLiquidTrade) GetBalance() (float64, error) {
if !h.configured {
return 0, fmt.Errorf("HL not configured")