Files
nofx/hook/hooks.go
T
tinkle-community 1744e7f38e feat: migrate to CoinAnk API and improve chart UI
- Chart improvements: professional styling, popular symbols quick selection, simplified B/S legend
- Data source migration: use CoinAnk API exclusively for all kline data
- Code cleanup: remove Binance WebSocket cache and related code (websocket_client.go, combined_streams.go, monitor.go)
- Log optimization: reduce hook spam, suppress 404 errors, increase P&L diff threshold
- Lighter integration: add order sync functionality, fix market order precision
- Remove ticker merge logic for simplicity
2025-12-26 00:58:12 +08:00

41 lines
1.0 KiB
Go

package hook
import (
"log"
)
type HookFunc func(args ...any) any
var (
Hooks map[string]HookFunc = map[string]HookFunc{}
EnableHooks = true
)
func HookExec[T any](key string, args ...any) *T {
if !EnableHooks {
// Hooks are disabled, skip silently
var zero *T
return zero
}
if hook, exists := Hooks[key]; exists && hook != nil {
log.Printf("🔌 Execute hook: %s", key)
res := hook(args...)
return res.(*T)
}
// Hook not found, skip silently (no log spam)
var zero *T
return zero
}
func RegisterHook(key string, hook HookFunc) {
Hooks[key] = hook
}
// hook list
const (
GETIP = "GETIP" // func (userID string) *IpResult
NEW_BINANCE_TRADER = "NEW_BINANCE_TRADER" // func (userID string, client *futures.Client) *NewBinanceTraderResult
NEW_ASTER_TRADER = "NEW_ASTER_TRADER" // func (userID string, client *http.Client) *NewAsterTraderResult
SET_HTTP_CLIENT = "SET_HTTP_CLIENT" // func (client *http.Client) *SetHttpClientResult
)