Skip to content

Commit fd01fd3

Browse files
committed
added mutual fund candles
1 parent 6e0b26c commit fd01fd3

17 files changed

+1237
-57
lines changed

.scripts/gomarkdoc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ process_group "options_lookup"
159159
process_group "options_quotes"
160160
process_group "options_strikes"
161161
process_group "options_chain"
162+
process_group "funds_candles"
162163
process_group "client"
163164
process_group "logging"
164165

.scripts/process_markdown.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"https://www.marketdata.app/docs/api/options/strikes": {"title": "Strikes", "sidebar_position": 3},
2020
"https://www.marketdata.app/docs/api/options/chain": {"title": "Option Chain", "sidebar_position": 4},
2121
"https://www.marketdata.app/docs/api/options/quotes": {"title": "Quotes", "sidebar_position": 5},
22+
"https://www.marketdata.app/docs/api/funds/candles": {"title": "Candles", "sidebar_position": 1},
2223
"https://www.marketdata.app/docs/sdk/go/client": {"title": "Client", "sidebar_position": 2},
2324
"https://www.marketdata.app/docs/sdk/go/logging": {"title": "Logging", "sidebar_position": 3},
2425

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22

3-
# Go SDK for Market Data v1.1
3+
# Go SDK for Market Data v1.2
44
### Access Financial Data with Ease
55

