Skip to content

Commit

Permalink
Added FMV messages to output channel (#382)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
justinpolygon and actions-user authored Dec 18, 2023
1 parent 15e9884 commit 0849de2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Polygon Go Client
![Coverage](https://img.shields.io/badge/Coverage-76.7%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-76.6%25-brightgreen)

<!-- todo: add a codecov badge -->
<!-- todo: figure out a way to show all build statuses -->
Expand Down
57 changes: 57 additions & 0 deletions websocket/example/fmv/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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: os.Getenv("POLYGON_API_KEY"),
Feed: polygonws.BusinessFeed,
Market: polygonws.Stocks,
Log: log,
})
if err != nil {
log.Fatal(err)
}
defer c.Close()

// FMV
_ = c.Subscribe(polygonws.BusinessFairMarketValue, "*")

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.FairMarketValue:
log.WithFields(logrus.Fields{"fmv": out}).Info()

default:
log.WithFields(logrus.Fields{"unknown": out}).Info()
}
}
}
}
1 change: 1 addition & 0 deletions websocket/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ func (c *Client) handleData(eventType string, msg json.RawMessage) {
if err := json.Unmarshal(msg, &out); err != nil {
c.log.Errorf("failed to unmarshal message: %v", err)
}
c.output <- out

default:
c.log.Infof("unknown message type '%s'", sanitize(eventType))
Expand Down

0 comments on commit 0849de2

Please sign in to comment.