Documentation ¶
Index ¶
- Constants
- type FundingFee
- type FuturesTransfer
- type MovingAverageConfig
- type PositionState
- type ProfitStats
- type State
- type Strategy
- func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.OrderExecutionRouter, ...) error
- func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession)
- func (s *Strategy) Defaults() error
- func (s *Strategy) ID() string
- func (s *Strategy) InstanceID() string
- func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, ...) error
- func (s *Strategy) Subscribe(session *bbgo.ExchangeSession)
- func (s *Strategy) Validate() error
Constants ¶
View Source
const ID = "xfunding"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FundingFee ¶
type FundingFee struct { Asset string `json:"asset"` Amount fixedpoint.Value `json:"amount"` Txn int64 `json:"txn"` Time time.Time `json:"time"` }
func (*FundingFee) SlackAttachment ¶
func (f *FundingFee) SlackAttachment() slack.Attachment
type FuturesTransfer ¶
type FuturesTransfer interface { TransferFuturesAccountAsset(ctx context.Context, asset string, amount fixedpoint.Value, io types.TransferDirection) error QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) }
type MovingAverageConfig ¶
type MovingAverageConfig struct { Interval types.Interval `json:"interval"` // MovingAverageType is the moving average indicator type that we want to use, // it could be SMA or EWMA MovingAverageType string `json:"movingAverageType"` // MovingAverageInterval is the interval of k-lines for the moving average indicator to calculate, // it could be "1m", "5m", "1h" and so on. note that, the moving averages are calculated from // the k-line data we subscribed // MovingAverageInterval types.Interval `json:"movingAverageInterval"` // // // MovingAverageWindow is the number of the window size of the moving average indicator. // // The number of k-lines in the window. generally used window sizes are 7, 25 and 99 in the TradingView. // MovingAverageWindow int `json:"movingAverageWindow"` MovingAverageIntervalWindow types.IntervalWindow `json:"movingAverageIntervalWindow"` }
type PositionState ¶
type PositionState int
Position State Transitions: NoOp -> Opening Opening -> Ready -> Closing Closing -> Closed -> Opening
const ( PositionClosed PositionState = iota PositionOpening PositionReady PositionClosing )
func (PositionState) String ¶
func (i PositionState) String() string
type ProfitStats ¶
type ProfitStats struct { *types.ProfitStats FundingFeeCurrency string `json:"fundingFeeCurrency"` TotalFundingFee fixedpoint.Value `json:"totalFundingFee"` FundingFeeRecords []FundingFee `json:"fundingFeeRecords"` LastFundingFeeTxn int64 `json:"lastFundingFeeTxn"` LastFundingFeeTime time.Time `json:"lastFundingFeeTime"` }
func (*ProfitStats) AddFundingFee ¶
func (s *ProfitStats) AddFundingFee(fee FundingFee) error
func (*ProfitStats) SlackAttachment ¶
func (s *ProfitStats) SlackAttachment() slack.Attachment
type State ¶
type State struct { PositionStartTime time.Time `json:"positionStartTime"` // PositionState is default to NoOp PositionState PositionState PendingBaseTransfer fixedpoint.Value `json:"pendingBaseTransfer"` TotalBaseTransfer fixedpoint.Value `json:"totalBaseTransfer"` UsedQuoteInvestment fixedpoint.Value `json:"usedQuoteInvestment"` }
type Strategy ¶
type Strategy struct { Environment *bbgo.Environment // These fields will be filled from the config file (it translates YAML to JSON) Symbol string `json:"symbol"` Interval types.Interval `json:"interval"` Market types.Market `json:"-"` // Leverage is the leverage of the futures position Leverage fixedpoint.Value `json:"leverage,omitempty"` // IncrementalQuoteQuantity is used for opening position incrementally with a small fixed quote quantity // for example, 100usdt per order IncrementalQuoteQuantity fixedpoint.Value `json:"incrementalQuoteQuantity"` QuoteInvestment fixedpoint.Value `json:"quoteInvestment"` MinHoldingPeriod types.Duration `json:"minHoldingPeriod"` // ShortFundingRate is the funding rate range for short positions // TODO: right now we don't support negative funding rate (long position) since it's rarer ShortFundingRate *struct { High fixedpoint.Value `json:"high"` Low fixedpoint.Value `json:"low"` } `json:"shortFundingRate"` SpotSession string `json:"spotSession"` FuturesSession string `json:"futuresSession"` // Reset your position info Reset bool `json:"reset"` // CloseFuturesPosition can be enabled to close the futures position and then transfer the collateral asset back to the spot account. CloseFuturesPosition bool `json:"closeFuturesPosition"` ProfitStats *ProfitStats `persistence:"profit_stats"` // SpotPosition is used for the spot position (usually long position) // so that we know how much spot we have bought and the average cost of the spot. SpotPosition *types.Position `persistence:"spot_position"` // FuturesPosition is used for the futures position // this position is the reverse side of the spot position, when spot position is long, then the futures position will be short. // but the base quantity should be the same as the spot position FuturesPosition *types.Position `persistence:"futures_position"` // NeutralPosition is used for sharing spot/futures position // when creating the spot position and futures position, there will be a spread between the spot position and the futures position. // this neutral position can calculate the spread cost between these two positions NeutralPosition *types.Position `persistence:"neutral_position"` State *State `persistence:"state"` // contains filtered or unexported fields }
Strategy is the xfunding fee strategy Right now it only supports short position in the USDT futures account. When opening the short position, it uses spot account to buy inventory, then transfer the inventory to the futures account as collateral assets.
func (*Strategy) CrossRun ¶
func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.OrderExecutionRouter, sessions map[string]*bbgo.ExchangeSession) error
func (*Strategy) CrossSubscribe ¶
func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession)
func (*Strategy) InstanceID ¶
func (*Strategy) Run ¶
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error
func (*Strategy) Subscribe ¶
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession)
Click to show internal directories.
Click to hide internal directories.