66
> This is the official Go SDK for [Market Data](https://www.marketdata.app/). It provides developers with a powerful, easy-to-use interface to obtain real-time and historical financial data. Ideal for building financial applications, trading bots, and investment strategies.
@@ -12,7 +12,7 @@
1212
[![License](https://img.shields.io/github/license/MarketDataApp/sdk-go.svg)](https://github.com/MarketDataApp/sdk-go/blob/master/LICENSE)
1313
![SDK Version](https://img.shields.io/badge/version-1.0.0-blue.svg)
1414
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/MarketDataApp/sdk-go)
15-
![Lines of Code](https://img.shields.io/badge/lines_of_code-8688-blue)
15+
![Lines of Code](https://img.shields.io/badge/lines_of_code-8710-blue)
1616

1717
#### Connect With The Market Data Community
1818

@@ -235,10 +235,14 @@ Market Data's Go SDK covers the vast majority of v1 endpoints. See our complete
235235
| | [Candles](https://www.marketdata.app/docs/api/indices/candles) | ✅ | ❌ |
236236
| | [Quotes](https://www.marketdata.app/docs/api/indices/quotes) | ✅ | ❌ |
237237
| | | | |
238+
| **[FUNDS](https://www.marketdata.app/docs/api/funds)** | | | |
239+
| | [Candles](https://www.marketdata.app/docs/api/indices/candles) | ✅ | ❌ |
240+
| | | | |
238241
| **[UTILITIES](https://www.marketdata.app/docs/api/utilities)** | | | |
239242
| | [Status](https://www.marketdata.app/docs/api/utilities/status) | ❌ | ❌ |
243+
| | [Headers](https://www.marketdata.app/docs/api/utilities/headers) | ❌ | ❌ |
240244
241-
> Note on v2: Even though some v2 endpoints are available for use in this SDK, Market Data has not yet released v2 of its API for clients and v2 usage is restricted to admins only. Clients should only use v1 endpoints at this time. Even after v2 is released, we do not plan on deprecating v1 endpoints, so please build your applications with confidence using v1 endpoints.
245+
> Note on v2: Even though some v2 endpoints are available for use in this SDK, Market Data has not yet released v2 of its API for clients and v2 usage is restricted to admins only. Clients should only use v1 endpoints at this time. Even after v2 is released, we do not plan on deprecating v1 endpoints, so please build your applications with confidence using our v1 endpoints.
242246
243247
### SDK License & Data Usage Terms
244248

baseRequest.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ func (br *baseRequest) getParams() ([]parameters.MarketDataParam, error) {
202202
return params, nil
203203
}
204204

205+
if fcr, ok := br.child.(*FundCandlesRequest); ok {
206+
params, err := fcr.getParams()
207+
if err != nil {
208+
return nil, err
209+
}
210+
return params, nil
211+
}
212+
205213
return []parameters.MarketDataParam{}, nil
206214
}
207215

endpoints.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ var endpoints = map[int]map[string]map[string]string{
2828
"quotes": "/v1/indices/quotes/{symbol}/",
2929
"candles": "/v1/indices/candles/{resolution}/{symbol}/",
3030
},
31+
"funds": {
32+
"candles": "/v1/funds/candles/{resolution}/{symbol}/",
33+
},
3134
},
3235
2: {
3336
"stocks": {

funds_candles.go

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
// Package client includes types and methods to access the Funds / Candles endpoint. Retrieve historical price candles for any supported stock symbol.
2+
//
3+
// # Making Requests
4+
//
5+
// Use [FundCandlesRequest] to make requests to the endpoint using any of the three supported execution methods:
6+
//
7+
// | Method | Execution | Return Type | Description |
8+
// |------------|---------------|-----------------------------|------------------------------------------------------------------------------------------------------------|
9+
// | **Get** | Direct | `[]Candle` | Directly returns a slice of `[]Candle`, facilitating individual access to each candle. |
10+
// | **Packed** | Intermediate | `*FundCandlesResponse` | Returns a packed `*FundCandlesResponse` object. Must be unpacked to access the `[]Candle` slice. |
11+
// | **Raw** | Low-level | `*resty.Response` | Provides the raw `*resty.Response` for maximum flexibility. Direct access to raw JSON or `*http.Response`. |
12+
package client
13+
14+
import (
15+
"fmt"
16+
17+
"github.com/MarketDataApp/sdk-go/helpers/parameters"
18+
"github.com/MarketDataApp/sdk-go/models"
19+
"github.com/go-resty/resty/v2"
20+
)
21+
22+
// FundCandlesRequest represents a request to the [/v1/funds/candles/] endpoint.
23+
// It encapsulates parameters for resolution, symbol, date, and additional stock-specific parameters to be used in the request.
24+
// This struct provides methods such as Resolution(), Symbol(), Date(), From(), To(), Countback(), AdjustSplits(), AdjustDividends(), Extended(), and Exchange() to set these parameters respectively.
25+
//
26+
// # Generated By
27+
//
28+
// - FundCandles() *FundCandlesRequest: FundCandles creates a new *FundCandlesRequest and returns a pointer to the request allowing for method chaining.
29+
//
30+
// # Setter Methods
31+
//
32+
// - Resolution(string) *FundCandlesRequest: Sets the resolution parameter for the request.
33+
// - Symbol(string) *FundCandlesRequest: Sets the symbol parameter for the request.
34+
// - Date(interface{}) *FundCandlesRequest: Sets the date parameter for the request.
35+
// - From(interface{}) *FundCandlesRequest: Sets the 'from' date parameter for the request.
36+
// - To(interface{}) *FundCandlesRequest: Sets the 'to' date parameter for the request.
37+
// - Countback(int) *FundCandlesRequest: Sets the countback parameter for the request.
38+
// - AdjustSplits(bool) *FundCandlesRequest: Sets the adjust splits parameter for the request.
39+
// - AdjustDividends(bool) *FundCandlesRequest: Sets the adjust dividends parameter for the request.
40+
// - Extended(bool) *FundCandlesRequest: Sets the extended hours data parameter for the request.
41+
// - Exchange(string) *FundCandlesRequest: Sets the exchange parameter for the request.
42+
//
43+
// # Execution Methods
44+
//
45+
// These methods are used to send the request in different formats or retrieve the data.
46+
// They handle the actual communication with the API endpoint.
47+
//
48+
// - Get() ([]Candle, error): Sends the request, unpacks the response, and returns the data in a user-friendly format.
49+
// - Packed() (*FundCandlesResponse, error): Returns a struct that contains equal-length slices of primitives. This packed response mirrors Market Data's JSON response.
50+
// - Raw() (*resty.Response, error): Sends the request as is and returns the raw HTTP response.
51+
//
52+
// [/v1/funds/candles/]: https://www.marketdata.app/docs/api/funds/candles
53+
type FundCandlesRequest struct {
54+
*baseRequest
55+
stockCandleParams *parameters.StockCandleParams
56+
resolutionParams *parameters.ResolutionParams
57+
symbolParams *parameters.SymbolParams
58+
dateParams *parameters.DateParams
59+
}
60+
61+
// Resolution sets the resolution parameter for the FundCandlesRequest.
62+
// This method is used to specify the granularity of the candle data to be retrieved.
63+
//
64+
// # Parameters
65+
//
66+
// - string: A string representing the resolution to be set.
67+
//
68+
// # Returns
69+
//
70+
// - *FundCandlesRequest: This method returns a pointer to the *FundCandlesRequest instance it was called on. This allows for method chaining.
71+
func (cr *FundCandlesRequest) Resolution(q string) *FundCandlesRequest {
72+
if cr == nil {
73+
return nil
74+
}
75+
err := cr.resolutionParams.SetResolution(q)
76+
if err != nil {
77+
cr.Error = err
78+
}
79+
return cr
80+
}
81+
82+
// Symbol sets the symbol parameter for the FundCandlesRequest.
83+
// This method is used to specify the stock symbol for which candle data is requested.
84+
//
85+
// # Parameters
86+
//
87+
// - string: A string representing the stock symbol to be set.
88+
//
89+
// # Returns
90+
//
91+
// - *FundCandlesRequest: This method returns a pointer to the *FundCandlesRequest instance it was called on. This allows for method chaining.
92+
func (fcr *FundCandlesRequest) Symbol(q string) *FundCandlesRequest {
93+
if fcr == nil {
94+
return nil
95+
}
96+
err := fcr.symbolParams.SetSymbol(q)
97+
if err != nil {
98+
fcr.Error = err
99+
}
100+
return fcr
101+
}
102+
103+
// Date sets the date parameter for the FundCandlesRequest.
104+
// This method is used to specify the date for which the stock candle data is requested.
105+
//
106+
// # Parameters
107+
//
108+
// - 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.
109+
//
110+
// # Returns
111+
//
112+
// - *FundCandlesRequest: This method returns a pointer to the *FundCandlesRequest instance it was called on. This allows for method chaining.
113+
func (fcr *FundCandlesRequest) Date(q interface{}) *FundCandlesRequest {
114+
err := fcr.dateParams.SetDate(q)
115+
if err != nil {
116+
fcr.baseRequest.Error = err
117+
}
118+
return fcr
119+
}
120+
121+
// From sets the 'from' date parameter for the FundCandlesRequest.
122+
// This method is used to specify the starting point of the date range for which the stock candle data is requested.
123+
//
124+
// # Parameters
125+
//
126+
// - 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.
127+
//
128+
// # Returns
129+
//
130+
// - *FundCandlesRequest: This method returns a pointer to the *FundCandlesRequest instance it was called on. This allows for method chaining.
131+
func (fcr *FundCandlesRequest) From(q interface{}) *FundCandlesRequest {
132+
err := fcr.dateParams.SetFrom(q)
133+
if err != nil {
134+
fcr.baseRequest.Error = err
135+
}
136+
return fcr
137+
}
138+
139+
// To sets the 'to' date parameter for the FundCandlesRequest.
140+
// This method is used to specify the ending point of the date range for which the stock candle data is requested.
141+
//
142+
// # Parameters
143+
//
144+
// - 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.
145+
//
146+
// # Returns
147+
//
148+
// - *FundCandlesRequest: This method returns a pointer to the *FundCandlesRequest instance it was called on
149+
func (fcr *FundCandlesRequest) To(q interface{}) *FundCandlesRequest {
150+
err := fcr.dateParams.SetTo(q)
151+
if err != nil {
152+
fcr.baseRequest.Error = err
153+
}
154+
return fcr
155+
}
156+
157+
// Countback sets the countback parameter for the FundCandlesRequest.
158+
// This method specifies the number of candles to return, counting backwards from the 'to' date.
159+
//
160+
// # Parameters
161+
//
162+
// - int: The number of candles to return.
163+
//
164+
// # Returns
165+
//
166+
// - *FundCandlesRequest: This method returns a pointer to the *FundCandlesRequest instance it was called on. This allows for method chaining.
167+
func (fcr *FundCandlesRequest) Countback(q int) *FundCandlesRequest {
168+
err := fcr.dateParams.SetCountback(q)
169+
if err != nil {
170+
fcr.baseRequest.Error = err
171+
}
172+
return fcr
173+
}
174+
175+
// AdjustSplits sets the adjust splits parameter for the FundCandlesRequest.
176+
// This method indicates whether the returned data should be adjusted for stock splits.
177+
//
178+
// # Parameters
179+
//
180+
// - bool: Whether to adjust for splits.
181+
//
182+
// # Returns
183+
//
184+
// - *FundCandlesRequest: This method returns a pointer to the *FundCandlesRequest instance it was called on. This allows for method chaining.
185+
func (fcr *FundCandlesRequest) AdjustSplits(q bool) *FundCandlesRequest {
186+
if fcr == nil {
187+
return nil
188+
}
189+
fcr.stockCandleParams.SetAdjustSplits(q)
190+
return fcr
191+
}
192+
193+
// getParams packs the CandlesRequest struct into a slice of interface{} and returns it.
194+
func (fcr *FundCandlesRequest) getParams() ([]parameters.MarketDataParam, error) {
195+
if fcr == nil {
196+
return nil, fmt.Errorf("FundCandlesRequest is nil")
197+
}
198+
params := []parameters.MarketDataParam{fcr.dateParams, fcr.symbolParams, fcr.resolutionParams}
199+
return params, nil
200+
}
201+
202+
// Raw executes the FundCandlesRequest and returns the raw *resty.Response.
203+
// This method returns the raw JSON or *http.Response for further processing without accepting an alternative MarketDataClient.
204+
//
205+
// # Returns
206+
//
207+
// - *resty.Response: The raw HTTP response from the executed request.
208+
// - error: An error object if the request fails due to execution errors.
209+
func (fcr *FundCandlesRequest) Raw() (*resty.Response, error) {
210+
return fcr.baseRequest.Raw()
211+
}
212+
213+
// Packed sends the FundCandlesRequest and returns the FundCandlesResponse.
214+
////
215+
// # Returns
216+
//
217+
// - *FundCandlesResponse: A pointer to the FundCandlesResponse obtained from the request.
218+
// - error: An error object that indicates a failure in sending the request.
219+
func (fcr *FundCandlesRequest) Packed() (*models.FundCandlesResponse, error) {
220+
if fcr == nil {
221+
return nil, fmt.Errorf("FundCandlesRequest is nil")
222+
}
223+
224+
var fcrResp models.FundCandlesResponse
225+
_, err := fcr.baseRequest.client.getFromRequest(fcr.baseRequest, &fcrResp)
226+
if err != nil {
227+
return nil, err
228+
}
229+
230+
return &fcrResp, nil
231+
}
232+
233+
// Get sends the FundCandlesRequest, unpacks the FundCandlesResponse, and returns a slice of StockCandle.
234+
// It returns an error if the request or unpacking fails.
235+
//
236+
// # Returns
237+
//
238+
// - []Candle: A slice of []Candle containing the unpacked candle data from the response.
239+
// - error: An error object that indicates a failure in sending the request or unpacking the response.
240+
func (fcr *FundCandlesRequest) Get() ([]models.Candle, error) {
241+
if fcr == nil {
242+
return nil, fmt.Errorf("FundCandlesRequest is nil")
243+
}
244+
245+
// Use the Packed method to make the request
246+
fcrResp, err := fcr.Packed()
247+
if err != nil {
248+
return nil, err
249+
}
250+
251+
// Unpack the data using the Unpack method in the response
252+
data, err := fcrResp.Unpack()
253+
if err != nil {
254+
return nil, err
255+
}
256+
257+
return data, nil
258+
}
259+
260+
// FundCandles initializes a new FundCandlesRequest with default parameters.
261+
// This function prepares a request to fetch stock candle data. It sets up all necessary parameters
262+
// and configurations to make the request ready to be sent.
263+
//
264+
// # Returns
265+
//
266+
// - *FundCandlesRequest: A pointer to the newly created FundCandlesRequest 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.
267+
func FundCandles() *FundCandlesRequest {
268+
baseReq := newBaseRequest()
269+
baseReq.path = endpoints[1]["funds"]["candles"]
270+
271+
fcr := &FundCandlesRequest{
272+
baseRequest: baseReq,
273+
dateParams: &parameters.DateParams{},
274+
resolutionParams: &parameters.ResolutionParams{},
275+
symbolParams: &parameters.SymbolParams{},
276+
}
277+
278+
// Set the date to the current time
279+
baseReq.child = fcr
280+
281+
return fcr
282+
}

funds_candles_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package client
2+
3+
import "fmt"
4+
5+
func ExampleFundCandlesRequest_raw() {
6+
fcr, err := FundCandles().Resolution("D").Symbol("VFINX").From("2023-01-01").To("2023-01-06").Raw()
7+
if err != nil {
8+
fmt.Print(err)
9+
return
10+
}
11+
fmt.Println(fcr)
12+
13+
// Output: {"s":"ok","t":[1672722000,1672808400,1672894800,1672981200],"o":[352.76,355.43,351.35,359.38],"h":[352.76,355.43,351.35,359.38],"l":[352.76,355.43,351.35,359.38],"c":[352.76,355.43,351.35,359.38]}
14+
}
15+
16+
func ExampleFundCandlesRequest_packed() {
17+
fcr, err := FundCandles().Resolution("D").Symbol("VFINX").From("2023-01-01").To("2023-01-06").Packed()
18+
if err != nil {
19+
fmt.Print(err)
20+
return
21+
}
22+
fmt.Println(fcr)
23+
24+
// Output: FundCandlesResponse{Date: [1672722000 1672808400 1672894800 1672981200], Open: [352.76 355.43 351.35 359.38], High: [352.76 355.43 351.35 359.38], Low: [352.76 355.43 351.35 359.38], Close: [352.76 355.43 351.35 359.38]}
25+
}
26+
27+
func ExampleFundCandlesRequest_get() {
28+
fcr, err := FundCandles().Resolution("D").Symbol("VFINX").From("2023-01-01").To("2023-01-06").Get()
29+
if err != nil {
30+
fmt.Print(err)
31+
return
32+
}
33+
34+
for _, candle := range fcr {
35+
fmt.Println(candle)
36+
}
37+
// Output: Candle{Date: 2023-01-03, Open: 352.76, High: 352.76, Low: 352.76, Close: 352.76}
38+
// Candle{Date: 2023-01-04, Open: 355.43, High: 355.43, Low: 355.43, Close: 355.43}
39+
// Candle{Date: 2023-01-05, Open: 351.35, High: 351.35, Low: 351.35, Close: 351.35}
40+
// Candle{Date: 2023-01-06, Open: 359.38, High: 359.38, Low: 359.38, Close: 359.38}
41+
}

0 commit comments

Comments
 (0)