From 62a396360e151bc81caa9436b5750c9925dee5d3 Mon Sep 17 00:00:00 2001 From: Nathan Hack Date: Sun, 10 Nov 2024 21:13:54 -0500 Subject: [PATCH 1/6] add GetOptionContracts & GetOptionContract --- alpaca/options.go | 94 +++++++ alpaca/options_easyjson.go | 526 +++++++++++++++++++++++++++++++++++++ alpaca/rest.go | 117 +++++++++ alpaca/rest_test.go | 118 +++++++++ 4 files changed, 855 insertions(+) create mode 100644 alpaca/options.go create mode 100644 alpaca/options_easyjson.go diff --git a/alpaca/options.go b/alpaca/options.go new file mode 100644 index 0000000..586b79b --- /dev/null +++ b/alpaca/options.go @@ -0,0 +1,94 @@ +package alpaca + +import ( + "cloud.google.com/go/civil" + "github.com/shopspring/decimal" +) + +//go:generate go install github.com/mailru/easyjson/...@v0.7.7 +//go:generate easyjson -all -snake_case $GOFILE + +type OptionStatus string + +const ( + OptionStatusActive OptionStatus = "active" + OptionStatusInactive OptionStatus = "inactive" +) + +type OptionType string + +const ( + OptionTypeCall OptionType = "call" + OptionTypePut OptionType = "put" +) + +type OptionStyle string + +const ( + OptionStyleAmerican OptionStyle = "american" + OptionStyleEuropean OptionStyle = "european" +) + +type DeliverableType string + +const ( + DeliverableTypeCash DeliverableType = "cash" + DeliverableTypeEquity DeliverableType = "equity" +) + +type DeliverableSettlementType string + +const ( + DeliverableSettlementTypeT0 DeliverableSettlementType = "T+0" + DeliverableSettlementTypeT1 DeliverableSettlementType = "T+1" + DeliverableSettlementTypeT2 DeliverableSettlementType = "T+2" + DeliverableSettlementTypeT3 DeliverableSettlementType = "T+3" + DeliverableSettlementTypeT4 DeliverableSettlementType = "T+4" + DeliverableSettlementTypeT5 DeliverableSettlementType = "T+5" +) + +type DeliverableSettlementMethod string + +const ( + DeliverableSettlementMethodBTOB DeliverableSettlementMethod = "BTOB" + DeliverableSettlementMethodCADF DeliverableSettlementMethod = "CADF" + DeliverableSettlementMethodCAFX DeliverableSettlementMethod = "CAFX" + DeliverableSettlementMethodCCC DeliverableSettlementMethod = "CCC" +) + +type OptionDeliverable struct { + Type DeliverableType `json:"type"` + Symbol string `json:"symbol"` + AssetID *string `json:"asset_id,omitempty"` + Amount string `json:"amount"` + AllocationPercentage string `json:"allocation_percentage"` + SettlementType DeliverableSettlementType `json:"settlement_method"` + DelayedSettlement bool `json:"delayed_settlement"` +} + +type OptionContract struct { + ID string `json:"id"` + Symbol string `json:"symbol"` + Name string `json:"name"` + Status string `json:"status"` + Tradable bool `json:"tradable"` + ExpirationDate civil.Date `json:"expiration_date"` + RootSymbol *string `json:"root_symbol,omitempty"` + UnderlyingSymbol string `json:"underlying_symbol"` + UnderlyingAssetID string `json:"underlying_assest_id"` + Type OptionType `json:"type"` + Style OptionStyle `json:"style"` + StrikePrice decimal.Decimal `json:"strike_price"` + Multiplier string `json:"multiplier"` + Size string `json:"size"` + OpenInterest *string `json:"open_interest"` + OpenInterestDate *civil.Date `json:"open_interest_date,omitempty"` + ClosePrice *decimal.Decimal `json:"close_price,omitempty"` + ClosePriceDate *civil.Date `json:"close_price_date,omitempty"` + Deliverables []OptionDeliverable `json:"deliverables,omitempty"` +} + +type optionContractsResponse struct { + OptionContracts []OptionContract `json:"option_contracts"` + NextPageToken *string `json:"next_page_token,omitempty"` +} diff --git a/alpaca/options_easyjson.go b/alpaca/options_easyjson.go new file mode 100644 index 0000000..24096ec --- /dev/null +++ b/alpaca/options_easyjson.go @@ -0,0 +1,526 @@ +// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. + +package alpaca + +import ( + civil "cloud.google.com/go/civil" + json "encoding/json" + easyjson "github.com/mailru/easyjson" + jlexer "github.com/mailru/easyjson/jlexer" + jwriter "github.com/mailru/easyjson/jwriter" + decimal "github.com/shopspring/decimal" +) + +// suppress unused package warning +var ( + _ *json.RawMessage + _ *jlexer.Lexer + _ *jwriter.Writer + _ easyjson.Marshaler +) + +func easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(in *jlexer.Lexer, out *optionContractsResponse) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "option_contracts": + if in.IsNull() { + in.Skip() + out.OptionContracts = nil + } else { + in.Delim('[') + if out.OptionContracts == nil { + if !in.IsDelim(']') { + out.OptionContracts = make([]OptionContract, 0, 0) + } else { + out.OptionContracts = []OptionContract{} + } + } else { + out.OptionContracts = (out.OptionContracts)[:0] + } + for !in.IsDelim(']') { + var v1 OptionContract + (v1).UnmarshalEasyJSON(in) + out.OptionContracts = append(out.OptionContracts, v1) + in.WantComma() + } + in.Delim(']') + } + case "next_page_token": + if in.IsNull() { + in.Skip() + out.NextPageToken = nil + } else { + if out.NextPageToken == nil { + out.NextPageToken = new(string) + } + *out.NextPageToken = string(in.String()) + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(out *jwriter.Writer, in optionContractsResponse) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"option_contracts\":" + out.RawString(prefix[1:]) + if in.OptionContracts == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v2, v3 := range in.OptionContracts { + if v2 > 0 { + out.RawByte(',') + } + (v3).MarshalEasyJSON(out) + } + out.RawByte(']') + } + } + if in.NextPageToken != nil { + const prefix string = ",\"next_page_token\":" + out.RawString(prefix) + out.String(string(*in.NextPageToken)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v optionContractsResponse) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v optionContractsResponse) MarshalEasyJSON(w *jwriter.Writer) { + easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *optionContractsResponse) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *optionContractsResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(l, v) +} +func easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(in *jlexer.Lexer, out *OptionDeliverable) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "type": + out.Type = DeliverableType(in.String()) + case "symbol": + out.Symbol = string(in.String()) + case "asset_id": + if in.IsNull() { + in.Skip() + out.AssetID = nil + } else { + if out.AssetID == nil { + out.AssetID = new(string) + } + *out.AssetID = string(in.String()) + } + case "amount": + out.Amount = string(in.String()) + case "allocation_percentage": + out.AllocationPercentage = string(in.String()) + case "settlement_method": + out.SettlementType = DeliverableSettlementType(in.String()) + case "delayed_settlement": + out.DelayedSettlement = bool(in.Bool()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(out *jwriter.Writer, in OptionDeliverable) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"type\":" + out.RawString(prefix[1:]) + out.String(string(in.Type)) + } + { + const prefix string = ",\"symbol\":" + out.RawString(prefix) + out.String(string(in.Symbol)) + } + if in.AssetID != nil { + const prefix string = ",\"asset_id\":" + out.RawString(prefix) + out.String(string(*in.AssetID)) + } + { + const prefix string = ",\"amount\":" + out.RawString(prefix) + out.String(string(in.Amount)) + } + { + const prefix string = ",\"allocation_percentage\":" + out.RawString(prefix) + out.String(string(in.AllocationPercentage)) + } + { + const prefix string = ",\"settlement_method\":" + out.RawString(prefix) + out.String(string(in.SettlementType)) + } + { + const prefix string = ",\"delayed_settlement\":" + out.RawString(prefix) + out.Bool(bool(in.DelayedSettlement)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v OptionDeliverable) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v OptionDeliverable) MarshalEasyJSON(w *jwriter.Writer) { + easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *OptionDeliverable) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *OptionDeliverable) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(l, v) +} +func easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(in *jlexer.Lexer, out *OptionContract) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "id": + out.ID = string(in.String()) + case "symbol": + out.Symbol = string(in.String()) + case "name": + out.Name = string(in.String()) + case "status": + out.Status = string(in.String()) + case "tradable": + out.Tradable = bool(in.Bool()) + case "expiration_date": + if data := in.UnsafeBytes(); in.Ok() { + in.AddError((out.ExpirationDate).UnmarshalText(data)) + } + case "root_symbol": + if in.IsNull() { + in.Skip() + out.RootSymbol = nil + } else { + if out.RootSymbol == nil { + out.RootSymbol = new(string) + } + *out.RootSymbol = string(in.String()) + } + case "underlying_symbol": + out.UnderlyingSymbol = string(in.String()) + case "underlying_assest_id": + out.UnderlyingAssetID = string(in.String()) + case "type": + out.Type = OptionType(in.String()) + case "style": + out.Style = OptionStyle(in.String()) + case "strike_price": + if data := in.Raw(); in.Ok() { + in.AddError((out.StrikePrice).UnmarshalJSON(data)) + } + case "multiplier": + out.Multiplier = string(in.String()) + case "size": + out.Size = string(in.String()) + case "open_interest": + if in.IsNull() { + in.Skip() + out.OpenInterest = nil + } else { + if out.OpenInterest == nil { + out.OpenInterest = new(string) + } + *out.OpenInterest = string(in.String()) + } + case "open_interest_date": + if in.IsNull() { + in.Skip() + out.OpenInterestDate = nil + } else { + if out.OpenInterestDate == nil { + out.OpenInterestDate = new(civil.Date) + } + if data := in.UnsafeBytes(); in.Ok() { + in.AddError((*out.OpenInterestDate).UnmarshalText(data)) + } + } + case "close_price": + if in.IsNull() { + in.Skip() + out.ClosePrice = nil + } else { + if out.ClosePrice == nil { + out.ClosePrice = new(decimal.Decimal) + } + if data := in.Raw(); in.Ok() { + in.AddError((*out.ClosePrice).UnmarshalJSON(data)) + } + } + case "close_price_date": + if in.IsNull() { + in.Skip() + out.ClosePriceDate = nil + } else { + if out.ClosePriceDate == nil { + out.ClosePriceDate = new(civil.Date) + } + if data := in.UnsafeBytes(); in.Ok() { + in.AddError((*out.ClosePriceDate).UnmarshalText(data)) + } + } + case "deliverables": + if in.IsNull() { + in.Skip() + out.Deliverables = nil + } else { + in.Delim('[') + if out.Deliverables == nil { + if !in.IsDelim(']') { + out.Deliverables = make([]OptionDeliverable, 0, 0) + } else { + out.Deliverables = []OptionDeliverable{} + } + } else { + out.Deliverables = (out.Deliverables)[:0] + } + for !in.IsDelim(']') { + var v4 OptionDeliverable + (v4).UnmarshalEasyJSON(in) + out.Deliverables = append(out.Deliverables, v4) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(out *jwriter.Writer, in OptionContract) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"id\":" + out.RawString(prefix[1:]) + out.String(string(in.ID)) + } + { + const prefix string = ",\"symbol\":" + out.RawString(prefix) + out.String(string(in.Symbol)) + } + { + const prefix string = ",\"name\":" + out.RawString(prefix) + out.String(string(in.Name)) + } + { + const prefix string = ",\"status\":" + out.RawString(prefix) + out.String(string(in.Status)) + } + { + const prefix string = ",\"tradable\":" + out.RawString(prefix) + out.Bool(bool(in.Tradable)) + } + { + const prefix string = ",\"expiration_date\":" + out.RawString(prefix) + out.RawText((in.ExpirationDate).MarshalText()) + } + if in.RootSymbol != nil { + const prefix string = ",\"root_symbol\":" + out.RawString(prefix) + out.String(string(*in.RootSymbol)) + } + { + const prefix string = ",\"underlying_symbol\":" + out.RawString(prefix) + out.String(string(in.UnderlyingSymbol)) + } + { + const prefix string = ",\"underlying_assest_id\":" + out.RawString(prefix) + out.String(string(in.UnderlyingAssetID)) + } + { + const prefix string = ",\"type\":" + out.RawString(prefix) + out.String(string(in.Type)) + } + { + const prefix string = ",\"style\":" + out.RawString(prefix) + out.String(string(in.Style)) + } + { + const prefix string = ",\"strike_price\":" + out.RawString(prefix) + out.Raw((in.StrikePrice).MarshalJSON()) + } + { + const prefix string = ",\"multiplier\":" + out.RawString(prefix) + out.String(string(in.Multiplier)) + } + { + const prefix string = ",\"size\":" + out.RawString(prefix) + out.String(string(in.Size)) + } + { + const prefix string = ",\"open_interest\":" + out.RawString(prefix) + if in.OpenInterest == nil { + out.RawString("null") + } else { + out.String(string(*in.OpenInterest)) + } + } + if in.OpenInterestDate != nil { + const prefix string = ",\"open_interest_date\":" + out.RawString(prefix) + out.RawText((*in.OpenInterestDate).MarshalText()) + } + if in.ClosePrice != nil { + const prefix string = ",\"close_price\":" + out.RawString(prefix) + out.Raw((*in.ClosePrice).MarshalJSON()) + } + if in.ClosePriceDate != nil { + const prefix string = ",\"close_price_date\":" + out.RawString(prefix) + out.RawText((*in.ClosePriceDate).MarshalText()) + } + if len(in.Deliverables) != 0 { + const prefix string = ",\"deliverables\":" + out.RawString(prefix) + { + out.RawByte('[') + for v5, v6 := range in.Deliverables { + if v5 > 0 { + out.RawByte(',') + } + (v6).MarshalEasyJSON(out) + } + out.RawByte(']') + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v OptionContract) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v OptionContract) MarshalEasyJSON(w *jwriter.Writer) { + easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *OptionContract) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *OptionContract) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(l, v) +} diff --git a/alpaca/rest.go b/alpaca/rest.go index 4846e5e..fdd7edf 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -9,10 +9,12 @@ import ( "net/http" "net/url" "os" + "reflect" "strconv" "strings" "time" + "cloud.google.com/go/civil" "github.com/mailru/easyjson" "github.com/shopspring/decimal" ) @@ -742,6 +744,121 @@ func (c *Client) GetAsset(symbol string) (*Asset, error) { return &asset, nil } +type GetOptionContractsRequest struct { + UnderlyingSymbols string `json:"underlying_symbols"` + ShowDeliverable *bool `json:"show_deliverables"` + Status *OptionStatus `json:"status"` + ExpirationDate *civil.Date `json:"expiration_date"` + ExpirationDateGTE *civil.Date `json:"expiration_date_gte"` + ExpirationDateLTE *civil.Date `json:"expiration_date_lte"` + RootSymbol *string `json:"root_symbol"` + Type *OptionType `json:"type"` + Style *OptionStyle `json:"style"` + StrikePriceGTE *decimal.Decimal `json:"strike_price_gte"` + StrikePriceLTE *decimal.Decimal `json:"strike_price_lte"` + Limit *int `json:"limit"` + PPInd *bool `json:"ppind"` +} + +// GetOptionContracts returns the list of Option Contracts. +func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionContract, error) { + u, err := url.Parse(fmt.Sprintf("%s/%s/options/contracts", c.opts.BaseURL, apiVersion)) + if err != nil { + return nil, err + } + + q := u.Query() + + structType := reflect.TypeOf(req) + structValue := reflect.ValueOf(req) + + for i := 0; i < structType.NumField(); i++ { + fieldType := structType.Field(i) + fieldValue := structValue.Field(i) + + kind := fieldType.Type.Kind() + + if kind == reflect.String { + v := fieldValue.String() + if v != "" { + q.Set(fieldType.Tag.Get("json"), v) + } + continue + } + + // else it's a reflect.Ptr: + if kind != reflect.Ptr { + panic("GetOptionContractsRequest's struct was changed this should be a pointer") + } + + // if it's not a nil value then we do somthing with it + if !fieldValue.IsNil() { + subFieldType := fieldType.Type.Elem() + subFieldValue := fieldValue.Elem() + + // again we only really care about the string because it could be empty + if subFieldType.Kind() == reflect.String { + v := subFieldValue.String() + if v != "" { + q.Set(fieldType.Tag.Get("json"), v) + } + } else { + q.Set(fieldType.Tag.Get("json"), fmt.Sprint(subFieldValue)) + } + } + } + + optionContracts := make([]OptionContract, 0) + for { + u.RawQuery = q.Encode() + + resp, err := c.get(u) + if err != nil { + return nil, err + } + + // bs, err := ioutil.ReadAll(resp.Body) + // fmt.Println(string(bs)) + + var response optionContractsResponse + if err = unmarshal(resp, &response); err != nil { + return nil, err + } + + optionContracts = append(optionContracts, response.OptionContracts...) + + if response.NextPageToken == nil { + break + } + + fmt.Println("setting page_token:", *response.NextPageToken) + q.Set("page_token", *response.NextPageToken) + closeResp(resp) + } + + return optionContracts, nil +} + +// GetOptionContract returns the Option Contracts. +func (c *Client) GetOptionContract(symbolOrID string) (*OptionContract, error) { + u, err := url.Parse(fmt.Sprintf("%s/%s/options/contracts/%v", c.opts.BaseURL, apiVersion, symbolOrID)) + if err != nil { + return nil, err + } + + resp, err := c.get(u) + if err != nil { + return nil, err + } + defer closeResp(resp) + + var optionContract OptionContract + if err = unmarshal(resp, &optionContract); err != nil { + return nil, err + } + return &optionContract, nil +} + type GetAnnouncementsRequest struct { CATypes []string `json:"ca_types"` Since time.Time `json:"since"` diff --git a/alpaca/rest_test.go b/alpaca/rest_test.go index 2a8afc6..8b4bda5 100644 --- a/alpaca/rest_test.go +++ b/alpaca/rest_test.go @@ -9,6 +9,7 @@ import ( "io" "net/http" "net/http/httptest" + "strconv" "strings" "testing" "time" @@ -908,6 +909,123 @@ func TestGetAssetFromJSON(t *testing.T) { assert.Nil(t, asset) } +func TestGetOptionContracts(t *testing.T) { + c := DefaultClient + // successful with nils + request := GetOptionContractsRequest{ + UnderlyingSymbols: "some_symbol1,some_symbol2", + } + expectedID := "some_id" + c.do = func(_ *Client, req *http.Request) (*http.Response, error) { + assert.Equal(t, request.UnderlyingSymbols, req.URL.Query().Get("underlying_symbols")) + response := optionContractsResponse{ + OptionContracts: []OptionContract{ + { + ID: expectedID, + ExpirationDate: civil.Date{Year: 1, Month: 1, Day: 1}, + }, + }, + } + return &http.Response{ + Body: genBody(response), + }, nil + } + + contracts, err := c.GetOptionContracts(request) + require.NoError(t, err) + require.Len(t, contracts, 1) + assert.Equal(t, expectedID, contracts[0].ID) + + // successful without nils + showDeliverable := true + status := OptionStatusActive + rootSymbol := "some_symbol" + ocType := OptionTypeCall + style := OptionStyleEuropean + priceGTE := decimal.NewFromInt(10) + limit := 5 + ppind := false + request = GetOptionContractsRequest{ + UnderlyingSymbols: "some_symbol", + ShowDeliverable: &showDeliverable, + Status: &status, + ExpirationDate: &civil.Date{Year: 2000, Month: 01, Day: 01}, + RootSymbol: &rootSymbol, + Type: &ocType, + Style: &style, + StrikePriceGTE: &priceGTE, + Limit: &limit, + PPInd: &ppind, + } + c.do = func(_ *Client, req *http.Request) (*http.Response, error) { + assert.Equal(t, request.UnderlyingSymbols, req.URL.Query().Get("underlying_symbols")) + assert.Equal(t, strconv.FormatBool(*request.ShowDeliverable), req.URL.Query().Get("show_deliverables")) + assert.Equal(t, fmt.Sprint(*request.Status), req.URL.Query().Get("status")) + assert.Equal(t, fmt.Sprint(*request.ExpirationDate), req.URL.Query().Get("expiration_date")) + assert.Equal(t, *request.RootSymbol, req.URL.Query().Get("root_symbol")) + assert.Equal(t, fmt.Sprint(*request.Type), req.URL.Query().Get("type")) + assert.Equal(t, fmt.Sprint(*request.Style), req.URL.Query().Get("style")) + assert.Equal(t, fmt.Sprint(*request.StrikePriceGTE), req.URL.Query().Get("strike_price_gte")) + assert.Equal(t, strconv.Itoa(*request.Limit), req.URL.Query().Get("limit")) + assert.Equal(t, strconv.FormatBool(*request.PPInd), req.URL.Query().Get("ppind")) + + assets := optionContractsResponse{ + OptionContracts: []OptionContract{ + { + ID: expectedID, + ExpirationDate: civil.Date{Year: 1, Month: 1, Day: 1}, + }, + }, + } + return &http.Response{ + Body: genBody(assets), + }, nil + } + + contracts, err = c.GetOptionContracts(request) + require.NoError(t, err) + require.Len(t, contracts, 1) + assert.Equal(t, expectedID, contracts[0].ID) + + // api failure + c.do = func(_ *Client, _ *http.Request) (*http.Response, error) { + return &http.Response{}, errors.New("fail") + } + + _, err = c.GetOptionContracts(GetOptionContractsRequest{}) + require.Error(t, err) +} + +func TestGetOptionContract(t *testing.T) { + c := DefaultClient + // successful with nils + expectedSymbol := "some_symbol" + expectedID := "some_id" + c.do = func(_ *Client, req *http.Request) (*http.Response, error) { + assert.True(t, strings.HasSuffix(req.URL.Path, expectedSymbol)) + + return &http.Response{ + Body: genBody(OptionContract{ + ID: expectedID, + ExpirationDate: civil.Date{Year: 1, Month: 1, Day: 1}, + }), + }, nil + } + + contract, err := c.GetOptionContract(expectedSymbol) + require.NoError(t, err) + require.NotNil(t, contract) + assert.Equal(t, expectedID, contract.ID) + + // api failure + c.do = func(_ *Client, _ *http.Request) (*http.Response, error) { + return &http.Response{}, errors.New("fail") + } + + _, err = c.GetOptionContract(expectedSymbol) + require.Error(t, err) +} + func TestTestVerify(t *testing.T) { // 200 resp := &http.Response{ From d0412f9ef31e5fbcf3ff4974f437b081d4371110 Mon Sep 17 00:00:00 2001 From: nathanhack Date: Mon, 11 Nov 2024 11:03:50 -0500 Subject: [PATCH 2/6] Update alpaca/rest.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gergely Novák --- alpaca/rest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alpaca/rest.go b/alpaca/rest.go index fdd7edf..2a27822 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -839,7 +839,7 @@ func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionCont return optionContracts, nil } -// GetOptionContract returns the Option Contracts. +// GetOptionContract returns an option contract by symbol or contract ID. func (c *Client) GetOptionContract(symbolOrID string) (*OptionContract, error) { u, err := url.Parse(fmt.Sprintf("%s/%s/options/contracts/%v", c.opts.BaseURL, apiVersion, symbolOrID)) if err != nil { From a310bc146ebb62c2b393636006cfdcac668c1df9 Mon Sep 17 00:00:00 2001 From: Nathan Hack Date: Mon, 11 Nov 2024 14:01:28 -0500 Subject: [PATCH 3/6] changes from code review --- alpaca/entities.go | 86 +++ alpaca/entities_easyjson.go | 1003 ++++++++++++++++++++++++++--------- alpaca/options.go | 94 ---- alpaca/options_easyjson.go | 526 ------------------ alpaca/rest.go | 133 +++-- alpaca/rest_test.go | 47 +- 6 files changed, 952 insertions(+), 937 deletions(-) delete mode 100644 alpaca/options.go delete mode 100644 alpaca/options_easyjson.go diff --git a/alpaca/entities.go b/alpaca/entities.go index a7a53a4..464bc76 100644 --- a/alpaca/entities.go +++ b/alpaca/entities.go @@ -388,3 +388,89 @@ type closeAllPositionsResponse struct { Status int `json:"status"` Body json.RawMessage `json:"body,omitempty"` } + +type OptionStatus string + +const ( + OptionStatusActive OptionStatus = "active" + OptionStatusInactive OptionStatus = "inactive" +) + +type OptionType string + +const ( + OptionTypeCall OptionType = "call" + OptionTypePut OptionType = "put" +) + +type OptionStyle string + +const ( + OptionStyleAmerican OptionStyle = "american" + OptionStyleEuropean OptionStyle = "european" +) + +type DeliverableType string + +const ( + DeliverableTypeCash DeliverableType = "cash" + DeliverableTypeEquity DeliverableType = "equity" +) + +type DeliverableSettlementType string + +const ( + DeliverableSettlementTypeT0 DeliverableSettlementType = "T+0" + DeliverableSettlementTypeT1 DeliverableSettlementType = "T+1" + DeliverableSettlementTypeT2 DeliverableSettlementType = "T+2" + DeliverableSettlementTypeT3 DeliverableSettlementType = "T+3" + DeliverableSettlementTypeT4 DeliverableSettlementType = "T+4" + DeliverableSettlementTypeT5 DeliverableSettlementType = "T+5" +) + +type DeliverableSettlementMethod string + +const ( + DeliverableSettlementMethodBTOB DeliverableSettlementMethod = "BTOB" + DeliverableSettlementMethodCADF DeliverableSettlementMethod = "CADF" + DeliverableSettlementMethodCAFX DeliverableSettlementMethod = "CAFX" + DeliverableSettlementMethodCCC DeliverableSettlementMethod = "CCC" +) + +type OptionDeliverable struct { + Type DeliverableType `json:"type"` + Symbol string `json:"symbol"` + AssetID *string `json:"asset_id,omitempty"` + Amount decimal.Decimal `json:"amount"` + AllocationPercentage decimal.Decimal `json:"allocation_percentage"` + SettlementType DeliverableSettlementType `json:"settlement_type"` + SettlementMethod DeliverableSettlementMethod `json:"settlement_method"` + DelayedSettlement bool `json:"delayed_settlement"` +} + +type OptionContract struct { + ID string `json:"id"` + Symbol string `json:"symbol"` + Name string `json:"name"` + Status OptionStatus `json:"status"` + Tradable bool `json:"tradable"` + ExpirationDate civil.Date `json:"expiration_date"` + RootSymbol *string `json:"root_symbol,omitempty"` + UnderlyingSymbol string `json:"underlying_symbol"` + UnderlyingAssetID string `json:"underlying_asset_id"` + Type OptionType `json:"type"` + Style OptionStyle `json:"style"` + StrikePrice decimal.Decimal `json:"strike_price"` + Multiplier decimal.Decimal `json:"multiplier"` + Size decimal.Decimal `json:"size"` + OpenInterest *decimal.Decimal `json:"open_interest"` + OpenInterestDate *civil.Date `json:"open_interest_date,omitempty"` + ClosePrice *decimal.Decimal `json:"close_price,omitempty"` + ClosePriceDate *civil.Date `json:"close_price_date,omitempty"` + Deliverables []OptionDeliverable `json:"deliverables,omitempty"` +} + +type optionContractsResponse struct { + OptionContracts []OptionContract `json:"option_contracts"` + NextPageToken *string `json:"next_page_token,omitempty"` +} diff --git a/alpaca/entities_easyjson.go b/alpaca/entities_easyjson.go index 6123a11..a6a3a7b 100644 --- a/alpaca/entities_easyjson.go +++ b/alpaca/entities_easyjson.go @@ -3,6 +3,7 @@ package alpaca import ( + civil "cloud.google.com/go/civil" json "encoding/json" easyjson "github.com/mailru/easyjson" jlexer "github.com/mailru/easyjson/jlexer" @@ -217,7 +218,120 @@ func (v *orderSlice) UnmarshalJSON(data []byte) error { func (v *orderSlice) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(in *jlexer.Lexer, out *closeAllPositionsSlice) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(in *jlexer.Lexer, out *optionContractsResponse) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "option_contracts": + if in.IsNull() { + in.Skip() + out.OptionContracts = nil + } else { + in.Delim('[') + if out.OptionContracts == nil { + if !in.IsDelim(']') { + out.OptionContracts = make([]OptionContract, 0, 0) + } else { + out.OptionContracts = []OptionContract{} + } + } else { + out.OptionContracts = (out.OptionContracts)[:0] + } + for !in.IsDelim(']') { + var v10 OptionContract + (v10).UnmarshalEasyJSON(in) + out.OptionContracts = append(out.OptionContracts, v10) + in.WantComma() + } + in.Delim(']') + } + case "next_page_token": + if in.IsNull() { + in.Skip() + out.NextPageToken = nil + } else { + if out.NextPageToken == nil { + out.NextPageToken = new(string) + } + *out.NextPageToken = string(in.String()) + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(out *jwriter.Writer, in optionContractsResponse) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"option_contracts\":" + out.RawString(prefix[1:]) + if in.OptionContracts == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v11, v12 := range in.OptionContracts { + if v11 > 0 { + out.RawByte(',') + } + (v12).MarshalEasyJSON(out) + } + out.RawByte(']') + } + } + if in.NextPageToken != nil { + const prefix string = ",\"next_page_token\":" + out.RawString(prefix) + out.String(string(*in.NextPageToken)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v optionContractsResponse) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v optionContractsResponse) MarshalEasyJSON(w *jwriter.Writer) { + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *optionContractsResponse) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *optionContractsResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(l, v) +} +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(in *jlexer.Lexer, out *closeAllPositionsSlice) { isTopLevel := in.IsStart() if in.IsNull() { in.Skip() @@ -234,9 +348,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(in *jlexer *out = (*out)[:0] } for !in.IsDelim(']') { - var v10 closeAllPositionsResponse - (v10).UnmarshalEasyJSON(in) - *out = append(*out, v10) + var v13 closeAllPositionsResponse + (v13).UnmarshalEasyJSON(in) + *out = append(*out, v13) in.WantComma() } in.Delim(']') @@ -245,16 +359,16 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(in *jlexer in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(out *jwriter.Writer, in closeAllPositionsSlice) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(out *jwriter.Writer, in closeAllPositionsSlice) { if in == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { out.RawString("null") } else { out.RawByte('[') - for v11, v12 := range in { - if v11 > 0 { + for v14, v15 := range in { + if v14 > 0 { out.RawByte(',') } - (v12).MarshalEasyJSON(out) + (v15).MarshalEasyJSON(out) } out.RawByte(']') } @@ -263,27 +377,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(out *jwrit // MarshalJSON supports json.Marshaler interface func (v closeAllPositionsSlice) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v closeAllPositionsSlice) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *closeAllPositionsSlice) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *closeAllPositionsSlice) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca3(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(in *jlexer.Lexer, out *closeAllPositionsResponse) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(in *jlexer.Lexer, out *closeAllPositionsResponse) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -320,7 +434,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(in *jlexer in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(out *jwriter.Writer, in closeAllPositionsResponse) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(out *jwriter.Writer, in closeAllPositionsResponse) { out.RawByte('{') first := true _ = first @@ -345,27 +459,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(out *jwrit // MarshalJSON supports json.Marshaler interface func (v closeAllPositionsResponse) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v closeAllPositionsResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *closeAllPositionsResponse) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *closeAllPositionsResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca4(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(in *jlexer.Lexer, out *calendarDaySlice) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(in *jlexer.Lexer, out *calendarDaySlice) { isTopLevel := in.IsStart() if in.IsNull() { in.Skip() @@ -382,9 +496,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(in *jlexer *out = (*out)[:0] } for !in.IsDelim(']') { - var v13 CalendarDay - (v13).UnmarshalEasyJSON(in) - *out = append(*out, v13) + var v16 CalendarDay + (v16).UnmarshalEasyJSON(in) + *out = append(*out, v16) in.WantComma() } in.Delim(']') @@ -393,16 +507,16 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(in *jlexer in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(out *jwriter.Writer, in calendarDaySlice) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(out *jwriter.Writer, in calendarDaySlice) { if in == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { out.RawString("null") } else { out.RawByte('[') - for v14, v15 := range in { - if v14 > 0 { + for v17, v18 := range in { + if v17 > 0 { out.RawByte(',') } - (v15).MarshalEasyJSON(out) + (v18).MarshalEasyJSON(out) } out.RawByte(']') } @@ -411,27 +525,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(out *jwrit // MarshalJSON supports json.Marshaler interface func (v calendarDaySlice) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v calendarDaySlice) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *calendarDaySlice) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *calendarDaySlice) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca5(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(in *jlexer.Lexer, out *assetSlice) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(in *jlexer.Lexer, out *assetSlice) { isTopLevel := in.IsStart() if in.IsNull() { in.Skip() @@ -448,9 +562,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(in *jlexer *out = (*out)[:0] } for !in.IsDelim(']') { - var v16 Asset - (v16).UnmarshalEasyJSON(in) - *out = append(*out, v16) + var v19 Asset + (v19).UnmarshalEasyJSON(in) + *out = append(*out, v19) in.WantComma() } in.Delim(']') @@ -459,16 +573,16 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(in *jlexer in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(out *jwriter.Writer, in assetSlice) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(out *jwriter.Writer, in assetSlice) { if in == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { out.RawString("null") } else { out.RawByte('[') - for v17, v18 := range in { - if v17 > 0 { + for v20, v21 := range in { + if v20 > 0 { out.RawByte(',') } - (v18).MarshalEasyJSON(out) + (v21).MarshalEasyJSON(out) } out.RawByte(']') } @@ -477,27 +591,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(out *jwrit // MarshalJSON supports json.Marshaler interface func (v assetSlice) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v assetSlice) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *assetSlice) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *assetSlice) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca6(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(in *jlexer.Lexer, out *announcementSlice) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(in *jlexer.Lexer, out *announcementSlice) { isTopLevel := in.IsStart() if in.IsNull() { in.Skip() @@ -514,9 +628,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(in *jlexer *out = (*out)[:0] } for !in.IsDelim(']') { - var v19 Announcement - (v19).UnmarshalEasyJSON(in) - *out = append(*out, v19) + var v22 Announcement + (v22).UnmarshalEasyJSON(in) + *out = append(*out, v22) in.WantComma() } in.Delim(']') @@ -525,16 +639,16 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(in *jlexer in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(out *jwriter.Writer, in announcementSlice) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(out *jwriter.Writer, in announcementSlice) { if in == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { out.RawString("null") } else { out.RawByte('[') - for v20, v21 := range in { - if v20 > 0 { + for v23, v24 := range in { + if v23 > 0 { out.RawByte(',') } - (v21).MarshalEasyJSON(out) + (v24).MarshalEasyJSON(out) } out.RawByte(']') } @@ -543,27 +657,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(out *jwrit // MarshalJSON supports json.Marshaler interface func (v announcementSlice) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v announcementSlice) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *announcementSlice) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *announcementSlice) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca7(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(in *jlexer.Lexer, out *accountSlice) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(in *jlexer.Lexer, out *accountSlice) { isTopLevel := in.IsStart() if in.IsNull() { in.Skip() @@ -580,9 +694,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(in *jlexer *out = (*out)[:0] } for !in.IsDelim(']') { - var v22 AccountActivity - (v22).UnmarshalEasyJSON(in) - *out = append(*out, v22) + var v25 AccountActivity + (v25).UnmarshalEasyJSON(in) + *out = append(*out, v25) in.WantComma() } in.Delim(']') @@ -591,16 +705,16 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(in *jlexer in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(out *jwriter.Writer, in accountSlice) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(out *jwriter.Writer, in accountSlice) { if in == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { out.RawString("null") } else { out.RawByte('[') - for v23, v24 := range in { - if v23 > 0 { + for v26, v27 := range in { + if v26 > 0 { out.RawByte(',') } - (v24).MarshalEasyJSON(out) + (v27).MarshalEasyJSON(out) } out.RawByte(']') } @@ -609,27 +723,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(out *jwrit // MarshalJSON supports json.Marshaler interface func (v accountSlice) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v accountSlice) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *accountSlice) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *accountSlice) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca8(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(in *jlexer.Lexer, out *Watchlist) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(in *jlexer.Lexer, out *Watchlist) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -674,9 +788,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(in *jlexer out.Assets = (out.Assets)[:0] } for !in.IsDelim(']') { - var v25 Asset - (v25).UnmarshalEasyJSON(in) - out.Assets = append(out.Assets, v25) + var v28 Asset + (v28).UnmarshalEasyJSON(in) + out.Assets = append(out.Assets, v28) in.WantComma() } in.Delim(']') @@ -691,7 +805,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(in *jlexer in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(out *jwriter.Writer, in Watchlist) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(out *jwriter.Writer, in Watchlist) { out.RawByte('{') first := true _ = first @@ -727,11 +841,11 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(out *jwrit out.RawString("null") } else { out.RawByte('[') - for v26, v27 := range in.Assets { - if v26 > 0 { + for v29, v30 := range in.Assets { + if v29 > 0 { out.RawByte(',') } - (v27).MarshalEasyJSON(out) + (v30).MarshalEasyJSON(out) } out.RawByte(']') } @@ -742,27 +856,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(out *jwrit // MarshalJSON supports json.Marshaler interface func (v Watchlist) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Watchlist) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Watchlist) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Watchlist) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca9(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(in *jlexer.Lexer, out *UpdateWatchlistRequest) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(in *jlexer.Lexer, out *UpdateWatchlistRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -799,9 +913,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(in *jlexe out.Symbols = (out.Symbols)[:0] } for !in.IsDelim(']') { - var v28 string - v28 = string(in.String()) - out.Symbols = append(out.Symbols, v28) + var v31 string + v31 = string(in.String()) + out.Symbols = append(out.Symbols, v31) in.WantComma() } in.Delim(']') @@ -816,7 +930,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(out *jwriter.Writer, in UpdateWatchlistRequest) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(out *jwriter.Writer, in UpdateWatchlistRequest) { out.RawByte('{') first := true _ = first @@ -832,11 +946,11 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(out *jwri out.RawString("null") } else { out.RawByte('[') - for v29, v30 := range in.Symbols { - if v29 > 0 { + for v32, v33 := range in.Symbols { + if v32 > 0 { out.RawByte(',') } - out.String(string(v30)) + out.String(string(v33)) } out.RawByte(']') } @@ -847,27 +961,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(out *jwri // MarshalJSON supports json.Marshaler interface func (v UpdateWatchlistRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v UpdateWatchlistRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *UpdateWatchlistRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *UpdateWatchlistRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca10(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(in *jlexer.Lexer, out *TradeUpdate) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(in *jlexer.Lexer, out *TradeUpdate) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -956,7 +1070,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(out *jwriter.Writer, in TradeUpdate) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(out *jwriter.Writer, in TradeUpdate) { out.RawByte('{') first := true _ = first @@ -1027,27 +1141,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(out *jwri // MarshalJSON supports json.Marshaler interface func (v TradeUpdate) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v TradeUpdate) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *TradeUpdate) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *TradeUpdate) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca11(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(in *jlexer.Lexer, out *RemoveSymbolFromWatchlistRequest) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(in *jlexer.Lexer, out *RemoveSymbolFromWatchlistRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1078,7 +1192,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(out *jwriter.Writer, in RemoveSymbolFromWatchlistRequest) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(out *jwriter.Writer, in RemoveSymbolFromWatchlistRequest) { out.RawByte('{') first := true _ = first @@ -1093,27 +1207,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(out *jwri // MarshalJSON supports json.Marshaler interface func (v RemoveSymbolFromWatchlistRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v RemoveSymbolFromWatchlistRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *RemoveSymbolFromWatchlistRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *RemoveSymbolFromWatchlistRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca12(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(in *jlexer.Lexer, out *Position) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(in *jlexer.Lexer, out *Position) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1266,7 +1380,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(out *jwriter.Writer, in Position) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(out *jwriter.Writer, in Position) { out.RawByte('{') first := true _ = first @@ -1398,27 +1512,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(out *jwri // MarshalJSON supports json.Marshaler interface func (v Position) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Position) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Position) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Position) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca13(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(in *jlexer.Lexer, out *PortfolioHistory) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(in *jlexer.Lexer, out *PortfolioHistory) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1457,11 +1571,11 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(in *jlexe out.Equity = (out.Equity)[:0] } for !in.IsDelim(']') { - var v31 decimal.Decimal + var v34 decimal.Decimal if data := in.Raw(); in.Ok() { - in.AddError((v31).UnmarshalJSON(data)) + in.AddError((v34).UnmarshalJSON(data)) } - out.Equity = append(out.Equity, v31) + out.Equity = append(out.Equity, v34) in.WantComma() } in.Delim(']') @@ -1482,11 +1596,11 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(in *jlexe out.ProfitLoss = (out.ProfitLoss)[:0] } for !in.IsDelim(']') { - var v32 decimal.Decimal + var v35 decimal.Decimal if data := in.Raw(); in.Ok() { - in.AddError((v32).UnmarshalJSON(data)) + in.AddError((v35).UnmarshalJSON(data)) } - out.ProfitLoss = append(out.ProfitLoss, v32) + out.ProfitLoss = append(out.ProfitLoss, v35) in.WantComma() } in.Delim(']') @@ -1507,11 +1621,11 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(in *jlexe out.ProfitLossPct = (out.ProfitLossPct)[:0] } for !in.IsDelim(']') { - var v33 decimal.Decimal + var v36 decimal.Decimal if data := in.Raw(); in.Ok() { - in.AddError((v33).UnmarshalJSON(data)) + in.AddError((v36).UnmarshalJSON(data)) } - out.ProfitLossPct = append(out.ProfitLossPct, v33) + out.ProfitLossPct = append(out.ProfitLossPct, v36) in.WantComma() } in.Delim(']') @@ -1534,9 +1648,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(in *jlexe out.Timestamp = (out.Timestamp)[:0] } for !in.IsDelim(']') { - var v34 int64 - v34 = int64(in.Int64()) - out.Timestamp = append(out.Timestamp, v34) + var v37 int64 + v37 = int64(in.Int64()) + out.Timestamp = append(out.Timestamp, v37) in.WantComma() } in.Delim(']') @@ -1551,7 +1665,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(out *jwriter.Writer, in PortfolioHistory) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(out *jwriter.Writer, in PortfolioHistory) { out.RawByte('{') first := true _ = first @@ -1567,11 +1681,11 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(out *jwri out.RawString("null") } else { out.RawByte('[') - for v35, v36 := range in.Equity { - if v35 > 0 { + for v38, v39 := range in.Equity { + if v38 > 0 { out.RawByte(',') } - out.Raw((v36).MarshalJSON()) + out.Raw((v39).MarshalJSON()) } out.RawByte(']') } @@ -1583,11 +1697,11 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(out *jwri out.RawString("null") } else { out.RawByte('[') - for v37, v38 := range in.ProfitLoss { - if v37 > 0 { + for v40, v41 := range in.ProfitLoss { + if v40 > 0 { out.RawByte(',') } - out.Raw((v38).MarshalJSON()) + out.Raw((v41).MarshalJSON()) } out.RawByte(']') } @@ -1599,11 +1713,11 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(out *jwri out.RawString("null") } else { out.RawByte('[') - for v39, v40 := range in.ProfitLossPct { - if v39 > 0 { + for v42, v43 := range in.ProfitLossPct { + if v42 > 0 { out.RawByte(',') } - out.Raw((v40).MarshalJSON()) + out.Raw((v43).MarshalJSON()) } out.RawByte(']') } @@ -1620,11 +1734,11 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(out *jwri out.RawString("null") } else { out.RawByte('[') - for v41, v42 := range in.Timestamp { - if v41 > 0 { + for v44, v45 := range in.Timestamp { + if v44 > 0 { out.RawByte(',') } - out.Int64(int64(v42)) + out.Int64(int64(v45)) } out.RawByte(']') } @@ -1635,27 +1749,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(out *jwri // MarshalJSON supports json.Marshaler interface func (v PortfolioHistory) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v PortfolioHistory) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *PortfolioHistory) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *PortfolioHistory) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca14(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(in *jlexer.Lexer, out *Order) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(in *jlexer.Lexer, out *Order) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1904,9 +2018,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(in *jlexe out.Legs = (out.Legs)[:0] } for !in.IsDelim(']') { - var v43 Order - (v43).UnmarshalEasyJSON(in) - out.Legs = append(out.Legs, v43) + var v46 Order + (v46).UnmarshalEasyJSON(in) + out.Legs = append(out.Legs, v46) in.WantComma() } in.Delim(']') @@ -1921,7 +2035,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(out *jwriter.Writer, in Order) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(out *jwriter.Writer, in Order) { out.RawByte('{') first := true _ = first @@ -2142,11 +2256,11 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(out *jwri out.RawString("null") } else { out.RawByte('[') - for v44, v45 := range in.Legs { - if v44 > 0 { + for v47, v48 := range in.Legs { + if v47 > 0 { out.RawByte(',') } - (v45).MarshalEasyJSON(out) + (v48).MarshalEasyJSON(out) } out.RawByte(']') } @@ -2157,27 +2271,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(out *jwri // MarshalJSON supports json.Marshaler interface func (v Order) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Order) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Order) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Order) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca15(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(in *jlexer.Lexer, out *CreateWatchlistRequest) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(in *jlexer.Lexer, out *OptionDeliverable) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2196,32 +2310,35 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(in *jlexe continue } switch key { - case "name": - out.Name = string(in.String()) - case "symbols": + case "type": + out.Type = DeliverableType(in.String()) + case "symbol": + out.Symbol = string(in.String()) + case "asset_id": if in.IsNull() { in.Skip() - out.Symbols = nil + out.AssetID = nil } else { - in.Delim('[') - if out.Symbols == nil { - if !in.IsDelim(']') { - out.Symbols = make([]string, 0, 4) - } else { - out.Symbols = []string{} - } - } else { - out.Symbols = (out.Symbols)[:0] - } - for !in.IsDelim(']') { - var v46 string - v46 = string(in.String()) - out.Symbols = append(out.Symbols, v46) - in.WantComma() + if out.AssetID == nil { + out.AssetID = new(string) } - in.Delim(']') + *out.AssetID = string(in.String()) } - default: + case "amount": + if data := in.Raw(); in.Ok() { + in.AddError((out.Amount).UnmarshalJSON(data)) + } + case "allocation_percentage": + if data := in.Raw(); in.Ok() { + in.AddError((out.AllocationPercentage).UnmarshalJSON(data)) + } + case "settlement_type": + out.SettlementType = DeliverableSettlementType(in.String()) + case "settlement_method": + out.SettlementMethod = DeliverableSettlementMethod(in.String()) + case "delayed_settlement": + out.DelayedSettlement = bool(in.Bool()) + default: in.SkipRecursive() } in.WantComma() @@ -2231,7 +2348,413 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(out *jwriter.Writer, in CreateWatchlistRequest) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(out *jwriter.Writer, in OptionDeliverable) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"type\":" + out.RawString(prefix[1:]) + out.String(string(in.Type)) + } + { + const prefix string = ",\"symbol\":" + out.RawString(prefix) + out.String(string(in.Symbol)) + } + if in.AssetID != nil { + const prefix string = ",\"asset_id\":" + out.RawString(prefix) + out.String(string(*in.AssetID)) + } + { + const prefix string = ",\"amount\":" + out.RawString(prefix) + out.Raw((in.Amount).MarshalJSON()) + } + { + const prefix string = ",\"allocation_percentage\":" + out.RawString(prefix) + out.Raw((in.AllocationPercentage).MarshalJSON()) + } + { + const prefix string = ",\"settlement_type\":" + out.RawString(prefix) + out.String(string(in.SettlementType)) + } + { + const prefix string = ",\"settlement_method\":" + out.RawString(prefix) + out.String(string(in.SettlementMethod)) + } + { + const prefix string = ",\"delayed_settlement\":" + out.RawString(prefix) + out.Bool(bool(in.DelayedSettlement)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v OptionDeliverable) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v OptionDeliverable) MarshalEasyJSON(w *jwriter.Writer) { + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *OptionDeliverable) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *OptionDeliverable) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(l, v) +} +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(in *jlexer.Lexer, out *OptionContract) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "id": + out.ID = string(in.String()) + case "symbol": + out.Symbol = string(in.String()) + case "name": + out.Name = string(in.String()) + case "status": + out.Status = OptionStatus(in.String()) + case "tradable": + out.Tradable = bool(in.Bool()) + case "expiration_date": + if data := in.UnsafeBytes(); in.Ok() { + in.AddError((out.ExpirationDate).UnmarshalText(data)) + } + case "root_symbol": + if in.IsNull() { + in.Skip() + out.RootSymbol = nil + } else { + if out.RootSymbol == nil { + out.RootSymbol = new(string) + } + *out.RootSymbol = string(in.String()) + } + case "underlying_symbol": + out.UnderlyingSymbol = string(in.String()) + case "underlying_asset_id": + out.UnderlyingAssetID = string(in.String()) + case "type": + out.Type = OptionType(in.String()) + case "style": + out.Style = OptionStyle(in.String()) + case "strike_price": + if data := in.Raw(); in.Ok() { + in.AddError((out.StrikePrice).UnmarshalJSON(data)) + } + case "multiplier": + if data := in.Raw(); in.Ok() { + in.AddError((out.Multiplier).UnmarshalJSON(data)) + } + case "size": + if data := in.Raw(); in.Ok() { + in.AddError((out.Size).UnmarshalJSON(data)) + } + case "open_interest": + if in.IsNull() { + in.Skip() + out.OpenInterest = nil + } else { + if out.OpenInterest == nil { + out.OpenInterest = new(decimal.Decimal) + } + if data := in.Raw(); in.Ok() { + in.AddError((*out.OpenInterest).UnmarshalJSON(data)) + } + } + case "open_interest_date": + if in.IsNull() { + in.Skip() + out.OpenInterestDate = nil + } else { + if out.OpenInterestDate == nil { + out.OpenInterestDate = new(civil.Date) + } + if data := in.UnsafeBytes(); in.Ok() { + in.AddError((*out.OpenInterestDate).UnmarshalText(data)) + } + } + case "close_price": + if in.IsNull() { + in.Skip() + out.ClosePrice = nil + } else { + if out.ClosePrice == nil { + out.ClosePrice = new(decimal.Decimal) + } + if data := in.Raw(); in.Ok() { + in.AddError((*out.ClosePrice).UnmarshalJSON(data)) + } + } + case "close_price_date": + if in.IsNull() { + in.Skip() + out.ClosePriceDate = nil + } else { + if out.ClosePriceDate == nil { + out.ClosePriceDate = new(civil.Date) + } + if data := in.UnsafeBytes(); in.Ok() { + in.AddError((*out.ClosePriceDate).UnmarshalText(data)) + } + } + case "deliverables": + if in.IsNull() { + in.Skip() + out.Deliverables = nil + } else { + in.Delim('[') + if out.Deliverables == nil { + if !in.IsDelim(']') { + out.Deliverables = make([]OptionDeliverable, 0, 0) + } else { + out.Deliverables = []OptionDeliverable{} + } + } else { + out.Deliverables = (out.Deliverables)[:0] + } + for !in.IsDelim(']') { + var v49 OptionDeliverable + (v49).UnmarshalEasyJSON(in) + out.Deliverables = append(out.Deliverables, v49) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(out *jwriter.Writer, in OptionContract) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"id\":" + out.RawString(prefix[1:]) + out.String(string(in.ID)) + } + { + const prefix string = ",\"symbol\":" + out.RawString(prefix) + out.String(string(in.Symbol)) + } + { + const prefix string = ",\"name\":" + out.RawString(prefix) + out.String(string(in.Name)) + } + { + const prefix string = ",\"status\":" + out.RawString(prefix) + out.String(string(in.Status)) + } + { + const prefix string = ",\"tradable\":" + out.RawString(prefix) + out.Bool(bool(in.Tradable)) + } + { + const prefix string = ",\"expiration_date\":" + out.RawString(prefix) + out.RawText((in.ExpirationDate).MarshalText()) + } + if in.RootSymbol != nil { + const prefix string = ",\"root_symbol\":" + out.RawString(prefix) + out.String(string(*in.RootSymbol)) + } + { + const prefix string = ",\"underlying_symbol\":" + out.RawString(prefix) + out.String(string(in.UnderlyingSymbol)) + } + { + const prefix string = ",\"underlying_asset_id\":" + out.RawString(prefix) + out.String(string(in.UnderlyingAssetID)) + } + { + const prefix string = ",\"type\":" + out.RawString(prefix) + out.String(string(in.Type)) + } + { + const prefix string = ",\"style\":" + out.RawString(prefix) + out.String(string(in.Style)) + } + { + const prefix string = ",\"strike_price\":" + out.RawString(prefix) + out.Raw((in.StrikePrice).MarshalJSON()) + } + { + const prefix string = ",\"multiplier\":" + out.RawString(prefix) + out.Raw((in.Multiplier).MarshalJSON()) + } + { + const prefix string = ",\"size\":" + out.RawString(prefix) + out.Raw((in.Size).MarshalJSON()) + } + { + const prefix string = ",\"open_interest\":" + out.RawString(prefix) + if in.OpenInterest == nil { + out.RawString("null") + } else { + out.Raw((*in.OpenInterest).MarshalJSON()) + } + } + if in.OpenInterestDate != nil { + const prefix string = ",\"open_interest_date\":" + out.RawString(prefix) + out.RawText((*in.OpenInterestDate).MarshalText()) + } + if in.ClosePrice != nil { + const prefix string = ",\"close_price\":" + out.RawString(prefix) + out.Raw((*in.ClosePrice).MarshalJSON()) + } + if in.ClosePriceDate != nil { + const prefix string = ",\"close_price_date\":" + out.RawString(prefix) + out.RawText((*in.ClosePriceDate).MarshalText()) + } + if len(in.Deliverables) != 0 { + const prefix string = ",\"deliverables\":" + out.RawString(prefix) + { + out.RawByte('[') + for v50, v51 := range in.Deliverables { + if v50 > 0 { + out.RawByte(',') + } + (v51).MarshalEasyJSON(out) + } + out.RawByte(']') + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v OptionContract) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v OptionContract) MarshalEasyJSON(w *jwriter.Writer) { + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *OptionContract) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *OptionContract) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(l, v) +} +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(in *jlexer.Lexer, out *CreateWatchlistRequest) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "name": + out.Name = string(in.String()) + case "symbols": + if in.IsNull() { + in.Skip() + out.Symbols = nil + } else { + in.Delim('[') + if out.Symbols == nil { + if !in.IsDelim(']') { + out.Symbols = make([]string, 0, 4) + } else { + out.Symbols = []string{} + } + } else { + out.Symbols = (out.Symbols)[:0] + } + for !in.IsDelim(']') { + var v52 string + v52 = string(in.String()) + out.Symbols = append(out.Symbols, v52) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(out *jwriter.Writer, in CreateWatchlistRequest) { out.RawByte('{') first := true _ = first @@ -2247,11 +2770,11 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(out *jwri out.RawString("null") } else { out.RawByte('[') - for v47, v48 := range in.Symbols { - if v47 > 0 { + for v53, v54 := range in.Symbols { + if v53 > 0 { out.RawByte(',') } - out.String(string(v48)) + out.String(string(v54)) } out.RawByte(']') } @@ -2262,27 +2785,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(out *jwri // MarshalJSON supports json.Marshaler interface func (v CreateWatchlistRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v CreateWatchlistRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *CreateWatchlistRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *CreateWatchlistRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca16(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(in *jlexer.Lexer, out *Clock) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(in *jlexer.Lexer, out *Clock) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2325,7 +2848,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(out *jwriter.Writer, in Clock) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(out *jwriter.Writer, in Clock) { out.RawByte('{') first := true _ = first @@ -2355,27 +2878,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(out *jwri // MarshalJSON supports json.Marshaler interface func (v Clock) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Clock) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Clock) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Clock) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca17(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(in *jlexer.Lexer, out *CalendarDay) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(in *jlexer.Lexer, out *CalendarDay) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2410,7 +2933,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(out *jwriter.Writer, in CalendarDay) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(out *jwriter.Writer, in CalendarDay) { out.RawByte('{') first := true _ = first @@ -2435,27 +2958,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(out *jwri // MarshalJSON supports json.Marshaler interface func (v CalendarDay) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v CalendarDay) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *CalendarDay) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *CalendarDay) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca18(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(in *jlexer.Lexer, out *Asset) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(in *jlexer.Lexer, out *Asset) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2514,9 +3037,9 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(in *jlexe out.Attributes = (out.Attributes)[:0] } for !in.IsDelim(']') { - var v49 string - v49 = string(in.String()) - out.Attributes = append(out.Attributes, v49) + var v55 string + v55 = string(in.String()) + out.Attributes = append(out.Attributes, v55) in.WantComma() } in.Delim(']') @@ -2531,7 +3054,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(out *jwriter.Writer, in Asset) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(out *jwriter.Writer, in Asset) { out.RawByte('{') first := true _ = first @@ -2602,11 +3125,11 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(out *jwri out.RawString("null") } else { out.RawByte('[') - for v50, v51 := range in.Attributes { - if v50 > 0 { + for v56, v57 := range in.Attributes { + if v56 > 0 { out.RawByte(',') } - out.String(string(v51)) + out.String(string(v57)) } out.RawByte(']') } @@ -2617,27 +3140,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(out *jwri // MarshalJSON supports json.Marshaler interface func (v Asset) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Asset) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Asset) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Asset) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca19(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(in *jlexer.Lexer, out *Announcement) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(in *jlexer.Lexer, out *Announcement) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2696,7 +3219,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(out *jwriter.Writer, in Announcement) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(out *jwriter.Writer, in Announcement) { out.RawByte('{') first := true _ = first @@ -2781,27 +3304,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(out *jwri // MarshalJSON supports json.Marshaler interface func (v Announcement) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Announcement) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Announcement) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Announcement) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca20(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(in *jlexer.Lexer, out *AddSymbolToWatchlistRequest) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(in *jlexer.Lexer, out *AddSymbolToWatchlistRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2832,7 +3355,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(out *jwriter.Writer, in AddSymbolToWatchlistRequest) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(out *jwriter.Writer, in AddSymbolToWatchlistRequest) { out.RawByte('{') first := true _ = first @@ -2847,27 +3370,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(out *jwri // MarshalJSON supports json.Marshaler interface func (v AddSymbolToWatchlistRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v AddSymbolToWatchlistRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *AddSymbolToWatchlistRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *AddSymbolToWatchlistRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca21(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(in *jlexer.Lexer, out *AccountConfigurations) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(in *jlexer.Lexer, out *AccountConfigurations) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2904,7 +3427,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(out *jwriter.Writer, in AccountConfigurations) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(out *jwriter.Writer, in AccountConfigurations) { out.RawByte('{') first := true _ = first @@ -2934,27 +3457,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(out *jwri // MarshalJSON supports json.Marshaler interface func (v AccountConfigurations) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v AccountConfigurations) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *AccountConfigurations) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *AccountConfigurations) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca22(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(in *jlexer.Lexer, out *AccountActivity) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca26(in *jlexer.Lexer, out *AccountActivity) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -3033,7 +3556,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(out *jwriter.Writer, in AccountActivity) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca26(out *jwriter.Writer, in AccountActivity) { out.RawByte('{') first := true _ = first @@ -3128,27 +3651,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(out *jwri // MarshalJSON supports json.Marshaler interface func (v AccountActivity) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca26(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v AccountActivity) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca26(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *AccountActivity) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca26(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *AccountActivity) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca26(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(in *jlexer.Lexer, out *Account) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca27(in *jlexer.Lexer, out *Account) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -3283,7 +3806,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(out *jwriter.Writer, in Account) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca27(out *jwriter.Writer, in Account) { out.RawByte('{') first := true _ = first @@ -3458,27 +3981,27 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(out *jwri // MarshalJSON supports json.Marshaler interface func (v Account) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca27(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Account) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca27(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Account) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca27(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Account) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca24(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca27(l, v) } -func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(in *jlexer.Lexer, out *APIError) { +func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca28(in *jlexer.Lexer, out *APIError) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -3511,7 +4034,7 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(in *jlexe in.Consumed() } } -func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(out *jwriter.Writer, in APIError) { +func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca28(out *jwriter.Writer, in APIError) { out.RawByte('{') first := true _ = first @@ -3536,23 +4059,23 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(out *jwri // MarshalJSON supports json.Marshaler interface func (v APIError) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(&w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca28(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v APIError) MarshalEasyJSON(w *jwriter.Writer) { - easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(w, v) + easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca28(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *APIError) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(&r, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca28(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *APIError) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca25(l, v) + easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca28(l, v) } diff --git a/alpaca/options.go b/alpaca/options.go deleted file mode 100644 index 586b79b..0000000 --- a/alpaca/options.go +++ /dev/null @@ -1,94 +0,0 @@ -package alpaca - -import ( - "cloud.google.com/go/civil" - "github.com/shopspring/decimal" -) - -//go:generate go install github.com/mailru/easyjson/...@v0.7.7 -//go:generate easyjson -all -snake_case $GOFILE - -type OptionStatus string - -const ( - OptionStatusActive OptionStatus = "active" - OptionStatusInactive OptionStatus = "inactive" -) - -type OptionType string - -const ( - OptionTypeCall OptionType = "call" - OptionTypePut OptionType = "put" -) - -type OptionStyle string - -const ( - OptionStyleAmerican OptionStyle = "american" - OptionStyleEuropean OptionStyle = "european" -) - -type DeliverableType string - -const ( - DeliverableTypeCash DeliverableType = "cash" - DeliverableTypeEquity DeliverableType = "equity" -) - -type DeliverableSettlementType string - -const ( - DeliverableSettlementTypeT0 DeliverableSettlementType = "T+0" - DeliverableSettlementTypeT1 DeliverableSettlementType = "T+1" - DeliverableSettlementTypeT2 DeliverableSettlementType = "T+2" - DeliverableSettlementTypeT3 DeliverableSettlementType = "T+3" - DeliverableSettlementTypeT4 DeliverableSettlementType = "T+4" - DeliverableSettlementTypeT5 DeliverableSettlementType = "T+5" -) - -type DeliverableSettlementMethod string - -const ( - DeliverableSettlementMethodBTOB DeliverableSettlementMethod = "BTOB" - DeliverableSettlementMethodCADF DeliverableSettlementMethod = "CADF" - DeliverableSettlementMethodCAFX DeliverableSettlementMethod = "CAFX" - DeliverableSettlementMethodCCC DeliverableSettlementMethod = "CCC" -) - -type OptionDeliverable struct { - Type DeliverableType `json:"type"` - Symbol string `json:"symbol"` - AssetID *string `json:"asset_id,omitempty"` - Amount string `json:"amount"` - AllocationPercentage string `json:"allocation_percentage"` - SettlementType DeliverableSettlementType `json:"settlement_method"` - DelayedSettlement bool `json:"delayed_settlement"` -} - -type OptionContract struct { - ID string `json:"id"` - Symbol string `json:"symbol"` - Name string `json:"name"` - Status string `json:"status"` - Tradable bool `json:"tradable"` - ExpirationDate civil.Date `json:"expiration_date"` - RootSymbol *string `json:"root_symbol,omitempty"` - UnderlyingSymbol string `json:"underlying_symbol"` - UnderlyingAssetID string `json:"underlying_assest_id"` - Type OptionType `json:"type"` - Style OptionStyle `json:"style"` - StrikePrice decimal.Decimal `json:"strike_price"` - Multiplier string `json:"multiplier"` - Size string `json:"size"` - OpenInterest *string `json:"open_interest"` - OpenInterestDate *civil.Date `json:"open_interest_date,omitempty"` - ClosePrice *decimal.Decimal `json:"close_price,omitempty"` - ClosePriceDate *civil.Date `json:"close_price_date,omitempty"` - Deliverables []OptionDeliverable `json:"deliverables,omitempty"` -} - -type optionContractsResponse struct { - OptionContracts []OptionContract `json:"option_contracts"` - NextPageToken *string `json:"next_page_token,omitempty"` -} diff --git a/alpaca/options_easyjson.go b/alpaca/options_easyjson.go deleted file mode 100644 index 24096ec..0000000 --- a/alpaca/options_easyjson.go +++ /dev/null @@ -1,526 +0,0 @@ -// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. - -package alpaca - -import ( - civil "cloud.google.com/go/civil" - json "encoding/json" - easyjson "github.com/mailru/easyjson" - jlexer "github.com/mailru/easyjson/jlexer" - jwriter "github.com/mailru/easyjson/jwriter" - decimal "github.com/shopspring/decimal" -) - -// suppress unused package warning -var ( - _ *json.RawMessage - _ *jlexer.Lexer - _ *jwriter.Writer - _ easyjson.Marshaler -) - -func easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(in *jlexer.Lexer, out *optionContractsResponse) { - isTopLevel := in.IsStart() - if in.IsNull() { - if isTopLevel { - in.Consumed() - } - in.Skip() - return - } - in.Delim('{') - for !in.IsDelim('}') { - key := in.UnsafeFieldName(false) - in.WantColon() - if in.IsNull() { - in.Skip() - in.WantComma() - continue - } - switch key { - case "option_contracts": - if in.IsNull() { - in.Skip() - out.OptionContracts = nil - } else { - in.Delim('[') - if out.OptionContracts == nil { - if !in.IsDelim(']') { - out.OptionContracts = make([]OptionContract, 0, 0) - } else { - out.OptionContracts = []OptionContract{} - } - } else { - out.OptionContracts = (out.OptionContracts)[:0] - } - for !in.IsDelim(']') { - var v1 OptionContract - (v1).UnmarshalEasyJSON(in) - out.OptionContracts = append(out.OptionContracts, v1) - in.WantComma() - } - in.Delim(']') - } - case "next_page_token": - if in.IsNull() { - in.Skip() - out.NextPageToken = nil - } else { - if out.NextPageToken == nil { - out.NextPageToken = new(string) - } - *out.NextPageToken = string(in.String()) - } - default: - in.SkipRecursive() - } - in.WantComma() - } - in.Delim('}') - if isTopLevel { - in.Consumed() - } -} -func easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(out *jwriter.Writer, in optionContractsResponse) { - out.RawByte('{') - first := true - _ = first - { - const prefix string = ",\"option_contracts\":" - out.RawString(prefix[1:]) - if in.OptionContracts == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { - out.RawString("null") - } else { - out.RawByte('[') - for v2, v3 := range in.OptionContracts { - if v2 > 0 { - out.RawByte(',') - } - (v3).MarshalEasyJSON(out) - } - out.RawByte(']') - } - } - if in.NextPageToken != nil { - const prefix string = ",\"next_page_token\":" - out.RawString(prefix) - out.String(string(*in.NextPageToken)) - } - out.RawByte('}') -} - -// MarshalJSON supports json.Marshaler interface -func (v optionContractsResponse) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - -// MarshalEasyJSON supports easyjson.Marshaler interface -func (v optionContractsResponse) MarshalEasyJSON(w *jwriter.Writer) { - easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(w, v) -} - -// UnmarshalJSON supports json.Unmarshaler interface -func (v *optionContractsResponse) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(&r, v) - return r.Error() -} - -// UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *optionContractsResponse) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca(l, v) -} -func easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(in *jlexer.Lexer, out *OptionDeliverable) { - isTopLevel := in.IsStart() - if in.IsNull() { - if isTopLevel { - in.Consumed() - } - in.Skip() - return - } - in.Delim('{') - for !in.IsDelim('}') { - key := in.UnsafeFieldName(false) - in.WantColon() - if in.IsNull() { - in.Skip() - in.WantComma() - continue - } - switch key { - case "type": - out.Type = DeliverableType(in.String()) - case "symbol": - out.Symbol = string(in.String()) - case "asset_id": - if in.IsNull() { - in.Skip() - out.AssetID = nil - } else { - if out.AssetID == nil { - out.AssetID = new(string) - } - *out.AssetID = string(in.String()) - } - case "amount": - out.Amount = string(in.String()) - case "allocation_percentage": - out.AllocationPercentage = string(in.String()) - case "settlement_method": - out.SettlementType = DeliverableSettlementType(in.String()) - case "delayed_settlement": - out.DelayedSettlement = bool(in.Bool()) - default: - in.SkipRecursive() - } - in.WantComma() - } - in.Delim('}') - if isTopLevel { - in.Consumed() - } -} -func easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(out *jwriter.Writer, in OptionDeliverable) { - out.RawByte('{') - first := true - _ = first - { - const prefix string = ",\"type\":" - out.RawString(prefix[1:]) - out.String(string(in.Type)) - } - { - const prefix string = ",\"symbol\":" - out.RawString(prefix) - out.String(string(in.Symbol)) - } - if in.AssetID != nil { - const prefix string = ",\"asset_id\":" - out.RawString(prefix) - out.String(string(*in.AssetID)) - } - { - const prefix string = ",\"amount\":" - out.RawString(prefix) - out.String(string(in.Amount)) - } - { - const prefix string = ",\"allocation_percentage\":" - out.RawString(prefix) - out.String(string(in.AllocationPercentage)) - } - { - const prefix string = ",\"settlement_method\":" - out.RawString(prefix) - out.String(string(in.SettlementType)) - } - { - const prefix string = ",\"delayed_settlement\":" - out.RawString(prefix) - out.Bool(bool(in.DelayedSettlement)) - } - out.RawByte('}') -} - -// MarshalJSON supports json.Marshaler interface -func (v OptionDeliverable) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - -// MarshalEasyJSON supports easyjson.Marshaler interface -func (v OptionDeliverable) MarshalEasyJSON(w *jwriter.Writer) { - easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(w, v) -} - -// UnmarshalJSON supports json.Unmarshaler interface -func (v *OptionDeliverable) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(&r, v) - return r.Error() -} - -// UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *OptionDeliverable) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca1(l, v) -} -func easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(in *jlexer.Lexer, out *OptionContract) { - isTopLevel := in.IsStart() - if in.IsNull() { - if isTopLevel { - in.Consumed() - } - in.Skip() - return - } - in.Delim('{') - for !in.IsDelim('}') { - key := in.UnsafeFieldName(false) - in.WantColon() - if in.IsNull() { - in.Skip() - in.WantComma() - continue - } - switch key { - case "id": - out.ID = string(in.String()) - case "symbol": - out.Symbol = string(in.String()) - case "name": - out.Name = string(in.String()) - case "status": - out.Status = string(in.String()) - case "tradable": - out.Tradable = bool(in.Bool()) - case "expiration_date": - if data := in.UnsafeBytes(); in.Ok() { - in.AddError((out.ExpirationDate).UnmarshalText(data)) - } - case "root_symbol": - if in.IsNull() { - in.Skip() - out.RootSymbol = nil - } else { - if out.RootSymbol == nil { - out.RootSymbol = new(string) - } - *out.RootSymbol = string(in.String()) - } - case "underlying_symbol": - out.UnderlyingSymbol = string(in.String()) - case "underlying_assest_id": - out.UnderlyingAssetID = string(in.String()) - case "type": - out.Type = OptionType(in.String()) - case "style": - out.Style = OptionStyle(in.String()) - case "strike_price": - if data := in.Raw(); in.Ok() { - in.AddError((out.StrikePrice).UnmarshalJSON(data)) - } - case "multiplier": - out.Multiplier = string(in.String()) - case "size": - out.Size = string(in.String()) - case "open_interest": - if in.IsNull() { - in.Skip() - out.OpenInterest = nil - } else { - if out.OpenInterest == nil { - out.OpenInterest = new(string) - } - *out.OpenInterest = string(in.String()) - } - case "open_interest_date": - if in.IsNull() { - in.Skip() - out.OpenInterestDate = nil - } else { - if out.OpenInterestDate == nil { - out.OpenInterestDate = new(civil.Date) - } - if data := in.UnsafeBytes(); in.Ok() { - in.AddError((*out.OpenInterestDate).UnmarshalText(data)) - } - } - case "close_price": - if in.IsNull() { - in.Skip() - out.ClosePrice = nil - } else { - if out.ClosePrice == nil { - out.ClosePrice = new(decimal.Decimal) - } - if data := in.Raw(); in.Ok() { - in.AddError((*out.ClosePrice).UnmarshalJSON(data)) - } - } - case "close_price_date": - if in.IsNull() { - in.Skip() - out.ClosePriceDate = nil - } else { - if out.ClosePriceDate == nil { - out.ClosePriceDate = new(civil.Date) - } - if data := in.UnsafeBytes(); in.Ok() { - in.AddError((*out.ClosePriceDate).UnmarshalText(data)) - } - } - case "deliverables": - if in.IsNull() { - in.Skip() - out.Deliverables = nil - } else { - in.Delim('[') - if out.Deliverables == nil { - if !in.IsDelim(']') { - out.Deliverables = make([]OptionDeliverable, 0, 0) - } else { - out.Deliverables = []OptionDeliverable{} - } - } else { - out.Deliverables = (out.Deliverables)[:0] - } - for !in.IsDelim(']') { - var v4 OptionDeliverable - (v4).UnmarshalEasyJSON(in) - out.Deliverables = append(out.Deliverables, v4) - in.WantComma() - } - in.Delim(']') - } - default: - in.SkipRecursive() - } - in.WantComma() - } - in.Delim('}') - if isTopLevel { - in.Consumed() - } -} -func easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(out *jwriter.Writer, in OptionContract) { - out.RawByte('{') - first := true - _ = first - { - const prefix string = ",\"id\":" - out.RawString(prefix[1:]) - out.String(string(in.ID)) - } - { - const prefix string = ",\"symbol\":" - out.RawString(prefix) - out.String(string(in.Symbol)) - } - { - const prefix string = ",\"name\":" - out.RawString(prefix) - out.String(string(in.Name)) - } - { - const prefix string = ",\"status\":" - out.RawString(prefix) - out.String(string(in.Status)) - } - { - const prefix string = ",\"tradable\":" - out.RawString(prefix) - out.Bool(bool(in.Tradable)) - } - { - const prefix string = ",\"expiration_date\":" - out.RawString(prefix) - out.RawText((in.ExpirationDate).MarshalText()) - } - if in.RootSymbol != nil { - const prefix string = ",\"root_symbol\":" - out.RawString(prefix) - out.String(string(*in.RootSymbol)) - } - { - const prefix string = ",\"underlying_symbol\":" - out.RawString(prefix) - out.String(string(in.UnderlyingSymbol)) - } - { - const prefix string = ",\"underlying_assest_id\":" - out.RawString(prefix) - out.String(string(in.UnderlyingAssetID)) - } - { - const prefix string = ",\"type\":" - out.RawString(prefix) - out.String(string(in.Type)) - } - { - const prefix string = ",\"style\":" - out.RawString(prefix) - out.String(string(in.Style)) - } - { - const prefix string = ",\"strike_price\":" - out.RawString(prefix) - out.Raw((in.StrikePrice).MarshalJSON()) - } - { - const prefix string = ",\"multiplier\":" - out.RawString(prefix) - out.String(string(in.Multiplier)) - } - { - const prefix string = ",\"size\":" - out.RawString(prefix) - out.String(string(in.Size)) - } - { - const prefix string = ",\"open_interest\":" - out.RawString(prefix) - if in.OpenInterest == nil { - out.RawString("null") - } else { - out.String(string(*in.OpenInterest)) - } - } - if in.OpenInterestDate != nil { - const prefix string = ",\"open_interest_date\":" - out.RawString(prefix) - out.RawText((*in.OpenInterestDate).MarshalText()) - } - if in.ClosePrice != nil { - const prefix string = ",\"close_price\":" - out.RawString(prefix) - out.Raw((*in.ClosePrice).MarshalJSON()) - } - if in.ClosePriceDate != nil { - const prefix string = ",\"close_price_date\":" - out.RawString(prefix) - out.RawText((*in.ClosePriceDate).MarshalText()) - } - if len(in.Deliverables) != 0 { - const prefix string = ",\"deliverables\":" - out.RawString(prefix) - { - out.RawByte('[') - for v5, v6 := range in.Deliverables { - if v5 > 0 { - out.RawByte(',') - } - (v6).MarshalEasyJSON(out) - } - out.RawByte(']') - } - } - out.RawByte('}') -} - -// MarshalJSON supports json.Marshaler interface -func (v OptionContract) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - -// MarshalEasyJSON supports easyjson.Marshaler interface -func (v OptionContract) MarshalEasyJSON(w *jwriter.Writer) { - easyjson24099d24EncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(w, v) -} - -// UnmarshalJSON supports json.Unmarshaler interface -func (v *OptionContract) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(&r, v) - return r.Error() -} - -// UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *OptionContract) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson24099d24DecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca2(l, v) -} diff --git a/alpaca/rest.go b/alpaca/rest.go index 2a27822..d1fe12b 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -9,7 +9,6 @@ import ( "net/http" "net/url" "os" - "reflect" "strconv" "strings" "time" @@ -744,20 +743,45 @@ func (c *Client) GetAsset(symbol string) (*Asset, error) { return &asset, nil } +const ( + optionContractsRequestsMaxLimit = 10000 +) + +func setQueryLimit(q url.Values, totalLimit, pageLimit, received, maxLimit int) { + limit := 0 // use server side default if unset + if pageLimit != 0 { + limit = pageLimit + } + if totalLimit != 0 { + remaining := totalLimit - received + if remaining <= 0 { // this should never happen + return + } + if (limit == 0 || limit > remaining) && remaining <= maxLimit { + limit = remaining + } + } + + if limit != 0 { + q.Set("limit", strconv.Itoa(limit)) + } +} + type GetOptionContractsRequest struct { - UnderlyingSymbols string `json:"underlying_symbols"` - ShowDeliverable *bool `json:"show_deliverables"` - Status *OptionStatus `json:"status"` - ExpirationDate *civil.Date `json:"expiration_date"` - ExpirationDateGTE *civil.Date `json:"expiration_date_gte"` - ExpirationDateLTE *civil.Date `json:"expiration_date_lte"` - RootSymbol *string `json:"root_symbol"` - Type *OptionType `json:"type"` - Style *OptionStyle `json:"style"` - StrikePriceGTE *decimal.Decimal `json:"strike_price_gte"` - StrikePriceLTE *decimal.Decimal `json:"strike_price_lte"` - Limit *int `json:"limit"` - PPInd *bool `json:"ppind"` + UnderlyingSymbols string + ShowDeliverable bool + Status OptionStatus + ExpirationDate civil.Date + ExpirationDateGTE civil.Date + ExpirationDateLTE civil.Date + RootSymbol string + Type OptionType + Style OptionStyle + StrikePriceGTE decimal.Decimal + StrikePriceLTE decimal.Decimal + PennyProgramIndicator bool + PageLimit int + TotalLimit int } // GetOptionContracts returns the list of Option Contracts. @@ -769,47 +793,60 @@ func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionCont q := u.Query() - structType := reflect.TypeOf(req) - structValue := reflect.ValueOf(req) + if req.UnderlyingSymbols != "" { + q.Set("underlying_symbols", req.UnderlyingSymbols) + } - for i := 0; i < structType.NumField(); i++ { - fieldType := structType.Field(i) - fieldValue := structValue.Field(i) + q.Set("show_deliverables", strconv.FormatBool(req.ShowDeliverable)) - kind := fieldType.Type.Kind() + if req.Status == OptionStatusActive || req.Status == OptionStatusInactive { + q.Set("status", string(req.Status)) + } - if kind == reflect.String { - v := fieldValue.String() - if v != "" { - q.Set(fieldType.Tag.Get("json"), v) - } - continue - } + defaultDate := civil.Date{} + if req.ExpirationDate != defaultDate { + q.Set("expiration_date", req.ExpirationDate.String()) + } - // else it's a reflect.Ptr: - if kind != reflect.Ptr { - panic("GetOptionContractsRequest's struct was changed this should be a pointer") - } + if req.ExpirationDateGTE != defaultDate { + q.Set("expiration_date_gte", req.ExpirationDateGTE.String()) + } - // if it's not a nil value then we do somthing with it - if !fieldValue.IsNil() { - subFieldType := fieldType.Type.Elem() - subFieldValue := fieldValue.Elem() - - // again we only really care about the string because it could be empty - if subFieldType.Kind() == reflect.String { - v := subFieldValue.String() - if v != "" { - q.Set(fieldType.Tag.Get("json"), v) - } - } else { - q.Set(fieldType.Tag.Get("json"), fmt.Sprint(subFieldValue)) - } - } + if req.ExpirationDateLTE != defaultDate { + q.Set("expiration_date_lte", req.ExpirationDateLTE.String()) } + if req.RootSymbol != "" { + q.Set("root_symbol", req.RootSymbol) + } + + if req.Type == OptionTypeCall || req.Type == OptionTypePut { + q.Set("type", string(req.Type)) + } + + if req.Style == OptionStyleAmerican || req.Style == OptionStyleEuropean { + q.Set("style", string(req.Style)) + } + + defaultStrikePrice := decimal.Decimal{} + if req.StrikePriceLTE.Cmp(defaultStrikePrice) != 0 { + q.Set("strike_price_lte", req.StrikePriceLTE.String()) + } + + if req.StrikePriceGTE.Cmp(defaultStrikePrice) != 0 { + q.Set("strike_price_gte", req.StrikePriceGTE.String()) + } + + q.Set("ppind", strconv.FormatBool(req.PennyProgramIndicator)) + optionContracts := make([]OptionContract, 0) for { + setQueryLimit(q, + req.TotalLimit, + req.PageLimit, + len(optionContracts), + optionContractsRequestsMaxLimit) + u.RawQuery = q.Encode() resp, err := c.get(u) @@ -817,9 +854,6 @@ func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionCont return nil, err } - // bs, err := ioutil.ReadAll(resp.Body) - // fmt.Println(string(bs)) - var response optionContractsResponse if err = unmarshal(resp, &response); err != nil { return nil, err @@ -831,7 +865,6 @@ func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionCont break } - fmt.Println("setting page_token:", *response.NextPageToken) q.Set("page_token", *response.NextPageToken) closeResp(resp) } diff --git a/alpaca/rest_test.go b/alpaca/rest_test.go index 8b4bda5..cf760a4 100644 --- a/alpaca/rest_test.go +++ b/alpaca/rest_test.go @@ -937,37 +937,30 @@ func TestGetOptionContracts(t *testing.T) { assert.Equal(t, expectedID, contracts[0].ID) // successful without nils - showDeliverable := true - status := OptionStatusActive - rootSymbol := "some_symbol" - ocType := OptionTypeCall - style := OptionStyleEuropean - priceGTE := decimal.NewFromInt(10) - limit := 5 - ppind := false + request = GetOptionContractsRequest{ - UnderlyingSymbols: "some_symbol", - ShowDeliverable: &showDeliverable, - Status: &status, - ExpirationDate: &civil.Date{Year: 2000, Month: 01, Day: 01}, - RootSymbol: &rootSymbol, - Type: &ocType, - Style: &style, - StrikePriceGTE: &priceGTE, - Limit: &limit, - PPInd: &ppind, + UnderlyingSymbols: "some_symbol", + ShowDeliverable: true, + Status: OptionStatusActive, + ExpirationDate: civil.Date{Year: 2000, Month: 01, Day: 01}, + RootSymbol: "some_symbol", + Type: OptionTypeCall, + Style: OptionStyleEuropean, + StrikePriceGTE: decimal.NewFromInt(10), + TotalLimit: 1, + PennyProgramIndicator: true, } c.do = func(_ *Client, req *http.Request) (*http.Response, error) { assert.Equal(t, request.UnderlyingSymbols, req.URL.Query().Get("underlying_symbols")) - assert.Equal(t, strconv.FormatBool(*request.ShowDeliverable), req.URL.Query().Get("show_deliverables")) - assert.Equal(t, fmt.Sprint(*request.Status), req.URL.Query().Get("status")) - assert.Equal(t, fmt.Sprint(*request.ExpirationDate), req.URL.Query().Get("expiration_date")) - assert.Equal(t, *request.RootSymbol, req.URL.Query().Get("root_symbol")) - assert.Equal(t, fmt.Sprint(*request.Type), req.URL.Query().Get("type")) - assert.Equal(t, fmt.Sprint(*request.Style), req.URL.Query().Get("style")) - assert.Equal(t, fmt.Sprint(*request.StrikePriceGTE), req.URL.Query().Get("strike_price_gte")) - assert.Equal(t, strconv.Itoa(*request.Limit), req.URL.Query().Get("limit")) - assert.Equal(t, strconv.FormatBool(*request.PPInd), req.URL.Query().Get("ppind")) + assert.Equal(t, strconv.FormatBool(request.ShowDeliverable), req.URL.Query().Get("show_deliverables")) + assert.Equal(t, string(request.Status), req.URL.Query().Get("status")) + assert.Equal(t, request.ExpirationDate.String(), req.URL.Query().Get("expiration_date")) + assert.Equal(t, request.RootSymbol, req.URL.Query().Get("root_symbol")) + assert.Equal(t, string(request.Type), req.URL.Query().Get("type")) + assert.Equal(t, string(request.Style), req.URL.Query().Get("style")) + assert.Equal(t, request.StrikePriceGTE.String(), req.URL.Query().Get("strike_price_gte")) + assert.Equal(t, strconv.Itoa(request.TotalLimit), req.URL.Query().Get("limit")) + assert.Equal(t, strconv.FormatBool(request.PennyProgramIndicator), req.URL.Query().Get("ppind")) assets := optionContractsResponse{ OptionContracts: []OptionContract{ From a9a07384f85c7e36d017d5411dbe20ab2b335727 Mon Sep 17 00:00:00 2001 From: Nathan Hack Date: Mon, 11 Nov 2024 14:04:33 -0500 Subject: [PATCH 4/6] Adding package-level functions --- alpaca/rest.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/alpaca/rest.go b/alpaca/rest.go index d1fe12b..5747c99 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -1197,6 +1197,16 @@ func GetAsset(symbol string) (*Asset, error) { return DefaultClient.GetAsset(symbol) } +// GetOptionContracts returns the list of Option Contracts. +func GetOptionContracts(req GetOptionContractsRequest) ([]OptionContract, error) { + return DefaultClient.GetOptionContracts(req) +} + +// GetOptionContract returns an option contract by symbol or contract ID. +func GetOptionContract(symbolOrID string) (*OptionContract, error) { + return DefaultClient.GetOptionContract(symbolOrID) +} + // GetAnnouncements returns a list of announcements // with the default Alpaca client. func GetAnnouncements(req GetAnnouncementsRequest) ([]Announcement, error) { From 743be168355ac0fbaecdae0207c67db1f88a2b73 Mon Sep 17 00:00:00 2001 From: Nathan Hack Date: Tue, 12 Nov 2024 18:30:03 -0500 Subject: [PATCH 5/6] code review updates --- alpaca/rest.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/alpaca/rest.go b/alpaca/rest.go index 5747c99..9e68246 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -799,20 +799,19 @@ func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionCont q.Set("show_deliverables", strconv.FormatBool(req.ShowDeliverable)) - if req.Status == OptionStatusActive || req.Status == OptionStatusInactive { + if req.Status != "" { q.Set("status", string(req.Status)) } - defaultDate := civil.Date{} - if req.ExpirationDate != defaultDate { + if !req.ExpirationDate.IsZero() { q.Set("expiration_date", req.ExpirationDate.String()) } - if req.ExpirationDateGTE != defaultDate { + if !req.ExpirationDateGTE.IsZero() { q.Set("expiration_date_gte", req.ExpirationDateGTE.String()) } - if req.ExpirationDateLTE != defaultDate { + if !req.ExpirationDateLTE.IsZero() { q.Set("expiration_date_lte", req.ExpirationDateLTE.String()) } @@ -820,27 +819,28 @@ func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionCont q.Set("root_symbol", req.RootSymbol) } - if req.Type == OptionTypeCall || req.Type == OptionTypePut { + if req.Type != "" { q.Set("type", string(req.Type)) } - if req.Style == OptionStyleAmerican || req.Style == OptionStyleEuropean { + if req.Style != "" { q.Set("style", string(req.Style)) } - defaultStrikePrice := decimal.Decimal{} - if req.StrikePriceLTE.Cmp(defaultStrikePrice) != 0 { + if req.StrikePriceLTE.IsZero() { q.Set("strike_price_lte", req.StrikePriceLTE.String()) } - if req.StrikePriceGTE.Cmp(defaultStrikePrice) != 0 { + if req.StrikePriceGTE.IsZero() { q.Set("strike_price_gte", req.StrikePriceGTE.String()) } - q.Set("ppind", strconv.FormatBool(req.PennyProgramIndicator)) + if req.PennyProgramIndicator { + q.Set("ppind", "true") + } optionContracts := make([]OptionContract, 0) - for { + for req.TotalLimit == 0 || len(optionContracts) < req.TotalLimit { setQueryLimit(q, req.TotalLimit, req.PageLimit, From 0f43d2f39325011e45682110f67e4f95226e5149 Mon Sep 17 00:00:00 2001 From: Nathan Hack Date: Wed, 13 Nov 2024 10:01:31 -0500 Subject: [PATCH 6/6] bug fix and outdated comments --- alpaca/rest.go | 4 ++-- alpaca/rest_test.go | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/alpaca/rest.go b/alpaca/rest.go index 9e68246..24b782d 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -827,11 +827,11 @@ func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionCont q.Set("style", string(req.Style)) } - if req.StrikePriceLTE.IsZero() { + if !req.StrikePriceLTE.IsZero() { q.Set("strike_price_lte", req.StrikePriceLTE.String()) } - if req.StrikePriceGTE.IsZero() { + if !req.StrikePriceGTE.IsZero() { q.Set("strike_price_gte", req.StrikePriceGTE.String()) } diff --git a/alpaca/rest_test.go b/alpaca/rest_test.go index cf760a4..d9261fd 100644 --- a/alpaca/rest_test.go +++ b/alpaca/rest_test.go @@ -911,7 +911,7 @@ func TestGetAssetFromJSON(t *testing.T) { func TestGetOptionContracts(t *testing.T) { c := DefaultClient - // successful with nils + // successful case with simple query request := GetOptionContractsRequest{ UnderlyingSymbols: "some_symbol1,some_symbol2", } @@ -936,8 +936,7 @@ func TestGetOptionContracts(t *testing.T) { require.Len(t, contracts, 1) assert.Equal(t, expectedID, contracts[0].ID) - // successful without nils - + // successful case with more paramters request = GetOptionContractsRequest{ UnderlyingSymbols: "some_symbol", ShowDeliverable: true, @@ -991,7 +990,7 @@ func TestGetOptionContracts(t *testing.T) { func TestGetOptionContract(t *testing.T) { c := DefaultClient - // successful with nils + // successful case expectedSymbol := "some_symbol" expectedID := "some_id" c.do = func(_ *Client, req *http.Request) (*http.Response, error) {