Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarketDataApp committed Feb 14, 2024
1 parent f1406ae commit 33d3f8f
Show file tree
Hide file tree
Showing 10 changed files with 3,181 additions and 20 deletions.
1,455 changes: 1,455 additions & 0 deletions .scripts/candles.mdx

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .scripts/gomarkdoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ TEST_FILE="indices_candles_test.go" # Corresponding test file
MODELS_DIR="models" # Models directory relative to the project root
MODEL_MAIN_FILE="$MODELS_DIR/indices_candles.go" # Main model file
MODEL_TEST_FILE="$MODELS_DIR/indices_candles_test.go" # Model test file
CANDLES_MAIN_FILE="$MODELS_DIR/candle.go" # Main model file
CANDLES_TEST_FILE="$MODELS_DIR/candle_test.go" # Main model file


# Step 1: Documentation for main files
TMP_DIR=$(create_tmp_dir)
Expand All @@ -36,6 +39,9 @@ echo "Using new temporary directory for model files: $TMP_DIR"
# Copy the model file and its test file to the new temporary directory
cp "$SRC_DIR/$MODEL_MAIN_FILE" "$TMP_DIR"
cp "$SRC_DIR/$MODEL_TEST_FILE" "$TMP_DIR"
cp "$SRC_DIR/$CANDLES_MAIN_FILE" "$TMP_DIR"
cp "$SRC_DIR/$CANDLES_TEST_FILE" "$TMP_DIR"


# Run gomarkdoc on the new temporary directory for model files
gomarkdoc --output "$OUTPUT_DIR/indices_candles_response.md" "$TMP_DIR"
Expand Down
376 changes: 376 additions & 0 deletions .scripts/indices_candles_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,376 @@




Get historical price candles for any supported stock index.

## Making Requests

Use [IndicesCandlesRequest](<#IndicesCandlesRequest>) to make requests to the endpoint using any of the three supported execution methods:

| Method | Execution | Return Type | Description |
|------------|---------------|----------------------------|-----------------------------------------------------------------------------------------------------------|
| **Get** | Direct | `[]Candle` | Directly returns a slice of `[]Candle`, making it straightforward to access each candle individually. |
| **Packed** | Intermediate | `IndicesCandlesResponse` | Returns a packed `IndicesCandlesResponse` object. Must be unpacked to access the `[]Candle` slice. |
| **Raw** | Low-level | `resty.Response` | Provides the raw `resty.Response` for maximum flexibility. Direct access to raw JSON or `*http.Response`. |


<a name="IndicesCandlesRequest"></a>
## type IndicesCandlesRequest

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

IndicesCandlesRequest represents a request to the [/v1/indices/candles/](<https://www.marketdata.app/docs/api/indices/candles>) endpoint. It encapsulates parameters for resolution, symbol, and dates to be used in the request.

#### Generated By

- <a href="#IndexCandles">`IndexCandles(client ...*MarketDataClient) *IndicesCandlesRequest`</a>

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


#### Setter Methods

These methods are used to set the parameters of the request. They allow for method chaining by returning a pointer to the \*IndicesCandlesRequest instance they modify.

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

Sets the resolution parameter for the request.

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

Sets the symbol parameter for the request.

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

Sets the date parameter for the request.

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

Sets the 'from' date 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="#IndicesCandlesRequest.Get">`Get(...*MarketDataClient) ([]Candle, error)`</a>

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

- <a href="#IndicesCandlesRequest.Packed">`Packed(...*MarketDataClient) (*IndicesCandlesResponse, error)`</a>

Packs the request parameters and sends the request, returning a structured response.

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

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




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




```go
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

```
Candle{Date: 2022-01-03, Open: 17.6, High: 18.54, Low: 16.56, Close: 16.6}
Candle{Date: 2022-01-04, Open: 16.57, High: 17.81, Low: 16.34, Close: 16.91}
Candle{Date: 2022-01-05, Open: 17.07, High: 20.17, Low: 16.58, Close: 19.73}
```

</TabItem>

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




```go
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]}
```

</TabItem>

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




```go
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]}
```

</TabItem>
</Tabs>

<a name="IndexCandles"></a>
### func IndexCandles

```go
func IndexCandles(client ...*MarketDataClient) *IndicesCandlesRequest
```

IndexCandles creates a new [IndicesCandlesRequest](<#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

- `...*MarketDataClient`

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.


<a name="IndicesCandlesRequest.Countback"></a>
### func \(\*IndicesCandlesRequest\) Countback

```go
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

- `int`

An int representing the number of candles to return.


#### Returns

- `*IndicesCandlesRequest`

A pointer to the \*IndicesCandlesRequest instance to allow for method chaining.


<a name="IndicesCandlesRequest.Date"></a>
### func \(\*IndicesCandlesRequest\) Date

```go
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 'date' field of the IndicesCandlesRequest instance to store the date value.

#### Parameters

- `interface{}`

An interface\{\} representing the date to be set. It can be a string, a time.Time object, a Unix int, or any other type that the underlying dates package 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.


#### Notes

- If an error occurs while setting the date \(e.g., if the date value is not supported\), the Error field of the request is set with the encountered error, but the method still returns the \*IndicesCandlesRequest instance to allow for further method calls.

<a name="IndicesCandlesRequest.From"></a>
### func \(\*IndicesCandlesRequest\) From

```go
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

- `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
- `*IndicesCandlesRequest`
A pointer to the \*IndicesCandlesRequest instance to allow for method chaining.
<a name="IndicesCandlesRequest.Get"></a>
### func \(\*IndicesCandlesRequest\) Get
```go
func (icr *IndicesCandlesRequest) Get(optionalClients ...*MarketDataClient) ([]models.Candle, error)
```

Get sends the [IndicesCandlesRequest](<#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

- `...*MarketDataClient`

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

- `[]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="IndicesCandlesRequest.Packed"></a>
### func \(\*IndicesCandlesRequest\) Packed

```go
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

- `...*MarketDataClient`

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.


<a name="IndicesCandlesRequest.Resolution"></a>
### func \(\*IndicesCandlesRequest\) Resolution

```go
func (icr *IndicesCandlesRequest) Resolution(q string) *IndicesCandlesRequest
```

Resolution sets the resolution parameter for the [IndicesCandlesRequest](<#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

- `string`

A string representing the resolution to be set. Valid resolutions may include values like "D", "5", "1h", etc. See 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.


#### Notes

- 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 by the caller.

<a name="IndicesCandlesRequest.Symbol"></a>
### func \(\*IndicesCandlesRequest\) Symbol

```go
func (icr *IndicesCandlesRequest) Symbol(q string) *IndicesCandlesRequest
```

Symbol sets the symbol parameter for the [IndicesCandlesRequest](<#IndicesCandlesRequest>). This method is used to specify the index symbol for which the candle data is requested.

#### Parameters

- `string`

A string representing the index 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.


#### Notes

- 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.

<a name="IndicesCandlesRequest.To"></a>
### func \(\*IndicesCandlesRequest\) To

```go
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

- `interface{}`

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.



Loading

0 comments on commit 33d3f8f

Please sign in to comment.