Documentation ¶
Overview ¶
Package quotes implements multiple price feed adapters.
Index ¶
- Variables
- func NewStrategyVWA(configs ...ConfFuncVWA) priceCalculator
- type BinanceConfig
- type BitfakerConfig
- type ConfFuncVWA
- type Config
- type DisabledFilter
- type Driver
- type DriverConfig
- type DriverType
- type Filter
- type FilterConfig
- type FilterType
- type IndexConfig
- type KrakenConfig
- type Market
- type OpendaxConfig
- type PriceCacheVWA
- type PriceDiffFilter
- type PriceDiffFilterConfig
- type SamplerFilterConfig
- type SyncswapConfig
- type TakerType
- type TradeEvent
- type UniswapV3ApiConfig
- type UniswapV3GethConfig
Constants ¶
This section is empty.
Variables ¶
var ( DefaultWeightsMap = map[DriverType]decimal.Decimal{ DriverKraken: decimal.NewFromInt(15), DriverBinance: decimal.NewFromInt(20), DriverUniswapV3Api: decimal.NewFromInt(50), DriverUniswapV3Geth: decimal.NewFromInt(50), DriverSyncswap: decimal.NewFromInt(50), } AllDrivers = []DriverConfig{ KrakenConfig{}, BinanceConfig{}, UniswapV3ApiConfig{}, SyncswapConfig{}, } )
var ( DriverIndex = DriverType{"index"} DriverBinance = DriverType{"binance"} DriverKraken = DriverType{"kraken"} DriverOpendax = DriverType{"opendax"} DriverBitfaker = DriverType{"bitfaker"} DriverUniswapV3Api = DriverType{"uniswap_v3_api"} DriverUniswapV3Geth = DriverType{"uniswap_v3_geth"} DriverSyncswap = DriverType{"syncswap"} )
var ( TakerTypeUnknown = TakerType{""} TakerTypeBuy = TakerType{"sell"} TakerTypeSell = TakerType{"buy"} )
Functions ¶
func NewStrategyVWA ¶ added in v0.0.26
func NewStrategyVWA(configs ...ConfFuncVWA) priceCalculator
NewStrategyVWA creates a new instance of Volume-Weighted Average Price index price calculator.
Types ¶
type BinanceConfig ¶ added in v0.0.23
type BinanceConfig struct {
Filter FilterConfig `yaml:"filter" env-prefix:"FILTER_"`
}
func (BinanceConfig) DriverType ¶ added in v0.0.23
func (BinanceConfig) DriverType() DriverType
type BitfakerConfig ¶ added in v0.0.23
type BitfakerConfig struct { Period time.Duration `yaml:"period" env:"PERIOD" env-default:"5s"` Filter FilterConfig `yaml:"filter" env-prefix:"FILTER_"` }
func (BitfakerConfig) DriverType ¶ added in v0.0.23
func (BitfakerConfig) DriverType() DriverType
type ConfFuncVWA ¶ added in v0.0.26
type ConfFuncVWA func(*strategyVWA)
func WithCustomPriceCacheVWA ¶ added in v0.0.26
func WithCustomPriceCacheVWA(priceCache *PriceCacheVWA) ConfFuncVWA
WithCustomPriceCacheVWA configures price cache. Should be passed as an argument to the NewStrategyVWA() constructor.
func WithCustomWeightsVWA ¶ added in v0.0.26
func WithCustomWeightsVWA(driversWeights map[DriverType]decimal.Decimal) ConfFuncVWA
WithCustomWeightsVWA configures custom drivers weights. Should be passed as an argument to the NewStrategyVWA() constructor.
type Config ¶
type Config struct { Driver DriverType `yaml:"driver" env:"QUOTES_DRIVER" env-default:"binance"` Binance BinanceConfig `yaml:"binance" env-prefix:"QUOTES_BINANCE_"` Kraken KrakenConfig `yaml:"kraken" env-prefix:"QUOTES_KRAKEN_"` Opendax OpendaxConfig `yaml:"opendax" env-prefix:"QUOTES_OPENDAX_"` Bitfaker BitfakerConfig `yaml:"bitfaker" env-prefix:"QUOTES_BITFAKER_"` UniswapV3Api UniswapV3ApiConfig `yaml:"uniswap_v3_api" env-prefix:"QUOTES_UNISWAP_V3_API_"` UniswapV3Geth UniswapV3GethConfig `yaml:"uniswap_v3_geth" env-prefix:"QUOTES_UNISWAP_V3_GETH_"` Syncswap SyncswapConfig `yaml:"syncswap" env-prefix:"QUOTES_SYNCSWAP_"` Index IndexConfig `yaml:"index" env-prefix:"QUOTES_INDEX_"` }
func NewConfigFromEnv ¶ added in v0.0.22
func NewConfigFromFile ¶ added in v0.0.24
func ToConfig ¶ added in v0.0.26
func ToConfig(driver DriverConfig) Config
type DisabledFilter ¶ added in v0.0.30
type DisabledFilter struct{}
func (DisabledFilter) Allow ¶ added in v0.0.30
func (f DisabledFilter) Allow(trade TradeEvent) bool
type Driver ¶
type Driver interface { Name() DriverType Start() error Stop() error Subscribe(market Market) error Unsubscribe(market Market) error }
func NewIndexAggregator ¶ added in v0.0.26
func NewIndexAggregator(driversConfigs []DriverConfig, strategy priceCalculator, outbox chan<- TradeEvent) Driver
NewIndexAggregator creates a new instance of IndexAggregator.
type DriverConfig ¶ added in v0.0.26
type DriverConfig interface {
DriverType() DriverType
}
type DriverType ¶
type DriverType struct {
// contains filtered or unexported fields
}
DriverType is enum that represents all available quotes providers.
func ToDriverType ¶
func ToDriverType(raw string) (DriverType, error)
func (DriverType) MarshalJSON ¶
func (t DriverType) MarshalJSON() ([]byte, error)
func (DriverType) MarshalYAML ¶
func (t DriverType) MarshalYAML() (any, error)
func (DriverType) String ¶
func (d DriverType) String() string
func (*DriverType) UnmarshalJSON ¶
func (t *DriverType) UnmarshalJSON(raw []byte) error
func (*DriverType) UnmarshalYAML ¶
func (t *DriverType) UnmarshalYAML(value *yaml.Node) error
type Filter ¶ added in v0.0.30
type Filter interface {
Allow(trade TradeEvent) bool
}
func FilterFactory ¶ added in v0.0.30
func FilterFactory(conf FilterConfig) Filter
type FilterConfig ¶ added in v0.0.30
type FilterConfig struct { FilterType FilterType `yaml:"filter_type" env:"TYPE" env-default:"disabled"` SamplerFilter SamplerFilterConfig `yaml:"sampler" env-prefix:"SAMPLER_"` PriceDiffFilter PriceDiffFilterConfig `yaml:"price_diff" env-prefix:"PRICE_DIFF_"` }
type FilterType ¶ added in v0.0.30
type FilterType string
const ( SamplerFilterType FilterType = "sampler" PriceDiffFilterType FilterType = "price_diff" DisabledFilterType FilterType = "disabled" )
type IndexConfig ¶ added in v0.0.26
type IndexConfig struct {
TradesCached int `yaml:"trades_cached" env:"TRADES_CACHED" env-default:"20"`
}
func (IndexConfig) DriverType ¶ added in v0.0.26
func (IndexConfig) DriverType() DriverType
type KrakenConfig ¶ added in v0.0.23
type KrakenConfig struct { URL string `yaml:"url" env:"URL" env-default:"wss://ws.kraken.com"` ReconnectPeriod time.Duration `yaml:"period" env:"RECONNECT_PERIOD" env-default:"5s"` Filter FilterConfig `yaml:"filter" env-prefix:"FILTER_"` }
func (KrakenConfig) DriverType ¶ added in v0.0.23
func (KrakenConfig) DriverType() DriverType
type Market ¶
type Market struct {
// contains filtered or unexported fields
}
func NewMarketFromString ¶ added in v0.0.26
NewMarketFromString returns a new Market from a string "btc/usdt" -> Market{btc, usdt} NOTE: string should contain "/" delimiter
type OpendaxConfig ¶ added in v0.0.23
type OpendaxConfig struct { URL string `yaml:"url" env:"URL" env-default:"wss://alpha.yellow.org/api/v1/finex/ws"` ReconnectPeriod time.Duration `yaml:"period" env:"RECONNECT_PERIOD" env-default:"5s"` Filter FilterConfig `yaml:"filter" env-prefix:"FILTER_"` }
func (OpendaxConfig) DriverType ¶ added in v0.0.23
func (OpendaxConfig) DriverType() DriverType
type PriceCacheVWA ¶ added in v0.0.26
type PriceCacheVWA struct {
// contains filtered or unexported fields
}
func NewPriceCacheVWA ¶ added in v0.0.26
func NewPriceCacheVWA(driversWeights map[DriverType]decimal.Decimal, nTrades int) *PriceCacheVWA
NewPriceCacheVWA initializes a new cache to store last n trades for each market.
func (*PriceCacheVWA) ActivateDriver ¶ added in v0.0.26
func (p *PriceCacheVWA) ActivateDriver(driver DriverType, market Market)
ActivateDriver makes the driver active for the market.
func (*PriceCacheVWA) ActiveWeights ¶ added in v0.0.26
func (p *PriceCacheVWA) ActiveWeights(market Market) decimal.Decimal
ActiveWeights returns the sum of active driver weights for the market. TODO: cache the weights inside the marketHistory
type PriceDiffFilter ¶ added in v0.0.30
type PriceDiffFilter struct {
// contains filtered or unexported fields
}
func (*PriceDiffFilter) Allow ¶ added in v0.0.30
func (f *PriceDiffFilter) Allow(trade TradeEvent) bool
type PriceDiffFilterConfig ¶ added in v0.0.30
type PriceDiffFilterConfig struct {
Threshold string `yaml:"threshold" env:"THRESHOLD" env-default:"0.05"`
}
type SamplerFilterConfig ¶ added in v0.0.30
type SamplerFilterConfig struct {
Percentage int64 `yaml:"percentage" env:"PERCENTAGE" env-default:"5"`
}
type SyncswapConfig ¶ added in v0.0.23
type SyncswapConfig struct { URL string `yaml:"url" env:"URL" env-default:""` AssetsURL string `` /* 136-byte string literal not displayed */ ClassicPoolFactoryAddress string `` /* 127-byte string literal not displayed */ Filter FilterConfig `yaml:"filter" env-prefix:"FILTER_"` }
func (SyncswapConfig) DriverType ¶ added in v0.0.23
func (SyncswapConfig) DriverType() DriverType
type TakerType ¶
type TakerType struct {
// contains filtered or unexported fields
}
TakerType is enum that represents the side of taker in a trade.
func ToTakerType ¶
func (TakerType) MarshalJSON ¶
func (TakerType) MarshalYAML ¶
func (*TakerType) UnmarshalJSON ¶
func (*TakerType) UnmarshalYAML ¶
type TradeEvent ¶
type TradeEvent struct { Source DriverType Market Market // e.g. `btc/usdt` Price decimal.Decimal Amount decimal.Decimal Total decimal.Decimal TakerType TakerType CreatedAt time.Time }
TradeEvent is a generic container for trades received from providers.
type UniswapV3ApiConfig ¶ added in v0.0.23
type UniswapV3ApiConfig struct { URL string `yaml:"url" env:"URL" env-default:"https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3"` WindowSize time.Duration `yaml:"window_size" env:"WINDOW_SIZE" env-default:"2s"` Filter FilterConfig `yaml:"filter" env-prefix:"FILTER_"` }
func (UniswapV3ApiConfig) DriverType ¶ added in v0.0.23
func (UniswapV3ApiConfig) DriverType() DriverType
type UniswapV3GethConfig ¶ added in v0.0.23
type UniswapV3GethConfig struct { URL string `yaml:"url" env:"GETH_URL" env-default:""` AssetsURL string `` /* 136-byte string literal not displayed */ FactoryAddress string `yaml:"factory_address" env:"FACTORY_ADDRESS" env-default:"0x1F98431c8aD98523631AE4a59f267346ea31F984"` Filter FilterConfig `yaml:"filter" env-prefix:"FILTER_"` }
func (UniswapV3GethConfig) DriverType ¶ added in v0.0.23
func (UniswapV3GethConfig) DriverType() DriverType
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Types and helpers for easy formatting and parsing open-finance protocol messages.
|
Types and helpers for easy formatting and parsing open-finance protocol messages. |
App for testing quotes drivers.
|
App for testing quotes drivers. |