Metrics Div and Earnings Added
Added Dividends and Earnings Metrics. Fixed MarketMetric function.
This commit is contained in:
41
metrics.go
41
metrics.go
@@ -6,6 +6,30 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type DividendInfo struct {
|
||||||
|
OccuredDate string `json:"occurred-date"`
|
||||||
|
Amount float32 `json:"amount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MarketMetricDividendResponse struct {
|
||||||
|
Data struct {
|
||||||
|
Items []DividendInfo `json:"items"`
|
||||||
|
}
|
||||||
|
Context string `json:"context"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type EarningsInfo struct {
|
||||||
|
OccuredDate string `json:"occurred-date"`
|
||||||
|
EPS float32 `json:"eps"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MarketMetricEarningResponse struct {
|
||||||
|
Data struct {
|
||||||
|
Items []EarningsInfo `json:"items"`
|
||||||
|
}
|
||||||
|
Context string `json:"context"`
|
||||||
|
}
|
||||||
|
|
||||||
type MarketMetricInfo struct {
|
type MarketMetricInfo struct {
|
||||||
Symbol string `json:"symbol"`
|
Symbol string `json:"symbol"`
|
||||||
ImpliedVolatilityIndex float32 `json:"implied-volatility-index"`
|
ImpliedVolatilityIndex float32 `json:"implied-volatility-index"`
|
||||||
@@ -23,22 +47,29 @@ type MarketMetricInfo struct {
|
|||||||
} `json:"option-expiration-implied-volatilities"`
|
} `json:"option-expiration-implied-volatilities"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *TastytradeAPI) GetMarketMetricInfo(symbol string) (MarketMetricInfo, error) {
|
type MarketMetricResponse struct {
|
||||||
|
Data struct {
|
||||||
|
Items []MarketMetricInfo `json:"items"`
|
||||||
|
}
|
||||||
|
Context string `json:"context"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *TastytradeAPI) GetMarketMetricInfo(symbol string) (MarketMetricResponse, error) {
|
||||||
urlVal := fmt.Sprintf("%s/market-metrics/%s", api.host, url.PathEscape(symbol))
|
urlVal := fmt.Sprintf("%s/market-metrics/%s", api.host, url.PathEscape(symbol))
|
||||||
data, err := api.fetchData(urlVal)
|
data, err := api.fetchData(urlVal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MarketMetricInfo{}, err
|
return MarketMetricResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var response MarketMetricInfo
|
var response MarketMetricResponse
|
||||||
jsonData, err := json.Marshal(data)
|
jsonData, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MarketMetricInfo{}, err
|
return MarketMetricResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(jsonData, &response)
|
err = json.Unmarshal(jsonData, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MarketMetricInfo{}, err
|
return MarketMetricResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user