diff --git a/internal/cmd/coinset/events.go b/internal/cmd/coinset/events.go index ac59b63..f8a1f54 100644 --- a/internal/cmd/coinset/events.go +++ b/internal/cmd/coinset/events.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "fmt" + "log" "os" "os/signal" "time" @@ -40,10 +41,15 @@ func runEvents(cmd *cobra.Command, args []string) { eventType = args[0] } - c, _, err := websocket.DefaultDialer.Dial("wss://api.coinset.org/ws", nil) + endpoint := fmt.Sprintf("wss://%s/ws", apiHost()) + + if api != "" { + endpoint = api + } + + c, _, err := websocket.DefaultDialer.Dial(endpoint, nil) if err != nil { - fmt.Println(err) - return + log.Fatal(err.Error()) } defer c.Close() diff --git a/internal/cmd/coinset/util.go b/internal/cmd/coinset/util.go index a7f73fb..525a154 100644 --- a/internal/cmd/coinset/util.go +++ b/internal/cmd/coinset/util.go @@ -31,6 +31,14 @@ func formatHex(str string) string { return "0x" + str } +func apiHost() string { + baseUrl, err := url.Parse(apiRoot()) + if err != nil { + log.Fatal(err.Error()) + } + return baseUrl.Host +} + func apiRoot() string { if api != "" { return api