github.com/polygon-io/client-go@v1.16.4/rest/indicators.go (about) 1 package polygon 2 3 import ( 4 "context" 5 "net/http" 6 7 "github.com/polygon-io/client-go/rest/client" 8 "github.com/polygon-io/client-go/rest/models" 9 ) 10 11 const ( 12 GetSMAPath = "/v1/indicators/sma/{ticker}" 13 GetEMAPath = "/v1/indicators/ema/{ticker}" 14 GetMACDPath = "/v1/indicators/macd/{ticker}" 15 GetRSIPath = "/v1/indicators/rsi/{ticker}" 16 ) 17 18 // IndicatorsClient defines a REST client for the Polygon Technical Indicators API. 19 type IndicatorsClient struct { 20 client.Client 21 } 22 23 // GetSMA retrieves simple moving average data over the given time range with the specified parameters. 24 // For example, if timespan = 'day' and window = '10', a 10-period simple moving average 25 // will be calculated using day aggregates for each period. 26 // For more details see https://polygon.io/docs/stocks/get_v1_indicators_sma__stockticker. 27 func (ic *IndicatorsClient) GetSMA(ctx context.Context, params *models.GetSMAParams, opts ...models.RequestOption) (*models.GetSMAResponse, error) { 28 res := &models.GetSMAResponse{} 29 err := ic.Call(ctx, http.MethodGet, GetSMAPath, params, res, opts...) 30 return res, err 31 } 32 33 // GetEMA retrieves exponential moving average data over the given time range with the specified parameters. 34 // For example, if timespan = 'day' and window = '10', a 10-period exponential moving average 35 // will be calculated using day aggregates for each period. 36 // For more details see https://polygon.io/docs/stocks/get_v1_indicators_ema__stockticker. 37 func (ic *IndicatorsClient) GetEMA(ctx context.Context, params *models.GetEMAParams, opts ...models.RequestOption) (*models.GetEMAResponse, error) { 38 res := &models.GetEMAResponse{} 39 err := ic.Call(ctx, http.MethodGet, GetEMAPath, params, res, opts...) 40 return res, err 41 } 42 43 // GetMACD retrieves moving average convergence divergence data over the given time range with the specified parameters. 44 // For example, if timespan = 'day', short_window = '12', long_window = '26' and signal_window = '9', 45 // the MACD will be calculated by taking the difference between a 26-period EMA and a 12-period EMA. The signal line values 46 // will be calculated by taking the 9-day ema of the difference, and the histogram values will be calculated by taking 47 // the difference between the MACD values and the signal line. 48 // For more details see https://polygon.io/docs/stocks/get_v1_indicators_macd__stockticker. 49 func (ic *IndicatorsClient) GetMACD(ctx context.Context, params *models.GetMACDParams, opts ...models.RequestOption) (*models.GetMACDResponse, error) { 50 res := &models.GetMACDResponse{} 51 err := ic.Call(ctx, http.MethodGet, GetMACDPath, params, res, opts...) 52 return res, err 53 } 54 55 // GetRSI retrieves relative strength index data over the given time range with the specified parameters. 56 // For example, if timespan = 'day' and window = '10', a 10-period relative strength index 57 // will be calculated using day aggregates for each period. 58 // For more details see https://polygon.io/docs/stocks/get_v1_indicators_rsi__stockticker. 59 func (ic *IndicatorsClient) GetRSI(ctx context.Context, params *models.GetRSIParams, opts ...models.RequestOption) (*models.GetRSIResponse, error) { 60 res := &models.GetRSIResponse{} 61 err := ic.Call(ctx, http.MethodGet, GetRSIPath, params, res, opts...) 62 return res, err 63 }