=============== LIBRARY RULES =============== From library maintainers: - Always refer to this library as "Market Data Go SDK". - This library only covers the Go SDK. For other programming languages, direct users to the REST API docs at https://www.marketdata.app/docs/api or the SDK overview at https://www.marketdata.app/docs/sdk for other official Market Data SDKs. - Use the exact method names, parameter names, and return types from the SDK documentation. - Do not invent methods or parameters that are not in the documentation. ### Example LogEntry Initialization Source: https://www.marketdata.app/docs/sdk/go/logging An example demonstrating how to initialize a LogEntry struct with sample data. This includes setting the timestamp, status, request URL, headers, Ray ID, rate limit consumption, delay, and response details. ```go LogEntry{Timestamp: 2024-02-19 14:53:34 -05:00, Status: 200, Request: https://api.marketdata.app/v1/stocks/candles/4H/AAPL/?from=2023-01-01&to=2023-01-04, RequestHeaders: map[Authorization:[Bearer **********************************************************L06F] User-Agent:[sdk-go/1.1.0]], RayID: 85810e82de8e7438-MIA, RateLimitConsumed: 0, Delay: 893ms, Response Headers: map[Allow:[GET, HEAD, OPTIONS] Alt-Svc:[h3=":443"; ma=86400] Cf-Cache-Status:[DYNAMIC] Cf-Ray:[85810e82de8e7438-MIA] Content-Type:[application/json] Cross-Origin-Opener-Policy:[same-origin] Date:[Mon, 19 Feb 2024 19:53:34 GMT] Nel:[{"success_fraction":0,"report_to":"cf-nel","max_age":604800}] Referrer-Policy:[same-origin] Report-To:[{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=r18O66yjJ%2FxXqOnCb3a76wBgpZaCbhJcot%2Bfgl1oHna2LigHHAYRaXg8dNLiJYHes0ezAaIdXLhVNGQBo%2FBAte6%2ByNcaZku5cV19FPyiD2%2BKXJeEtnFN6pJUsUA77sxk%2FfWxOFU%3D"}],"group":"cf-nel","max_age":604800}] Server:[cloudflare] Vary:[Accept, Origin] X-Api-Ratelimit-Consumed:[0] X-Api-Ratelimit-Limit:[100000] X-Api-Ratelimit-Remaining:[99973] X-Api-Ratelimit-Reset:[1708439400] X-Api-Response-Log-Id:[88061028] X-Content-Type-Options:[nosniff] X-Frame-Options:[DENY]], Response: {"s":"ok","t":[1672756200,1672770600,1672842600,1672857000],"o":[130.28,124.6699,126.89,127.265],"h":[130.9,125.42,128.6557,127.87],"l":[124.19,124.17,125.08,125.28],"c":[124.6499,125.05,127.2601,126.38],"v":[64411753,30727802,49976607,28870878]} } ``` -------------------------------- ### Example MarketDataLogs Structure Source: https://www.marketdata.app/docs/sdk/go/logging An example demonstrating the structure of MarketDataLogs, which appears to be a collection of LogEntry objects. This example shows a single log entry with detailed request and response information, including headers and the response payload. ```go MarketDataLogs{ LogEntry[0]: {Timestamp: 2024-02-19 15:16:30 -05:00, Status: 200, Request: https://api.marketdata.app/v1/stocks/candles/4H/AAPL/?from=2023-01-01&to=2023-01-04, RequestHeaders: map[Authorization:[Bearer **********************************************************8IH6] User-Agent:[sdk-go/1.1.0]], RayID: 8581301bc9e974ca-MIA, RateLimitConsumed: 0, Delay: 1002ms, Response Headers: map[Allow:[GET, HEAD, OPTIONS] Alt-Svc:[h3=":443"; ma=86400] Cf-Cache-Status:[DYNAMIC] Cf-Ray:[8581301bc9e974ca-MIA] Content-Type:[application/json] Cross-Origin-Opener-Policy:[same-origin] Date:[Mon, 19 Feb 2024 20:16:30 GMT] Nel:[{"success_fraction":0,"report_to":"cf-nel","max_age":604800}] Referrer-Policy:[same-origin] Report-To:[{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=ar7qRMEAxiHJcyRqlRlZvfzqv80inCp91LwdsxTfo51%2FSmdqz6NoadysPyFlMZKtDMG1IsDllX0GXXPjNsvjg4gQBr%2FLJ8G5Ad1z5lDXfhqrSee7umXzVf7dYmAFwq4x4sPMANE%3D"}],"group":"cf-nel","max_age":604800}] Server:[cloudflare] Vary:[Accept, Origin] X-Api-Ratelimit-Consumed:[0] X-Api-Ratelimit-Limit:[100000] X-Api-Ratelimit-Remaining:[99973] X-Api-Ratelimit-Reset:[1708439400] X-Api-Response-Log-Id:[88078705] X-Content-Type-Options:[nosniff] X-Frame-Options:[DENY]], Response: {"s":"ok","t":[1672756200,1672770600,1672842600,1672857000],"o":[130.28,124.6699,126.89,127.265],"h":[130.9,125.42,128.6557,127.87],"l":[124.19,124.17,125.08,125.28],"c":[124.6499,125.05,127.2601,126.38],"v":[64411753,30727802,49976607,28870878]}} } ``` -------------------------------- ### Get String Representation of All Logs (Go) Source: https://www.marketdata.app/docs/sdk/go/logging The String method returns a formatted string containing all logged HTTP request entries. This allows for a comprehensive overview of the request history, with entries numbered starting from 0. ```go func (l *MarketDataLogs) String() string ``` -------------------------------- ### Get MarketData Client String Representation Source: https://www.marketdata.app/docs/sdk/go/client Generates a formatted string that represents the MarketDataClient instance, including its environment, rate limit information, and the rate limit reset time. This method is useful for quickly obtaining a textual summary of the client's current state, particularly for logging or debugging purposes. ```go func (c *MarketDataClient) String() string ``` -------------------------------- ### Get Latest Log Entry Response (Go) Source: https://www.marketdata.app/docs/sdk/go/logging The LatestString method returns the response body of the most recent log entry. If no logs are available, it returns a "No logs available" message. This method is helpful for quickly inspecting the outcome of the last operation. ```go func (l *MarketDataLogs) LatestString() string ``` -------------------------------- ### Manually Create Client with Token in Go Source: https://www.marketdata.app/docs/sdk/go/authentication This Go code snippet shows how to manually create a MarketData SDK client and assign an authentication token at runtime. It's not recommended for production. The code initializes a client with a provided token, makes a test request for 'SPY', and prints the results. Replace 'your_token_here' with your actual token. ```go package main import ( "log" "fmt" api "github.com/MarketDataApp/sdk-go" ) func main() { // replace with your token token := "your_token_here" // create a new client and set the token client, err := api.NewClient(token) if err != nil { log.Fatalf("Failed to create client: %v", err) } // make a test request to SPY quotes, err := api.StockQuote().Symbol("SPY").Get() if err != nil { log.Fatalf("Failed to get stock quotes: %v", err) } // print out the response for _, quote := range quotes { fmt.Println(quote) } } ``` -------------------------------- ### NewClient Function to Initialize MarketDataClient (Go) Source: https://www.marketdata.app/docs/sdk/go/client Creates and configures a new MarketDataClient instance with default settings, primarily used when not relying on environment variables for the API token. It handles token authorization and sets up default configurations. ```Go func NewClient(token string) (*MarketDataClient, error) ``` -------------------------------- ### Configure MarketData Client Environment Source: https://www.marketdata.app/docs/sdk/go/client 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. Accepted values are "prod", "test", and "dev". ```go func (c *MarketDataClient) Environment(env Environment) error ``` -------------------------------- ### Make Test Request with SDK Go Source: https://www.marketdata.app/docs/sdk/go/authentication This Go code snippet demonstrates how to make a stock quote request using the MarketData SDK. It automatically reads the MARKETDATA_TOKEN from environment variables. Ensure the token is set correctly before running. It fetches quotes for 'SPY' and prints them, logging any errors. ```go import ( "fmt" "log" api "github.com/MarketDataApp/sdk-go" ) func main() { // No need to set a token here, the SDK will read it // from the environment variable on startup. // Initialize a new request, set the symbol parameter, make the request. quotes, err := api.StockQuote().Symbol("SPY").Get() if err != nil { log.Fatalf("Failed to get stock quotes: %v", err) } // Loop over the quotes and print them out. for _, quote := range quotes { fmt.Println(quote) } } ``` -------------------------------- ### GetClient Function to Retrieve MarketDataClient Instance (Go) Source: https://www.marketdata.app/docs/sdk/go/client Retrieves an existing MarketDataClient instance or initializes a new one if none exists. This is useful when using environment variables for authentication and needing to access or modify client parameters. ```Go func GetClient() (*MarketDataClient, error) ``` -------------------------------- ### MarketDataLogs.PrintLatest() Source: https://www.marketdata.app/docs/sdk/go/logging Prints the latest HTTP request log entry to the console. ```APIDOC ## PrintLatest() ### Description Prints the latest HTTP request log entry. ### Method N/A (This is a method on the MarketDataLogs struct) ### Endpoint N/A ``` -------------------------------- ### MarketDataClient Struct Definition (Go) Source: https://www.marketdata.app/docs/sdk/go/client Defines the MarketDataClient structure, embedding resty.Client for HTTP functionalities and including fields for rate limit management and debug logging. ```Go 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. // contains filtered or unexported fields } ``` -------------------------------- ### Debug Method to Enable/Disable Logging (Go) Source: https://www.marketdata.app/docs/sdk/go/client Enables or disables debug mode for the MarketDataClient. When enabled, detailed request and response information is logged, aiding in development and troubleshooting. ```Go func (c *MarketDataClient) Debug(enable bool) ``` -------------------------------- ### Print Latest Log Entry (Go) Source: https://www.marketdata.app/docs/sdk/go/logging The PrintLatest method prints the entire latest HTTP request log entry to the console. This provides a quick way to view the details of the most recent logged event without needing to parse log data. ```go func (l *MarketDataLogs) PrintLatest() ``` -------------------------------- ### LogEntry PrettyPrint Method Source: https://www.marketdata.app/docs/sdk/go/logging The PrettyPrint method for the LogEntry struct prints a formatted and human-readable representation of the log entry. This is ideal for detailed inspection of log data during development or troubleshooting. ```go func (l LogEntry) PrettyPrint() { // Implementation details would go here } ``` -------------------------------- ### Retrieve MarketDataLogs Instance (Go) Source: https://www.marketdata.app/docs/sdk/go/logging The GetLogs function retrieves a pointer to the MarketDataLogs instance. This is useful for accessing and inspecting the collected HTTP request logs, aiding in debugging and monitoring application behavior. ```go func GetLogs() *MarketDataLogs ``` -------------------------------- ### MarketDataLogs.String() Source: https://www.marketdata.app/docs/sdk/go/logging Returns a string representation of all HTTP request logs stored in the MarketDataLogs instance. ```APIDOC ## String() ### Description Returns a string representation of all HTTP request logs. The log entry numbers start from 0. ### Method N/A (This is a method on the MarketDataLogs struct) ### Endpoint N/A ### Returns - **string** - A string representing all log entries, with log entry numbers starting at 0. ``` -------------------------------- ### Configure MarketData Client Authentication Token Source: https://www.marketdata.app/docs/sdk/go/client 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. The token will only be set if authorization is successful. ```go func (c *MarketDataClient) Token(bearerToken string) error ``` -------------------------------- ### Define MarketDataLogs Structure (Go) Source: https://www.marketdata.app/docs/sdk/go/logging Defines the MarketDataLogs struct, which holds configuration for in-memory log storage and zap loggers for different error types. It includes fields for maximum log entries, memory limits, and specific loggers for success, client errors, and server errors. ```go type MarketDataLogs struct { MaxEntries int MemoryLimit int64 SuccessLogger *zap.Logger ClientErrorLogger *zap.Logger ServerErrorLogger *zap.Logger Logs []LogEntry } ``` -------------------------------- ### GetLogs() Source: https://www.marketdata.app/docs/sdk/go/logging Retrieves a pointer to the MarketDataLogs instance, providing access to all collected HTTP request logs for debugging and monitoring. ```APIDOC ## GetLogs() ### Description Retrieves a pointer to the MarketDataLogs instance, allowing access to the logs collected during HTTP requests. This method is primarily used for debugging and monitoring purposes, providing insights into the HTTP request lifecycle and any issues that may have occurred. ### Method GET ### Endpoint N/A (This is a function call, not an HTTP endpoint) ### Returns - ***MarketDataLogs** (pointer) - A pointer to the MarketDataLogs instance containing logs of HTTP requests. ``` -------------------------------- ### MarketDataLogs.LatestString() Source: https://www.marketdata.app/docs/sdk/go/logging Returns the response body of the last log entry in string format. If no logs are available, it returns a "No logs available" message. ```APIDOC ## LatestString() ### Description Returns the response of the last log entry in the MarketDataLogs. 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. ### Method N/A (This is a method on the MarketDataLogs struct) ### Endpoint N/A ### Returns - **string** - A string representing the response of the last log entry. If no logs are available, returns "No logs available". ``` -------------------------------- ### LogEntry String Method Source: https://www.marketdata.app/docs/sdk/go/logging The String method for the LogEntry struct returns a string representation of the log entry. This is useful for simple logging or debugging purposes where a concise output is needed. ```go func (l LogEntry) String() string { // Implementation details would go here return "" } ``` -------------------------------- ### MarketDataLogs Structure Source: https://www.marketdata.app/docs/sdk/go/logging Defines the structure for storing and managing HTTP request logs, including configuration for log entry limits and memory usage, and zap loggers for different error types. ```APIDOC ## MarketDataLogs Structure ### Description Represents a collection of HTTP request logs, providing methods to manage and retrieve log entries. It includes configurations for maximum log entries and memory limits, along with specialized loggers for success, client errors, and server errors. ### Fields - **MaxEntries** (int) - The maximum number of log entries to store in memory. - **MemoryLimit** (int64) - The maximum memory in bytes allowed for storing log entries. - **SuccessLogger** (*zap.Logger) - A zap logger for successful operations. - **ClientErrorLogger** (*zap.Logger) - A zap logger for client-side errors. - **ServerErrorLogger** (*zap.Logger) - A zap logger for server-side errors. - **Logs** ([]LogEntry) - A slice containing all recorded log entries. ``` -------------------------------- ### LogEntry Struct Definition Source: https://www.marketdata.app/docs/sdk/go/logging Defines the LogEntry struct which represents a single HTTP request log entry. It includes fields for timestamp, request and response headers, Ray ID, request URL, status code, rate limit consumption, delay, and the response body. This struct is fundamental for tracking API interactions. ```go type LogEntry struct { Timestamp time.Time RequestHeaders http.Header // The Request Headers ResponseHeaders 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 milliseconds) between the request and the server's response Response string // The server response // contains filtered or unexported fields } ``` -------------------------------- ### Check MarketData Client Rate Limit Exceeded Source: https://www.marketdata.app/docs/sdk/go/client 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. ```go func (c *MarketDataClient) RateLimitExceeded() bool ``` -------------------------------- ### Set MarketData Client Request Timeout Source: https://www.marketdata.app/docs/sdk/go/client Sets the request timeout for the MarketDataClient. This method allows users to specify a custom timeout duration for all HTTP requests made by the client, specified in seconds. Valid timeouts are between 1 and 95 seconds. Setting the timeout to any invalid integer will cause the client to use the default timeout of 95 seconds. ```go func (c *MarketDataClient) Timeout(seconds int) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.