Closed avikdev closed 1 year ago
@avikdev - the format is Javascript's representation of a large integer (could be other languages as well). What we did was store the value in an interface then convert it into an Int. It's just how Golang parses the value. I can see why they did this because it saves space in the response.
Just as a sample we did the following:
VolumeAtCloseRAW interface{} `json:"v" bson:", truncate"`
VolumeAtClose int64 `json:"-"`
Then on the struct we created a function like this:
func (p *PreviousClose) CopyRawVolume() { if v, ok := p.VolumeAtCloseRAW.(int); ok { p.VolumeAtClose = int64(v) } if v, ok := p.VolumeAtCloseRAW.(int32); ok { p.VolumeAtClose = int64(v) } if v, ok := p.VolumeAtCloseRAW.(float64); ok { p.VolumeAtClose = int64(v) } if v, ok := p.VolumeAtCloseRAW.(int64); ok { p.VolumeAtClose = v } }
It's just an added step and you can make that function more generic so you can use it on other structs.
We recommend using our Go client library: https://github.com/polygon-io/client-go
URL https://api.polygon.io/v2/aggs/ticker/AAPL/range/1/minute/2021-11-22/2021-11-22?adjusted=false&sort=asc&limit=5000&apiKey=
Result The volume field in aggregate bars (JSON integer field) are output in exponential format, which makes it difficult to parse in GOLang.
Expected Result Please output all integer fields in decimal format. More details in the additional context below.
Screenshots n/a
Desktop (please complete the following information): n/a
Additional context
The following are a selected few of the broken down entries from the JSON output which correspond to 1-minute bars of the stock "TSLA" on Nov-22. See the 4-th row, the volume field is output in exponential format ("2.384421e+06").
I am parsing the result in GoLang using the standard "encoding/json" package, which fails to parse the JSON due to this exponential field, I have defined the type as int64 and the actual value is much less than what int64 can hold. The actual error is
"panic: json: cannot unmarshal number 3.331533e+06 into Go struct field _aggregateBar.results.v of type int64"
I know there is a temporary workaround - to use float64 instead of int64, but since the volume is originally an int field, I don't want to do that. And I guess other languages might possibly have this error as well. Is it possible to make the change necessary Polygon API to emit the volume fields always as decimal int64 ?
Thanks.