parameters

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package parameters defines structures and functions for handling request parameters across various API endpoints. It includes types for universal parameters, specific request types like stock quotes, options, and user inputs, and utilities for parsing and setting these parameters in API requests. The package leverages reflection for dynamic parameter parsing and validation, ensuring that API requests are constructed correctly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseAndSetParams

func ParseAndSetParams(params MarketDataParam, request *resty.Request) error

Types

type BulkStockParams added in v1.0.0

type BulkStockParams struct {
	Symbols  string `query:"symbols" validate:"required"`
	Snapshot bool   `query:"snapshot" validate:"optional"`
}

func (*BulkStockParams) SetParams added in v1.0.0

func (bsp *BulkStockParams) SetParams(request *resty.Request) error

SetParams sets the parameters for the BulkStockParams. It uses the parseAndSetParams function to parse and set the parameters.

func (*BulkStockParams) SetSnapshot added in v1.0.0

func (bsp *BulkStockParams) SetSnapshot(snapshot bool)

SetSnapshot sets the snapshot parameter for the BulkStockParams. It allows enabling or disabling the snapshot feature in the request.

Parameters

  • snapshot: A boolean value to enable or disable the snapshot feature.

func (*BulkStockParams) SetSymbols added in v1.0.0

func (bsp *BulkStockParams) SetSymbols(symbols []string) error

SetSymbols sets the symbols parameter for the BulkStockParams. It validates that the symbols slice is not empty and then sets them as a comma-separated string. If the validation fails, it returns an error.

type CountryParams

type CountryParams struct {
	Country string `query:"country"` // Country code used in various API requests.
}

CountryParams represents the parameters for identifying a country in requests. It encapsulates a country code as a string.

func (*CountryParams) SetCountry

func (cp *CountryParams) SetCountry(q string) error

SetCountry sets the country code in CountryParams after validating it. The country code must be exactly 2 characters long and consist only of alphabetic characters.

Parameters

  • q: A string representing the country code to be set.

Returns

  • An error if the country code is invalid (either not 2 characters long or contains non-alphabetic characters).

func (*CountryParams) SetParams

func (cp *CountryParams) SetParams(request *resty.Request) error

SetParams sets the country parameter for a given request. It utilizes the ParseAndSetParams function to apply the parameters to the request.

Parameters

  • request: A pointer to a resty.Request object where the country parameter will be set.

Returns

  • An error if parsing and setting the parameters fail.

type DateKeyParam

type DateKeyParam struct {
	DateKey string `path:"datekey" validate:"required"` // The date key in string format.
}

DateKeyParam represents the date key parameter for a request. It encapsulates a date key string that is utilized in various API requests, particularly mandatory for V2 requests.

func (*DateKeyParam) SetDateKey

func (dk *DateKeyParam) SetDateKey(q string) error

SetDateKey sets the date key parameter for a request. This method validates the date key to ensure it adheres to the expected format as defined in the dates package.

Parameters

  • q: A string representing the date key to be set.

Returns

  • An error if the date key is in an invalid format, otherwise nil.

func (*DateKeyParam) SetParams

func (dk *DateKeyParam) SetParams(request *resty.Request) error

SetParams sets the parameters for the DateKeyParam within a given request. It leverages the ParseAndSetParams function to parse the DateKeyParam and apply it to the request.

Parameters

  • request: A pointer to a resty.Request object where the date key parameter will be set.

Returns

  • An error if parsing and setting the parameters fail, otherwise nil.

type DateParams

type DateParams struct {
	Date      string `query:"date"`
	From      string `query:"from"`
	To        string `query:"to"`
	Countback *int   `query:"countback"`
}

DateParams represents the parameters for a date request. It includes a date, from, to, and countback, which are used in various requests.

func (*DateParams) SetCountback

func (dp *DateParams) SetCountback(q int) error

SetCountback sets the countback parameter of the DateParams.

Parameters

  • q: The countback value to be set, must be an integer.

Returns

  • error: Always returns nil. Future implementations might return an error if needed.

func (*DateParams) SetDate

func (dp *DateParams) SetDate(q interface{}) error

SetDate sets the date parameter of the DateParams. It validates the date using the ToDayString function from the dates package.

Parameters

  • q: The date to be set, can be of any type that ToDayString can process.

Returns

  • error: An error if the date validation fails.

func (*DateParams) SetFrom

func (dp *DateParams) SetFrom(q interface{}) error

