grid2

package
v1.43.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: AGPL-3.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const ID = "grid2"

Variables

This section is empty.

Functions

This section is empty.

Types

type Grid

type Grid struct {
	UpperPrice fixedpoint.Value `json:"upperPrice"`
	LowerPrice fixedpoint.Value `json:"lowerPrice"`

	// Size is the number of total grids
	Size fixedpoint.Value `json:"size"`

	// TickSize is the price tick size, this is used for truncating price
	TickSize fixedpoint.Value `json:"tickSize"`

	// Spread is a immutable number
	Spread fixedpoint.Value `json:"spread"`

	// Pins are the pinned grid prices, from low to high
	Pins []Pin `json:"pins"`
	// contains filtered or unexported fields
}

func NewGrid

func NewGrid(lower, upper, size, tickSize fixedpoint.Value) *Grid

func (*Grid) Above

func (g *Grid) Above(price fixedpoint.Value) bool

func (*Grid) Below

func (g *Grid) Below(price fixedpoint.Value) bool

func (*Grid) BottomPin

func (g *Grid) BottomPin() Pin

func (*Grid) CalculateArithmeticPins

func (g *Grid) CalculateArithmeticPins()

func (*Grid) CalculateGeometricPins

func (g *Grid) CalculateGeometricPins()

func (*Grid) ExtendLowerPrice

func (g *Grid) ExtendLowerPrice(lower fixedpoint.Value) (newPins []Pin)

func (*Grid) ExtendUpperPrice

func (g *Grid) ExtendUpperPrice(upper fixedpoint.Value) (newPins []Pin)

func (*Grid) HasPin

func (g *Grid) HasPin(pin Pin) (ok bool)

func (*Grid) Height

func (g *Grid) Height() fixedpoint.Value

func (*Grid) NextHigherPin

func (g *Grid) NextHigherPin(price fixedpoint.Value) (Pin, bool)

NextHigherPin finds the next higher pin

func (*Grid) NextLowerPin

func (g *Grid) NextLowerPin(price fixedpoint.Value) (Pin, bool)

NextLowerPin finds the next lower pin

func (*Grid) OutOfRange

func (g *Grid) OutOfRange(price fixedpoint.Value) bool

func (*Grid) SearchPin

func (g *Grid) SearchPin(price fixedpoint.Value) int

func (*Grid) String

func (g *Grid) String() string

func (*Grid) TopPin

func (g *Grid) TopPin() Pin

type GridProfit

type GridProfit struct {
	Currency string           `json:"currency"`
	Profit   fixedpoint.Value `json:"profit"`
	Time     time.Time        `json:"time"`
	Order    types.Order      `json:"order"`
}

func (*GridProfit) PlainText

func (p *GridProfit) PlainText() string

func (*GridProfit) SlackAttachment

func (p *GridProfit) SlackAttachment() slack.Attachment

func (*GridProfit) String

func (p *GridProfit) String() string

type GridProfitStats

type GridProfitStats struct {
	Symbol           string                      `json:"symbol"`
	TotalBaseProfit  fixedpoint.Value            `json:"totalBaseProfit,omitempty"`
	TotalQuoteProfit fixedpoint.Value            `json:"totalQuoteProfit,omitempty"`
	FloatProfit      fixedpoint.Value            `json:"floatProfit,omitempty"`
	GridProfit       fixedpoint.Value            `json:"gridProfit,omitempty"`
	ArbitrageCount   int                         `json:"arbitrageCount,omitempty"`
	TotalFee         map[string]fixedpoint.Value `json:"totalFee,omitempty"`
	Volume           fixedpoint.Value            `json:"volume,omitempty"`
	Market           types.Market                `json:"market,omitempty"`
	ProfitEntries    []*GridProfit               `json:"profitEntries,omitempty"`
	Since            *time.Time                  `json:"since,omitempty"`
}

func (*GridProfitStats) AddProfit

func (s *GridProfitStats) AddProfit(profit *GridProfit)

func (*GridProfitStats) AddTrade

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

func (*GridProfitStats) SlackAttachment

func (s *GridProfitStats) SlackAttachment() slack.Attachment

type OrderExecutor

