-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b314c28
commit bb97231
Showing
26 changed files
with
2,787 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package bot | ||
|
||
import ( | ||
"code.vegaprotocol.io/liqbot/config" | ||
|
||
ppconfig "code.vegaprotocol.io/priceproxy/config" | ||
ppservice "code.vegaprotocol.io/priceproxy/service" | ||
tcwallet "code.vegaprotocol.io/vega/wallet" | ||
) | ||
|
||
// PricingEngine is the source of price information from the price proxy. | ||
//go:generate go run github.com/golang/mock/mockgen -destination mocks/pricingengine_mock.go -package mocks code.vegaprotocol.io/liqbot/bot PricingEngine | ||
type PricingEngine interface { | ||
GetPrice(pricecfg ppconfig.PriceConfig) (pi ppservice.PriceResponse, err error) | ||
} | ||
|
||
// LiqBot represents one liquidity bot. | ||
type LiqBot struct { | ||
config config.BotConfig | ||
pricingEngine PricingEngine | ||
walletServer tcwallet.WalletHandler | ||
} | ||
|
||
// New returns a new instance of LiqBot. | ||
func New(config config.BotConfig, pe PricingEngine, ws tcwallet.WalletHandler) *LiqBot { | ||
lb := LiqBot{ | ||
config: config, | ||
pricingEngine: pe, | ||
walletServer: ws, | ||
} | ||
return &lb | ||
} | ||
|
||
// Start starts the liquidity bot goroutine(s). | ||
func (lb *LiqBot) Start() { | ||
go lb.run() | ||
} | ||
|
||
// Stop stops the liquidity bot goroutine(s). | ||
func (lb *LiqBot) Stop() { | ||
// TBD | ||
} | ||
|
||
func (lb *LiqBot) run() { | ||
// TBD | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Command liqbot runs one application instance which may contain many bots that | ||
// provide liquidity. Each bot connects to one Vega node and submits orders to | ||
// one market. | ||
// | ||
// $ make install | ||
// $ $GOPATH/bin/liqbot -config=config.yml | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package config contains structures and functions for configuring the app. | ||
package config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package core | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"sort" | ||
"strings" | ||
|
||
ppconfig "code.vegaprotocol.io/priceproxy/config" | ||
"code.vegaprotocol.io/vega/proto" | ||
) | ||
|
||
var currencyPairBaseTags = []string{ | ||
"base:", | ||
"ticker:", | ||
} | ||
|
||
var currencyPairQuoteTags = []string{ | ||
"quote:", | ||
} | ||
|
||
var currencyPairCountryTags = []string{ | ||
"country:", | ||
} | ||
|
||
var countryToCurrency = map[string]string{ | ||
"US": "USD", | ||
} | ||
|
||
// MarketToPriceConfig converts a Market object to a PriceConfig object by looking in the Market's instrument metadata tag list. | ||
func MarketToPriceConfig(mkt *proto.Market) (*ppconfig.PriceConfig, error) { | ||
if mkt == nil || mkt.TradableInstrument == nil || mkt.TradableInstrument.Instrument == nil || | ||
mkt.TradableInstrument.Instrument.Metadata == nil { | ||
return nil, errors.New("failed to create PriceConfig from Market (nil)") | ||
} | ||
if len(mkt.TradableInstrument.Instrument.Metadata.Tags) == 0 { | ||
return nil, errors.New("failed to create PriceConfig from Market (zero Tags)") | ||
} | ||
base := "?" | ||
quote := "?" | ||
sort.Strings(mkt.TradableInstrument.Instrument.Metadata.Tags) | ||
for _, tag := range mkt.TradableInstrument.Instrument.Metadata.Tags { | ||
for _, pfx := range currencyPairBaseTags { | ||
if strings.HasPrefix(tag, pfx) { | ||
base = tag[len(pfx):] | ||
} | ||
} | ||
for _, pfx := range currencyPairQuoteTags { | ||
if strings.HasPrefix(tag, pfx) { | ||
quote = tag[len(pfx):] | ||
} | ||
} | ||
for _, pfx := range currencyPairCountryTags { | ||
if strings.HasPrefix(tag, pfx) { | ||
var found bool | ||
quote, found = countryToCurrency[tag[len(pfx):]] | ||
if !found { | ||
return nil, fmt.Errorf("can't map country to currency: %s", tag[len(pfx):]) | ||
} | ||
} | ||
} | ||
} | ||
if base == "?" { | ||
return nil, errors.New("failed to create PriceConfig from Market (missing Base)") | ||
} | ||
if quote == "?" { | ||
return nil, errors.New("failed to create PriceConfig from Market (missing Quote)") | ||
} | ||
|
||
return &ppconfig.PriceConfig{Base: base, Quote: quote}, nil | ||
} |
Oops, something went wrong.