Added First Metrics
All checks were successful
Continuous Integration / CI (push) Successful in 2m46s
All checks were successful
Continuous Integration / CI (push) Successful in 2m46s
This commit is contained in:
46
metrics.go
Normal file
46
metrics.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package tastytrade
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MarketMetricInfo struct {
|
||||||
|
Symbol string `json:"symbol"`
|
||||||
|
ImpliedVolatilityIndex float32 `json:"implied-volatility-index"`
|
||||||
|
ImpliedVolatilityIndex5DayChange float32 `json:"implied-volatility-index-5-day-change"`
|
||||||
|
ImpliedVolatilityRank float32 `json:"implied-volatility-rank"`
|
||||||
|
ImpliedVolatilityPercentile float32 `json:"implied-volatility-percentile"`
|
||||||
|
Liquidity float32 `json:"liquidity"`
|
||||||
|
LiquidityRank float32 `json:"liquidity-rank"`
|
||||||
|
LiquidityRating int32 `json:"liquidity-rating"`
|
||||||
|
OptionExpirationImpliedVolatilities []struct {
|
||||||
|
ExpirationDate string `json:"expiration-date"`
|
||||||
|
SettlementType string `json:"settlement-type"`
|
||||||
|
OptionChainType string `json:"option-chain-type"`
|
||||||
|
ImpliedVolatility float64 `json:"implied-volatility"`
|
||||||
|
} `json:"option-expiration-implied-volatilities"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *TastytradeAPI) GetMarketMetricInfo(symbol string) (MarketMetricInfo, error) {
|
||||||
|
urlVal := fmt.Sprintf("%s/market-metrics/%s", api.host, url.PathEscape(symbol))
|
||||||
|
data, err := api.fetchData(urlVal)
|
||||||
|
if err != nil {
|
||||||
|
return MarketMetricInfo{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var response MarketMetricInfo
|
||||||
|
jsonData, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return MarketMetricInfo{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(jsonData, &response)
|
||||||
|
if err != nil {
|
||||||
|
return MarketMetricInfo{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user