polygon-io / client-go

The official Go client library for the Polygon REST and WebSocket API.
MIT License
127 stars 36 forks source link

Bug fix for FMV with stocks, options, forex, or crypto #376

Closed justinpolygon closed 9 months ago

justinpolygon commented 9 months ago

This PR addresses a bug related to the support of BusinessFairMarketValue (FMV) in different market types. Previously, our supports function in the Market type only checked if a topic was within predefined min-max ranges for each market type (Stocks, Options, Forex, Crypto). This implementation did not account for FMV, which falls outside these ranges but is relevant and essential for these market types.

Changes Made:

Impact:

Here's a text script:

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()
            }
        }
    }
}
justinpolygon commented 9 months ago

I'm not sure what the lint errors are about these are unrelated to my change.

ttong-ai commented 9 months ago

Would you be able to merge this and publish a new release? We are waiting for this release :-)

justinpolygon commented 9 months ago

@ttong-ai FYI - v1.16.2 has been released with this fix.