SetFrom sets the from parameter of the DateParams. It validates the from date using the ToDayString function from the dates package.

Parameters

  • q: The from date to be set, can be of any type that ToDayString can process.

Returns

  • error: An error if the from date validation fails.

func (*DateParams) SetParams

func (dp *DateParams) SetParams(request *resty.Request) error

SetParams sets the parameters for the DateParams. It uses the ParseAndSetParams function to parse and set the parameters.

Parameters

  • request: A pointer to a resty.Request to which the parameters will be applied.

Returns

  • error: An error if parsing and setting the parameters fail.

func (*DateParams) SetTo

func (dp *DateParams) SetTo(q interface{}) error

SetTo sets the to parameter of the DateParams. It validates the to date using the ToDayString function from the dates package.

Parameters

  • q: The to date to be set, can be of any type that ToDayString can process.

Returns

  • error: An error if the to date validation fails.

type FiftyTwoWeekParams

type FiftyTwoWeekParams struct {
	FiftyTwoWeek bool `query:"52week"`
}

FiftyTwoWeekParams represents the unique parameters for a StockQuoteRequest

func (*FiftyTwoWeekParams) SetFiftyTwoWeek

func (sqp *FiftyTwoWeekParams) SetFiftyTwoWeek(q bool)

SetFiftyTwoWeek sets the FiftyTwoWeek parameter for the FiftyTwoWeekParams.

func (*FiftyTwoWeekParams) SetParams

func (sqp *FiftyTwoWeekParams) SetParams(request *resty.Request) error

SetParams sets the FiftyTwoWeek parameter for the FiftyTwoWeekParams. If the parsing and setting of parameters fail, it returns an error.

type MarketDataParam

type MarketDataParam interface {
	SetParams(*resty.Request) error
}

MarketDataParam defines an interface for setting parameters on a resty.Request. Implementations of this interface should provide logic to modify a given resty.Request by setting necessary parameters for making API calls to fetch market data.

type OptionParams added in v0.0.5

type OptionParams struct {
	Expiration         string  `query:"expiration" validate:"optional"` // ISO 8601, unix, spreadsheet, or "all"
	Month              int     `query:"month" validate:"optional"`      // 1-12
	Year               int     `query:"year" validate:"optional"`
	Weekly             *bool   `query:"weekly" validate:"optional"`
	Monthly            *bool   `query:"monthly" validate:"optional"`
	Quarterly          *bool   `query:"quarterly" validate:"optional"`
	Nonstandard        *bool   `query:"nonstandard" validate:"optional"`
	DTE                *int    `query:"dte" validate:"optional"` // Days to expiry
	Delta              float64 `query:"delta" validate:"optional"`
	Side               string  `query:"side" validate:"optional"`  // "call" or "put"
	Range              string  `query:"range" validate:"optional"` // "itm", "otm", "atm", "all"
	Strike             float64 `query:"strike" validate:"optional"`
	StrikeLimit        int     `query:"strikeLimit" validate:"optional"`
	MinOpenInterest    int     `query:"minOpenInterest" validate:"optional"`
	MinVolume          int     `query:"minVolume" validate:"optional"`
	MinAsk             float64 `query:"minAsk" validate:"optional"`
	MaxAsk             float64 `query:"maxAsk" validate:"optional"`
	MinBid             float64 `query:"minBid" validate:"optional"`
	MaxBid             float64 `query:"maxBid" validate:"optional"`
	MaxBidAskSpread    float64 `query:"maxBidAskSpread" validate:"optional"`
	MaxBidAskSpreadPct float64 `query:"maxBidAskSpreadPct" validate:"optional"` // Percent relative to the underlying
}

OptionParams represents the parameters for an options request.

func (*OptionParams) SetDTE added in v0.0.5

func (op *OptionParams) SetDTE(dte int) error

SetDTE sets the Days to Expiry parameter for the OptionParams. It validates that the DTE is not negative.

func (*OptionParams) SetDelta added in v0.0.5

func (op *OptionParams) SetDelta(delta float64) error

SetDelta sets the Delta parameter for the OptionParams.

func (*OptionParams) SetExpiration added in v0.0.5

func (op *OptionParams) SetExpiration(q interface{}) error

SetExpiration sets the Expiration parameter for the OptionParams. It checks if the input is the special case "all" (case insensitive) and sets it directly. Otherwise, it validates the expiration date using the ToDayString function from the dates package. If the validation fails, it returns an error.

func (*OptionParams) SetMaxAsk added in v1.2.0

