Created
August 13, 2023 18:17
-
-
Save JohnAllen/50e1d078bdbe7d0f0bd9c47db8b850d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"os/signal" | |
polygonws "github.com/polygon-io/client-go/websocket" | |
"github.com/polygon-io/client-go/websocket/models" | |
"github.com/sirupsen/logrus" | |
) | |
func main() { | |
log := logrus.New() | |
log.SetLevel(logrus.DebugLevel) | |
log.SetFormatter(&logrus.JSONFormatter{}) | |
c, err := polygonws.New(polygonws.Config{ | |
APIKey: "someapikey", | |
Feed: polygonws.RealTime, | |
Market: polygonws.Crypto, | |
Log: log, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer c.Close() | |
_ = c.Subscribe(polygonws.CryptoQuotes, "ETH-USD") | |
if err := c.Connect(); err != nil { | |
log.Error(err) | |
return | |
} | |
sigint := make(chan os.Signal, 1) | |
signal.Notify(sigint, os.Interrupt) | |
for { | |
select { | |
case <-sigint: | |
return | |
case <-c.Error(): | |
return | |
case out, more := <-c.Output(): | |
if !more { | |
return | |
} | |
switch out.(type) { | |
case models.CryptoQuote: | |
log.WithFields(logrus.Fields{"quote": out}).Info() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment