mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-14 08:16:56 +08:00
fix(hyperliquid): stop SDK init panic from crashing trader creation with 500
go-hyperliquid's NewExchange auto-fetches meta/spotMeta/perpDexs and panics if any of those API calls fail (NewInfo: panic(err)). The quick trade flow constructs a probe trader inside POST /api/traders, so any transient Hyperliquid API hiccup crashed the request with a recovered panic and a bare 500. Wrap the constructor in initExchangeClient, which converts the panic into an error that surfaces through the existing exchange-probe validation path as an honest, retryable message.
This commit is contained in:
22
trader/hyperliquid/client_init.go
Normal file
22
trader/hyperliquid/client_init.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package hyperliquid
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
hl "github.com/sonirico/go-hyperliquid"
|
||||
)
|
||||
|
||||
// initExchangeClient runs the SDK exchange constructor and converts its
|
||||
// panic-on-failure behavior into an error. go-hyperliquid's NewExchange
|
||||
// auto-fetches meta/spotMeta/perpDexs when they are passed as nil and panics
|
||||
// if any of those API calls fail (NewInfo: panic(err)), so a transient
|
||||
// Hyperliquid API hiccup would otherwise crash the calling HTTP handler
|
||||
// with a 500.
|
||||
func initExchangeClient(build func() *hl.Exchange) (ex *hl.Exchange, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("hyperliquid client initialization failed: %v", r)
|
||||
}
|
||||
}()
|
||||
return build(), nil
|
||||
}
|
||||
Reference in New Issue
Block a user