func (op *OptionParams) SetMaxAsk(maxAsk float64) error

SetMaxAsk sets the MaxAsk parameter for the OptionParams. It validates that the MaxAsk is not negative.

func (*OptionParams) SetMaxBid added in v1.2.0

func (op *OptionParams) SetMaxBid(maxBid float64) error

SetMaxBid sets the MaxBid parameter for the OptionParams. It validates that the MaxBid is not negative.

func (*OptionParams) SetMaxBidAskSpread added in v0.0.5

func (op *OptionParams) SetMaxBidAskSpread(maxBidAskSpread float64) error

SetMaxBidAskSpread sets the MaxBidAskSpread parameter for the OptionParams. It validates that the MaxBidAskSpread is not negative.

func (*OptionParams) SetMaxBidAskSpreadPct added in v0.0.5

func (op *OptionParams) SetMaxBidAskSpreadPct(maxBidAskSpreadPct float64) error

SetMaxBidAskSpreadPct sets the MaxBidAskSpreadPct parameter for the OptionParams. It validates that the MaxBidAskSpreadPct is not negative.

func (*OptionParams) SetMinAsk added in v1.2.0

func (op *OptionParams) SetMinAsk(minAsk float64) error

SetMinAsk sets the MinAsk parameter for the OptionParams. It validates that the MinAsk is not negative.

func (*OptionParams) SetMinBid added in v1.2.0

func (op *OptionParams) SetMinBid(minBid float64) error

SetMinBid sets the MinBid parameter for the OptionParams. It validates that the MinBid is not negative.

func (*OptionParams) SetMinOpenInterest added in v0.0.5

func (op *OptionParams) SetMinOpenInterest(minOpenInterest int) error

SetMinOpenInterest sets the MinOpenInterest parameter for the OptionParams. It validates that the MinOpenInterest is not negative.

func (*OptionParams) SetMinVolume added in v0.0.5

func (op *OptionParams) SetMinVolume(minVolume int) error

SetMinVolume sets the MinVolume parameter for the OptionParams. It validates that the MinVolume is not negative.

func (*OptionParams) SetMonth added in v0.0.5

func (op *OptionParams) SetMonth(month int) error

SetMonth sets the Month parameter for the OptionParams. It validates that the month is within the 1-12 range. If the validation fails, it returns an error.

func (*OptionParams) SetMonthly added in v0.0.5

func (op *OptionParams) SetMonthly(monthly bool) error

SetMonthly sets the Monthly parameter for the OptionParams.

func (*OptionParams) SetNonstandard added in v0.0.5

func (op *OptionParams) SetNonstandard(nonstandard bool) error

SetNonstandard sets the Nonstandard parameter for the OptionParams.

func (*OptionParams) SetParams added in v0.0.5

func (op *OptionParams) SetParams(request *resty.Request) error

SetParams sets the parameters for the OptionParams. If the parsing and setting of parameters fail, it returns an error.

func (*OptionParams) SetQuarterly added in v0.0.5

func (op *OptionParams) SetQuarterly(quarterly bool) error

SetQuarterly sets the Quarterly parameter for the OptionParams.

func (*OptionParams) SetRange added in v0.0.5

func (op *OptionParams) SetRange(rangeParam string) error

SetRange sets the Range parameter for the OptionParams allowing case-insensitive input.

func (*OptionParams) SetSide added in v0.0.5

func (op *OptionParams) SetSide(side string) error

SetSide sets the Side parameter for the OptionParams allowing case-insensitive input.

func (*OptionParams) SetStrike added in v0.0.5

func (op *OptionParams) SetStrike(strike float64) error

SetStrike sets the Strike parameter for the OptionParams. It validates that the strike is between >0 and <99999.99.

func (*OptionParams) SetStrikeLimit added in v0.0.5

func (op *OptionParams) SetStrikeLimit(strikeLimit int) error

SetStrikeLimit sets the StrikeLimit parameter for the OptionParams. It validates that the StrikeLimit is not negative.

func (*OptionParams) SetWeekly added in v0.0.5

func (op *OptionParams) SetWeekly(weekly bool) error

SetWeekly sets the Weekly parameter for the OptionParams.

func (*OptionParams) SetYear added in v0.0.5

func (op *OptionParams) SetYear(year int) error

SetYear sets the Year parameter for the OptionParams. It validates that the year is after 2000. If the validation fails, it returns an error.

type ResolutionParams

type ResolutionParams struct {
	Resolution string `path:"resolution" validate:"required"`
}

