Documentation ¶
Overview ¶
Package dola provides cryptocurrency trading primitives: exchange integrations (via github.com/thrasher-corp/gocryptotrader), event-driven strategies, utilities and more.
Holdings contains related functions / types
The toolbelt is a set of helper functions that eases strategies and cross usage.
Index ¶
- Constants
- Variables
- func CheckerAssert()
- func CheckerPop(xs ...string)
- func CheckerPush(xs ...string)
- func Code(e *zerolog.Event, code string)
- func ConfigFile(inp string) string
- func ExpandUser(path string) string
- func FileExists(path string) bool
- func Location() string
- func Location2() string
- func Loop(ctx context.Context, k *Keep, e exchange.IBotExchange, s Strategy) error
- func ModifyOrder(ctx context.Context, k *Keep, e exchange.IBotExchange, mod order.Modify) (ans order.Modify, err error)
- func ModifyToCancel(mod order.Modify) order.Cancel
- func ModifyToSubmit(mod order.Modify) order.Submit
- func Msg(e *zerolog.Event)
- func RandomOrderID(prefix string) string
- func Stream(ctx context.Context, k *Keep, e exchange.IBotExchange, s Strategy) error
- func Ticker(p interface{}) ticker.Price
- func What(e *zerolog.Event, what string)
- type Array
- type AugmentConfigFunc
- type AwakenLogger
- type BalancesStrategy
- func (b *BalancesStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
- func (b *BalancesStrategy) ExchangeHoldings(exchangeName string) (*ExchangeHoldings, error)
- func (b *BalancesStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
- func (b *BalancesStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
- func (b *BalancesStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
- func (b *BalancesStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
- func (b *BalancesStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
- func (b *BalancesStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
- func (b *BalancesStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
- func (b *BalancesStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
- func (b *BalancesStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
- func (b *BalancesStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
- func (b *BalancesStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
- type CircularArray
- func (a *CircularArray) At(index int) interface{}
- func (a *CircularArray) Floats() []float64
- func (a *CircularArray) Index(i int) int
- func (a *CircularArray) Last() interface{}
- func (a *CircularArray) LastFloat() float64
- func (a *CircularArray) LastIndex() int
- func (a *CircularArray) Len() int
- func (a *CircularArray) Push(x interface{})
- type CurrencyBalance
- type DedicatedStrategy
- func (d *DedicatedStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
- func (d *DedicatedStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
- func (d *DedicatedStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
- func (d *DedicatedStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
- func (d *DedicatedStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
- func (d *DedicatedStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
- func (d *DedicatedStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
- func (d *DedicatedStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
- func (d *DedicatedStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
- func (d *DedicatedStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
- func (d *DedicatedStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
- func (d *DedicatedStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
- type ErrorWaitGroup
- type ExchangeFactory
- type ExchangeHoldings
- type GCTConsoleWriter
- type Historian
- type HistoryStrategy
- func (r *HistoryStrategy) AddHistorian(exchangeName, eventName string, interval time.Duration, stateLength int, ...) error
- func (r *HistoryStrategy) BindOnPrice(unit *Historian)
- func (r *HistoryStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
- func (r *HistoryStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
- func (r *HistoryStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
- func (r *HistoryStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
- func (r *HistoryStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
- func (r *HistoryStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
- func (r *HistoryStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
- func (r *HistoryStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
- func (r *HistoryStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
- func (r *HistoryStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
- func (r *HistoryStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
- func (r *HistoryStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
- type Keep
- func (bot *Keep) ActivateAsset(e exchange.IBotExchange, a asset.Item) error
- func (bot *Keep) ActivatePair(e exchange.IBotExchange, a asset.Item, p currency.Pair) error
- func (bot *Keep) AddHistorian(exchangeName, eventName string, interval time.Duration, stateLength int, ...) error
- func (bot *Keep) CancelAllOrders(ctx context.Context, exchangeOrName interface{}, assetType asset.Item, ...) (order.CancelAllResponse, error)
- func (bot *Keep) CancelOrder(ctx context.Context, exchangeOrName interface{}, x order.Cancel) error
- func (bot *Keep) CancelOrdersByPrefix(ctx context.Context, exchangeOrName interface{}, x order.Cancel, prefix string) error
- func (bot *Keep) GetActiveOrders(ctx context.Context, exchangeOrName interface{}, ...) ([]order.Detail, error)
- func (bot *Keep) GetEnabledPairAssetType(e exchange.IBotExchange, c currency.Pair) (asset.Item, error)
- func (bot *Keep) GetExchangeByName(name string) (exchange.IBotExchange, error)
- func (bot *Keep) GetExchanges() []exchange.IBotExchange
- func (bot *Keep) GetOrderValue(exchangeName, orderID string) (OrderValue, bool)
- func (bot *Keep) ModifyOrder(ctx context.Context, exchangeOrName interface{}, mod order.Modify) (order.Modify, error)
- func (bot *Keep) OnOrder(e exchange.IBotExchange, x order.Detail)
- func (bot *Keep) ReportEvent(m Metric, labels ...string)
- func (bot *Keep) ReportLatency(m Metric, t time.Time, labels ...string)
- func (bot *Keep) ReportValue(m Metric, v float64, labels ...string)
- func (bot *Keep) Run(ctx context.Context)
- func (bot *Keep) SubmitOrder(ctx context.Context, exchangeOrName interface{}, submit order.Submit) (order.SubmitResponse, error)
- func (bot *Keep) SubmitOrderUD(ctx context.Context, exchangeOrName interface{}, submit order.Submit, ...) (order.SubmitResponse, error)
- func (bot *Keep) SubmitOrders(ctx context.Context, e exchange.IBotExchange, xs ...order.Submit) error
- type KeepBuilder
- func (b *KeepBuilder) Augment(f AugmentConfigFunc) *KeepBuilder
- func (b *KeepBuilder) Balances(refreshRate time.Duration) *KeepBuilder
- func (b *KeepBuilder) Build(ctx context.Context) (*Keep, error)
- func (b *KeepBuilder) CustomExchange(f ExchangeFactory) *KeepBuilder
- func (b *KeepBuilder) Reporter(r Reporter) *KeepBuilder
- func (b *KeepBuilder) Settings(s engine.Settings) *KeepBuilder
- type LogState
- type Metric
- type OnFilledObserver
- type OrderKey
- type OrderRegistry
- type OrderValue
- type Profiler
- type Reporter
- type RootStrategy
- func (m *RootStrategy) Add(name string, s Strategy)
- func (m *RootStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
- func (m *RootStrategy) Delete(name string) (Strategy, error)
- func (m *RootStrategy) Get(name string) (Strategy, error)
- func (m *RootStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
- func (m *RootStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
- func (m *RootStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
- func (m *RootStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
- func (m *RootStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
- func (m *RootStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
- func (m *RootStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
- func (m *RootStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
- func (m *RootStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
- func (m *RootStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
- func (m *RootStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
- type Slots
- type Strategy
- type SubAccount
- type TickerStrategy
- func (s *TickerStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
- func (s *TickerStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
- func (s *TickerStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
- func (s *TickerStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
- func (s *TickerStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
- func (s *TickerStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
- func (s *TickerStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
- func (s *TickerStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
- func (s *TickerStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
- func (s *TickerStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
- func (s *TickerStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
- func (s *TickerStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
- type Trade
- type VerboseStrategy
- func (v VerboseStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
- func (v VerboseStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
- func (v VerboseStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
- func (v VerboseStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
- func (v VerboseStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
- func (v VerboseStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
- func (v VerboseStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
- func (v VerboseStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
- func (v VerboseStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
- func (v VerboseStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
- func (v VerboseStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
- func (v VerboseStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
Examples ¶
Constants ¶
const ( // In dormant mode the AwakenLogger outputs trace logs as info // every once in a while. Dormant = iota // In awaken mode everything is outputted as-is. Awaken = iota )
Variables ¶
var ( ErrNoExchangesLoaded = errors.New("no exchanges have been loaded") ErrExchangeFailedToLoad = errors.New("exchange failed to load") )
var ( ErrAccountIndexOutOfRange = errors.New("no account with this index exists") ErrHoldingsNotFound = errors.New("holdings not found for exchange") ErrAccountNotFound = errors.New("account not found in holdings") ErrAssetNotFound = errors.New("asset not found in account") ErrCurrencyNotFound = errors.New("currency not found in asset") )
var ( ErrStrategyNotFound = errors.New("strategy not found") ErrNotStrategy = errors.New("given object is not a strategy") )
var ( ErrWebsocketNotSupported = errors.New("websocket not supported") ErrWebsocketNotEnabled = errors.New("websocket is not enabled") )
var ErrCreatorNotRegistered = errors.New("exchange creator not registered")
var ErrNeedBalancesStrategy = errors.New("Keep should be configured with balances support")
var ErrNoAssetType = errors.New("asset type not associated with currency pair")
var ErrOrdersAlreadyExists = errors.New("order already exists")
var ErrUnknownEvent = errors.New("unknown event")
Functions ¶
func CheckerPop ¶
func CheckerPop(xs ...string)
func CheckerPush ¶
func CheckerPush(xs ...string)
func ConfigFile ¶
ConfigFile checks whether a file with the given path exists. If it doesnt, it falls back to: (1) $DOLA_CONFIG, (2) ~/.dola.config.json or (3) returns an empty string.
func ExpandUser ¶
ExpandUser returns the argument with an initial ~ replaced by user's home directory.
func FileExists ¶
func Location2 ¶
func Location2() string
Location2 returns the name of the caller of the caller function.
func ModifyOrder ¶
func RandomOrderID ¶
RandomOrderID uses code and ideas from: https://stackoverflow.com/questions/32349807 and https://stackoverflow.com/questions/13378815 .
Length of produced client order ID is encoded in the code. See `seed`.
Types ¶
type AugmentConfigFunc ¶
type AwakenLogger ¶
type AwakenLogger struct {
// contains filtered or unexported fields
}
func NewAwakenLogger ¶
func NewAwakenLogger(d time.Duration) AwakenLogger
func (*AwakenLogger) Trace ¶
func (t *AwakenLogger) Trace() *zerolog.Event
func (*AwakenLogger) WakeUp ¶
func (t *AwakenLogger) WakeUp()
WakeUp gets the AwakenLogger out of its dormant state for a an amount of time.
type BalancesStrategy ¶
type BalancesStrategy struct {
// contains filtered or unexported fields
}
func (*BalancesStrategy) Deinit ¶
func (b *BalancesStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
func (*BalancesStrategy) ExchangeHoldings ¶
func (b *BalancesStrategy) ExchangeHoldings(exchangeName string) (*ExchangeHoldings, error)
func (*BalancesStrategy) Init ¶
func (b *BalancesStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
func (*BalancesStrategy) OnBalanceChange ¶
func (b *BalancesStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
func (*BalancesStrategy) OnFill ¶
func (b *BalancesStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
func (*BalancesStrategy) OnFunding ¶
func (b *BalancesStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
func (*BalancesStrategy) OnKline ¶
func (b *BalancesStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
func (*BalancesStrategy) OnModify ¶
func (b *BalancesStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
func (*BalancesStrategy) OnOrder ¶
func (b *BalancesStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
func (*BalancesStrategy) OnOrderBook ¶
func (b *BalancesStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
func (*BalancesStrategy) OnPrice ¶
func (b *BalancesStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
func (*BalancesStrategy) OnTrade ¶
func (b *BalancesStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
func (*BalancesStrategy) OnUnrecognized ¶
func (b *BalancesStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
type CircularArray ¶
type CircularArray struct { Offset int // contains filtered or unexported fields }
func NewCircularArray ¶
func NewCircularArray(n int) CircularArray
func (*CircularArray) At ¶
func (a *CircularArray) At(index int) interface{}
func (*CircularArray) Floats ¶
func (a *CircularArray) Floats() []float64
func (*CircularArray) Index ¶
func (a *CircularArray) Index(i int) int
Index maps an external 0-based index to the corresponding internal index.
func (*CircularArray) Last ¶
func (a *CircularArray) Last() interface{}
func (*CircularArray) LastFloat ¶
func (a *CircularArray) LastFloat() float64
func (*CircularArray) LastIndex ¶
func (a *CircularArray) LastIndex() int
func (*CircularArray) Len ¶
func (a *CircularArray) Len() int
func (*CircularArray) Push ¶
func (a *CircularArray) Push(x interface{})
type CurrencyBalance ¶
Balance is a sub type to store currency name and individual totals.
type DedicatedStrategy ¶
DedicatedStrategy is a Strategy wrapper that executes wrapped methods only when events come from a particular exchange.
func (*DedicatedStrategy) Deinit ¶
func (d *DedicatedStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
func (*DedicatedStrategy) Init ¶
func (d *DedicatedStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
func (*DedicatedStrategy) OnBalanceChange ¶
func (d *DedicatedStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
func (*DedicatedStrategy) OnFill ¶
func (d *DedicatedStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
func (*DedicatedStrategy) OnFunding ¶
func (d *DedicatedStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
func (*DedicatedStrategy) OnKline ¶
func (d *DedicatedStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
func (*DedicatedStrategy) OnModify ¶
func (d *DedicatedStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
func (*DedicatedStrategy) OnOrder ¶
func (d *DedicatedStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
func (*DedicatedStrategy) OnOrderBook ¶
func (d *DedicatedStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
func (*DedicatedStrategy) OnPrice ¶
func (d *DedicatedStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
func (*DedicatedStrategy) OnTrade ¶
func (d *DedicatedStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
func (*DedicatedStrategy) OnUnrecognized ¶
func (d *DedicatedStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
type ErrorWaitGroup ¶
type ErrorWaitGroup struct {
// contains filtered or unexported fields
}
func (*ErrorWaitGroup) Add ¶
func (m *ErrorWaitGroup) Add(delta int)
func (*ErrorWaitGroup) Done ¶
func (m *ErrorWaitGroup) Done(right error)
func (*ErrorWaitGroup) Wait ¶
func (m *ErrorWaitGroup) Wait() error
type ExchangeFactory ¶
type ExchangeFactory func(name string) (exchange.IBotExchange, error)
func (ExchangeFactory) NewExchangeByName ¶
func (e ExchangeFactory) NewExchangeByName(name string) (exchange.IBotExchange, error)
NewExchangeByName implements gocryptotrader/engine.CustomExchangeBuilder.
type ExchangeHoldings ¶
type ExchangeHoldings struct {
Accounts map[string]SubAccount
}
Holdings maps account ids to SubAccounts.
func NewExchangeHoldings ¶
func NewExchangeHoldings() *ExchangeHoldings
func (*ExchangeHoldings) CurrencyBalance ¶
func (h *ExchangeHoldings) CurrencyBalance(accountID string, asset asset.Item, code currency.Code) (CurrencyBalance, error)
type GCTConsoleWriter ¶
type GCTConsoleWriter struct{}
type Historian ¶
type Historian struct {
// contains filtered or unexported fields
}
func NewHistorian ¶
type HistoryStrategy ¶
type HistoryStrategy struct {
// contains filtered or unexported fields
}
func NewHistoryStrategy ¶
func NewHistoryStrategy() HistoryStrategy
func (*HistoryStrategy) AddHistorian ¶
func (*HistoryStrategy) BindOnPrice ¶
func (r *HistoryStrategy) BindOnPrice(unit *Historian)
func (*HistoryStrategy) Deinit ¶
func (r *HistoryStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
func (*HistoryStrategy) Init ¶
func (r *HistoryStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
func (*HistoryStrategy) OnBalanceChange ¶
func (r *HistoryStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
func (*HistoryStrategy) OnFill ¶
func (r *HistoryStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
func (*HistoryStrategy) OnFunding ¶
func (r *HistoryStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
func (*HistoryStrategy) OnKline ¶
func (r *HistoryStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
func (*HistoryStrategy) OnModify ¶
func (r *HistoryStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
func (*HistoryStrategy) OnOrder ¶
func (r *HistoryStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
func (*HistoryStrategy) OnOrderBook ¶
func (r *HistoryStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
func (*HistoryStrategy) OnPrice ¶
func (r *HistoryStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
func (*HistoryStrategy) OnTrade ¶
func (r *HistoryStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
func (*HistoryStrategy) OnUnrecognized ¶
func (r *HistoryStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
type Keep ¶
type Keep struct { Config config.Config ExchangeManager engine.ExchangeManager Root RootStrategy Settings engine.Settings // contains filtered or unexported fields }
Example ¶
package main import ( "context" "github.com/numeusxyz/dola" ) func main() { keep, _ := dola.NewKeepBuilder().Build(context.Background()) keep.Root.Add("verbose", dola.VerboseStrategy{}) //nolint:exhaustivestruct keep.Run(context.Background()) }
Output:
func (*Keep) ActivateAsset ¶
ActivatePair activates and makes available the provided currency pair. nolint: stylecheck
func (*Keep) ActivatePair ¶
ActivatePair activates and makes available the provided asset type, currency pair.
func (*Keep) AddHistorian ¶
func (*Keep) CancelAllOrders ¶
func (*Keep) CancelOrder ¶
func (*Keep) CancelOrdersByPrefix ¶
func (*Keep) GetActiveOrders ¶
func (*Keep) GetEnabledPairAssetType ¶
func (bot *Keep) GetEnabledPairAssetType(e exchange.IBotExchange, c currency.Pair) (asset.Item, error)
GetEnabledPairAssetType returns the asset type that matches with the enabled provided currency pair, returns the first matching asset.
func (*Keep) GetExchangeByName ¶
func (bot *Keep) GetExchangeByName(name string) (exchange.IBotExchange, error)
GetExchangeByName returns an exchange interface given it's name.
func (*Keep) GetExchanges ¶
func (bot *Keep) GetExchanges() []exchange.IBotExchange
GetExchanges is a wrapper of GCT's Engine.GetExchanges. nolint
func (*Keep) GetOrderValue ¶
func (bot *Keep) GetOrderValue(exchangeName, orderID string) (OrderValue, bool)
func (*Keep) ModifyOrder ¶
func (*Keep) ReportEvent ¶
func (*Keep) ReportLatency ¶
func (*Keep) Run ¶
Run is the entry point of all exchange data streams. Strategy.On*() events for a single exchange are invoked from the same thread. Thus, if a strategy deals with multiple exchanges simultaneously, there may be race conditions.
func (*Keep) SubmitOrder ¶
func (*Keep) SubmitOrderUD ¶
func (*Keep) SubmitOrders ¶
type KeepBuilder ¶
type KeepBuilder struct {
// contains filtered or unexported fields
}
func NewKeepBuilder ¶
func NewKeepBuilder() *KeepBuilder
func (*KeepBuilder) Augment ¶
func (b *KeepBuilder) Augment(f AugmentConfigFunc) *KeepBuilder
func (*KeepBuilder) Balances ¶
func (b *KeepBuilder) Balances(refreshRate time.Duration) *KeepBuilder
func (*KeepBuilder) Build ¶
func (b *KeepBuilder) Build(ctx context.Context) (*Keep, error)
nolint: funlen
func (*KeepBuilder) CustomExchange ¶
func (b *KeepBuilder) CustomExchange(f ExchangeFactory) *KeepBuilder
func (*KeepBuilder) Reporter ¶
func (b *KeepBuilder) Reporter(r Reporter) *KeepBuilder
func (*KeepBuilder) Settings ¶
func (b *KeepBuilder) Settings(s engine.Settings) *KeepBuilder
type LogState ¶
type LogState struct {
// contains filtered or unexported fields
}
LogState keeps track of what the current state is.
func NewLogState ¶
type Metric ¶
type Metric int
const ( // Submit order metrics. SubmitOrderMetric Metric = iota SubmitOrderLatencyMetric SubmitOrderErrorMetric // Submit bulk orders metrics. SubmitBulkOrderMetric SubmitBulkOrderLatencyMetric // Modify order metrics. ModifyOrderMetric ModifyOrderLatencyMetric ModifyOrderErrorMetric // Cancel order metrics. CancelOrderMetric CancelOrderLatencyMetric CancelOrderErrorMetric // Cancel all orders metrics. CancelAllOrdersMetric CancelAllOrdersLatencyMetric CancelAllOrdersErrorMetric // Get Active orders metrics. GetActiveOrdersMetric GetActiveOrdersLatencyMetric GetActiveOrdersErrorMetric // this should always be the last one. MaxMetrics )
type OnFilledObserver ¶
type OnFilledObserver interface {
OnFilled(k *Keep, e exchange.IBotExchange, x order.Detail)
}
type OrderRegistry ¶
type OrderRegistry struct {
// contains filtered or unexported fields
}
func NewOrderRegistry ¶
func NewOrderRegistry() *OrderRegistry
func (*OrderRegistry) GetOrderValue ¶
func (r *OrderRegistry) GetOrderValue(exchangeName, orderID string) (OrderValue, bool)
func (*OrderRegistry) Length ¶
func (r *OrderRegistry) Length() int
func (*OrderRegistry) Store ¶
func (r *OrderRegistry) Store(exchangeName string, response order.SubmitResponse, userData interface{}) bool
Store saves order details. If such an order exists (matched by exchange name and order ID), false is returned.
type OrderValue ¶
type OrderValue struct { SubmitResponse order.SubmitResponse UserData interface{} }
type Reporter ¶
type Reporter interface { // Event metrics is a single occurrence Event(m Metric, labels ...string) // Latency metrics provides visibility over latencies Latency(m Metric, d time.Duration, labels ...string) // Value metrics provide visibility over arbitrary values Value(m Metric, v float64, labels ...string) }
type RootStrategy ¶
type RootStrategy struct {
// contains filtered or unexported fields
}
func NewRootStrategy ¶
func NewRootStrategy() RootStrategy
func (*RootStrategy) Add ¶
func (m *RootStrategy) Add(name string, s Strategy)
func (*RootStrategy) Deinit ¶
func (m *RootStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
func (*RootStrategy) Init ¶
func (m *RootStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
func (*RootStrategy) OnBalanceChange ¶
func (m *RootStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
func (*RootStrategy) OnFill ¶
func (m *RootStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
func (*RootStrategy) OnFunding ¶
func (m *RootStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
func (*RootStrategy) OnKline ¶
func (m *RootStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
func (*RootStrategy) OnModify ¶
func (m *RootStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
func (*RootStrategy) OnOrder ¶
func (m *RootStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
func (*RootStrategy) OnOrderBook ¶
func (m *RootStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
func (*RootStrategy) OnPrice ¶
func (m *RootStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
func (*RootStrategy) OnTrade ¶
func (m *RootStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
func (*RootStrategy) OnUnrecognized ¶
func (m *RootStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
type Slots ¶
type Slots struct {
OnFilledSlot func(k *Keep, e exchange.IBotExchange, x order.Detail)
}
type Strategy ¶
type Strategy interface { Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error Deinit(k *Keep, e exchange.IBotExchange) error }
func NewBalancesStrategy ¶
type SubAccount ¶
SubAccount defines a singular account type with asocciated currency balances.
type TickerStrategy ¶
type TickerStrategy struct { Interval time.Duration TickFunc func(k *Keep, e exchange.IBotExchange) // contains filtered or unexported fields }
func (*TickerStrategy) Deinit ¶
func (s *TickerStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
func (*TickerStrategy) Init ¶
func (s *TickerStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
func (*TickerStrategy) OnBalanceChange ¶
func (s *TickerStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
func (*TickerStrategy) OnFill ¶
func (s *TickerStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
func (*TickerStrategy) OnFunding ¶
func (s *TickerStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
func (*TickerStrategy) OnKline ¶
func (s *TickerStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
func (*TickerStrategy) OnModify ¶
func (s *TickerStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
func (*TickerStrategy) OnOrder ¶
func (s *TickerStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
func (*TickerStrategy) OnOrderBook ¶
func (s *TickerStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
func (*TickerStrategy) OnPrice ¶
func (s *TickerStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
func (*TickerStrategy) OnTrade ¶
func (s *TickerStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
func (*TickerStrategy) OnUnrecognized ¶
func (s *TickerStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error
type VerboseStrategy ¶
type VerboseStrategy struct { SilencePrice bool SilenceKline bool SilenceOrderBook bool SilenceOrder bool }
func (VerboseStrategy) Deinit ¶
func (v VerboseStrategy) Deinit(k *Keep, e exchange.IBotExchange) error
func (VerboseStrategy) Init ¶
func (v VerboseStrategy) Init(ctx context.Context, k *Keep, e exchange.IBotExchange) error
func (VerboseStrategy) OnBalanceChange ¶
func (v VerboseStrategy) OnBalanceChange(k *Keep, e exchange.IBotExchange, x account.Change) error
func (VerboseStrategy) OnFill ¶
func (v VerboseStrategy) OnFill(k *Keep, e exchange.IBotExchange, x []fill.Data) error
func (VerboseStrategy) OnFunding ¶
func (v VerboseStrategy) OnFunding(k *Keep, e exchange.IBotExchange, x stream.FundingData) error
func (VerboseStrategy) OnKline ¶
func (v VerboseStrategy) OnKline(k *Keep, e exchange.IBotExchange, x stream.KlineData) error
func (VerboseStrategy) OnModify ¶
func (v VerboseStrategy) OnModify(k *Keep, e exchange.IBotExchange, x order.Modify) error
func (VerboseStrategy) OnOrder ¶
func (v VerboseStrategy) OnOrder(k *Keep, e exchange.IBotExchange, x order.Detail) error
func (VerboseStrategy) OnOrderBook ¶
func (v VerboseStrategy) OnOrderBook(k *Keep, e exchange.IBotExchange, x orderbook.Base) error
func (VerboseStrategy) OnPrice ¶
func (v VerboseStrategy) OnPrice(k *Keep, e exchange.IBotExchange, x ticker.Price) error
func (VerboseStrategy) OnTrade ¶
func (v VerboseStrategy) OnTrade(k *Keep, e exchange.IBotExchange, x []trade.Data) error
func (VerboseStrategy) OnUnrecognized ¶
func (v VerboseStrategy) OnUnrecognized(k *Keep, e exchange.IBotExchange, x interface{}) error