Documentation
¶
Index ¶
- Constants
- type Collector
- type ProfitStats
- type Round
- type State
- type Strategy
- func (s *Strategy) CleanUp(ctx context.Context) error
- func (s *Strategy) Close(ctx context.Context) error
- func (s *Strategy) ContinueNextRound()
- func (s *Strategy) Defaults() error
- func (s *Strategy) EmitPositionUpdate(position *types.Position)
- func (s *Strategy) EmitProfit(profitStats *ProfitStats)
- func (s *Strategy) ID() string
- func (s *Strategy) Initialize() error
- func (s *Strategy) InstanceID() string
- func (s *Strategy) OnPositionUpdate(cb func(*types.Position))
- func (s *Strategy) OnProfit(cb func(*ProfitStats))
- func (s *Strategy) PauseNextRound()
- func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error
- func (s *Strategy) Subscribe(session *bbgo.ExchangeSession)
- func (s *Strategy) UpdateProfitStats(ctx context.Context) (bool, error)
- func (s *Strategy) UpdateProfitStatsUntilSuccessful(ctx context.Context) error
- func (s *Strategy) Validate() error
Constants ¶
const (
ID = "dca2"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶ added in v1.59.0
type Collector struct {
// contains filtered or unexported fields
}
func NewCollector ¶ added in v1.59.0
func (Collector) CollectCurrentRound ¶ added in v1.59.0
func (*Collector) CollectFinishRounds ¶ added in v1.59.0
type ProfitStats ¶ added in v1.56.0
type ProfitStats struct {
Symbol string `json:"symbol"`
Market types.Market `json:"market,omitempty"`
FromOrderID uint64 `json:"fromOrderID,omitempty"`
Round int64 `json:"round,omitempty"`
QuoteInvestment fixedpoint.Value `json:"quoteInvestment,omitempty"`
CurrentRoundProfit fixedpoint.Value `json:"currentRoundProfit,omitempty"`
CurrentRoundFee map[string]fixedpoint.Value `json:"currentRoundFee,omitempty"`
TotalProfit fixedpoint.Value `json:"totalProfit,omitempty"`
TotalFee map[string]fixedpoint.Value `json:"totalFee,omitempty"`
// used to flexible recovery
OpenPositionPVs []types.PriceVolume `json:"openPositionPVs,omitempty"`
types.PersistenceTTL
}
func (*ProfitStats) AddTrade ¶ added in v1.56.0
func (s *ProfitStats) AddTrade(trade types.Trade)
func (*ProfitStats) NewRound ¶ added in v1.56.0
func (s *ProfitStats) NewRound()
func (*ProfitStats) String ¶ added in v1.56.0
func (s *ProfitStats) String() string
type Round ¶ added in v1.56.0
Round contains the open-position orders and the take-profit orders 1. len(OpenPositionOrders) == 0 -> not open position 2. len(TakeProfitOrders) == 0 -> not in the take-profit stage 3. There are take-profit orders only when open-position orders are cancelled 4. We need to make sure the order: open-position (BUY) -> take-profit (SELL) -> open-position (BUY) -> take-profit (SELL) -> ... 5. When there is one filled take-profit order, this round must be finished. We need to verify all take-profit orders are not active
type Strategy ¶
type Strategy struct {
Position *types.Position `json:"position,omitempty" persistence:"position"`
ProfitStats *ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"`
PersistenceTTL types.Duration `json:"persistenceTTL"`
Environment *bbgo.Environment
ExchangeSession *bbgo.ExchangeSession
OrderExecutor *bbgo.GeneralOrderExecutor
Market types.Market
Symbol string `json:"symbol"`
// setting
QuoteInvestment fixedpoint.Value `json:"quoteInvestment"`
MaxOrderCount int64 `json:"maxOrderCount"`
PriceDeviation fixedpoint.Value `json:"priceDeviation"`
TakeProfitRatio fixedpoint.Value `json:"takeProfitRatio"`
CoolDownInterval types.Duration `json:"coolDownInterval"`
// OrderGroupID is the group ID used for the strategy instance for canceling orders
OrderGroupID uint32 `json:"orderGroupID"`
DisableOrderGroupIDFilter bool `json:"disableOrderGroupIDFilter"`
// RecoverWhenStart option is used for recovering dca states
RecoverWhenStart bool `json:"recoverWhenStart"`
DisableProfitStatsRecover bool `json:"disableProfitStatsRecover"`
DisablePositionRecover bool `json:"disablePositionRecover"`
// EnableQuoteInvestmentReallocate set to true, the quote investment will be reallocated when the notional or quantity is under minimum.
EnableQuoteInvestmentReallocate bool `json:"enableQuoteInvestmentReallocate"`
// KeepOrdersWhenShutdown option is used for keeping the grid orders when shutting down bbgo
KeepOrdersWhenShutdown bool `json:"keepOrdersWhenShutdown"`
// UniversalCancelAllOrdersWhenClose close all orders even though the orders don't belong to this strategy
UniversalCancelAllOrdersWhenClose bool `json:"universalCancelAllOrdersWhenClose"`
LogFields logrus.Fields `json:"logFields"`
// PrometheusLabels will be used as the base prometheus labels
PrometheusLabels prometheus.Labels `json:"prometheusLabels"`
// callbacks
common.StatusCallbacks
// contains filtered or unexported fields
}
func (*Strategy) ContinueNextRound ¶ added in v1.58.0
func (s *Strategy) ContinueNextRound()
func (*Strategy) EmitPositionUpdate ¶ added in v1.59.0
func (*Strategy) EmitProfit ¶ added in v1.56.0
func (s *Strategy) EmitProfit(profitStats *ProfitStats)
func (*Strategy) Initialize ¶
func (*Strategy) InstanceID ¶
func (*Strategy) OnPositionUpdate ¶ added in v1.59.0
func (*Strategy) OnProfit ¶ added in v1.56.0
func (s *Strategy) OnProfit(cb func(*ProfitStats))
func (*Strategy) PauseNextRound ¶ added in v1.58.0
func (s *Strategy) PauseNextRound()
PauseNextRound will stop openning open-position orders at the next round
func (*Strategy) Run ¶
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error
func (*Strategy) Subscribe ¶
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession)
func (*Strategy) UpdateProfitStats ¶ added in v1.58.0
UpdateProfitStats will collect round from closed orders and emit update profit stats return true, nil -> there is at least one finished round and all the finished rounds we collect update profit stats successfully return false, nil -> there is no finished round! return true, error -> At least one round update profit stats successfully but there is error when collecting other rounds