---
title: Bulk Candles
sidebar_position: 2
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";





Get bulk historical price data for many stock symbols at once or even obtain a full market snapshot.

## Making Requests

Utilize the [BulkStockCandlesRequest](<#BulkStockCandlesRequest>) for querying the endpoint through one of the three available methods:

| Method     | Execution       | Return Type                 | Description                                                                                                             |
|------------|-----------------|-----------------------------|-------------------------------------------------------------------------------------------------------------------------|
| **Get**    | Direct          | `[]Candle`                  | Immediately fetches and returns a slice of `[]Candle`, allowing direct access to each candle's data.                    |
| **Packed** | Intermediate    | `*BulkStockCandlesResponse` | Delivers a `*StockCandlesResponse` object containing the data, which requires unpacking to access the `[]Candle` slice. |
| **Raw**    | Low-level       | `*resty.Response`           | Offers the unprocessed `*resty.Response` for those seeking full control and access to the raw JSON or `*http.Response`. |


<a name="BulkStockCandlesRequest"></a>
## BulkStockCandlesRequest

```go
type BulkStockCandlesRequest struct {
    // contains filtered or unexported fields
}
```

BulkStockCandlesRequest represents a request to the [/v1/stocks/bulkcandles/](<https://www.marketdata.app/docs/api/stocks/bulkcandles>) 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.

#### Generated By

- <a href="#BulkStockCandles">`BulkStockCandles() *BulkStockCandlesRequest`</a>

  BulkStockCandles creates a new \*BulkStockCandlesRequest and returns a pointer to the request allowing for method chaining.


#### Setter Methods

- <a href="#BulkStockCandlesRequest.Resolution">`Resolution(string) *BulkStockCandlesRequest`</a>

  Sets the resolution parameter for the request.

- <a href="#BulkStockCandlesRequest.Symbol">`Symbol(string) *BulkStockCandlesRequest`</a>

  Sets the symbol parameter for the request.

- <a href="#BulkStockCandlesRequest.Date">`Date(interface{}) *BulkStockCandlesRequest`</a>

  Sets the date parameter for the request.

- <a href="#BulkStockCandlesRequest.AdjustSplits">`AdjustSplits(bool) *BulkStockCandlesRequest`</a>

  Sets the adjust splits parameter for the request.

- <a href="#BulkStockCandlesRequest.AdjustDividends">`AdjustDividends(bool) *BulkStockCandlesRequest`</a>

  Sets the adjust dividends parameter for the request.

- <a href="#BulkStockCandlesRequest.Extended">`Extended(bool) *BulkStockCandlesRequest`</a>

  Sets the extended hours data parameter for the request.

- <a href="#BulkStockCandlesRequest.Exchange">`Exchange(string) *BulkStockCandlesRequest`</a>

  Sets the exchange 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.

- <a href="#BulkStockCandlesRequest.Get">`Get() ([]Candle, error)`</a>

  Sends the request, unpacks the response, and returns the data in a user\-friendly format.

- <a href="#BulkStockCandlesRequest.Packed">`Packed() (*BulkStockCandlesResponse, error)`</a>

  Returns a struct that contains equal\-length slices of primitives. This packed response mirrors Market Data's JSON response.

- <a href="#BulkStockCandlesRequest.Raw">`Raw() (*resty.Response, error)`</a>

  Sends the request as is and returns the raw HTTP response.




<Tabs>
<TabItem value="Example (Get)" label="Example (Get)">




```go
symbols := []string{"AAPL", "META", "MSFT"}
bscr, err := BulkStockCandles().Resolution("D").Symbols(symbols).Date("2024-02-06").Get()
if err != nil {
	fmt.Print(err)
	return
}
for _, candle := range bscr {
	fmt.Println(candle)
}
```

#### Output

```
Candle{Symbol: AAPL, Date: 2024-02-06, Open: 186.86, High: 189.31, Low: 186.7695, Close: 189.3, Volume: 43490759}
Candle{Symbol: META, Date: 2024-02-06, Open: 464, High: 467.12, Low: 453, Close: 454.72, Volume: 21653114}
Candle{Symbol: MSFT, Date: 2024-02-06, Open: 405.88, High: 407.97, Low: 402.91, Close: 405.49, Volume: 18382624}
```

</TabItem>

<TabItem value="Example (Packed)" label="Example (Packed)">




```go
symbols := []string{"AAPL", "META", "MSFT"}
bscr, err := BulkStockCandles().Resolution("D").Symbols(symbols).Date("2024-02-06").Packed()
if err != nil {
	fmt.Print(err)
	return
}
fmt.Println(bscr)
```

#### Output

```
BulkStockCandlesResponse{Symbol: [AAPL META MSFT], Date: [1707195600 1707195600 1707195600], Open: [186.86 464 405.88], High: [189.31 467.12 407.97], Low: [186.7695 453 402.91], Close: [189.3 454.72 405.49], Volume: [43490759 21653114 18382624]}
```

</TabItem>

<TabItem value="Example (Raw)" label="Example (Raw)">




```go
symbols := []string{"AAPL", "META", "MSFT"}
bscr, err := BulkStockCandles().Resolution("D").Symbols(symbols).Date("2024-02-06").Raw()
if err != nil {
	fmt.Print(err)
	return
}
fmt.Println(bscr)
```

#### Output

```
{"s":"ok","symbol":["AAPL","META","MSFT"],"o":[186.86,464.0,405.88],"h":[189.31,467.12,407.97],"l":[186.7695,453.0,402.91],"c":[189.3,454.72,405.49],"v":[43490759,21653114,18382624],"t":[1707195600,1707195600,1707195600]}
```

</TabItem>
</Tabs>

<a name="BulkStockCandles"></a>
### BulkStockCandles

```go
func BulkStockCandles(client ...*MarketDataClient) *BulkStockCandlesRequest
```

BulkStockCandles initializes a new BulkStockCandlesRequest with default parameters. This function prepares a request to fetch bulk stock candles data. It sets up all necessary parameters and configurations to make the request ready to be sent. The function accepts a variadic parameter that allows passing an optional MarketDataClient. If a client is provided, it will be used for the request; otherwise, a default client is initialized and used.

#### Parameters

- `...*MarketDataClient`

  A variadic parameter that can accept zero or one MarketDataClient pointer. This allows for the optional customization of the client used for the request. If no client is provided, a default client is initialized and used.


#### Returns

- `*BulkStockCandlesRequest`

  A pointer to the newly created BulkStockCandlesRequest instance. This instance contains all the necessary parameters set to their default values and is ready to have additional parameters set or to be sent.

## BulkStockCandlesRequest Setter Methods

<a name="BulkStockCandlesRequest.AdjustSplits"></a>
### AdjustSplits

```go
func (bscr *BulkStockCandlesRequest) AdjustSplits(q bool) *BulkStockCandlesRequest
```

AdjustSplits sets the adjust splits parameter for the BulkStockCandlesRequest. This method indicates whether the returned data should be adjusted for stock splits.

#### Parameters

- `bool`

  Whether to adjust for splits.


#### Returns

- `*BulkStockCandlesRequest`

  This method returns a pointer to the \*BulkStockCandlesRequest instance it was called on. This allows for method chaining.


<a name="BulkStockCandlesRequest.Date"></a>
### Date

```go
func (bscr *BulkStockCandlesRequest) Date(q interface{}) *BulkStockCandlesRequest
```

Date sets the date parameter for the BulkStockCandlesRequest. This method is used to specify the date for which the stock candle data is requested.

#### Parameters

- `interface{}`

  An interface\{\} representing the date to be set. It can be a string, a time.Time object, a Unix timestamp as an int, or any other type that the underlying dates package method can process.


#### Returns

- `*BulkStockCandlesRequest`

  This method returns a pointer to the \*BulkStockCandlesRequest instance it was called on. This allows for method chaining.


<a name="BulkStockCandlesRequest.Resolution"></a>
### Resolution

```go
func (cr *BulkStockCandlesRequest) Resolution(q string) *BulkStockCandlesRequest
```

Resolution sets the resolution parameter for the BulkStockCandlesRequest. This method is used to specify the granularity of the candle data to be retrieved.

#### Parameters

- `string`

  The resolution to be set.


#### Returns

- `*BulkStockCandlesRequest`

  This method returns a pointer to the \*BulkStockCandlesRequest instance it was called on. This allows for method chaining.


<a name="BulkStockCandlesRequest.Snapshot"></a>
### Snapshot

```go
func (bscr *BulkStockCandlesRequest) Snapshot(q bool) *BulkStockCandlesRequest
```

Snapshot sets the snapshot parameter for the BulkStockCandlesRequest. This method is used to enable or disable the snapshot feature in the request and will result in all available tickers being returned in the response.

#### Parameters

- `bool`

  A boolean value representing whether to enable or disable the snapshot feature.


#### Returns

- `*BulkStockCandlesRequest`

  This method returns a pointer to the \*BulkStockCandlesRequest instance it was called on. This allows for method chaining.


<a name="BulkStockCandlesRequest.Symbols"></a>
### Symbols

```go
func (cr *BulkStockCandlesRequest) Symbols(q []string) *BulkStockCandlesRequest
```

Symbols sets the symbols parameter for the BulkStockCandlesRequest. This method is used to specify multiple stock symbols for which candle data is requested.

#### Parameters

- `[]string`

  A slice of \[\]string representing the stock symbols to be set.


#### Returns

- `*BulkStockCandlesRequest`

  This method returns a pointer to the \*BulkStockCandlesRequest instance it was called on. This allows for method chaining.



## BulkStockCandlesRequest Execution Methods
<a name="BulkStockCandlesRequest.Get"></a>
### Get

```go
func (bscr *BulkStockCandlesRequest) Get() ([]models.Candle, error)
```

Get sends the BulkStockCandlesRequest, unpacks the StockCandlesResponse, and returns a slice of \[\]Candle. It returns an error if the request or unpacking fails.

#### Returns

- `[]models.Candle`

  A slice of \[\]Candle containing the unpacked candle data from the response.

- `error`

  An error object that indicates a failure in sending the request or unpacking the response.



<a name="BulkStockCandlesRequest.Packed"></a>
### Packed

```go
func (bscr *BulkStockCandlesRequest) Packed() (*models.BulkStockCandlesResponse, error)
```

Packed sends the BulkStockCandlesRequest and returns the StockCandlesResponse.

#### Returns

- `*models.BulkStockCandlesResponse`

  A pointer to the BulkStockCandlesResponse obtained from the request.

- `error`

  An error object that indicates a failure in sending the request.


<a name="BulkStockCandlesRequest.Raw"></a>
### Raw

```go
func (bscr *BulkStockCandlesRequest) Raw() (*resty.Response, error)
```

Raw executes the request and returns the raw \*resty.Response. This method allows for obtaining the raw JSON or \*http.Response directly from the executed request.

#### Returns

- `*resty.Response`

  The raw response from the executed request.

- `error`

  An error object if the request is nil or if an error occurs during the request execution.



<a name="StockCandlesResponse"></a>
## StockCandlesResponse

```go
type StockCandlesResponse struct {
    Date   []int64    `json:"t"`              // Date holds UNIX timestamps for each candle.
    Open   []float64  `json:"o"`              // Open holds the opening prices for each candle.
    High   []float64  `json:"h"`              // High holds the highest prices reached in each candle.
    Low    []float64  `json:"l"`              // Low holds the lowest prices reached in each candle.
    Close  []float64  `json:"c"`              // Close holds the closing prices for each candle.
    Volume []int64    `json:"v"`              // Volume represents the trading volume in each candle.
    VWAP   *[]float64 `json:"vwap,omitempty"` // VWAP holds the Volume Weighted Average Price for each candle, optional.
    N      *[]int64   `json:"n,omitempty"`    // N holds the number of trades for each candle, optional.
}
```

StockCandlesResponse encapsulates the data structure for the JSON response of stock candles data. It includes detailed information about stock prices at different times, such as opening, closing, highest, and lowest prices, along with the trading volume. For version 2 candles, it optionally includes the Volume Weighted Average Price \(VWAP\) and the number of trades.

#### Generated By

- <a href="#StockCandlesRequest.Packed">`StockCandlesRequest.Packed()`</a>

  Sends a StockCandlesRequest and unmarshals the response into StockCandlesResponse.


#### Methods

- <a href="#StockCandlesResponse.Unpack">`Unpack() ([]Candle, error)`</a>

  Converts a StockCandlesResponse into a slice of Candle.

- <a href="#Candle.String">`String() string`</a>

  Returns a string representation of the StockCandlesResponse.

- <a href="#StockCandlesResponse.IsValid">`IsValid() bool`</a>

  Checks if a StockCandlesResponse is valid.

- <a href="#StockCandlesResponse.Validate">`Validate() error`</a>

  Validates a StockCandlesResponse.

- <a href="#Candle.MarshalJSON">`MarshalJSON() ([]byte, error)`</a>

  Marshals a StockCandlesResponse into JSON.

- <a href="#Candle.UnmarshalJSON">`UnmarshalJSON(data []byte) error`</a>

  Unmarshals JSON into a StockCandlesResponse.

- <a href="#StockCandlesResponse.GetDateRange">`GetDateRange() (dates.DateRange, error)`</a>

  Returns the date range of a StockCandlesResponse.

- <a href="#StockCandlesResponse.PruneOutsideDateRange">`PruneOutsideDateRange(dr dates.DateRange) error`</a>

  Removes data points outside a specified date range.


#### Notes

- The optional fields VWAP and N are only available for version 2 candles.
- The Date field uses UNIX timestamps to represent the date and time of each candle.



<a name="CombineStockCandles"></a>
### CombineStockCandles

```go
func CombineStockCandles(s1, s2 *StockCandlesResponse) (*StockCandlesResponse, error)
```

CombineStockCandles merges two StockCandlesResponse structs into a single one. It checks if the versions of the two structs are the same, ensures there is no time overlap between them, and then combines their data into a new StockCandlesResponse struct. If the versions are both V2, it also combines the VWAP and N slices. Finally, it validates the combined struct.

#### Parameters

- `*StockCandlesResponse`

  The first StockCandlesResponse struct to be combined.

- `*StockCandlesResponse`

  The second StockCandlesResponse struct to be combined.


#### Returns

- `*StockCandlesResponse`

  A pointer to the newly combined StockCandlesResponse struct.

- `error`

  An error if the versions do not match, there is a time overlap, or the combined struct fails validation.


<a name="StockCandlesResponse.GetDateRange"></a>
### GetDateRange

```go
func (s *StockCandlesResponse) GetDateRange() (dates.DateRange, error)
```

GetDateRange calculates and returns the date range covered by the StockCandlesResponse. This method is useful for determining the span of time that the stock candle data encompasses, allowing users to understand the temporal scope of the data they are working with.

#### Returns

- `dates.DateRange`

  The range of dates covered by the StockCandlesResponse.

- `error`

  An error if calculating the date range fails.


#### Notes

- This method is particularly useful when filtering data based on specific time frames.

<a name="StockCandlesResponse.IsValid"></a>
### IsValid

```go
func (s *StockCandlesResponse) IsValid() bool
```

IsValid determines the validity of a StockCandlesResponse. It is primarily used to ensure that the data within the response adheres to expected formats and logical constraints before further processing or analysis.

#### Returns

- `bool`

  Indicates whether the StockCandlesResponse is valid.


#### Notes

- This method should be used to prevent the propagation of invalid or corrupt data within applications that rely on stock candle information.

<a name="StockCandlesResponse.MarshalJSON"></a>
### MarshalJSON

```go
func (s *StockCandlesResponse) MarshalJSON() ([]byte, error)
```

MarshalJSON converts a StockCandlesResponse instance into its JSON representation. This method is primarily used for encoding the StockCandlesResponse into a JSON format that can be easily transmitted or stored. It organizes the stock candle data into a structured JSON format, ensuring compatibility with systems that consume JSON.

#### Returns

- `[]byte`

  The JSON\-encoded representation of the StockCandlesResponse.

- `error`

  An error object that will be non\-nil if the marshaling process encounters any issues.


<a name="StockCandlesResponse.PruneOutsideDateRange"></a>
### PruneOutsideDateRange

```go
func (s *StockCandlesResponse) PruneOutsideDateRange(dr dates.DateRange) error
```

PruneOutsideDateRange method is used to filter out data points from a StockCandlesResponse that fall outside a specified date range. This method is essential when the user needs to focus on analyzing stock candle data within a specific period, thereby excluding irrelevant data points that do not fall within the desired date range.

#### Parameters

- `dr dates.DateRange`

  A struct specifying the start and end dates for the range within which data points should be retained.


#### Returns

- `error`

  An error if pruning fails, otherwise nil.


#### Notes

- This method modifies the StockCandlesResponse in place, removing any data points that are outside the specified date range.

<a name="StockCandlesResponse.String"></a>
### String

```go
func (s *StockCandlesResponse) String() string
```

String generates a string representation of a StockCandlesResponse. This method is primarily used for logging or debugging purposes, allowing developers to easily view the contents of a StockCandlesResponse in a human\-readable format. It dynamically adjusts the output based on the presence of optional fields.

#### Returns

- `string`

  A string representation of the StockCandlesResponse.


#### Notes

- The output format may vary depending on the version of the struct and the presence of optional fields.

<a name="StockCandlesResponse.UnmarshalJSON"></a>
### UnmarshalJSON

```go
func (s *StockCandlesResponse) UnmarshalJSON(data []byte) error
```

UnmarshalJSON converts JSON data into a StockCandlesResponse instance. This method is essential for decoding JSON data received from external sources into a structured StockCandlesResponse object. It facilitates the easy consumption of JSON data by converting it into a more manageable Go struct. Additionally, it performs validation on the unmarshalled data to ensure it meets the expected format and constraints of a StockCandlesResponse.

#### Parameters

- `[]byte`

  The JSON\-encoded data that needs to be converted into a StockCandlesResponse.


#### Returns

- `error`

  An error object that will be non\-nil if the unmarshaling process encounters any issues or if the validation of the unmarshalled data fails.


#### Notes

- This method leverages an auxiliary struct to prevent infinite recursion during the unmarshalling process.

<a name="StockCandlesResponse.Unpack"></a>
### Unpack

```go
func (scr *StockCandlesResponse) Unpack() ([]Candle, error)
```

Unpack converts a StockCandlesResponse into a slice of StockCandle. This method is primarily used to transform the aggregated stock candles data from a structured response format into a more accessible slice of individual candle data. It allows users to iterate over or manipulate the stock candle data more conveniently in their applications.

#### Returns

- `[]Candle`

  A slice of Candle containing the unpacked data from the StockCandlesResponse.

- `error`

  An error if the slices within StockCandlesResponse are not of equal length, indicating inconsistent data.


#### Notes

- This method ensures that all slices within the StockCandlesResponse have the same length before unpacking to prevent data misalignment.

<a name="StockCandlesResponse.Validate"></a>
### Validate

```go
func (s *StockCandlesResponse) Validate() error
```

Validate checks the integrity and consistency of a StockCandlesResponse. It ensures that the data within the response adheres to expected formats and logical constraints, such as time being in ascending order and all data slices being of equal length. This method is crucial for preventing the propagation of invalid or corrupt data within an application that relies on stock candle information.

#### Returns

- `error`

  An error if the StockCandlesResponse is not valid. A nil error indicates a valid StockCandlesResponse.


#### Notes

- This method performs multiple checks in parallel to efficiently validate the response.








<a name="Candle"></a>
## Candle

```go
type Candle struct {
    Symbol string    `json:"symbol,omitempty"` // The symbol of the candle.
    Date   time.Time `json:"t"`                // Date represents the date and time of the candle.
    Open   float64   `json:"o"`                // Open is the opening price of the candle.
    High   float64   `json:"h"`                // High is the highest price reached during the candle's time.
    Low    float64   `json:"l"`                // Low is the lowest price reached during the candle's time.
    Close  float64   `json:"c"`                // Close is the closing price of the candle.
    Volume int64     `json:"v,omitempty"`      // Volume represents the trading volume during the candle's time.
    VWAP   float64   `json:"vwap,omitempty"`   // VWAP is the Volume Weighted Average Price, optional.
    N      int64     `json:"n,omitempty"`      // N is the number of trades that occurred, optional.
}
```

Candle represents a single candle in a stock candlestick chart, encapsulating the time, open, high, low, close prices, volume, and optionally the symbol, VWAP, and number of trades.

#### Generated By

- <a href="#StockCandlesResponse.Unpack">`StockCandlesResponse.Unpack()`</a>

  Generates Candle instances from a StockCandlesResponse.

- <a href="#BulkStockCandlesResponse.Unpack">`BulkStockCandlesResponse.Unpack()`</a>

  Generates Candle instances from a BulkStockStockCandlesResponse.

- <a href="#IndicesCandlesResponse.Unpack">`IndicesCandlesResponse.Unpack()`</a>

  Generates Candle instances from a IndicesCandlesResponse.


#### Methods

- <a href="#Candle.String">`String() string`</a>

  Provides a string representation of the Candle.

- <a href="#Candle.Equals">`Equals(other Candle) bool`</a>

  Checks if two Candle instances are equal.

- <a href="#Candle.MarshalJSON">`MarshalJSON() ([]byte, error)`</a>

  Customizes the JSON output of Candle.

- <a href="#Candle.UnmarshalJSON">`UnmarshalJSON(data []byte) error`</a>

  Customizes the JSON input processing of Candle.


#### Notes

- The VWAP, N fields are optional and will only be present in v2 Stock Candles.
- The Volume field is optional and will not be present in Index Candles.
- The Symbol field is optional and only be present in candles that were generated using the bulkcandles endpoint.



<a name="Candle.Clone"></a>
### Clone

```go
func (c Candle) Clone() Candle
```

Clones the current Candle instance, creating a new instance with the same values. This method is useful when you need a copy of a Candle instance without modifying the original instance.

#### Returns

- `Candle`

  A new Candle instance with the same values as the current instance.


<a name="Candle.Equals"></a>
### Equals

```go
func (c Candle) Equals(other Candle) bool
```

Equals compares the current Candle instance with another Candle instance to determine if they represent the same candle data. This method is useful for validating if two Candle instances have identical properties, including symbol, date/time, open, high, low, close prices, volume, VWAP, and number of trades. It's primarily used in scenarios where candle data integrity needs to be verified or when deduplicating candle data.

#### Parameters

- `Candle`

  The other Candle instance to compare against the current instance.


#### Returns

- `bool`

  Indicates whether the two Candle instances are identical. True if all properties match, false otherwise.


#### Notes

- This method performs a deep equality check on all Candle properties, including date/time which is compared using the Equal method from the time package to account for potential timezone differences.

<a name="Candle.IsAfter"></a>
### IsAfter

```go
func (c Candle) IsAfter(other Candle) bool
```

IsAfter determines if the current Candle instance occurred after another specified Candle instance. This method is useful for chronological comparisons between two Candle instances, particularly in time series analysis or when organizing historical financial data in ascending order.

#### Parameters

- `Candle`

  The other Candle instance to compare with the current Candle instance.


#### Returns

- `bool`

  Indicates whether the current Candle's date is after the 'other' Candle's date. Returns true if it is; otherwise, false.


<a name="Candle.IsBefore"></a>
### IsBefore

```go
func (c Candle) IsBefore(other Candle) bool
```

IsBefore determines whether the current Candle instance occurred before another specified Candle instance. This method is primarily used for comparing the dates of two Candle instances to establish their chronological order, which can be useful in time series analysis or when organizing historical financial data.

#### Parameters

- `Candle`

  The other Candle instance to compare with the current Candle instance.


#### Returns

- `bool`

  Returns true if the date of the current Candle instance is before the date of the 'other' Candle instance; otherwise, returns false.


#### Notes

- This method only compares the dates of the Candle instances, ignoring other fields such as Open, Close, High, Low, etc.

<a name="Candle.IsValid"></a>
### IsValid

```go
func (c Candle) IsValid() bool
```

IsValid evaluates the financial data of a Candle to determine its validity. This method is essential for ensuring that the Candle's data adheres to basic financial integrity rules, making it a critical step before performing further analysis or operations with Candle data. A Candle is deemed valid if its high, open, and close prices are logically consistent with each other and its volume is non\-negative.

#### Returns

- `bool`

  Indicates whether the Candle is valid based on its financial data. Returns true if all validity criteria are met; otherwise, false.


<a name="Candle.MarshalJSON"></a>
### MarshalJSON

```go
func (c Candle) MarshalJSON() ([]byte, error)
```

MarshalJSON customizes the JSON output of the Candle struct, primarily used for converting the Candle data into a JSON format that includes the Date as a Unix timestamp instead of the standard time.Time format. This method is particularly useful when the Candle data needs to be serialized into JSON for storage or transmission over networks where a compact and universally understood date format is preferred.

#### Returns

- `[]byte`

  The JSON\-encoded representation of the Candle.

- `error`

  An error if the JSON marshaling fails.


#### Notes

- The Date field of the Candle is converted to a Unix timestamp to facilitate easier handling of date and time in JSON.

<a name="Candle.String"></a>
### String

```go
func (c Candle) String() string
```

String provides a textual representation of the Candle instance. This method is primarily used for logging or debugging purposes, where a developer needs a quick and easy way to view the contents of a Candle instance in a human\-readable format.

#### Returns

- `string`

  A string that represents the Candle instance, including its symbol, date/time, open, high, low, close prices, volume, VWAP, and number of trades, if available.


#### Notes

- The output format is designed to be easily readable, with each field labeled and separated by commas.
- Fields that are not applicable or not set \(e.g., VWAP, N, Volume for Index Candles\) are omitted from the output.

<a name="Candle.UnmarshalJSON"></a>
### UnmarshalJSON

```go
func (c *Candle) UnmarshalJSON(data []byte) error
```

UnmarshalJSON customizes the JSON input processing of Candle.

UnmarshalJSON customizes the JSON input processing for the Candle struct, allowing for the Date field to be correctly interpreted from a Unix timestamp \(integer\) back into a Go time.Time object. This method is essential for deserializing Candle data received in JSON format, where date and time are represented as Unix timestamps, ensuring the Candle struct accurately reflects the original data.

#### Parameters

- `data []byte`

  The JSON\-encoded data that is to be unmarshaled into the Candle struct.


#### Returns

- `error`

  An error if the JSON unmarshaling fails, nil otherwise.


#### Notes

- The Date field in the JSON is expected to be a Unix timestamp \(integer\). This method converts it back to a time.Time object, ensuring the Candle struct's Date field is correctly populated.

<a name="ByClose"></a>
## ByClose

```go
type ByClose []Candle
```

ByClose implements sort.Interface for \[\]Candle based on the Close field.



<Tabs>
<TabItem value="Example" label="Example">




```go
// Create a slice of Candle instances
candles := []Candle{
	{Symbol: "AAPL", Date: time.Now(), Open: 100, High: 105, Low: 95, Close: 102, Volume: 1000},
	{Symbol: "AAPL", Date: time.Now(), Open: 102, High: 106, Low: 98, Close: 104, Volume: 1500},
	{Symbol: "AAPL", Date: time.Now(), Open: 99, High: 103, Low: 97, Close: 100, Volume: 1200},
}

// Sort the candles by their Close value using sort.Sort and ByClose
sort.Sort(ByClose(candles))

// Print the sorted candles to demonstrate the order
for _, candle := range candles {
	fmt.Printf("Close: %v\n", candle.Close)
}

```

#### Output

```
Close: 100
Close: 102
Close: 104
```

</TabItem>
</Tabs>

<a name="ByClose.Len"></a>
### Len

```go
func (a ByClose) Len() int
```



<a name="ByClose.Less"></a>
### Less

```go
func (a ByClose) Less(i, j int) bool
```



<a name="ByClose.Swap"></a>
### Swap

```go
func (a ByClose) Swap(i, j int)
```



<a name="ByDate"></a>
## ByDate

```go
type ByDate []Candle
```

ByDate implements sort.Interface for \[\]Candle based on the Date field. This allows for sorting a slice of Candle instances by their Date field in ascending order.



<Tabs>
<TabItem value="Example" label="Example">




```go
// Assuming the Candle struct has at least a Date field of type time.Time
candles := []Candle{
	{Date: time.Date(2023, 3, 10, 0, 0, 0, 0, time.UTC)},
	{Date: time.Date(2023, 1, 5, 0, 0, 0, 0, time.UTC)},
	{Date: time.Date(2023, 2, 20, 0, 0, 0, 0, time.UTC)},
}

// Sorting the slice of Candle instances by their Date field in ascending order
sort.Sort(ByDate(candles))

// Printing out the sorted dates to demonstrate the order
for _, candle := range candles {
	fmt.Println(candle.Date.Format("2006-01-02"))
}

```

#### Output

```
2023-01-05
2023-02-20
2023-03-10
```

</TabItem>
</Tabs>

<a name="ByDate.Len"></a>
### Len

```go
func (a ByDate) Len() int
```



<a name="ByDate.Less"></a>
### Less

```go
func (a ByDate) Less(i, j int) bool
```



<a name="ByDate.Swap"></a>
### Swap

```go
func (a ByDate) Swap(i, j int)
```



<a name="ByHigh"></a>
## ByHigh

```go
type ByHigh []Candle
```

ByHigh implements sort.Interface for \[\]Candle based on the High field.



<Tabs>
<TabItem value="Example" label="Example">




```go
// Assuming the Candle struct has at least a High field of type float64
candles := []Candle{
	{High: 15.2},
	{High: 11.4},
	{High: 13.5},
}

// Sorting the slice of Candle instances by their High field in ascending order
sort.Sort(ByHigh(candles))

// Printing out the sorted High values to demonstrate the order
for _, candle := range candles {
	fmt.Printf("%.1f\n", candle.High)
}

```

#### Output

```
11.4
13.5
15.2
```

</TabItem>
</Tabs>

<a name="ByHigh.Len"></a>
### Len

```go
func (a ByHigh) Len() int
```



<a name="ByHigh.Less"></a>
### Less

```go
func (a ByHigh) Less(i, j int) bool
```



<a name="ByHigh.Swap"></a>
### Swap

```go
func (a ByHigh) Swap(i, j int)
```



<a name="ByLow"></a>
## ByLow

```go
type ByLow []Candle
```

ByLow implements sort.Interface for \[\]Candle based on the Low field.



<Tabs>
<TabItem value="Example" label="Example">




```go
// Assuming the Candle struct has at least a Low field of type float64
candles := []Candle{
	{Low: 5.5},
	{Low: 7.2},
	{Low: 6.3},
}

// Sorting the slice of Candle instances by their Low field in ascending order
sort.Sort(ByLow(candles))

// Printing out the sorted Low values to demonstrate the order
for _, candle := range candles {
	fmt.Printf("%.1f\n", candle.Low)
}

```

#### Output

```
5.5
6.3
7.2
```

</TabItem>
</Tabs>

<a name="ByLow.Len"></a>
### Len

```go
func (a ByLow) Len() int
```



<a name="ByLow.Less"></a>
### Less

```go
func (a ByLow) Less(i, j int) bool
```



<a name="ByLow.Swap"></a>
### Swap

```go
func (a ByLow) Swap(i, j int)
```



<a name="ByN"></a>
## ByN

```go
type ByN []Candle
```

ByN implements sort.Interface for \[\]Candle based on the N field.



<Tabs>
<TabItem value="Example" label="Example">




```go
// Assuming the Candle struct has at least an N field of type int (or any comparable type)
candles := []Candle{
	{N: 3},
	{N: 1},
	{N: 2},
}

// Sorting the slice of Candle instances by their N field in ascending order
sort.Sort(ByN(candles))

// Printing out the sorted N values to demonstrate the order
for _, candle := range candles {
	fmt.Println(candle.N)
}

```

#### Output

```
1
2
3
```

</TabItem>
</Tabs>

<a name="ByN.Len"></a>
### Len

```go
func (a ByN) Len() int
```



<a name="ByN.Less"></a>
### Less

```go
func (a ByN) Less(i, j int) bool
```



<a name="ByN.Swap"></a>
### Swap

```go
func (a ByN) Swap(i, j int)
```



<a name="ByOpen"></a>
## ByOpen

```go
type ByOpen []Candle
```

ByOpen implements sort.Interface for \[\]Candle based on the Open field.



<Tabs>
<TabItem value="Example" label="Example">




```go
// Assuming the Candle struct has at least an Open field of type float64
candles := []Candle{
	{Open: 10.5},
	{Open: 8.2},
	{Open: 9.7},
}

// Sorting the slice of Candle instances by their Open field in ascending order
sort.Sort(ByOpen(candles))

// Printing out the sorted Open values to demonstrate the order
for _, candle := range candles {
	fmt.Printf("%.1f\n", candle.Open)
}

```

#### Output

```
8.2
9.7
10.5
```

</TabItem>
</Tabs>

<a name="ByOpen.Len"></a>
### Len

```go
func (a ByOpen) Len() int
```



<a name="ByOpen.Less"></a>
### Less

```go
func (a ByOpen) Less(i, j int) bool
```



<a name="ByOpen.Swap"></a>
### Swap

```go
func (a ByOpen) Swap(i, j int)
```



<a name="BySymbol"></a>
## BySymbol

```go
type BySymbol []Candle
```

BySymbol implements sort.Interface for \[\]Candle based on the Symbol field. Candles are sorted in ascending order.



<Tabs>
<TabItem value="Example" label="Example">




```go
// Create a slice of Candle instances with different symbols
candles := []Candle{
	{Symbol: "MSFT", Date: time.Date(2023, 4, 10, 0, 0, 0, 0, time.UTC), Open: 250.0, High: 255.0, Low: 248.0, Close: 252.0, Volume: 3000},
	{Symbol: "AAPL", Date: time.Date(2023, 4, 10, 0, 0, 0, 0, time.UTC), Open: 150.0, High: 155.0, Low: 149.0, Close: 152.0, Volume: 2000},
	{Symbol: "GOOGL", Date: time.Date(2023, 4, 10, 0, 0, 0, 0, time.UTC), Open: 1200.0, High: 1210.0, Low: 1195.0, Close: 1205.0, Volume: 1000},
}

// Sort the candles by their Symbol using sort.Sort and BySymbol
sort.Sort(BySymbol(candles))

// Print the sorted candles to demonstrate the order
for _, candle := range candles {
	fmt.Printf("Symbol: %s, Close: %.2f\n", candle.Symbol, candle.Close)
}

```

#### Output

```
Symbol: AAPL, Close: 152.00
Symbol: GOOGL, Close: 1205.00
Symbol: MSFT, Close: 252.00
```

</TabItem>
</Tabs>

<a name="BySymbol.Len"></a>
### Len

```go
func (a BySymbol) Len() int
```



<a name="BySymbol.Less"></a>
### Less

```go
func (a BySymbol) Less(i, j int) bool
```



<a name="BySymbol.Swap"></a>
### Swap

```go
func (a BySymbol) Swap(i, j int)
```



<a name="ByVWAP"></a>
## ByVWAP

```go
type ByVWAP []Candle
```

ByVWAP implements sort.Interface for \[\]Candle based on the VWAP field.



<Tabs>
<TabItem value="Example" label="Example">




```go
// Assuming the Candle struct has at least a VWAP (Volume Weighted Average Price) field of type float64
candles := []Candle{
	{VWAP: 10.5},
	{VWAP: 8.2},
	{VWAP: 9.7},
}

// Sorting the slice of Candle instances by their VWAP field in ascending order
sort.Sort(ByVWAP(candles))

// Printing out the sorted VWAP values to demonstrate the order
for _, candle := range candles {
	fmt.Printf("%.1f\n", candle.VWAP)
}

```

#### Output

```
8.2
9.7
10.5
```

</TabItem>
</Tabs>

<a name="ByVWAP.Len"></a>
### Len

```go
func (a ByVWAP) Len() int
```



<a name="ByVWAP.Less"></a>
### Less

```go
func (a ByVWAP) Less(i, j int) bool
```



<a name="ByVWAP.Swap"></a>
### Swap

```go
func (a ByVWAP) Swap(i, j int)
```



<a name="ByVolume"></a>
## ByVolume

```go
type ByVolume []Candle
```

ByVolume implements sort.Interface for \[\]Candle based on the Volume field.



<Tabs>
<TabItem value="Example" label="Example">




```go
// Assuming the Candle struct has at least a Volume field of type int
candles := []Candle{
	{Volume: 300},
	{Volume: 100},
	{Volume: 200},
}

// Sorting the slice of Candle instances by their Volume field in ascending order
sort.Sort(ByVolume(candles))

// Printing out the sorted volumes to demonstrate the order
for _, candle := range candles {
	fmt.Println(candle.Volume)
}

```

#### Output

```
100
200
300
```

</TabItem>
</Tabs>

<a name="ByVolume.Len"></a>
### Len

```go
func (a ByVolume) Len() int
```



<a name="ByVolume.Less"></a>
### Less

```go
func (a ByVolume) Less(i, j int) bool
```



<a name="ByVolume.Swap"></a>
### Swap

```go
func (a ByVolume) Swap(i, j int)
```




