Documentation
¶
Overview ¶
Package client provides a Go SDK for interacting with the Market Data API. It includes functionality for making API requests, handling responses, managing rate limits, and logging. The SDK supports various data types including stocks, options, and market status information.
Usage: To use the SDK, you first need to create an instance of MarketDataClient using the NewClient function. This client will then be used to make API requests to the Market Data API.
Example:
client := NewClient() client.Debug(true) // Enable debug mode to log detailed request and response information quote, err := client.StockQuotes().Symbol("AAPL").Get()
Authentication: The SDK uses an API token for authentication. The token can be set as an environment variable (MARKETDATA_TOKEN) or directly in your code. However, storing tokens in your code is not recommended for security reasons.
Rate Limiting: The MarketDataClient automatically tracks and manages the API's rate limits. You can check if the rate limit has been exceeded with the RateLimitExceeded method.
Logging: The SDK logs all unsuccessful (400-499 and 500-599) responses to specific log files based on the response status code. Successful responses (200-299) are logged when debug mode is enabled. Logs include detailed information such as request and response headers, response status code, and the response body.
Debug Mode: Debug mode can be enabled by calling the Debug method on the MarketDataClient instance. When enabled, the SDK will log detailed information about each request and response, which is useful for troubleshooting.
Environment: The SDK can be configured to work with different environments (production, test, development) by setting the appropriate host URL. The default environment is production.
Package stocks provides the /stocks endpoints
Index ¶
- Constants
- Variables
- type HttpRequestLog
- type HttpRequestLogs
- type IndexQuoteRequest
- func (iqr *IndexQuoteRequest) FiftyTwoWeek(q bool) *IndexQuoteRequest
- func (iqr *IndexQuoteRequest) Get(optionalClients ...*MarketDataClient) ([]models.IndexQuote, error)
- func (iqr *IndexQuoteRequest) Packed(optionalClients ...*MarketDataClient) (*models.IndexQuotesResponse, error)
- func (request IndexQuoteRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (iqr *IndexQuoteRequest) Symbol(q string) *IndexQuoteRequest
- type IndicesCandlesRequest
- func (icr *IndicesCandlesRequest) Countback(q int) *IndicesCandlesRequest
- func (icr *IndicesCandlesRequest) Date(q interface{}) *IndicesCandlesRequest
- func (icr *IndicesCandlesRequest) From(q interface{}) *IndicesCandlesRequest
- func (icr *IndicesCandlesRequest) Get(optionalClients ...*MarketDataClient) ([]models.IndexCandle, error)
- func (icr *IndicesCandlesRequest) Packed(optionalClients ...*MarketDataClient) (*models.IndicesCandlesResponse, error)
- func (request IndicesCandlesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (icr *IndicesCandlesRequest) Resolution(q string) *IndicesCandlesRequest
- func (icr *IndicesCandlesRequest) Symbol(q string) *IndicesCandlesRequest
- func (icr *IndicesCandlesRequest) To(q interface{}) *IndicesCandlesRequest
- type MarketDataClient
- func (c *MarketDataClient) Debug(enable bool) *MarketDataClient
- func (c *MarketDataClient) Environment(env string) *MarketDataClient
- func (c *MarketDataClient) GetFromRequest(br *baseRequest, result interface{}) (*resty.Response, error)
- func (c *MarketDataClient) GetRawResponse(br *baseRequest) (*resty.Response, error)
- func (c *MarketDataClient) RateLimitExceeded() bool
- func (c *MarketDataClient) String() string
- func (c *MarketDataClient) Token(bearerToken string) *MarketDataClient
- type MarketDataPacked
- type MarketStatusRequest
- func (msr *MarketStatusRequest) Countback(q int) *MarketStatusRequest
- func (msr *MarketStatusRequest) Country(q string) *MarketStatusRequest
- func (msr *MarketStatusRequest) Date(q interface{}) *MarketStatusRequest
- func (msr *MarketStatusRequest) From(q interface{}) *MarketStatusRequest
- func (msr *MarketStatusRequest) Get(optionalClients ...*MarketDataClient) ([]models.MarketStatusReport, error)
- func (msr *MarketStatusRequest) Packed(optionalClients ...*MarketDataClient) (*models.MarketStatusResponse, error)
- func (request MarketStatusRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (msr *MarketStatusRequest) To(q interface{}) *MarketStatusRequest
- type OptionChainRequest
- func (ocr *OptionChainRequest) DTE(dte int) *OptionChainRequest
- func (ocr *OptionChainRequest) Date(q interface{}) *OptionChainRequest
- func (ocr *OptionChainRequest) Delta(delta float64) *OptionChainRequest
- func (ocr *OptionChainRequest) Expiration(q interface{}) *OptionChainRequest
- func (ocr *OptionChainRequest) Get(optionalClients ...*MarketDataClient) ([]models.OptionQuote, error)
- func (ocr *OptionChainRequest) MaxBidAskSpread(maxBidAskSpread float64) *OptionChainRequest
- func (ocr *OptionChainRequest) MaxBidAskSpreadPct(maxBidAskSpreadPct float64) *OptionChainRequest
- func (ocr *OptionChainRequest) MinOpenInterest(minOpenInterest int) *OptionChainRequest
- func (ocr *OptionChainRequest) MinVolume(minVolume int) *OptionChainRequest
- func (ocr *OptionChainRequest) Month(month int) *OptionChainRequest
- func (ocr *OptionChainRequest) Monthly(monthly bool) *OptionChainRequest
- func (ocr *OptionChainRequest) Nonstandard(nonstandard bool) *OptionChainRequest
- func (ocr *OptionChainRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionQuotesResponse, error)
- func (ocr *OptionChainRequest) Quarterly(quarterly bool) *OptionChainRequest
- func (ocr *OptionChainRequest) Range(rangeParam string) *OptionChainRequest
- func (request OptionChainRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (ocr *OptionChainRequest) Side(side string) *OptionChainRequest
- func (ocr *OptionChainRequest) Strike(strike float64) *OptionChainRequest
- func (ocr *OptionChainRequest) StrikeLimit(strikeLimit int) *OptionChainRequest
- func (ocr *OptionChainRequest) UnderlyingSymbol(q string) *OptionChainRequest
- func (ocr *OptionChainRequest) Weekly(weekly bool) *OptionChainRequest
- func (ocr *OptionChainRequest) Year(year int) *OptionChainRequest
- type OptionLookupRequest
- func (o *OptionLookupRequest) Get(optionalClients ...*MarketDataClient) (string, error)
- func (o *OptionLookupRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionLookupResponse, error)
- func (request OptionLookupRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (o *OptionLookupRequest) UserInput(userInput string) *OptionLookupRequest
- type OptionQuoteRequest
- func (oqr *OptionQuoteRequest) Date(q interface{}) *OptionQuoteRequest
- func (oqr *OptionQuoteRequest) From(q interface{}) *OptionQuoteRequest
- func (oqr *OptionQuoteRequest) Get(optionalClients ...*MarketDataClient) ([]models.OptionQuote, error)
- func (oqr *OptionQuoteRequest) OptionSymbol(q string) *OptionQuoteRequest
- func (oqr *OptionQuoteRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionQuotesResponse, error)
- func (request OptionQuoteRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (oqr *OptionQuoteRequest) To(q interface{}) *OptionQuoteRequest
- type OptionsExpirationsRequest
- func (oer *OptionsExpirationsRequest) Date(q interface{}) *OptionsExpirationsRequest
- func (o *OptionsExpirationsRequest) Get(optionalClients ...*MarketDataClient) ([]time.Time, error)
- func (o *OptionsExpirationsRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionsExpirationsResponse, error)
- func (request OptionsExpirationsRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (o *OptionsExpirationsRequest) Strike(strike float64) *OptionsExpirationsRequest
- func (o *OptionsExpirationsRequest) UnderlyingSymbol(symbol string) *OptionsExpirationsRequest
- type OptionsStrikesRequest
- func (o *OptionsStrikesRequest) Date(date string) *OptionsStrikesRequest
- func (o *OptionsStrikesRequest) Expiration(expiration string) *OptionsStrikesRequest
- func (osr *OptionsStrikesRequest) Get(optionalClients ...*MarketDataClient) ([]models.OptionsStrikes, error)
- func (osr *OptionsStrikesRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionsStrikesResponse, error)
- func (request OptionsStrikesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (o *OptionsStrikesRequest) UnderlyingSymbol(underlyingSymbol string) *OptionsStrikesRequest
- type StockCandlesRequest
- func (scr *StockCandlesRequest) AdjustDividends(q bool) *StockCandlesRequest
- func (scr *StockCandlesRequest) AdjustSplits(q bool) *StockCandlesRequest
- func (scr *StockCandlesRequest) Countback(q int) *StockCandlesRequest
- func (scr *StockCandlesRequest) Date(q interface{}) *StockCandlesRequest
- func (scr *StockCandlesRequest) Exchange(q string) *StockCandlesRequest
- func (scr *StockCandlesRequest) Extended(q bool) *StockCandlesRequest
- func (scr *StockCandlesRequest) From(q interface{}) *StockCandlesRequest
- func (scr *StockCandlesRequest) Get(optionalClients ...*MarketDataClient) ([]models.StockCandle, error)
- func (scr *StockCandlesRequest) Packed(optionalClients ...*MarketDataClient) (*models.StockCandlesResponse, error)
- func (request StockCandlesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (cr *StockCandlesRequest) Resolution(q string) *StockCandlesRequest
- func (cr *StockCandlesRequest) Symbol(q string) *StockCandlesRequest
- func (scr *StockCandlesRequest) To(q interface{}) *StockCandlesRequest
- type StockCandlesRequestV2
- func (cr *StockCandlesRequestV2) DateKey(q string) *StockCandlesRequestV2
- func (scrV2 *StockCandlesRequestV2) Get(optionalClients ...*MarketDataClient) ([]models.StockCandle, error)
- func (scrV2 *StockCandlesRequestV2) Packed(optionalClients ...*MarketDataClient) (*models.StockCandlesResponse, error)
- func (request StockCandlesRequestV2) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (cr *StockCandlesRequestV2) Resolution(q string) *StockCandlesRequestV2
- func (cr *StockCandlesRequestV2) Symbol(q string) *StockCandlesRequestV2
- type StockEarningsRequest
- func (ser *StockEarningsRequest) Countback(q int) *StockEarningsRequest
- func (ser *StockEarningsRequest) Date(q interface{}) *StockEarningsRequest
- func (ser *StockEarningsRequest) From(q interface{}) *StockEarningsRequest
- func (ser *StockEarningsRequest) Get(optionalClients ...*MarketDataClient) ([]models.StockEarningsReport, error)
- func (ser *StockEarningsRequest) Packed(optionalClients ...*MarketDataClient) (*models.StockEarningsResponse, error)
- func (request StockEarningsRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (ser *StockEarningsRequest) Report(q string) *StockEarningsRequest
- func (ser *StockEarningsRequest) Symbol(q string) *StockEarningsRequest
- func (ser *StockEarningsRequest) To(q interface{}) *StockEarningsRequest
- type StockNewsRequest
- func (snr *StockNewsRequest) Countback(q int) *StockNewsRequest
- func (snr *StockNewsRequest) Date(q interface{}) *StockNewsRequest
- func (snr *StockNewsRequest) From(q interface{}) *StockNewsRequest
- func (snr *StockNewsRequest) Get(optionalClients ...*MarketDataClient) ([]models.StockNews, error)
- func (snr *StockNewsRequest) Packed(optionalClients ...*MarketDataClient) (*models.StockNewsResponse, error)
- func (request StockNewsRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (snr *StockNewsRequest) Symbol(q string) *StockNewsRequest
- func (snr *StockNewsRequest) To(q interface{}) *StockNewsRequest
- type StockQuoteRequest
- func (sqr *StockQuoteRequest) FiftyTwoWeek(q bool) *StockQuoteRequest
- func (sqr *StockQuoteRequest) Get(optionalClients ...*MarketDataClient) ([]models.StockQuote, error)
- func (sqr *StockQuoteRequest) Packed(optionalClients ...*MarketDataClient) (*models.StockQuotesResponse, error)
- func (request StockQuoteRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
- func (sqr *StockQuoteRequest) Symbol(q string) *StockQuoteRequest
- type TickersRequest
Examples ¶
- IndicesCandlesRequest (Get)
- IndicesCandlesRequest (Packed)
- IndicesCandlesRequest (Raw)
- MarketStatus (Get)
- MarketStatus (Packed)
- OptionChainRequest (Get)
- OptionChainRequest (Packed)
- OptionLookupRequest (Get)
- OptionLookupRequest (Packed)
- OptionQuoteRequest (Get)
- OptionQuoteRequest (Packed)
- OptionsStrikesRequest (Get)
- OptionsStrikesRequest (Packed)
Constants ¶
const (
Version = "0.1.0" // Version specifies the current version of the SDK.
)
Variables ¶
var ( SuccessLogger *zap.Logger ClientErrorLogger *zap.Logger ServerErrorLogger *zap.Logger Logs *HttpRequestLogs MaxLogEntries = 100000 // MaxLogEntries is the maximum number of log entries that will be stored in memory. MemoryLimit int64 = 100 * 1048576 // MemoryLimit is the limit (in bytes) of log entries that will be stored in memory. )
Functions ¶
This section is empty.
Types ¶
type HttpRequestLog ¶
type HttpRequestLog struct { Timestamp time.Time ReqHeaders http.Header // The Request Headers ResHeaders http.Header // The Response Headers RayID string // The Ray ID from the HTTP response Request string // The URL of the HTTP Request Status int // The status code of the response RateLimitConsumed int // The number of requests consumed from the rate limit Delay int64 // The time (in miliseconds) between the request and the server's response Response string // The server response // contains filtered or unexported fields }
HttpRequestLog represents a single HTTP request log entry. It includes detailed information about the request and response, such as headers, status code, and response body.
Public Methods:
- WriteToLog(debug bool): Writes the log entry to the appropriate logger based on the HTTP response status.
- String() string: Returns a string representation of the HTTP request log entry.
- PrettyPrint(): Prints a formatted representation of the HTTP request log entry.
func AddToLog ¶
func AddToLog(h *HttpRequestLogs, timestamp time.Time, rayID string, request string, rateLimitConsumed int, delay int64, status int, body string, reqHeaders http.Header, resHeaders http.Header) *HttpRequestLog
AddToLog adds a new HTTP request log entry to the HttpRequestLogs.
This method creates a new HttpRequestLog entry based on the provided parameters and appends it to the HttpRequestLogs. If the request URL starts with "https://api.marketdata.app/user/", the log entry is not added, and the method returns nil. After adding a new log entry, it trims the log to ensure the total memory usage and the number of log entries are below their limits.
Parameters:
- h *HttpRequestLogs: A pointer to the HttpRequestLogs to which the new log entry will be added.
- timestamp time.Time: The timestamp of the HTTP request.
- rayID string: The unique identifier for the request.
- request string: The URL of the HTTP request.
- rateLimitConsumed int: The amount of rate limit consumed by the request.
- delay int64: The delay experienced during the request, in milliseconds.
- status int: The HTTP status code of the response.
- body string: The body of the HTTP response.
- reqHeaders http.Header: The HTTP headers of the request.
- resHeaders http.Header: The HTTP headers of the response.
Returns:
- *HttpRequestLog: A pointer to the newly added HttpRequestLog entry. Returns nil if the log entry is not added.
func NewHttpRequestLog ¶
func (HttpRequestLog) PrettyPrint ¶
func (h HttpRequestLog) PrettyPrint()
PrettyPrint prints a formatted representation of the HTTP request log entry.
func (HttpRequestLog) String ¶
func (h HttpRequestLog) String() string
String returns a string representation of the HTTP request log entry. Returns:
- A string representing the log entry.
func (HttpRequestLog) WriteToLog ¶
func (h HttpRequestLog) WriteToLog(debug bool)
WriteToLog writes the log entry to the appropriate logger based on the HTTP response status. Parameters:
- debug: A boolean indicating whether to log as a debug message.
type HttpRequestLogs ¶
type HttpRequestLogs struct {
Logs []HttpRequestLog
}
HttpRequestLogs represents a collection of HTTP request logs. It provides methods to manipulate and retrieve log entries.
Public Methods:
- String() string: Returns a string representation of all HTTP request logs.
- PrintLatest(): Prints the latest HTTP request log entry.
func GetLogs ¶
func GetLogs() *HttpRequestLogs
GetLogs returns a pointer to the HttpRequestLogs instance. This function is useful for accessing the logs that have been collected during HTTP requests.
func (*HttpRequestLogs) GetLastLogResponse ¶
func (h *HttpRequestLogs) GetLastLogResponse() string
GetLastLogResponse returns the response of the last log entry in the HttpRequestLogs.
This method checks if there are any logs present. If there are no logs, it returns a message indicating that no logs are available. If logs are present, it calculates the index of the last log entry, accesses it, and returns its response.
Returns:
- A string representing the response of the last log entry. If no logs are available, returns "No logs available".
func (*HttpRequestLogs) PrintLatest ¶
func (h *HttpRequestLogs) PrintLatest()
PrintLatest prints the latest HTTP request log entry.
func (*HttpRequestLogs) String ¶
func (h *HttpRequestLogs) String() string
String returns a string representation of all HTTP request logs. Returns:
- A string representing all log entries.
type IndexQuoteRequest ¶
type IndexQuoteRequest struct {
// contains filtered or unexported fields
}
IndexQuoteRequest represents a request to the /indices/quote endpoint. It encapsulates parameters for symbol and fifty-two-week data to be used in the request. This struct provides methods such as Symbol() and FiftyTwoWeek() to set these parameters respectively.
Public Methods:
- Symbol(q string) *IndexQuoteRequest: Sets the symbol parameter for the request.
- FiftyTwoWeek(q bool) *IndexQuoteRequest: Sets the fifty-two-week parameter for the request.
func IndexQuotes ¶
func IndexQuotes(client ...*MarketDataClient) *IndexQuoteRequest
IndexQuotes creates a new IndexQuoteRequest and associates it with the provided client. If no client is provided, it uses the default client. This function initializes the request with default parameters for symbol and fifty-two-week data, and sets the request path based on the predefined endpoints for index quotes. Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *IndexQuoteRequest: A pointer to the newly created IndexQuoteRequest with default parameters and associated client.
func (*IndexQuoteRequest) FiftyTwoWeek ¶
func (iqr *IndexQuoteRequest) FiftyTwoWeek(q bool) *IndexQuoteRequest
FiftyTwoWeek sets the FiftyTwoWeek parameter for the IndexQuoteRequest. This method is used to specify whether to include fifty-two-week high and low data in the quote. It modifies the fiftyTwoWeekParams field of the IndexQuoteRequest instance to store the boolean value.
Parameters:
- q: A boolean indicating whether to include fifty-two-week data.
Returns:
- *IndexQuoteRequest: This method returns a pointer to the IndexQuoteRequest instance it was called on. This allows for method chaining. If the receiver (*IndexQuoteRequest) is nil, it returns nil to prevent a panic.
func (*IndexQuoteRequest) Get ¶
func (iqr *IndexQuoteRequest) Get(optionalClients ...*MarketDataClient) ([]models.IndexQuote, error)
Get sends the IndexQuoteRequest, unpacks the IndexQuotesResponse, and returns a slice of IndexQuote. It returns an error if the request or unpacking fails. This method is crucial for obtaining the actual quote data from the index quote request. The method first checks if the IndexQuoteRequest receiver is nil, which would result in an error as the request cannot be sent. It then proceeds to send the request using the Packed method. Upon receiving the response, it unpacks the data into a slice of IndexQuote using the Unpack method from the response. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.IndexQuote: A slice of IndexQuote containing the unpacked quote data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*IndexQuoteRequest) Packed ¶
func (iqr *IndexQuoteRequest) Packed(optionalClients ...*MarketDataClient) (*models.IndexQuotesResponse, error)
Packed sends the IndexQuoteRequest and returns the IndexQuotesResponse. This method checks if the IndexQuoteRequest receiver is nil, returning an error if true. An optional MarketDataClient can be passed to replace the client used in the request. Otherwise, it proceeds to send the request and returns the IndexQuotesResponse along with any error encountered during the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.IndexQuotesResponse: A pointer to the IndexQuotesResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (IndexQuoteRequest) Raw ¶
func (request IndexQuoteRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*IndexQuoteRequest) Symbol ¶
func (iqr *IndexQuoteRequest) Symbol(q string) *IndexQuoteRequest
Symbol sets the symbol parameter for the IndexQuoteRequest. This method is used to specify the market symbol for which the quote data is requested. It modifies the symbolParams field of the IndexQuoteRequest instance to store the symbol value.
Parameters:
- q: A string representing the market symbol to be set.
Returns:
- *IndexQuoteRequest: This method returns a pointer to the IndexQuoteRequest instance it was called on. This allows for method chaining, where multiple setter methods can be called in a single statement. If the receiver (*IndexQuoteRequest) is nil, it returns nil to prevent a panic.
Note:
- If an error occurs while setting the symbol (e.g., if the symbol value is not supported), the Error field of the IndexQuoteRequest is set with the encountered error, but the method still returns the IndexQuoteRequest instance to allow for further method calls or error handling by the caller.
type IndicesCandlesRequest ¶
type IndicesCandlesRequest struct {
// contains filtered or unexported fields
}
IndicesCandlesRequest represents a request to the /v1/indices/candles endpoint. It encapsulates parameters for resolution, symbol, and date to be used in the request. This struct provides methods such as Resolution(), Symbol(), Date(), and From() to set these parameters respectively.
Public Methods:
- Resolution(q string) *IndicesCandlesRequest: Sets the resolution parameter for the request.
- Symbol(q string) *IndicesCandlesRequest: Sets the symbol parameter for the request.
- Date(q interface{}) *IndicesCandlesRequest: Sets the date parameter for the request.
- From(q interface{}) *IndicesCandlesRequest: Sets the 'from' date parameter for the request.
Example (Get) ¶
vix, err := IndexCandles().Symbol("VIX").Resolution("D").From("2022-01-01").To("2022-01-05").Get() if err != nil { println("Error retrieving VIX index candles:", err.Error()) return } for _, candle := range vix { fmt.Println(candle) }
Output: IndexCandle{Time: 2022-01-03 00:00:00 -05:00, Open: 17.6, High: 18.54, Low: 16.56, Close: 16.6} IndexCandle{Time: 2022-01-04 00:00:00 -05:00, Open: 16.57, High: 17.81, Low: 16.34, Close: 16.91} IndexCandle{Time: 2022-01-05 00:00:00 -05:00, Open: 17.07, High: 20.17, Low: 16.58, Close: 19.73}
Example (Packed) ¶
vix, err := IndexCandles().Symbol("VIX").Resolution("D").To("2022-01-05").Countback(3).Packed() if err != nil { println("Error retrieving VIX index candles:", err.Error()) return } fmt.Println(vix)
Output: IndicesCandlesResponse{Time: [1641186000 1641272400 1641358800], Open: [17.6 16.57 17.07], High: [18.54 17.81 20.17], Low: [16.56 16.34 16.58], Close: [16.6 16.91 19.73]}
Example (Raw) ¶
vix, err := IndexCandles().Symbol("VIX").Resolution("D").From("2022-01-01").To("2022-01-05").Raw() if err != nil { println("Error retrieving VIX index candles:", err.Error()) return } fmt.Println(vix)
Output: {"s":"ok","t":[1641186000,1641272400,1641358800],"o":[17.6,16.57,17.07],"h":[18.54,17.81,20.17],"l":[16.56,16.34,16.58],"c":[16.6,16.91,19.73]}
func IndexCandles ¶
func IndexCandles(client ...*MarketDataClient) *IndicesCandlesRequest
IndexCandles creates a new IndicesCandlesRequest and associates it with the provided client. If no client is provided, it uses the default client. This function initializes the request with default parameters for date, resolution, and symbol, and sets the request path based on the predefined endpoints for indices candles.
Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *IndicesCandlesRequest: A pointer to the newly created IndicesCandlesRequest with default parameters and associated client.
func (*IndicesCandlesRequest) Countback ¶
func (icr *IndicesCandlesRequest) Countback(q int) *IndicesCandlesRequest
Countback sets the countback parameter for the IndicesCandlesRequest. It specifies the number of candles to return, counting backwards from the 'to' date. Parameters:
- q: An int representing the number of candles to return.
Returns:
- *IndicesCandlesRequest: A pointer to the IndicesCandlesRequest instance to allow for method chaining.
func (*IndicesCandlesRequest) Date ¶
func (icr *IndicesCandlesRequest) Date(q interface{}) *IndicesCandlesRequest
Date sets the date parameter for the IndicesCandlesRequest. This method is used to specify the date for which the candle data is requested. It modifies the dateParams field of the IndicesCandlesRequest instance to store the date value.
Parameters:
- q: An interface{} representing the date to be set. It can be a string, a time.Time object, or any other type that the underlying SetDate method can process.
Returns:
- *IndicesCandlesRequest: This method returns a pointer to the IndicesCandlesRequest instance it was called on. This allows for method chaining, where multiple setter methods can be called in a single statement. If the receiver (*IndicesCandlesRequest) is nil, it returns nil to prevent a panic.
Note:
- If an error occurs while setting the date (e.g., if the date value is not supported), the Error field of the baseRequest is set with the encountered error, but the method still returns the IndicesCandlesRequest instance to allow for further method calls or error handling by the caller.
func (*IndicesCandlesRequest) From ¶
func (icr *IndicesCandlesRequest) From(q interface{}) *IndicesCandlesRequest
From sets the 'from' date parameter for the IndicesCandlesRequest. It configures the starting point of the date range for which the candle data is requested. Parameters:
- q: An interface{} that represents the starting date. It can be a string, a time.Time object, or any other type that the underlying SetFrom method can process.
Returns:
- *IndicesCandlesRequest: A pointer to the IndicesCandlesRequest instance to allow for method chaining.
func (*IndicesCandlesRequest) Get ¶
func (icr *IndicesCandlesRequest) Get(optionalClients ...*MarketDataClient) ([]models.IndexCandle, error)
Get sends the IndicesCandlesRequest, unpacks the IndicesCandlesResponse, and returns a slice of IndexCandle. It returns an error if the request or unpacking fails. This method is crucial for obtaining the actual candle data from the indices candles request. The method first checks if the IndicesCandlesRequest receiver is nil, which would result in an error as the request cannot be sent. It then proceeds to send the request using the Packed method. Upon receiving the response, it unpacks the data into a slice of IndexCandle using the Unpack method from the response. An optional MarketDataClient can be passed to replace the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.IndexCandle: A slice of IndexCandle containing the unpacked candle data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*IndicesCandlesRequest) Packed ¶
func (icr *IndicesCandlesRequest) Packed(optionalClients ...*MarketDataClient) (*models.IndicesCandlesResponse, error)
Packed sends the IndicesCandlesRequest and returns the IndicesCandlesResponse. This method checks if the IndicesCandlesRequest receiver is nil, returning an error if true. An optional MarketDataClient can be passed to replace the client used in the request. Otherwise, it proceeds to send the request and returns the IndicesCandlesResponse along with any error encountered during the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.IndicesCandlesResponse: A pointer to the IndicesCandlesResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (IndicesCandlesRequest) Raw ¶
func (request IndicesCandlesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*IndicesCandlesRequest) Resolution ¶
func (icr *IndicesCandlesRequest) Resolution(q string) *IndicesCandlesRequest
Resolution sets the resolution parameter for the IndicesCandlesRequest. This method is used to specify the granularity of the candle data to be retrieved. It modifies the resolutionParams field of the IndicesCandlesRequest instance to store the resolution value.
Parameters:
- q: A string representing the resolution to be set. Valid resolutions may include values like "1min", "5min", "1h", etc., depending on the API's supported resolutions.
Returns:
- *IndicesCandlesRequest: This method returns a pointer to the IndicesCandlesRequest instance it was called on. This allows for method chaining, where multiple setter methods can be called in a single statement. If the receiver (*IndicesCandlesRequest) is nil, it returns nil to prevent a panic.
Note:
- If an error occurs while setting the resolution (e.g., if the resolution value is not supported), the Error field of the IndicesCandlesRequest is set with the encountered error, but the method still returns the IndicesCandlesRequest instance to allow for further method calls or error handling by the caller.
func (*IndicesCandlesRequest) Symbol ¶
func (icr *IndicesCandlesRequest) Symbol(q string) *IndicesCandlesRequest
Symbol sets the symbol parameter for the IndicesCandlesRequest. This method is used to specify the market symbol for which the candle data is requested. It modifies the symbolParams field of the IndicesCandlesRequest instance to store the symbol value.
Parameters:
- q: A string representing the market symbol to be set.
Returns:
- *IndicesCandlesRequest: This method returns a pointer to the IndicesCandlesRequest instance it was called on. This allows for method chaining, where multiple setter methods can be called in a single statement. If the receiver (*IndicesCandlesRequest) is nil, it returns nil to prevent a panic.
Note:
- If an error occurs while setting the symbol (e.g., if the symbol value is not supported), the Error field of the IndicesCandlesRequest is set with the encountered error, but the method still returns the IndicesCandlesRequest instance to allow for further method calls or error handling by the caller.
func (*IndicesCandlesRequest) To ¶
func (icr *IndicesCandlesRequest) To(q interface{}) *IndicesCandlesRequest
To sets the 'to' date parameter for the IndicesCandlesRequest. It configures the ending point of the date range for which the candle data is requested. Parameters:
- q: An interface{} that represents the ending date. It can be a string, a time.Time object, or any other type that the underlying SetTo method can process.
Returns:
- *IndicesCandlesRequest: A pointer to the IndicesCandlesRequest instance to allow for method chaining.
type MarketDataClient ¶
type MarketDataClient struct { *resty.Client // Embedding resty.Client to utilize its HTTP client functionalities. RateLimitLimit int // RateLimitLimit represents the maximum number of requests that can be made in a rate limit window. RateLimitRemaining int // RateLimitRemaining tracks the number of requests that can still be made before hitting the rate limit. RateLimitReset time.Time // RateLimitReset indicates the time when the rate limit will be reset. Error error // Error captures any errors that occur during the execution of API calls. // contains filtered or unexported fields }
func GetClient ¶
func GetClient(token ...string) (*MarketDataClient, error)
func NewClient ¶
func NewClient() *MarketDataClient
NewClient initializes and returns a new instance of MarketDataClient with default settings. It sets the default rate limit reset time, environment to production, and configures common headers and hooks for the HTTP client.
func (*MarketDataClient) Debug ¶
func (c *MarketDataClient) Debug(enable bool) *MarketDataClient
Debug is a method that enables or disables the debug mode of the client. Debug mode will result in the request and response headers being printed to the terminal with each request.
func (*MarketDataClient) Environment ¶
func (c *MarketDataClient) Environment(env string) *MarketDataClient
Environment configures the base URL of the MarketDataClient based on the provided environment string. This method allows the client to switch between different environments such as production, testing, and development.
Parameters:
- env: A string representing the environment to configure. Accepted values are "prodEnv", "testEnv", and "devEnv".
Returns:
- A pointer to the MarketDataClient instance with the configured environment.
If an invalid environment is provided, the client's Error field is set, and the same instance is returned.
func (*MarketDataClient) GetFromRequest ¶
func (c *MarketDataClient) GetFromRequest(br *baseRequest, result interface{}) (*resty.Response, error)
GetFromRequest executes a prepared request and returns the response. It handles any errors that occur during the request execution and checks for errors in the response. If an error is found in the response, it is returned as part of the response object.
Parameters:
- br: A pointer to a baseRequest object containing the request details.
- result: An interface where the result of the request will be stored if successful.
Returns:
- A pointer to a resty.Response object containing the response from the server.
- An error object if an error occurred during the request execution or if the response contains an error.
func (*MarketDataClient) GetRawResponse ¶
func (c *MarketDataClient) GetRawResponse(br *baseRequest) (*resty.Response, error)
GetRawResponse executes a prepared request without processing the response. This function is useful when the caller needs the raw response for custom processing.
Parameters:
- br: A pointer to a baseRequest object containing the request details.
Returns:
- A pointer to a resty.Response object containing the raw response from the server.
- An error object if an error occurred during the request execution.
func (*MarketDataClient) RateLimitExceeded ¶
func (c *MarketDataClient) RateLimitExceeded() bool
RateLimitExceeded checks if the rate limit for API requests has been exceeded. It returns true if the number of remaining requests is less than or equal to zero and the current time is before the rate limit reset time, indicating that the client must wait before making further requests. Otherwise, it returns false, indicating that the client can continue making requests.
func (*MarketDataClient) String ¶
func (c *MarketDataClient) String() string
String returns a formatted string representation of the MarketDataClient instance. It includes the client type (environment), rate limit information, and the rate limit reset time.
func (*MarketDataClient) Token ¶
func (c *MarketDataClient) Token(bearerToken string) *MarketDataClient
Token configures the authentication token for the MarketDataClient. This method sets the authentication scheme to "Bearer" and assigns the provided bearerToken for subsequent requests. It also makes an initial request to the MarketData API to authorize the token and fetch rate limit information.
Parameters:
- bearerToken: A string representing the authentication token to be used for API requests.
Returns:
- A pointer to the MarketDataClient instance with the configured authentication token.
If an error occurs during the initial request or if the response indicates a failure, the client's Error field is set, and the same instance is returned.
type MarketDataPacked ¶
type MarketStatusRequest ¶
type MarketStatusRequest struct {
// contains filtered or unexported fields
}
MarketStatusRequest represents a request for market status information. It encapsulates parameters for country, universal, and date to be used in the request. This struct provides methods such as Country(), Date(), From(), To(), and Countback() to set these parameters respectively.
Public Methods:
- Country(q string) *MarketStatusRequest: Sets the country parameter for the request.
- Date(q interface{}) *MarketStatusRequest: Sets the date parameter for the request.
- From(q interface{}) *MarketStatusRequest: Sets the 'from' date parameter for the request.
- To(q interface{}) *MarketStatusRequest: Sets the 'to' date parameter for the request.
- Countback(q int) *MarketStatusRequest: Sets the countback parameter for the request.
func MarketStatus ¶
func MarketStatus(clients ...*MarketDataClient) *MarketStatusRequest
MarketStatus creates a new MarketStatusRequest and associates it with the provided client. If no client is provided, it uses the default client. This function initializes the request with default parameters for country, universal, and date, and sets the request path based on the predefined endpoints for market status. Parameters:
- clients: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *MarketStatusRequest: A pointer to the newly created MarketStatusRequest with default parameters and associated client.
Example (Get) ¶
msr, err := MarketStatus().From("2022-01-01").To("2022-01-10").Get() if err != nil { fmt.Print(err) return } for _, report := range msr { fmt.Println(report) }
Output: MarketStatusReport{Date: 2022-01-01 00:00:00 -0500 EST, Open: false, Closed: true} MarketStatusReport{Date: 2022-01-02 00:00:00 -0500 EST, Open: false, Closed: true} MarketStatusReport{Date: 2022-01-03 00:00:00 -0500 EST, Open: true, Closed: false} MarketStatusReport{Date: 2022-01-04 00:00:00 -0500 EST, Open: true, Closed: false} MarketStatusReport{Date: 2022-01-05 00:00:00 -0500 EST, Open: true, Closed: false} MarketStatusReport{Date: 2022-01-06 00:00:00 -0500 EST, Open: true, Closed: false} MarketStatusReport{Date: 2022-01-07 00:00:00 -0500 EST, Open: true, Closed: false} MarketStatusReport{Date: 2022-01-08 00:00:00 -0500 EST, Open: false, Closed: true} MarketStatusReport{Date: 2022-01-09 00:00:00 -0500 EST, Open: false, Closed: true} MarketStatusReport{Date: 2022-01-10 00:00:00 -0500 EST, Open: true, Closed: false}
Example (Packed) ¶
msr, err := MarketStatus().From("2022-01-01").To("2022-01-10").Packed() if err != nil { fmt.Print(err) return } fmt.Println(msr)
Output: MarketStatusResponse{Date: [1641013200, 1641099600, 1641186000, 1641272400, 1641358800, 1641445200, 1641531600, 1641618000, 1641704400, 1641790800], Status: ["closed", "closed", "open", "open", "open", "open", "open", "closed", "closed", "open"]}
func (*MarketStatusRequest) Countback ¶
func (msr *MarketStatusRequest) Countback(q int) *MarketStatusRequest
Countback sets the countback parameter for the MarketStatusRequest. It specifies the number of days to return, counting backwards from the 'to' date. Parameters:
- q: An int representing the number of days to return.
Returns:
- *MarketStatusRequest: A pointer to the MarketStatusRequest instance to allow for method chaining.
func (*MarketStatusRequest) Country ¶
func (msr *MarketStatusRequest) Country(q string) *MarketStatusRequest
Country sets the country parameter of the MarketStatusRequest. This method is used to specify the country for which the market status is requested. It modifies the countryParams field of the MarketStatusRequest instance to store the country value.
Parameters:
- q: A string representing the country to be set.
Returns:
- *MarketStatusRequest: This method returns a pointer to the MarketStatusRequest instance it was called on. This allows for method chaining, where multiple setter methods can be called in a single statement. If the receiver (*MarketStatusRequest) is nil, it returns nil to prevent a panic.
func (*MarketStatusRequest) Date ¶
func (msr *MarketStatusRequest) Date(q interface{}) *MarketStatusRequest
Date sets the date parameter of the MarketStatusRequest. This method is used to specify the date for which the market status is requested. It modifies the dateParams field of the MarketStatusRequest instance to store the date value.
Parameters:
- q: An interface{} representing the date to be set.
Returns:
- *MarketStatusRequest: This method returns a pointer to the MarketStatusRequest instance it was called on. This allows for method chaining. If the receiver (*MarketStatusRequest) is nil, it returns nil to prevent a panic.
func (*MarketStatusRequest) From ¶
func (msr *MarketStatusRequest) From(q interface{}) *MarketStatusRequest
From sets the 'from' date parameter of the MarketStatusRequest. This method is used to specify the starting date of the period for which the market status is requested. It modifies the dateParams field of the MarketStatusRequest instance to store the 'from' date value.
Parameters:
- q: An interface{} representing the 'from' date to be set.
Returns:
- *MarketStatusRequest: This method returns a pointer to the MarketStatusRequest instance it was called on. This allows for method chaining. If the receiver (*MarketStatusRequest) is nil, it returns nil to prevent a panic.
func (*MarketStatusRequest) Get ¶
func (msr *MarketStatusRequest) Get(optionalClients ...*MarketDataClient) ([]models.MarketStatusReport, error)
Get sends the MarketStatusRequest, unpacks the MarketStatusResponse, and returns a slice of MarketStatusReport. It returns an error if the request or unpacking fails. This method is crucial for obtaining the actual market status data from the market status request. The method first checks if the MarketStatusRequest receiver is nil, which would result in an error as the request cannot be sent. It then proceeds to send the request using the Packed method. Upon receiving the response, it unpacks the data into a slice of MarketStatusReport using the Unpack method from the response. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.MarketStatusReport: A slice of MarketStatusReport containing the unpacked market status data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*MarketStatusRequest) Packed ¶
func (msr *MarketStatusRequest) Packed(optionalClients ...*MarketDataClient) (*models.MarketStatusResponse, error)
Packed sends the MarketStatusRequest and returns the MarketStatusResponse. This method checks if the MarketStatusRequest receiver is nil, returning an error if true. An optional MarketDataClient can be passed to replace the client used in the request. Otherwise, it proceeds to send the request and returns the MarketStatusResponse along with any error encountered during the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.MarketStatusResponse: A pointer to the MarketStatusResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (MarketStatusRequest) Raw ¶
func (request MarketStatusRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*MarketStatusRequest) To ¶
func (msr *MarketStatusRequest) To(q interface{}) *MarketStatusRequest
To sets the 'to' date parameter of the MarketStatusRequest. This method is used to specify the ending date of the period for which the market status is requested. It modifies the dateParams field of the MarketStatusRequest instance to store the 'to' date value.
Parameters:
- q: An interface{} representing the 'to' date to be set.
Returns:
- *MarketStatusRequest: This method returns a pointer to the MarketStatusRequest instance it was called on. This allows for method chaining. If the receiver (*MarketStatusRequest) is nil, it returns nil to prevent a panic.
type OptionChainRequest ¶
type OptionChainRequest struct {
// contains filtered or unexported fields
}
OptionChainRequest represents a request to the /options/chain endpoint. It encapsulates parameters for symbol, date, and various option-specific parameters to be used in the request. This struct provides methods to set these parameters, such as UnderlyingSymbol(), Date(), Expiration(), and Strike(), among others.
Public Methods:
- UnderlyingSymbol(q string) *OptionChainRequest: Sets the underlying symbol parameter for the request.
- Date(q interface{}) *OptionChainRequest: Sets the date parameter for the request.
- Expiration(q interface{}) *OptionChainRequest: Sets the expiration parameter for the request.
- Strike(strike float64) *OptionChainRequest: Sets the strike price parameter for the request.
- and other option-specific parameter setting methods like Month(), Year(), Weekly(), Monthly(), etc.
Example (Get) ¶
resp, err := OptionChain().UnderlyingSymbol("AAPL").Side("call").Date("2022-01-03").DTE(60).StrikeLimit(2).Range("itm").Get() if err != nil { fmt.Println("Error fetching option chain:", err) return } for _, contract := range resp { fmt.Println(contract) }
Output: OptionQuote{OptionSymbol: "AAPL220318C00175000", Underlying: "AAPL", Expiration: 2022-03-18 16:00:00 -04:00, Side: "call", Strike: 175, FirstTraded: 2021-07-13 09:30:00 -04:00, DTE: 73, Ask: 13.1, AskSize: 2, Bid: 12.95, BidSize: 3, Mid: 13.02, Last: 12.9, Volume: 1295, OpenInterest: 15232, UnderlyingPrice: 182.01, InTheMoney: true, Updated: "2022-01-03 16:00:00 -05:00", IV: nil, Delta: nil, Gamma: nil, Theta: nil, Vega: nil, Rho: nil, IntrinsicValue: 7.01, ExtrinsicValue: 6.02} OptionQuote{OptionSymbol: "AAPL220318C00180000", Underlying: "AAPL", Expiration: 2022-03-18 16:00:00 -04:00, Side: "call", Strike: 180, FirstTraded: 2021-07-13 09:30:00 -04:00, DTE: 73, Ask: 10.2, AskSize: 12, Bid: 10, BidSize: 38, Mid: 10.1, Last: 10.1, Volume: 4609, OpenInterest: 18299, UnderlyingPrice: 182.01, InTheMoney: true, Updated: "2022-01-03 16:00:00 -05:00", IV: nil, Delta: nil, Gamma: nil, Theta: nil, Vega: nil, Rho: nil, IntrinsicValue: 2.01, ExtrinsicValue: 8.09}
Example (Packed) ¶
resp, err := OptionChain().UnderlyingSymbol("AAPL").Side("call").Date("2022-01-03"). Month(2).Year(2022).Range("itm").Strike(150).Weekly(false).Monthly(true).Quarterly(false).Nonstandard(false).Packed() if err != nil { fmt.Println("Error fetching packed option chain:", err) return } fmt.Println(resp)
Output: OptionQuotesResponse{OptionSymbol: ["AAPL220121C00150000"], Underlying: ["AAPL"], Expiration: [1642798800], Side: ["call"], Strike: [150], FirstTraded: [1568640600], DTE: [18], Ask: [32.15], AskSize: [2], Bid: [31.8], BidSize: [359], Mid: [31.98], Last: [32], Volume: [3763], OpenInterest: [98804], UnderlyingPrice: [182.01], InTheMoney: [true], Updated: [1641243600], IV: [nil], Delta: [nil], Gamma: [], Theta: [nil], Vega: [nil], Rho: [nil], IntrinsicValue: [32.01], ExtrinsicValue: [0.03]}
func OptionChain ¶
func OptionChain(client ...*MarketDataClient) *OptionChainRequest
OptionChain creates a new OptionChainRequest and associates it with the provided client. If no client is provided, it uses the default client. This function initializes the request with default parameters for symbol, date, and option-specific parameters, and sets the request path based on the predefined endpoints for option chains. Parameters:
- clients: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *OptionChainRequest: A pointer to the newly created OptionChainRequest with default parameters and associated client.
func (*OptionChainRequest) DTE ¶
func (ocr *OptionChainRequest) DTE(dte int) *OptionChainRequest
DTE (Days to Expiration) sets the DTE parameter for the OptionChainRequest. This method specifies the number of days to expiration for the options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the DTE value.
Parameters:
- dte: An int representing the days to expiration to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Date ¶
func (ocr *OptionChainRequest) Date(q interface{}) *OptionChainRequest
Date sets the date parameter for the OptionChainRequest. This method is used to specify the date for which the option chain is requested. It modifies the dateParams field of the OptionChainRequest instance to store the date value.
Parameters:
- q: An interface{} representing the date to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Delta ¶
func (ocr *OptionChainRequest) Delta(delta float64) *OptionChainRequest
Delta sets the Delta parameter for the OptionChainRequest. This method is used to specify a particular Delta value for the options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the Delta value.
Parameters:
- delta: A float64 representing the Delta value to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Expiration ¶
func (ocr *OptionChainRequest) Expiration(q interface{}) *OptionChainRequest
Expiration sets the expiration parameter for the OptionChainRequest. This method is used to specify the expiration date for the options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the expiration value.
Parameters:
- q: An interface{} representing the expiration date to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Get ¶
func (ocr *OptionChainRequest) Get(optionalClients ...*MarketDataClient) ([]models.OptionQuote, error)
Get sends the OptionChainRequest, unpacks the OptionChainResponse, and returns a slice of OptionQuote. It returns an error if the request or unpacking fails. This method is crucial for obtaining the actual option chain data from the option chain request. The method first checks if the OptionChainRequest receiver is nil, which would result in an error as the request cannot be sent. It then proceeds to send the request using the Packed method. Upon receiving the response, it unpacks the data into a slice of OptionQuote using the Unpack method from the response. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.OptionQuote: A slice of OptionQuote containing the unpacked option chain data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*OptionChainRequest) MaxBidAskSpread ¶
func (ocr *OptionChainRequest) MaxBidAskSpread(maxBidAskSpread float64) *OptionChainRequest
MaxBidAskSpread sets the MaxBidAskSpread parameter for the OptionChainRequest. This method is used to specify the maximum bid-ask spread for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the maximum bid-ask spread value.
Parameters:
- maxBidAskSpread: A float64 representing the maximum bid-ask spread to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) MaxBidAskSpreadPct ¶
func (ocr *OptionChainRequest) MaxBidAskSpreadPct(maxBidAskSpreadPct float64) *OptionChainRequest
MaxBidAskSpreadPct sets the MaxBidAskSpreadPct parameter for the OptionChainRequest. This method is used to specify the maximum bid-ask spread percentage for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the maximum bid-ask spread percentage value.
Parameters:
- maxBidAskSpreadPct: A float64 representing the maximum bid-ask spread percentage to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) MinOpenInterest ¶
func (ocr *OptionChainRequest) MinOpenInterest(minOpenInterest int) *OptionChainRequest
MinOpenInterest sets the MinOpenInterest parameter for the OptionChainRequest. This method is used to specify the minimum open interest for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the minimum open interest value.
Parameters:
- minOpenInterest: An int representing the minimum open interest to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) MinVolume ¶
func (ocr *OptionChainRequest) MinVolume(minVolume int) *OptionChainRequest
MinVolume sets the MinVolume parameter for the OptionChainRequest. This method is used to specify the minimum volume for options to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the minimum volume value.
Parameters:
- minVolume: An int representing the minimum volume to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Month ¶
func (ocr *OptionChainRequest) Month(month int) *OptionChainRequest
Month sets the month parameter for the OptionChainRequest. This method is used to specify the month for which the option chain is requested. It modifies the optionParams field of the OptionChainRequest instance to store the month value.
Parameters:
- month: An int representing the month to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Monthly ¶
func (ocr *OptionChainRequest) Monthly(monthly bool) *OptionChainRequest
Monthly sets the monthly parameter for the OptionChainRequest. This method is used to specify whether to include monthly options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the monthly value.
Parameters:
- monthly: A bool indicating whether to include monthly options.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Nonstandard ¶
func (ocr *OptionChainRequest) Nonstandard(nonstandard bool) *OptionChainRequest
Nonstandard sets the nonstandard parameter for the OptionChainRequest. This method is used to specify whether to include nonstandard options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the nonstandard value.
Parameters:
- nonstandard: A bool indicating whether to include nonstandard options.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Packed ¶
func (ocr *OptionChainRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionQuotesResponse, error)
Packed sends the OptionChainRequest and returns the OptionChainResponse. This method checks if the OptionChainRequest receiver is nil, returning an error if true. An optional MarketDataClient can be passed to replace the client used in the request. Otherwise, it proceeds to send the request and returns the OptionChainResponse along with any error encountered during the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.OptionQuotesResponse: A pointer to the OptionQuotesResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (*OptionChainRequest) Quarterly ¶
func (ocr *OptionChainRequest) Quarterly(quarterly bool) *OptionChainRequest
Quarterly sets the quarterly parameter for the OptionChainRequest. This method is used to specify whether to include quarterly options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the quarterly value.
Parameters:
- quarterly: A bool indicating whether to include quarterly options.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Range ¶
func (ocr *OptionChainRequest) Range(rangeParam string) *OptionChainRequest
Range sets the Range parameter for the OptionChainRequest. This method is used to specify the range of options to be included in the option chain based on their strike price. It modifies the optionParams field of the OptionChainRequest instance to store the range value.
Parameters:
- rangeParam: A string representing the range of options to be included. The expected values can vary, such as "ITM" (In The Money), "OTM" (Out of The Money), "ATM" (At The Money), etc.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (OptionChainRequest) Raw ¶
func (request OptionChainRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*OptionChainRequest) Side ¶
func (ocr *OptionChainRequest) Side(side string) *OptionChainRequest
Side sets the Side parameter for the OptionChainRequest. This method is used to specify the side of the market for the options in the option chain (e.g., call or put). It modifies the optionParams field of the OptionChainRequest instance to store the side value.
Parameters:
- side: A string representing the side of the market to be set. Expected values are typically "call" or "put".
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Strike ¶
func (ocr *OptionChainRequest) Strike(strike float64) *OptionChainRequest
Strike sets the strike price parameter for the OptionChainRequest. This method is used to specify a particular strike price for the options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the strike price value.
Parameters:
- strike: A float64 representing the strike price to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) StrikeLimit ¶
func (ocr *OptionChainRequest) StrikeLimit(strikeLimit int) *OptionChainRequest
StrikeLimit sets the StrikeLimit parameter for the OptionChainRequest. This method is used to specify the maximum number of strike prices to be included in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the strike limit value.
Parameters:
- strikeLimit: An int representing the maximum number of strike prices to be included.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) UnderlyingSymbol ¶
func (ocr *OptionChainRequest) UnderlyingSymbol(q string) *OptionChainRequest
UnderlyingSymbol sets the underlyingSymbol parameter for the OptionChainRequest. This method is used to specify the symbol of the underlying asset for which the option chain is requested. It modifies the symbolParams field of the OptionChainRequest instance to store the symbol value.
Parameters:
- q: A string representing the underlying symbol to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining, where multiple setter methods can be called in a single statement. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Weekly ¶
func (ocr *OptionChainRequest) Weekly(weekly bool) *OptionChainRequest
Weekly sets the weekly parameter for the OptionChainRequest. This method is used to specify whether to include weekly options in the option chain. It modifies the optionParams field of the OptionChainRequest instance to store the weekly value.
Parameters:
- weekly: A bool indicating whether to include weekly options.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
func (*OptionChainRequest) Year ¶
func (ocr *OptionChainRequest) Year(year int) *OptionChainRequest
Year sets the year parameter for the OptionChainRequest. This method is used to specify the year for which the option chain is requested. It modifies the optionParams field of the OptionChainRequest instance to store the year value.
Parameters:
- year: An int representing the year to be set.
Returns:
- *OptionChainRequest: This method returns a pointer to the OptionChainRequest instance it was called on. This allows for method chaining. If the receiver (*OptionChainRequest) is nil, it returns nil to prevent a panic.
type OptionLookupRequest ¶
type OptionLookupRequest struct {
// contains filtered or unexported fields
}
OptionsLookupRequest represents a request for retrieving options data based on user input. It encapsulates parameters for user input to be used in the request.
Public Methods:
- UserInput(userInput string) *OptionLookupRequest: Sets the user input parameter for the request.
Example (Get) ¶
resp, err := OptionLookup().UserInput("AAPL 7/28/2023 200 Call").Get() if err != nil { fmt.Print(err) return } fmt.Println(resp)
Output: AAPL230728C00200000
Example (Packed) ¶
resp, err := OptionLookup().UserInput("AAPL 7/28/2023 200 Call").Packed() if err != nil { fmt.Print(err) return } fmt.Println(resp)
Output: OptionLookupResponse{OptionSymbol: "AAPL230728C00200000"}
func OptionLookup ¶
func OptionLookup(client ...*MarketDataClient) *OptionLookupRequest
OptionLookup creates a new OptionsLookupRequest and associates it with the provided client. If no client is provided, it uses the default client. Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *OptionsLookupRequest: A pointer to the newly created OptionsLookupRequest with default parameters and associated client.
func (*OptionLookupRequest) Get ¶
func (o *OptionLookupRequest) Get(optionalClients ...*MarketDataClient) (string, error)
Get sends the OptionLookupRequest, unpacks the OptionsLookupResponse, and returns the unpacked data as a string. It returns an error if the request or unpacking fails. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- string: A string containing the unpacked options data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*OptionLookupRequest) Packed ¶
func (o *OptionLookupRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionLookupResponse, error)
Packed sends the OptionLookupRequest and returns the OptionsLookupResponse. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.OptionsLookupResponse: A pointer to the OptionsLookupResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (OptionLookupRequest) Raw ¶
func (request OptionLookupRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*OptionLookupRequest) UserInput ¶
func (o *OptionLookupRequest) UserInput(userInput string) *OptionLookupRequest
UserInput sets the user input parameter for the OptionsLookupRequest. This method is used to specify the user input for which the options data is requested. Parameters:
- userInput: A string representing the user input to be set.
Returns:
- *OptionsLookupRequest: This method returns a pointer to the OptionsLookupRequest instance it was called on, allowing for method chaining.
type OptionQuoteRequest ¶
type OptionQuoteRequest struct {
// contains filtered or unexported fields
}
OptionQuotesRequest represents a request for retrieving options quotes. It encapsulates parameters for symbol, expiration, and strike to be used in the request.
Public Methods:
- OptionSymbol(symbol string) *OptionQuoteRequest: Sets the symbol parameter for the request.
- Date(date interface{}) *OptionQuoteRequest: Sets the date parameter for the request, accepting flexible date input.
- From(from interface{}) *OptionQuoteRequest: Sets the start date of a date range for the request, accepting flexible date input.
- To(from interface{}) *OptionQuoteRequest: Sets the start date of a date range for the request, accepting flexible date input.
Example (Get) ¶
resp, err := OptionQuote().OptionSymbol("AAPL250117C00150000").Date("2024-02-05").Get() if err != nil { fmt.Print(err) return } for _, quote := range resp { fmt.Println(quote) }
Output: OptionQuote{OptionSymbol: "AAPL250117C00150000", Underlying: "AAPL", Expiration: 2025-01-17 16:00:00 -05:00, Side: "call", Strike: 150, FirstTraded: 2022-09-10 09:30:00 -04:00, DTE: 347, Ask: 47.7, AskSize: 17, Bid: 47.2, BidSize: 36, Mid: 47.45, Last: 48.65, Volume: 202, OpenInterest: 10768, UnderlyingPrice: 187.68, InTheMoney: true, Updated: "2024-02-05 16:00:00 -05:00", IV: nil, Delta: nil, Gamma: nil, Theta: nil, Vega: nil, Rho: nil, IntrinsicValue: 37.68, ExtrinsicValue: 9.77}
Example (Packed) ¶
resp, err := OptionQuote().OptionSymbol("AAPL250117P00150000").Date("2024-02-05").Packed() if err != nil { fmt.Print(err) return } fmt.Println(resp)
Output: OptionQuotesResponse{OptionSymbol: ["AAPL250117P00150000"], Underlying: ["AAPL"], Expiration: [1737147600], Side: ["put"], Strike: [150], FirstTraded: [1662816600], DTE: [347], Ask: [3.65], AskSize: [292], Bid: [3.5], BidSize: [634], Mid: [3.58], Last: [3.55], Volume: [44], OpenInterest: [18027], UnderlyingPrice: [187.68], InTheMoney: [false], Updated: [1707166800], IV: [], Delta: [], Gamma: [], Theta: [], Vega: [], Rho: [], IntrinsicValue: [0], ExtrinsicValue: [3.58]}
func OptionQuote ¶
func OptionQuote(client ...*MarketDataClient) *OptionQuoteRequest
OptionQuotes creates a new OptionQuotesRequest and associates it with the provided client. If no client is provided, it uses the default client. Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *OptionQuotesRequest: A pointer to the newly created OptionQuotesRequest with default parameters and associated client.
func (*OptionQuoteRequest) Date ¶
func (oqr *OptionQuoteRequest) Date(q interface{}) *OptionQuoteRequest
Date sets the date parameter for the OptionQuotesRequest. This method is used to specify the date for which the option quote is requested. It allows for flexibility in the type of date input (e.g., string, time.Time) through the use of an interface{} parameter. Parameters:
- date: An interface{} representing the date to be set. The actual type accepted can vary (e.g., string, time.Time), depending on implementation.
Returns:
- *OptionQuotesRequest: This method returns a pointer to the OptionQuotesRequest instance it was called on, allowing for method chaining. If the receiver (*OptionQuotesRequest) is nil, it returns nil to prevent a panic.
func (*OptionQuoteRequest) From ¶
func (oqr *OptionQuoteRequest) From(q interface{}) *OptionQuoteRequest
From sets the from parameter for the OptionQuotesRequest. This method is used to specify the start date of a date range for which the option quote is requested. Similar to the Date method, it accepts a flexible date input through an interface{} parameter. Parameters:
- from: An interface{} representing the start date of the range to be set. The actual type accepted can vary, depending on implementation.
Returns:
- *OptionQuotesRequest: This method returns a pointer to the OptionQuotesRequest instance it was called on, allowing for method chaining. If the receiver (*OptionQuotesRequest) is nil, it returns nil to prevent a panic.
func (*OptionQuoteRequest) Get ¶
func (oqr *OptionQuoteRequest) Get(optionalClients ...*MarketDataClient) ([]models.OptionQuote, error)
Get sends the OptionQuoteRequest, unpacks the OptionQuotesResponse, and returns a slice of OptionQuote. It returns an error if the request or unpacking fails. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.OptionQuote: A slice of OptionQuote containing the unpacked options quotes data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*OptionQuoteRequest) OptionSymbol ¶
func (oqr *OptionQuoteRequest) OptionSymbol(q string) *OptionQuoteRequest
OptionSymbol sets the symbol parameter for the OptionQuotesRequest. This method is used to specify the symbol of the option for which the quote is requested. Parameters:
- symbol: A string representing the symbol to be set.
Returns:
- *OptionQuotesRequest: This method returns a pointer to the OptionQuotesRequest instance it was called on, allowing for method chaining.
func (*OptionQuoteRequest) Packed ¶
func (oqr *OptionQuoteRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionQuotesResponse, error)
Packed sends the OptionQuoteRequest and returns the OptionQuotesResponse. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.OptionQuotesResponse: A pointer to the OptionQuotesResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (OptionQuoteRequest) Raw ¶
func (request OptionQuoteRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*OptionQuoteRequest) To ¶
func (oqr *OptionQuoteRequest) To(q interface{}) *OptionQuoteRequest
To sets the to parameter for the OptionQuotesRequest. This method is used to specify the end date of a date range for which the option quote is requested. It accepts a flexible date input through an interface{} parameter, similar to the From method. Parameters:
- to: An interface{} representing the end date of the range to be set. The actual type accepted can vary, depending on implementation.
Returns:
- *OptionQuotesRequest: This method returns a pointer to the OptionQuotesRequest instance it was called on, allowing for method chaining. If the receiver (*OptionQuotesRequest) is nil, it returns nil to prevent a panic.
type OptionsExpirationsRequest ¶
type OptionsExpirationsRequest struct {
// contains filtered or unexported fields
}
OptionsExpirationsRequest represents a request for retrieving options expirations data. It encapsulates parameters for the underlying symbol and strike price to be used in the request. This struct provides methods such as UnderlyingSymbol() and Strike() to set these parameters respectively.
Public Methods:
- Strike(strike float64) *OptionsExpirationsRequest: Sets the strike price parameter for the options expirations request.
- UnderlyingSymbol(symbol string) *OptionsExpirationsRequest: Sets the underlying symbol parameter for the options expirations request.
func OptionsExpirations ¶
func OptionsExpirations(client ...*MarketDataClient) *OptionsExpirationsRequest
OptionsExpirations creates a new OptionsExpirationsRequest and associates it with the provided client. If no client is provided, it uses the default client. Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *OptionsExpirationsRequest: A pointer to the newly created OptionsExpirationsRequest with default parameters and associated client.
func (*OptionsExpirationsRequest) Date ¶
func (oer *OptionsExpirationsRequest) Date(q interface{}) *OptionsExpirationsRequest
Date sets the date parameter for the OptionsExpirationsRequest. This method is used to specify the date for which the options expirations are requested. It modifies the dateParams field of the OptionsExpirationsRequest instance to store the date value.
Parameters:
- q: An interface{} representing the date to be set.
Returns:
- *OptionsExpirationsRequest: This method returns a pointer to the OptionsExpirationsRequest instance it was called on. This allows for method chaining. If the receiver (*OptionsExpirationsRequest) is nil, it returns nil to prevent a panic.
func (*OptionsExpirationsRequest) Get ¶
func (o *OptionsExpirationsRequest) Get(optionalClients ...*MarketDataClient) ([]time.Time, error)
Get sends the OptionsExpirationsRequest, unpacks the OptionsExpirationsResponse, and returns a slice of time.Time. It returns an error if the request or unpacking fails. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []time.Time: A slice of time.Time containing the unpacked options expirations data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*OptionsExpirationsRequest) Packed ¶
func (o *OptionsExpirationsRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionsExpirationsResponse, error)
Packed sends the OptionsExpirationsRequest and returns the OptionsExpirationsResponse. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.OptionsExpirationsResponse: A pointer to the OptionsExpirationsResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (OptionsExpirationsRequest) Raw ¶
func (request OptionsExpirationsRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*OptionsExpirationsRequest) Strike ¶
func (o *OptionsExpirationsRequest) Strike(strike float64) *OptionsExpirationsRequest
Strike sets the strike price parameter for the OptionsExpirationsRequest. This method is used to specify a particular strike price for filtering the options expirations. Parameters:
- strike: A float64 representing the strike price to be set.
Returns:
- *OptionsExpirationsRequest: This method returns a pointer to the OptionsExpirationsRequest instance it was called on, allowing for method chaining.
func (*OptionsExpirationsRequest) UnderlyingSymbol ¶
func (o *OptionsExpirationsRequest) UnderlyingSymbol(symbol string) *OptionsExpirationsRequest
UnderlyingSymbol sets the underlying symbol parameter for the OptionsExpirationsRequest. This method is used to specify the symbol of the underlying asset for which the options expirations are requested. Parameters:
- symbol: A string representing the underlying symbol to be set.
Returns:
- *OptionsExpirationsRequest: This method returns a pointer to the OptionsExpirationsRequest instance it was called on, allowing for method chaining.
type OptionsStrikesRequest ¶
type OptionsStrikesRequest struct {
// contains filtered or unexported fields
}
OptionsStrikesRequest represents a request to the options strikes endpoint. It encapsulates parameters for underlying symbol, expiration, and date to be used in the request. This struct provides methods such as UnderlyingSymbol(), Expiration(), and Date() to set these parameters respectively.
Public Methods:
- UnderlyingSymbol(symbol string) *OptionsStrikesRequest: Sets the underlying symbol parameter for the request.
- Expiration(expiration string) *OptionsStrikesRequest: Sets the expiration parameter for the request.
- Date(date string) *OptionsStrikesRequest: Sets the date parameter for the request.
- Packed() (*models.OptionsStrikesResponse, error): Sends the OptionsStrikesRequest and returns the OptionsStrikesResponse.
- Get() ([]models.OptionsStrikes, error): Sends the OptionsStrikesRequest, unpacks the OptionsStrikesResponse, and returns a slice of OptionsStrikes.
Example (Get) ¶
resp, err := OptionsStrikes().UnderlyingSymbol("AAPL").Date("2009-02-09").Get() if err != nil { fmt.Print(err) return } for _, expiration := range resp { fmt.Println(expiration) }
Output: OptionsStrikes{Expiration: 2009-02-21, Strikes: [40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00 140.00]} OptionsStrikes{Expiration: 2009-03-21, Strikes: [35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00]} OptionsStrikes{Expiration: 2009-04-18, Strikes: [15.00 17.50 20.00 22.50 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00 140.00 145.00 150.00 155.00 160.00 165.00 170.00 175.00 180.00 185.00 190.00 195.00 200.00 210.00 220.00 230.00 240.00 250.00 260.00 270.00 280.00 290.00 300.00]} OptionsStrikes{Expiration: 2009-07-18, Strikes: [12.50 15.00 17.50 20.00 22.50 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00 140.00 145.00 150.00 155.00 160.00 165.00 170.00 175.00 180.00 185.00 190.00]} OptionsStrikes{Expiration: 2010-01-16, Strikes: [22.50 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 120.00 125.00 130.00 135.00 140.00 145.00 150.00 155.00 160.00 170.00 180.00 190.00 200.00 210.00 220.00 230.00 240.00 250.00 260.00 270.00 280.00 290.00 300.00 310.00 320.00 330.00 340.00 350.00 360.00 370.00 380.00 390.00 400.00]} OptionsStrikes{Expiration: 2011-01-22, Strikes: [20.00 30.00 40.00 50.00 60.00 70.00 80.00 85.00 90.00 95.00 100.00 110.00 120.00 125.00 130.00 140.00 150.00 160.00 170.00 180.00 190.00 200.00 210.00 220.00 230.00 240.00]}
Example (Packed) ¶
resp, err := OptionsStrikes().UnderlyingSymbol("AAPL").Date("2009-02-09").Packed() if err != nil { fmt.Print(err) return } fmt.Println(resp)
Output: OptionsStrikesResponse{Strikes: [2009-02-21:[40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00 140.00], 2009-03-21:[35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00], 2009-04-18:[15.00 17.50 20.00 22.50 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00 140.00 145.00 150.00 155.00 160.00 165.00 170.00 175.00 180.00 185.00 190.00 195.00 200.00 210.00 220.00 230.00 240.00 250.00 260.00 270.00 280.00 290.00 300.00], 2009-07-18:[12.50 15.00 17.50 20.00 22.50 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 115.00 120.00 125.00 130.00 135.00 140.00 145.00 150.00 155.00 160.00 165.00 170.00 175.00 180.00 185.00 190.00], 2010-01-16:[22.50 25.00 30.00 35.00 40.00 45.00 50.00 55.00 60.00 65.00 70.00 75.00 80.00 85.00 90.00 95.00 100.00 105.00 110.00 120.00 125.00 130.00 135.00 140.00 145.00 150.00 155.00 160.00 170.00 180.00 190.00 200.00 210.00 220.00 230.00 240.00 250.00 260.00 270.00 280.00 290.00 300.00 310.00 320.00 330.00 340.00 350.00 360.00 370.00 380.00 390.00 400.00], 2011-01-22:[20.00 30.00 40.00 50.00 60.00 70.00 80.00 85.00 90.00 95.00 100.00 110.00 120.00 125.00 130.00 140.00 150.00 160.00 170.00 180.00 190.00 200.00 210.00 220.00 230.00 240.00]], Updated: 1234155600}
func OptionsStrikes ¶
func OptionsStrikes(client ...*MarketDataClient) *OptionsStrikesRequest
OptionsStrikes creates a new OptionsStrikesRequest and associates it with the provided client. If no client is provided, it uses the default client. This function initializes the request with default parameters for underlying symbol, expiration, and date, and sets the request path based on the predefined endpoints for options strikes.
Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *OptionsStrikesRequest: A pointer to the newly created OptionsStrikesRequest with default parameters and associated client.
func (*OptionsStrikesRequest) Date ¶
func (o *OptionsStrikesRequest) Date(date string) *OptionsStrikesRequest
Date sets the date parameter for the OptionsStrikesRequest. This method is used to specify the date for which the options strikes data is requested.
Parameters:
- date: A string representing the date to be set.
Returns:
- *OptionsStrikesRequest: This method returns a pointer to the OptionsStrikesRequest instance it was called on. This allows for method chaining.
func (*OptionsStrikesRequest) Expiration ¶
func (o *OptionsStrikesRequest) Expiration(expiration string) *OptionsStrikesRequest
Expiration sets the expiration parameter for the OptionsStrikesRequest. This method is used to specify the expiration date of the options for which strikes data is requested.
Parameters:
- expiration: A string representing the expiration date to be set.
Returns:
- *OptionsStrikesRequest: This method returns a pointer to the OptionsStrikesRequest instance it was called on. This allows for method chaining.
func (*OptionsStrikesRequest) Get ¶
func (osr *OptionsStrikesRequest) Get(optionalClients ...*MarketDataClient) ([]models.OptionsStrikes, error)
Get sends the OptionsStrikesRequest, unpacks the OptionsStrikesResponse, and returns a slice of OptionsStrikes. It returns an error if the request or unpacking fails. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.OptionsStrikes: A slice of OptionsStrikes containing the unpacked options strikes data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*OptionsStrikesRequest) Packed ¶
func (osr *OptionsStrikesRequest) Packed(optionalClients ...*MarketDataClient) (*models.OptionsStrikesResponse, error)
Packed sends the OptionsStrikesRequest and returns the OptionsStrikesResponse. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.OptionsStrikesResponse: A pointer to the OptionsStrikesResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (OptionsStrikesRequest) Raw ¶
func (request OptionsStrikesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*OptionsStrikesRequest) UnderlyingSymbol ¶
func (o *OptionsStrikesRequest) UnderlyingSymbol(underlyingSymbol string) *OptionsStrikesRequest
UnderlyingSymbol sets the underlying symbol parameter for the OptionsStrikesRequest. This method is used to specify the symbol of the underlying asset for which options strikes data is requested.
Parameters:
- underlyingSymbol: A string representing the symbol to be set.
Returns:
- *OptionsStrikesRequest: This method returns a pointer to the OptionsStrikesRequest instance it was called on. This allows for method chaining.
type StockCandlesRequest ¶
type StockCandlesRequest struct {
// contains filtered or unexported fields
}
StockCandlesRequest represents a request to the /v1/stocks/candles endpoint. It encapsulates parameters for resolution, symbol, date, and additional stock-specific parameters to be used in the request. This struct provides methods such as Resolution(), Symbol(), Date(), From(), To(), Countback(), AdjustSplits(), AdjustDividends(), Extended(), and Exchange() to set these parameters respectively.
Public Methods:
- Resolution(q string) *StockCandlesRequest: Sets the resolution parameter for the request.
- Symbol(q string) *StockCandlesRequest: Sets the symbol parameter for the request.
- Date(q interface{}) *StockCandlesRequest: Sets the date parameter for the request.
- From(q interface{}) *StockCandlesRequest: Sets the 'from' date parameter for the request.
- To(q interface{}) *StockCandlesRequest: Sets the 'to' date parameter for the request.
- Countback(q int) *StockCandlesRequest: Sets the countback parameter for the request.
- AdjustSplits(q bool) *StockCandlesRequest: Sets the adjust splits parameter for the request.
- AdjustDividends(q bool) *StockCandlesRequest: Sets the adjust dividends parameter for the request.
- Extended(q bool) *StockCandlesRequest: Sets the extended hours data parameter for the request.
- Exchange(q string) *StockCandlesRequest: Sets the exchange parameter for the request.
- Packed() (*models.StockCandlesResponse, error): Sends the StockCandlesRequest and returns the StockCandlesResponse.
- Get() ([]models.StockCandle, error): Sends the StockCandlesRequest, unpacks the StockCandlesResponse, and returns a slice of StockCandle.
func StockCandles ¶
func StockCandles(client ...*MarketDataClient) *StockCandlesRequest
Get sends the StockCandlesRequest, unpacks the StockCandlesResponse, and returns a slice of StockCandle. It returns an error if the request or unpacking fails. This method is crucial for obtaining the actual stock candle data from the stock candles request. The method first checks if the StockCandlesRequest receiver is nil, which would result in an error as the request cannot be sent. It then proceeds to send the request using the Packed method. Upon receiving the response, it unpacks the data into a slice of StockCandle using the Unpack method from the response.
Returns:
- []models.StockCandle: A slice of StockCandle containing the unpacked candle data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*StockCandlesRequest) AdjustDividends ¶
func (scr *StockCandlesRequest) AdjustDividends(q bool) *StockCandlesRequest
AdjustDividends sets the adjust dividends parameter for the StockCandlesRequest. This method indicates whether the returned data should be adjusted for dividends.
Parameters:
- q: A bool indicating whether to adjust for dividends.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on. This allows for method chaining.
func (*StockCandlesRequest) AdjustSplits ¶
func (scr *StockCandlesRequest) AdjustSplits(q bool) *StockCandlesRequest
AdjustSplits sets the adjust splits parameter for the StockCandlesRequest. This method indicates whether the returned data should be adjusted for stock splits.
Parameters:
- q: A bool indicating whether to adjust for splits.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on. This allows for method chaining.
func (*StockCandlesRequest) Countback ¶
func (scr *StockCandlesRequest) Countback(q int) *StockCandlesRequest
Countback sets the countback parameter for the StockCandlesRequest. This method specifies the number of candles to return, counting backwards from the 'to' date.
Parameters:
- q: An int representing the number of candles to return.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on. This allows for method chaining.
func (*StockCandlesRequest) Date ¶
func (scr *StockCandlesRequest) Date(q interface{}) *StockCandlesRequest
Date sets the date parameter for the StockCandlesRequest. This method is used to specify the date for which the stock candle data is requested.
Parameters:
- q: An interface{} representing the date to be set.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on. This allows for method chaining.
func (*StockCandlesRequest) Exchange ¶
func (scr *StockCandlesRequest) Exchange(q string) *StockCandlesRequest
Exchange sets the exchange parameter for the StockCandlesRequest. This method is used to specify the exchange from which the stock candle data is requested.
Parameters:
- q: A string representing the exchange to be set.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on. This allows for method chaining.
func (*StockCandlesRequest) Extended ¶
func (scr *StockCandlesRequest) Extended(q bool) *StockCandlesRequest
Extended sets the extended hours data parameter for the StockCandlesRequest. This method indicates whether the returned data should include extended hours trading data.
Parameters:
- q: A bool indicating whether to include extended hours data.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on. This allows for method chaining.
func (*StockCandlesRequest) From ¶
func (scr *StockCandlesRequest) From(q interface{}) *StockCandlesRequest
From sets the 'from' date parameter for the StockCandlesRequest. This method is used to specify the starting point of the date range for which the stock candle data is requested.
Parameters:
- q: An interface{} representing the starting date.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on. This allows for method chaining.
func (*StockCandlesRequest) Get ¶
func (scr *StockCandlesRequest) Get(optionalClients ...*MarketDataClient) ([]models.StockCandle, error)
Get sends the StockCandlesRequest, unpacks the StockCandlesResponse, and returns a slice of StockCandle. It returns an error if the request or unpacking fails. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.StockCandle: A slice of StockCandle containing the unpacked candle data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*StockCandlesRequest) Packed ¶
func (scr *StockCandlesRequest) Packed(optionalClients ...*MarketDataClient) (*models.StockCandlesResponse, error)
Packed sends the StockCandlesRequest and returns the StockCandlesResponse. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.StockCandlesResponse: A pointer to the StockCandlesResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (StockCandlesRequest) Raw ¶
func (request StockCandlesRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*StockCandlesRequest) Resolution ¶
func (cr *StockCandlesRequest) Resolution(q string) *StockCandlesRequest
Resolution sets the resolution parameter for the StockCandlesRequest. This method is used to specify the granularity of the candle data to be retrieved.
Parameters:
- q: A string representing the resolution to be set.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on. This allows for method chaining.
func (*StockCandlesRequest) Symbol ¶
func (cr *StockCandlesRequest) Symbol(q string) *StockCandlesRequest
Symbol sets the symbol parameter for the StockCandlesRequest. This method is used to specify the stock symbol for which candle data is requested.
Parameters:
- q: A string representing the stock symbol to be set.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on. This allows for method chaining.
func (*StockCandlesRequest) To ¶
func (scr *StockCandlesRequest) To(q interface{}) *StockCandlesRequest
To sets the 'to' date parameter for the StockCandlesRequest. This method is used to specify the ending point of the date range for which the stock candle data is requested.
Parameters:
- q: An interface{} representing the ending date.
Returns:
- *StockCandlesRequest: This method returns a pointer to the StockCandlesRequest instance it was called on
type StockCandlesRequestV2 ¶
type StockCandlesRequestV2 struct {
// contains filtered or unexported fields
}
StockCandlesRequestV2 represents a request to the /v2/stocks/candles endpoint.
func StockCandlesV2 ¶
func StockCandlesV2(client ...*MarketDataClient) *StockCandlesRequestV2
StockCandles creates a new CandlesRequest and associates it with the provided client. If no client is provided, it uses the default client.
func (*StockCandlesRequestV2) DateKey ¶
func (cr *StockCandlesRequestV2) DateKey(q string) *StockCandlesRequestV2
Date sets the date parameter for the CandlesRequest.
func (*StockCandlesRequestV2) Get ¶
func (scrV2 *StockCandlesRequestV2) Get(optionalClients ...*MarketDataClient) ([]models.StockCandle, error)
Get sends the StockCandlesRequestV2, unpacks the StockCandlesResponse, and returns a slice of StockCandle. It returns an error if the request or unpacking fails. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.StockCandle: A slice of StockCandle containing the unpacked candle data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*StockCandlesRequestV2) Packed ¶
func (scrV2 *StockCandlesRequestV2) Packed(optionalClients ...*MarketDataClient) (*models.StockCandlesResponse, error)
Packed sends the StockCandlesRequestV2 and returns the StockCandlesResponse. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.StockCandlesResponse: A pointer to the StockCandlesResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (StockCandlesRequestV2) Raw ¶
func (request StockCandlesRequestV2) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*StockCandlesRequestV2) Resolution ¶
func (cr *StockCandlesRequestV2) Resolution(q string) *StockCandlesRequestV2
Resolution sets the resolution parameter for the CandlesRequest.
func (*StockCandlesRequestV2) Symbol ¶
func (cr *StockCandlesRequestV2) Symbol(q string) *StockCandlesRequestV2
Symbol sets the symbol parameter for the CandlesRequest.
type StockEarningsRequest ¶
type StockEarningsRequest struct {
// contains filtered or unexported fields
}
StockEarningsRequest represents a request to the /stocks/earnings endpoint. It encapsulates parameters for symbol, report type, and date to be used in the request. This struct provides methods such as Report(), Symbol(), Date(), From(), To(), and Countback() to set these parameters respectively.
Public Methods:
- Report(q string) *StockEarningsRequest: Sets the report type parameter for the request.
- Symbol(q string) *StockEarningsRequest: Sets the symbol parameter for the request.
- Date(q interface{}) *StockEarningsRequest: Sets the date parameter for the request.
- From(q interface{}) *StockEarningsRequest: Sets the 'from' date parameter for the request.
- To(q interface{}) *StockEarningsRequest: Sets the 'to' date parameter for the request.
- Countback(q int) *StockEarningsRequest: Sets the countback parameter for the request.
- Packed() (*models.StockEarningsResponse, error): Sends the StockEarningsRequest and returns the StockEarningsResponse.
- Get() ([]models.StockEarningsReport, error): Sends the StockEarningsRequest, unpacks the StockEarningsResponse, and returns a slice of StockEarningsReport.
func StockEarnings ¶
func StockEarnings(client ...*MarketDataClient) *StockEarningsRequest
StockEarnings creates a new StockEarningsRequest and associates it with the provided client. If no client is provided, it uses the default client. This function initializes the request with default parameters for symbol, report type, and date, and sets the request path based on the predefined endpoints for stock earnings.
Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *StockEarningsRequest: A pointer to the newly created StockEarningsRequest with default parameters and associated client.
func (*StockEarningsRequest) Countback ¶
func (ser *StockEarningsRequest) Countback(q int) *StockEarningsRequest
Countback sets the countback parameter for the StockEarningsRequest. This method specifies the number of periods to return, counting backwards from the 'to' date.
Parameters:
- q: An int representing the number of periods to return.
Returns:
- *StockEarningsRequest: This method returns a pointer to the StockEarningsRequest instance it was called on. This allows for method chaining.
func (*StockEarningsRequest) Date ¶
func (ser *StockEarningsRequest) Date(q interface{}) *StockEarningsRequest
Date sets the date parameter for the StockEarningsRequest. This method is used to specify the date for which the stock earnings data is requested.
Parameters:
- q: An interface{} representing the date to be set.
Returns:
- *StockEarningsRequest: This method returns a pointer to the StockEarningsRequest instance it was called on. This allows for method chaining.
func (*StockEarningsRequest) From ¶
func (ser *StockEarningsRequest) From(q interface{}) *StockEarningsRequest
From sets the 'from' date parameter for the StockEarningsRequest. This method is used to specify the starting point of the date range for which the stock earnings data is requested.
Parameters:
- q: An interface{} representing the starting date.
Returns:
- *StockEarningsRequest: This method returns a pointer to the StockEarningsRequest instance it was called on. This allows for method chaining.
func (*StockEarningsRequest) Get ¶
func (ser *StockEarningsRequest) Get(optionalClients ...*MarketDataClient) ([]models.StockEarningsReport, error)
Get sends the StockEarningsRequest, unpacks the StockEarningsResponse, and returns a slice of StockEarningsReport. It returns an error if the request or unpacking fails. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.StockEarningsReport: A slice of StockEarningsReport containing the unpacked earnings data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*StockEarningsRequest) Packed ¶
func (ser *StockEarningsRequest) Packed(optionalClients ...*MarketDataClient) (*models.StockEarningsResponse, error)
Packed sends the StockEarningsRequest and returns the StockEarningsResponse. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.StockEarningsResponse: A pointer to the StockEarningsResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (StockEarningsRequest) Raw ¶
func (request StockEarningsRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*StockEarningsRequest) Report ¶
func (ser *StockEarningsRequest) Report(q string) *StockEarningsRequest
Report sets the report type parameter for the StockEarningsRequest. This method is used to specify which earnings report to be retrieved.
Parameters:
- q: A string representing which report to be returned.
Returns:
- *StockEarningsRequest: This method returns a pointer to the StockEarningsRequest instance it was called on. This allows for method chaining.
func (*StockEarningsRequest) Symbol ¶
func (ser *StockEarningsRequest) Symbol(q string) *StockEarningsRequest
Symbol sets the symbol parameter for the StockEarningsRequest. This method is used to specify the stock symbol for which earnings data is requested.
Parameters:
- q: A string representing the stock symbol to be set.
Returns:
- *StockEarningsRequest: This method returns a pointer to the StockEarningsRequest instance it was called on. This allows for method chaining.
func (*StockEarningsRequest) To ¶
func (ser *StockEarningsRequest) To(q interface{}) *StockEarningsRequest
To sets the 'to' date parameter for the StockEarningsRequest. This method is used to specify the ending point of the date range for which the stock earnings data is requested.
Parameters:
- q: An interface{} representing the ending date.
Returns:
- *StockEarningsRequest: This method returns a pointer to the StockEarningsRequest instance it was called on. This allows for method chaining.
type StockNewsRequest ¶
type StockNewsRequest struct {
// contains filtered or unexported fields
}
StockNewsRequest represents a request to the /stocks/news endpoint. It encapsulates parameters for symbol, date, and additional news-specific parameters to be used in the request. This struct provides methods such as Symbol(), Date(), From(), To(), and Countback() to set these parameters respectively.
Public Methods:
- Symbol(q string) *StockNewsRequest: Sets the symbol parameter for the request.
- Date(q interface{}) *StockNewsRequest: Sets the date parameter for the request.
- From(q interface{}) *StockNewsRequest: Sets the 'from' date parameter for the request.
- To(q interface{}) *StockNewsRequest: Sets the 'to' date parameter for the request.
- Countback(q int) *StockNewsRequest: Sets the countback parameter for the request.
func StockNews ¶
func StockNews(client ...*MarketDataClient) *StockNewsRequest
StockNews creates a new StockNewsRequest and associates it with the provided client. If no client is provided, it uses the default client. This function initializes the request with default parameters for symbol, date, and additional news-specific parameters, and sets the request path based on the predefined endpoints for stock news.
Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *StockNewsRequest: A pointer to the newly created StockNewsRequest with default parameters and associated client.
func (*StockNewsRequest) Countback ¶
func (snr *StockNewsRequest) Countback(q int) *StockNewsRequest
Countback sets the countback parameter for the StockNewsRequest. This method specifies the number of news items to return, counting backwards from the 'to' date.
Parameters:
- q: An int representing the number of news items to return.
Returns:
- *StockNewsRequest: This method returns a pointer to the StockNewsRequest instance it was called on. This allows for method chaining.
func (*StockNewsRequest) Date ¶
func (snr *StockNewsRequest) Date(q interface{}) *StockNewsRequest
Date sets the date parameter for the StockNewsRequest. This method is used to specify the date for which the stock news data is requested.
Parameters:
- q: An interface{} representing the date to be set.
Returns:
- *StockNewsRequest: This method returns a pointer to the StockNewsRequest instance it was called on. This allows for method chaining.
func (*StockNewsRequest) From ¶
func (snr *StockNewsRequest) From(q interface{}) *StockNewsRequest
From sets the 'from' date parameter for the StockNewsRequest. This method is used to specify the starting point of the date range for which the stock news data is requested.
Parameters:
- q: An interface{} representing the starting date.
Returns:
- *StockNewsRequest: This method returns a pointer to the StockNewsRequest instance it was called on. This allows for method chaining.
func (*StockNewsRequest) Get ¶
func (snr *StockNewsRequest) Get(optionalClients ...*MarketDataClient) ([]models.StockNews, error)
Get sends the StockNewsRequest, unpacks the StockNewsResponse, and returns a slice of StockNews. It returns an error if the request or unpacking fails. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.StockNews: A slice of StockNews containing the unpacked news data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*StockNewsRequest) Packed ¶
func (snr *StockNewsRequest) Packed(optionalClients ...*MarketDataClient) (*models.StockNewsResponse, error)
Packed sends the StockNewsRequest and returns the StockNewsResponse. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.StockNewsResponse: A pointer to the StockNewsResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (StockNewsRequest) Raw ¶
func (request StockNewsRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*StockNewsRequest) Symbol ¶
func (snr *StockNewsRequest) Symbol(q string) *StockNewsRequest
Symbol sets the symbol parameter for the StockNewsRequest. This method is used to specify the stock symbol for which news data is requested.
Parameters:
- q: A string representing the stock symbol to be set.
Returns:
- *StockNewsRequest: This method returns a pointer to the StockNewsRequest instance it was called on. This allows for method chaining.
func (*StockNewsRequest) To ¶
func (snr *StockNewsRequest) To(q interface{}) *StockNewsRequest
To sets the 'to' date parameter for the StockNewsRequest. This method is used to specify the ending point of the date range for which the stock news data is requested.
Parameters:
- q: An interface{} representing the ending date.
Returns:
- *StockNewsRequest: This method returns a pointer to the StockNewsRequest instance it was called on. This allows for method chaining.
type StockQuoteRequest ¶
type StockQuoteRequest struct {
// contains filtered or unexported fields
}
StockQuoteRequest represents a request to the /stocks/quote endpoint. It encapsulates parameters for symbol and fifty-two-week data to be used in the request. This struct provides methods such as Symbol() and FiftyTwoWeek() to set these parameters respectively.
Public Methods:
- Symbol(q string) *StockQuoteRequest: Sets the symbol parameter for the request.
- FiftyTwoWeek(q bool) *StockQuoteRequest: Sets the fifty-two-week data parameter for the request.
func StockQuote ¶
func StockQuote(client ...*MarketDataClient) *StockQuoteRequest
StockQuote creates a new StockQuoteRequest and associates it with the provided client. If no client is provided, it uses the default client. This function initializes the request with default parameters for symbol and fifty-two-week data, and sets the request path based on the predefined endpoints for stock quotes.
Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *StockQuoteRequest: A pointer to the newly created StockQuoteRequest with default parameters and associated client.
func (*StockQuoteRequest) FiftyTwoWeek ¶
func (sqr *StockQuoteRequest) FiftyTwoWeek(q bool) *StockQuoteRequest
FiftyTwoWeek sets the fifty-two-week data parameter for the StockQuoteRequest. This method indicates whether to include fifty-two-week high and low data in the quote.
Parameters:
- q: A bool indicating whether to include fifty-two-week data.
Returns:
- *StockQuoteRequest: This method returns a pointer to the StockQuoteRequest instance it was called on. This allows for method chaining.
func (*StockQuoteRequest) Get ¶
func (sqr *StockQuoteRequest) Get(optionalClients ...*MarketDataClient) ([]models.StockQuote, error)
Get sends the StockQuoteRequest, unpacks the StockQuotesResponse, and returns a slice of StockQuote. It returns an error if the request or unpacking fails. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- []models.StockQuote: A slice of StockQuote containing the unpacked quote data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*StockQuoteRequest) Packed ¶
func (sqr *StockQuoteRequest) Packed(optionalClients ...*MarketDataClient) (*models.StockQuotesResponse, error)
Packed sends the StockQuoteRequest and returns the StockQuotesResponse. An optional MarketDataClient can be passed to replace the client used in the request. Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If a client is provided, it replaces the current client for this request.
Returns:
- *models.StockQuotesResponse: A pointer to the StockQuotesResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (StockQuoteRequest) Raw ¶
func (request StockQuoteRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
func (*StockQuoteRequest) Symbol ¶
func (sqr *StockQuoteRequest) Symbol(q string) *StockQuoteRequest
Symbol sets the symbol parameter for the StockQuoteRequest. This method is used to specify the stock symbol for which quote data is requested.
Parameters:
- q: A string representing the stock symbol to be set.
Returns:
- *StockQuoteRequest: This method returns a pointer to the StockQuoteRequest instance it was called on. This allows for method chaining.
type TickersRequest ¶
type TickersRequest struct {
// contains filtered or unexported fields
}
TickersRequest represents a request to the /stocks/tickers endpoint. It encapsulates the date parameter to be used in the request. This struct provides the method DateKey() to set this parameter.
Public Methods:
- DateKey(q string) *TickersRequest: Sets the date parameter for the TickersRequest.
func StockTickers ¶
func StockTickers(client ...*MarketDataClient) *TickersRequest
StockTickers creates a new TickersRequest and associates it with the provided client. If no client is provided, it uses the default client. This function initializes the request with the default date parameter and sets the request path based on the predefined endpoints for stock tickers.
Parameters:
- client: A variadic parameter that can accept zero or one MarketDataClient pointer. If no client is provided, the default client is used.
Returns:
- *TickersRequest: A pointer to the newly created TickersRequest with default parameters and associated client.
func (*TickersRequest) DateKey ¶
func (tr *TickersRequest) DateKey(q string) *TickersRequest
DateKey sets the date parameter for the TickersRequest. This method is used to specify the date for which the stock tickers data is requested.
Parameters:
- q: A string representing the date to be set.
Returns:
- *TickersRequest: This method returns a pointer to the TickersRequest instance it was called on. This allows for method chaining.
func (*TickersRequest) Get ¶
func (tr *TickersRequest) Get() ([]models.Ticker, error)
Get sends the TickersRequest, unpacks the TickersResponse, and returns a slice of Ticker. It returns an error if the request or unpacking fails. This method is crucial for obtaining the actual stock tickers data from the stock tickers request. The method first checks if the TickersRequest receiver is nil, which would result in an error as the request cannot be sent. It then proceeds to send the request using the Packed method. Upon receiving the response, it unpacks the data into a slice of Ticker using the Unpack method from the response.
Returns:
- []models.Ticker: A slice of Ticker containing the unpacked tickers data from the response.
- error: An error object that indicates a failure in sending the request or unpacking the response.
func (*TickersRequest) Packed ¶
func (tr *TickersRequest) Packed() (*models.TickersResponse, error)
Packed sends the TickersRequest and returns the TickersResponse. This method checks if the TickersRequest receiver is nil, returning an error if true. Otherwise, it proceeds to send the request and returns the TickersResponse along with any error encountered during the request.
Returns:
- *models.TickersResponse: A pointer to the TickersResponse obtained from the request.
- error: An error object that indicates a failure in sending the request.
func (TickersRequest) Raw ¶
func (request TickersRequest) Raw(optionalClients ...*MarketDataClient) (*resty.Response, error)
Raw executes the request and returns the raw resty.Response. This method allows for an optional MarketDataClient to be passed which, if provided, replaces the client used in the request.
Parameters:
- optionalClients: A variadic parameter that can accept zero or one MarketDataClient pointer. If provided, the first MarketDataClient in the slice replaces the current client for this request.
Returns:
- *resty.Response: The raw response from the executed request.
- error: An error object if the baseRequest is nil, the MarketDataClient is nil, or if an error occurs during the request execution.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
helpers
|
|
dates
Package dates provides utilities for parsing, formatting, and manipulating dates and times.
|
Package dates provides utilities for parsing, formatting, and manipulating dates and times. |
parameters
Package parameters defines structures and functions for handling request parameters across various API endpoints.
|
Package parameters defines structures and functions for handling request parameters across various API endpoints. |
types
Package types provides utility functions for checking the type and value of variables.
|
Package types provides utility functions for checking the type and value of variables. |
Package models defines the data structures used to represent the responses from the Market Data API.
|
Package models defines the data structures used to represent the responses from the Market Data API. |