Status
Retrieve current, future, and historical open / closed status information.
Making Requests
Utilize MarketStatusRequest to make requests to the endpoint through one of the three supported execution methods:
Method | Execution | Return Type | Description |
---|---|---|---|
Get | Direct | []MarketStatusReport | Directly returns a slice of []MarketStatusReport , facilitating individual access to each market status entry. |
Packed | Intermediate | *MarketStatusResponse | Returns a packed *MarketStatusResponse object. Must be unpacked to access the []MarketStatusReport slice. |
Raw | Low-level | *resty.Response | Offers the raw *resty.Response for utmost flexibility. Direct access to raw JSON or *http.Response . |
MarketStatusRequest
type MarketStatusRequest struct {
// contains filtered or unexported fields
}
MarketStatusRequest represents a request to the /v1/markets/status/ endpoint for market status information. It encapsulates parameters for country, 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.
Generated By
-
MarketStatus() *MarketStatusRequest
MarketStatus creates a new *MarketStatusRequest and returns a pointer to the request allowing for method chaining.
Setter Methods
-
Country(string) *MarketStatusRequest
Sets the country parameter for the request.
-
Date(interface{}) *MarketStatusRequest
Sets the date parameter for the request.
-
From(interface{}) *MarketStatusRequest
Sets the 'from' date parameter for the request.
-
To(interface{}) *MarketStatusRequest
Sets the 'to' date parameter for the request.
-
Countback(int) *MarketStatusRequest
Sets the countback parameter for the request.
Execution Methods
These methods are used to send the request in different formats or retrieve the data. They handle the actual communication with the API endpoint.
-
Get() ([]MarketStatusReport, error)
Sends the request, unpacks the response, and returns the data in a user-friendly format.
-
Packed() (*MarketStatusResponse, error)
Returns a struct that contains equal-length slices of primitives. This packed response mirrors Market Data's JSON response.
-
Raw() (*resty.Response, error)
Sends the request as is and returns the raw HTTP response.
MarketStatus
func MarketStatus() *MarketStatusRequest
MarketStatus creates a new MarketStatusRequest. 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.
Returns
-
*MarketStatusRequest
A pointer to the newly created *MarketStatusRequest with default parameters.
- Example (Get)
- Example (Packed)
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, Open: false, Closed: true}
MarketStatusReport{Date: 2022-01-02, Open: false, Closed: true}
MarketStatusReport{Date: 2022-01-03, Open: true, Closed: false}
MarketStatusReport{Date: 2022-01-04, Open: true, Closed: false}
MarketStatusReport{Date: 2022-01-05, Open: true, Closed: false}
MarketStatusReport{Date: 2022-01-06, Open: true, Closed: false}
MarketStatusReport{Date: 2022-01-07, Open: true, Closed: false}
MarketStatusReport{Date: 2022-01-08, Open: false, Closed: true}
MarketStatusReport{Date: 2022-01-09, Open: false, Closed: true}
MarketStatusReport{Date: 2022-01-10, Open: true, Closed: false}
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"]}
Output
MarketStatusResponse{Date: [1641013200, 1641099600, 1641186000, 1641272400, 1641358800, 1641445200, 1641531600, 1641618000, 1641704400, 1641790800], Status: ["closed", "closed", "open", "open", "open", "open", "open", "closed", "closed", "open"]}
MarketStatusRequest Setter Methods
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
-
int
The number of days to return before `to`.
Returns
-
*MarketStatusRequest
A pointer to the MarketStatusRequest instance to allow for method chaining.
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.
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
-
interface{}
An interface{} that represents the starting date. It can be a string, a time.Time object, a Unix timestamp or any other type that the underlying dates package can process.
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.
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
-
interface{}
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.
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
-
interface{}
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.
MarketStatusRequest Execution Methods
Get
func (msr *MarketStatusRequest) Get() ([]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.
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.
Packed
func (msr *MarketStatusRequest) Packed() (*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. It proceeds to send the request and returns the MarketStatusResponse along with any error encountered during the 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.
Raw
func (msr *MarketStatusRequest) Raw() (*resty.Response, error)
Raw executes the MarketStatusRequest and returns the raw *resty.Response. The *resty.Response can be directly used to access the raw JSON or *http.Response for further processing.
Returns
-
*resty.Response
The raw HTTP response from the executed MarketStatusRequest.
-
error
An error object if the MarketStatusRequest is nil or if an error occurs during the request execution.
MarketStatusResponse
type MarketStatusResponse struct {
Date []int64 `json:"date"` // Date contains UNIX timestamps for each market status entry.
Status []string `json:"status"` // Status is a pointer to a slice of market status strings, which can be omitted if empty.
}
MarketStatusResponse encapsulates the response data for market status queries, including dates and optionally, the corresponding market statuses.
Generated By
-
MarketStatusRequest.Get()
Generates a MarketStatusResponse containing market status information for requested dates.
Methods
-
String()
Returns a string representation of the MarketStatusResponse.
GetClosedDates
func (msr *MarketStatusResponse) GetClosedDates() ([]time.Time, error)
GetClosedDates identifies and returns all dates when the market was reported as closed. This method is useful for analyzing market activity over a period, allowing users to focus on days when trading was not possible.
Returns
-
[]time.Time
A slice of time.Time objects, each representing a date when the market was closed.
-
error
An error object indicating issues encountered while unpacking the MarketStatusResponse.
Notes
- This method relies on the Unpack function to interpret the MarketStatusResponse. Any errors in unpacking will be propagated.
GetDateRange
func (msr *MarketStatusResponse) GetDateRange() (*dates.DateRange, error)
GetDateRange calculates and returns the date range covered by the MarketStatusResponse. This method is primarily used when a user needs to determine the span of dates over which market status data is available, allowing for analysis of market trends within a specific timeframe.
Returns
-
*dates.DateRange
A pointer to a DateRange object encapsulating the earliest and latest dates found in the MarketStatusResponse.
-
error
An error object if there's an issue identifying the earliest or latest date within the MarketStatusResponse.
Notes
- This method relies on the dates.Earliest and dates.Latest functions to compute the date range. Any errors encountered by these functions will be returned to the caller.
GetOpenDates
func (msr *MarketStatusResponse) GetOpenDates() ([]time.Time, error)
Returns
-
[]time.Time
A slice of time.Time objects, each representing a date when the market was open.
-
error
An error object indicating issues encountered while unpacking the MarketStatusResponse.
Notes
- This method relies on the Unpack function to interpret the MarketStatusResponse. Any errors in unpacking will be propagated.
IsValid
func (msr *MarketStatusResponse) IsValid() bool
IsValid determines whether the MarketStatusResponse instance has at least one date entry. This method is primarily used to verify that the response is not empty, indicating that there is market status data available for processing.
Returns
-
bool
Indicates whether there is at least one date entry in the MarketStatusResponse. True if at least one date is present, false otherwise.
String
func (msr *MarketStatusResponse) String() string
String provides a formatted string representation of the MarketStatusResponse instance. This method is primarily used for logging or debugging purposes, allowing the user to easily view the contents of a MarketStatusResponse object in a human-readable format. It concatenates the dates and their corresponding statuses into a single string.
Returns
-
string
A formatted string containing the dates and their corresponding statuses.
Unpack
func (msr *MarketStatusResponse) Unpack() ([]MarketStatusReport, error)
Unpack transforms the MarketStatusResponse into a slice of MarketStatusReport, facilitating the analysis or processing of market status data in a structured format. This method is particularly useful when there's a need to iterate over market statuses, perform conditional checks, or when preparing the data for display. It ensures that each market status entry is paired with its corresponding date, converting UNIX timestamps to time.Time objects and mapping status strings to boolean open/closed indicators.
Returns
-
[]MarketStatusReport
A slice of MarketStatusReport, each representing a market status entry with its date and open/closed status.
-
error
An error indicating issues with data consistency, such as mismatched slice lengths, or any other processing error.
Notes
- The method assumes that the lengths of the Date and Status slices in the MarketStatusResponse are equal. An error is returned if this is not the case.
MarketStatusReport
type MarketStatusReport struct {
Date time.Time `json:"date"`
Open bool `json:"open"`
Closed bool `json:"closed"`
}
MarketStatusReport encapsulates the operational status of a market on a specific date.
Generated By
-
MarketStatusResponse.Unpack()
Generates a slice of []MarketStatusReport instances from a MarketStatusResponse.
Methods
-
String() string
Provides a string representation of the MarketStatusReport.
Notes
- This struct is used to convey whether a market is open or closed on a particular date.
- The 'Open' and 'Closed' fields are mutually exclusive.
String
func (ms MarketStatusReport) String() string
String returns a string representation of the MarketStatusReport.
Returns
-
string
A string representation of the MarketStatusReport.