type OrderExecutor interface {
	SubmitOrders(ctx context.Context, submitOrders ...types.SubmitOrder) (types.OrderSlice, error)
	ClosePosition(ctx context.Context, percentage fixedpoint.Value, tags ...string) error
	GracefulCancel(ctx context.Context, orders ...types.Order) error
}

type Pin

type Pin fixedpoint.Value

type PinCalculator

type PinCalculator func() []Pin

type Strategy

type Strategy struct {
	Environment *bbgo.Environment

	// Market stores the configuration of the market, for example, VolumePrecision, PricePrecision, MinLotSize... etc
	// This field will be injected automatically since we defined the Symbol field.
	types.Market `json:"-"`

	// These fields will be filled from the config file (it translates YAML to JSON)
	Symbol string `json:"symbol"`

	// ProfitSpread is the fixed profit spread you want to submit the sell order
	// When ProfitSpread is enabled, the grid will shift up, e.g.,
	// If you opened a grid with the price range 10_000 to 20_000
	// With profit spread set to 3_000
	// The sell orders will be placed in the range 13_000 to 23_000
	// And the buy orders will be placed in the original price range 10_000 to 20_000
	ProfitSpread fixedpoint.Value `json:"profitSpread"`

	// GridNum is the grid number, how many orders you want to post on the orderbook.
	GridNum int64 `json:"gridNumber"`

	UpperPrice fixedpoint.Value `json:"upperPrice"`

	LowerPrice fixedpoint.Value `json:"lowerPrice"`

	// Compound option is used for buying more inventory when
	// the profit is made by the filled sell order.
	Compound bool `json:"compound"`

	// EarnBase option is used for earning profit in base currency.
	// e.g. earn BTC in BTCUSDT and earn ETH in ETHUSDT
	// instead of earn USDT in BTCUSD
	EarnBase bool `json:"earnBase"`

	// QuantityOrAmount embeds the Quantity field and the Amount field
	// If you set up the Quantity field or the Amount field, you don't need to set the QuoteInvestment and BaseInvestment
	bbgo.QuantityOrAmount

	// If Quantity and Amount is not set, we can use the quote investment to calculate our quantity.
	QuoteInvestment fixedpoint.Value `json:"quoteInvestment"`

	// BaseInvestment is the total base quantity you want to place as the sell order.
	BaseInvestment fixedpoint.Value `json:"baseInvestment"`

	TriggerPrice fixedpoint.Value `json:"triggerPrice"`

	StopLossPrice   fixedpoint.Value `json:"stopLossPrice"`
	TakeProfitPrice fixedpoint.Value `json:"takeProfitPrice"`

	// CloseWhenCancelOrder option is used to close the grid if any of the order is canceled.
	// This option let you simply remote control the grid from the crypto exchange mobile app.
	CloseWhenCancelOrder bool `json:"closeWhenCancelOrder"`

	// KeepOrdersWhenShutdown option is used for keeping the grid orders when shutting down bbgo
	KeepOrdersWhenShutdown bool `json:"keepOrdersWhenShutdown"`

	// ClearOpenOrdersWhenStart
	// If this is set, when bbgo started, it will clear the open orders in the same market (by symbol)
	ClearOpenOrdersWhenStart bool `json:"clearOpenOrdersWhenStart"`

	ResetPositionWhenStart bool `json:"resetPositionWhenStart"`

	// FeeRate is used for calculating the minimal profit spread.
	// it makes sure that your grid configuration is profitable.
	FeeRate fixedpoint.Value `json:"feeRate"`

	SkipSpreadCheck bool `json:"skipSpreadCheck"`

	GridProfitStats *GridProfitStats   `persistence:"grid_profit_stats"`
	ProfitStats     *types.ProfitStats `persistence:"profit_stats"`
	Position        *types.Position    `persistence:"position"`
	// contains filtered or unexported fields
}

func (*Strategy) ID

func (s *Strategy) ID() string

func (*Strategy) InstanceID

func (s *Strategy) InstanceID() string

InstanceID returns the instance identifier from the current grid configuration parameters

func (*Strategy) Run

func (*Strategy) Subscribe

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

func (*Strategy) Validate

func (s *Strategy) Validate() error

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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