func (*ResolutionParams) SetParams

func (rp *ResolutionParams) SetParams(request *resty.Request) error

SetParams sets the parameters for the CandleParams. It uses the parseAndSetParams function to parse and set the parameters.

func (*ResolutionParams) SetResolution

func (rp *ResolutionParams) SetResolution(resolution string) error

SetResolution sets the resolution parameter for the ResolutionParams. It validates that the resolution is not an empty string. If the validation fails, it returns an error.

type StockCandleParams

type StockCandleParams struct {
	AdjustSplits    bool   `query:"adjustsplits" validate:"optional"`
	AdjustDividends bool   `query:"adjustdividends" validate:"optional"` // Not yet implemented in the API
	Extended        bool   `query:"extended" validate:"optional"`
	Exchange        string `query:"exchange" validate:"optional"` // Not needed until non-US exchanges are added
}

CandleParams represents the parameters for a stock candle request.

func (*StockCandleParams) SetAdjustDividends

func (scp *StockCandleParams) SetAdjustDividends(adjustDividends bool)

SetAdjustDividends sets the AdjustDividends parameter for the StockCandleParams.

func (*StockCandleParams) SetAdjustSplits

func (scp *StockCandleParams) SetAdjustSplits(adjustSplits bool)

SetAdjustSplits sets the AdjustSplits parameter for the StockCandleParams.

func (*StockCandleParams) SetExchange

func (scp *StockCandleParams) SetExchange(exchange string) error

SetExchange sets the Exchange parameter for the StockCandleParams. It validates that the exchange is not an empty string. If the validation fails, it returns an error.

func (*StockCandleParams) SetExtended

func (scp *StockCandleParams) SetExtended(extended bool)

SetExtended sets the Extended parameter for the StockCandleParams.

func (*StockCandleParams) SetParams

func (scp *StockCandleParams) SetParams(request *resty.Request) error

SetParams sets the parameters for the StockCandleParams. It uses the parseAndSetParams function to parse and set the parameters.

type StockEarningsParams

type StockEarningsParams struct {
	Report string `query:"report"`
}

func (*StockEarningsParams) SetParams

func (sep *StockEarningsParams) SetParams(request *resty.Request) error

SetParams sets the parameters for the StockEarningsParams. If the parsing and setting of parameters fail, it returns an error.

func (*StockEarningsParams) SetReport

func (ep *StockEarningsParams) SetReport(q string) error

SetReport sets the report parameter for the EarningsParams. It validates the report parameter using the IsValidDateKey function from the dates package.

type SymbolParams

type SymbolParams struct {
	Symbol string `path:"symbol" validate:"required"`
}

func (*SymbolParams) SetParams

func (sp *SymbolParams) SetParams(request *resty.Request) error

SetParams sets the parameters for the CandleParams. It uses the parseAndSetParams function to parse and set the parameters.

func (*SymbolParams) SetSymbol

func (sp *SymbolParams) SetSymbol(symbol string) error

SetSymbol sets the symbol parameter for the SymbolParams. It validates that the symbol is not an empty string. If the validation fails, it returns an error.

type UniversalParams

type UniversalParams struct {
	Limit      int    `query:"limit"`
	DateFormat string `query:"dateformat"`
	Offset     int    `query:"offset"`
	Format     string `query:"format"`
	Headers    bool   `query:"headers"`
	Columns    string `query:"columns"`
	Human      bool   `query:"human"`
	Error      error
}

UniversalParams represents the universal parameters for a request. It includes limit, date format, offset, format, headers, columns, human, and error.

func (*UniversalParams) SetParams

func (up *UniversalParams) SetParams(request *resty.Request) error

SetParams sets the parameters for the UniversalParams. It uses the parseAndSetParams function to parse and set the parameters.

type UserInputParams added in v0.0.5

type UserInputParams struct {
	UserInput string `path:"userInput" validate:"required"`
}

UserInputParams represents the user input parameter for a request. It includes a user input that is used in various requests and is required.

func (*UserInputParams) SetParams added in v0.0.5

func (u *UserInputParams) SetParams(request *resty.Request) error

SetParams sets the parameters for the UserInputParams. It uses the parseAndSetParams function to parse and set the parameters.

func (*UserInputParams) SetUserInput added in v0.0.5

func (u *UserInputParams) SetUserInput(q string) error

SetUserInput sets the user input parameter for the OptionsLookupRequest. It validates that the user input is not empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL