Skip to content

Commit

Permalink
Merge pull request #202 from vegaprotocol/add-metadata-filters
Browse files Browse the repository at this point in the history
feat: add metadata filters for markets fetch
  • Loading branch information
daniel1302 authored May 22, 2023
2 parents 30650e8 + cec56ac commit f85f45a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
51 changes: 44 additions & 7 deletions bot/normal/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ func New(config config.BotConfig, pe PricingEngine, ws *wallets.Handler) (b *Bot
return
}

func validMetadata(tags []string, metadata string) bool {
if len(tags) < 1 {
return false
}

for _, tag := range tags {
if tag == metadata {
return true
}
}

return false
}

// Start starts the liquidity bot goroutine(s).
func (b *Bot) Start() error {
_, err := b.setupWallet()
Expand Down Expand Up @@ -198,23 +212,46 @@ func (b *Bot) Start() error {
}
}
}
if base == b.config.InstrumentBase && quote == b.config.InstrumentQuote {
future := mkt.TradableInstrument.Instrument.GetFuture()
if future != nil {
b.settlementAssetID = future.SettlementAsset
b.market = mkt
break
if base != b.config.InstrumentBase || quote != b.config.InstrumentQuote {
continue
}

future := mkt.TradableInstrument.Instrument.GetFuture()
if future == nil {
continue
}

if len(b.config.MetadataFilters) > 0 {
// We want additional metadata to filter markets, but market does not have any
if mkt.TradableInstrument.Instrument.Metadata == nil {
continue
}

filtersMatch := false
for _, filter := range b.config.MetadataFilters {
// Market has no expected metadata
if validMetadata(mkt.TradableInstrument.Instrument.Metadata.Tags, filter) {
filtersMatch = true
}
}

if !filtersMatch {
continue
}
}

b.settlementAssetID = future.SettlementAsset
b.market = mkt
}
}
if b.market == nil {
return fmt.Errorf("failed to find futures markets: base/ticker=%s, quote=%s", b.config.InstrumentBase, b.config.InstrumentQuote)
return fmt.Errorf("failed to find futures markets: base/ticker=%s, quote=%s, metadata_filters=%#v", b.config.InstrumentBase, b.config.InstrumentQuote, b.config.MetadataFilters)
}
b.log.WithFields(log.Fields{
"id": b.market.Id,
"base/ticker": b.config.InstrumentBase,
"quote": b.config.InstrumentQuote,
"metadata_filters": b.config.MetadataFilters,
"settlementAssetID": b.settlementAssetID,
}).Info("Fetched market info")

Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type BotConfig struct {

// StrategyDetails contains the parameters needed by the strategy algorithm.
StrategyDetails Strategy `yaml:"strategyDetails"`

// Additional metadata filters for the selecting markets
MetadataFilters []string `yaml:"metadataFilters"`
}

// Strategy describes parameters for the bot's strategy.
Expand Down

0 comments on commit f85f45a

Please sign in to comment.