Skip to content

Commit

Permalink
feat: gate provider implementation (#611)
Browse files Browse the repository at this point in the history
## Description



Adds gate.io as a provider to support [umee/usdt](https://www.gate.io/trade/UMEE_USDT)

closes: #604

----

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added appropriate labels to the PR
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
adamewozniak authored Mar 8, 2022
1 parent 026def7 commit 9e4b1aa
Show file tree
Hide file tree
Showing 8 changed files with 654 additions and 0 deletions.
12 changes: 12 additions & 0 deletions price-feeder/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
ProviderOsmosis = "osmosis"
ProviderHuobi = "huobi"
ProviderOkx = "okx"
ProviderGate = "gate"
ProviderMock = "mock"
)

Expand All @@ -40,6 +41,7 @@ var (
ProviderOsmosis: {},
ProviderOkx: {},
ProviderHuobi: {},
ProviderGate: {},
ProviderMock: {},
}
)
Expand Down Expand Up @@ -197,5 +199,15 @@ func ParseConfig(configPath string) (Config, error) {
}
}

gatePairs := []string{}
for base, providers := range pairs {
if _, ok := providers["gate"]; ok {
gatePairs = append(gatePairs, base)
}
}
if len(gatePairs) > 1 {
return cfg, fmt.Errorf("gate provider does not support multiple pairs: %v", gatePairs)
}

return cfg, cfg.Validate()
}
7 changes: 7 additions & 0 deletions price-feeder/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ func (o *Oracle) getOrSetProvider(ctx context.Context, providerName string) (pro
}
priceProvider = okxProvider

case config.ProviderGate:
gateProvider, err := provider.NewGateProvider(ctx, o.logger, o.providerPairs[config.ProviderGate]...)
if err != nil {
return nil, err
}
priceProvider = gateProvider

case config.ProviderMock:
priceProvider = provider.NewMockProvider()
}
Expand Down
8 changes: 8 additions & 0 deletions price-feeder/oracle/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (m mockProvider) GetCandlePrices(_ ...types.CurrencyPair) (map[string][]pro
return candles, nil
}

func (m mockProvider) SubscribeCurrencyPairs(_ ...types.CurrencyPair) error {
return nil
}

type failingProvider struct {
prices map[string]provider.TickerPrice
}
Expand All @@ -53,6 +57,10 @@ func (m failingProvider) GetCandlePrices(_ ...types.CurrencyPair) (map[string][]
return nil, fmt.Errorf("unable to get candle prices")
}

func (m failingProvider) SubscribeCurrencyPairs(_ ...types.CurrencyPair) error {
return nil
}

type OracleTestSuite struct {
suite.Suite

Expand Down
Loading

0 comments on commit 9e4b1aa

Please sign in to comment.