-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
models.Date doesn't marshal correctly
Expected behavior
I would expect models.Date to marshal and unmarshal correctly.
Example:
https://go.dev/play/p/6t85zeW7AHr
package main
import (
"encoding/json"
"fmt"
"os"
"time"
"github.com/polygon-io/client-go/rest/models"
)
func main() {
s := `{
"cfi": "OCASPS",
"contract_type": "call",
"exercise_style": "american",
"expiration_date": "2025-02-24",
"primary_exchange": "BATO",
"shares_per_contract": 100,
"strike_price": 400,
"ticker": "O:SPY250224C00400000",
"underlying_ticker": "SPY"
}`
var m1 models.OptionsContract
err := json.Unmarshal([]byte(s), &m1)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
fmt.Println("expiration_date:", m1.ExpirationDate)
fmt.Println("expiration_date:", time.Time(m1.ExpirationDate))
bs, err := json.Marshal(m1)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
fmt.Printf("bs: %s\n", bs)
var m2 models.OptionsContract
err = json.Unmarshal(bs, &m2)
if err != nil {
fmt.Println(err)
os.Exit(-1)
}
fmt.Println("expiration_date:", m2.ExpirationDate)
fmt.Println("expiration_date:", time.Time(m2.ExpirationDate))
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working