dca2

package
v0.0.0-...-c0411a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ID = "dca2"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DevMode

type DevMode struct {
	Enabled      bool `json:"enabled"`
	IsNewAccount bool `json:"isNewAccount"`
}

DevMode, if Enabled is true. it means it will check the running field

type ProfitStats

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"`

	types.PersistenceTTL
}

func (*ProfitStats) AddTrade

func (s *ProfitStats) AddTrade(trade types.Trade)

func (*ProfitStats) NewRound

func (s *ProfitStats) NewRound()

func (*ProfitStats) String

func (s *ProfitStats) String() string

type RecoverApiQueryService

type RecoverApiQueryService interface {
	types.ExchangeOrderQueryService
	types.ExchangeTradeService
	// contains filtered or unexported methods
}

type Round

type Round struct {
	OpenPositionOrders []types.Order
	TakeProfitOrder    types.Order
}

type RoundCollector

type RoundCollector struct {
	// contains filtered or unexported fields
}

func NewRoundCollector

func NewRoundCollector(logger *logrus.Entry, symbol string, groupID uint32, ex types.Exchange) *RoundCollector

func (*RoundCollector) CollectFinishRounds

func (rc *RoundCollector) CollectFinishRounds(ctx context.Context, fromOrderID uint64) ([]Round, error)

func (*RoundCollector) CollectRoundTrades

func (rc *RoundCollector) CollectRoundTrades(ctx context.Context, round Round) ([]types.Trade, error)

type State

type State int64
const (
	None State = iota
	WaitToOpenPosition
	PositionOpening
	OpenPositionReady
	OpenPositionOrderFilled
	OpenPositionOrdersCancelling
	OpenPositionOrdersCancelled
	TakeProfitReady
)

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"`

	// 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"`

	// UseCancelAllOrdersApiWhenClose uses a different API to cancel all the orders on the market when closing a grid
	UseCancelAllOrdersApiWhenClose bool `json:"useCancelAllOrdersApiWhenClose"`

	// dev mode
	DevMode *DevMode `json:"devMode"`

	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) CleanUp

func (s *Strategy) CleanUp(ctx context.Context) error

func (*Strategy) Close

func (s *Strategy) Close(ctx context.Context) error

func (*Strategy) ContinueNextRound

func (s *Strategy) ContinueNextRound()

func (*Strategy) Defaults

func (s *Strategy) Defaults() error

func (*Strategy) EmitPosition

func (s *Strategy) EmitPosition(position *types.Position)

func (*Strategy) EmitProfit

func (s *Strategy) EmitProfit(profitStats *ProfitStats)

func (*Strategy) ID

func (s *Strategy) ID() string

func (*Strategy) Initialize

func (s *Strategy) Initialize() error

func (*Strategy) InstanceID

func (s *Strategy) InstanceID() string

func (*Strategy) OnPosition

func (s *Strategy) OnPosition(cb func(*types.Position))

func (*Strategy) OnProfit

func (s *Strategy) OnProfit(cb func(*ProfitStats))

func (*Strategy) PauseNextRound

func (s *Strategy) PauseNextRound()

PauseNextRound will stop openning open-position orders at the next round

func (*Strategy) Run

func (*Strategy) Subscribe

func (s *Strategy) Subscribe(session *bbgo.ExchangeSession)

func (*Strategy) UpdateProfitStats

func (s *Strategy) UpdateProfitStats(ctx context.Context) (bool, error)

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

func (*Strategy) UpdateProfitStatsUntilSuccessful

func (s *Strategy) UpdateProfitStatsUntilSuccessful(ctx context.Context) error

func (*Strategy) Validate

func (s *Strategy) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL