Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle astroport asset response returning inconsistent data type #332

Merged
merged 8 commits into from
Jan 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions oracle/provider/astroport.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@

// AstroportAssetResponse is the response from the Astroport assets endpoint.
AstroportAssetResponse struct {
BaseID string `json:"base_id"`
BaseName string `json:"base_name"`
BaseSymbol string `json:"base_symbol"`
QuoteID string `json:"quote_id"`
QuoteName string `json:"quote_name"`
QuoteSymbol string `json:"quote_symbol"`
LastPrice float64 `json:"last_price"`
BaseVolume float64 `json:"base_volume"`
QuoteVolume float64 `json:"quote_volume"`
USDVolume float64 `json:"USD_volume"`
BaseID string `json:"base_id"`
BaseName string `json:"base_name"`
BaseSymbol string `json:"base_symbol"`
QuoteID string `json:"quote_id"`
QuoteName string `json:"quote_name"`
QuoteSymbol interface{} `json:"quote_symbol"`
LastPrice float64 `json:"last_price"`
BaseVolume float64 `json:"base_volume"`
QuoteVolume float64 `json:"quote_volume"`
USDVolume float64 `json:"USD_volume"`
}
// AstroportTickersResponse is the response from the Astroport tickers endpoint.
AstroportTickersResponse struct {
Expand Down Expand Up @@ -215,9 +215,18 @@
availablePairs := map[string]types.CurrencyPair{}
for _, assetMap := range astroportAssets {
for tickerID, asset := range assetMap {
// Some responses can return a 0 number value for Quote Symbol which
// needs to be handled here.
quoteSymbol := ""
switch asset.QuoteSymbol.(type) {

Check failure on line 221 in oracle/provider/astroport.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

typeSwitchVar: 1 case can benefit from type switch with assignment (gocritic)
case string:
quoteSymbol = strings.ToUpper(asset.QuoteSymbol.(string))
default:
// leave quote symbol to be empty string
}
availablePairs[tickerID] = types.CurrencyPair{
Base: strings.ToUpper(asset.BaseSymbol),
Quote: strings.ToUpper(asset.QuoteSymbol),
Quote: quoteSymbol,
}
}
}
Expand Down
Loading