-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FMV messages to output channel (#382)
Co-authored-by: GitHub Action <[email protected]>
- Loading branch information
1 parent
15e9884
commit 0849de2
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
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() | ||
} | ||
} | ||
} | ||
} |
This file contains 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