Documentation
¶
Index ¶
- Constants
- func AdjustHedgeQuantityWithAvailableBalance(account *types.Account, market types.Market, side types.SideType, ...) fixedpoint.Value
- type BaseHedgeExecutorConfig
- type BollingerBandTrendSignal
- type CounterpartyHedgeExecutor
- type CounterpartyHedgeExecutorConfig
- type DelayedHedge
- type DepthRatioSignal
- type HedgeExecutor
- type HedgeMarket
- func (m *HedgeMarket) InstanceID() string
- func (m *HedgeMarket) Restore(ctx context.Context, namespace string) error
- func (m *HedgeMarket) Start(ctx context.Context) error
- func (m *HedgeMarket) Stop(shutdownCtx context.Context)
- func (m *HedgeMarket) Sync(ctx context.Context, namespace string)
- func (m *HedgeMarket) WaitForReady(ctx context.Context)
- type HedgeMarketConfig
- type HedgeMethod
- type KLineShapeSignal
- type MarketOrderHedgeExecutor
- type MarketOrderHedgeExecutorConfig
- type MutexFloat64
- type OrderBookBestPriceVolumeSignal
- type PositionExposure
- func (m *PositionExposure) Close(delta fixedpoint.Value)
- func (m *PositionExposure) Cover(delta fixedpoint.Value)
- func (m *PositionExposure) EmitClose(d fixedpoint.Value)
- func (m *PositionExposure) EmitCover(d fixedpoint.Value)
- func (m *PositionExposure) GetUncovered() fixedpoint.Value
- func (m *PositionExposure) IsClosed() bool
- func (m *PositionExposure) OnClose(cb func(d fixedpoint.Value))
- func (m *PositionExposure) OnCover(cb func(d fixedpoint.Value))
- func (m *PositionExposure) Open(delta fixedpoint.Value)
- type ProfitStats
- type Quote
- type SessionBinder
- type SignalConfig
- type SignalMargin
- type SignalNumber
- type SignalProvider
- type SpreadMaker
- type State
- type Strategy
- func (s *Strategy) CrossRun(ctx context.Context, _ 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) Initialize() error
- func (s *Strategy) InstanceID() string
- func (s *Strategy) PrintConfig(f io.Writer, pretty bool, withColor ...bool)
- func (s *Strategy) Validate() error
- type StreamBookSetter
- type SyntheticHedge
- func (s *SyntheticHedge) GetQuotePrices() (fixedpoint.Value, fixedpoint.Value, bool)
- func (s *SyntheticHedge) Hedge(_ context.Context, uncoveredPosition fixedpoint.Value) error
- func (s *SyntheticHedge) InitializeAndBind(sessions map[string]*bbgo.ExchangeSession, strategy *Strategy) error
- func (s *SyntheticHedge) Start(ctx context.Context) error
- func (s *SyntheticHedge) Stop(shutdownCtx context.Context) error
- type TradeVolumeWindowSignal
Constants ¶
const ( SignalNumberMaxLong = 2.0 SignalNumberMaxShort = -2.0 )
const ID = "xmaker"
const TradeTagMock = "mock"
Variables ¶
This section is empty.
Functions ¶
func AdjustHedgeQuantityWithAvailableBalance ¶ added in v1.61.0
func AdjustHedgeQuantityWithAvailableBalance( account *types.Account, market types.Market, side types.SideType, quantity, lastPrice fixedpoint.Value, ) fixedpoint.Value
Types ¶
type BaseHedgeExecutorConfig ¶ added in v1.63.0
type BaseHedgeExecutorConfig struct {
}
type BollingerBandTrendSignal ¶ added in v1.60.1
type BollingerBandTrendSignal struct {
types.IntervalWindow
MinBandWidth float64 `json:"minBandWidth"`
MaxBandWidth float64 `json:"maxBandWidth"`
// contains filtered or unexported fields
}
func (*BollingerBandTrendSignal) Bind ¶ added in v1.60.1
func (s *BollingerBandTrendSignal) Bind(ctx context.Context, session *bbgo.ExchangeSession, symbol string) error
func (*BollingerBandTrendSignal) CalculateSignal ¶ added in v1.60.1
func (s *BollingerBandTrendSignal) CalculateSignal(ctx context.Context) (float64, error)
type CounterpartyHedgeExecutor ¶ added in v1.63.0
type CounterpartyHedgeExecutor struct {
*HedgeMarket
// contains filtered or unexported fields
}
type CounterpartyHedgeExecutorConfig ¶ added in v1.63.0
type CounterpartyHedgeExecutorConfig struct {
BaseHedgeExecutorConfig
PriceLevel int `json:"priceLevel"`
}
type DelayedHedge ¶ added in v1.61.0
type DelayedHedge struct {
// EnableDelayHedge enables the delay hedge feature
Enabled bool `json:"enabled"`
// MaxDelayDuration is the maximum delay duration to hedge the position
MaxDelayDuration types.Duration `json:"maxDelay"`
// FixedDelayDuration is the fixed delay duration
FixedDelayDuration types.Duration `json:"fixedDelay"`
// SignalThreshold is the signal threshold to trigger the delay hedge
SignalThreshold float64 `json:"signalThreshold"`
// DynamicDelayScale is the dynamic delay scale
DynamicDelayScale *bbgo.SlideRule `json:"dynamicDelayScale,omitempty"`
}
type DepthRatioSignal ¶ added in v1.61.0
type DepthRatioSignal struct {
// PriceRange, 2% depth ratio means 2% price range from the mid price
PriceRange fixedpoint.Value `json:"priceRange"`
MinRatio float64 `json:"minRatio"`
// contains filtered or unexported fields
}
func (*DepthRatioSignal) Bind ¶ added in v1.61.0
func (s *DepthRatioSignal) Bind(ctx context.Context, session *bbgo.ExchangeSession, symbol string) error
func (*DepthRatioSignal) CalculateSignal ¶ added in v1.61.0
func (s *DepthRatioSignal) CalculateSignal(ctx context.Context) (float64, error)
func (*DepthRatioSignal) SetStreamBook ¶ added in v1.61.0
func (s *DepthRatioSignal) SetStreamBook(book *types.StreamOrderBook)
type HedgeExecutor ¶ added in v1.63.0
type HedgeExecutor interface {
// contains filtered or unexported methods
}
type HedgeMarket ¶ added in v1.63.0
type HedgeMarket struct {
*HedgeMarketConfig
Position *types.Position
// contains filtered or unexported fields
}
func (*HedgeMarket) InstanceID ¶ added in v1.63.0
func (m *HedgeMarket) InstanceID() string
func (*HedgeMarket) Restore ¶ added in v1.63.0
func (m *HedgeMarket) Restore(ctx context.Context, namespace string) error
Restore loads the position from persistence and restores it to the HedgeMarket.
func (*HedgeMarket) Stop ¶ added in v1.63.0
func (m *HedgeMarket) Stop(shutdownCtx context.Context)
func (*HedgeMarket) Sync ¶ added in v1.63.0
func (m *HedgeMarket) Sync(ctx context.Context, namespace string)
func (*HedgeMarket) WaitForReady ¶ added in v1.63.0
func (m *HedgeMarket) WaitForReady(ctx context.Context)
type HedgeMarketConfig ¶ added in v1.63.0
type HedgeMarketConfig struct {
SymbolSelector string `json:"symbolSelector"`
HedgeMethod HedgeMethod `json:"hedgeMethod"`
HedgeInterval types.Duration `json:"hedgeInterval"`
HedgeMethodMarket *MarketOrderHedgeExecutorConfig `json:"hedgeMethodMarket,omitempty"` // for backward compatibility, this is the default hedge method
HedgeMethodCounterparty *CounterpartyHedgeExecutorConfig `json:"hedgeMethodCounterparty,omitempty"` // for backward compatibility, this is the default hedge method
HedgeMethodQueue *struct {
PriceLevel int `json:"priceLevel"`
} `json:"hedgeMethodQueue,omitempty"` // for backward compatibility, this is the default hedge method
QuotingDepth fixedpoint.Value `json:"quotingDepth"`
QuotingDepthInQuote fixedpoint.Value `json:"quotingDepthInQuote"`
}
type HedgeMethod ¶ added in v1.63.0
type HedgeMethod string
const ( // HedgeMethodMarket is the default hedge method that uses the market order to hedge HedgeMethodMarket HedgeMethod = "market" // HedgeMethodCounterparty is a hedge method that uses limit order at the specific counterparty price level to hedge HedgeMethodCounterparty HedgeMethod = "counterparty" // HedgeMethodQueue is a hedge method that uses limit order at the first price level in the queue to hedge HedgeMethodQueue HedgeMethod = "queue" )
type KLineShapeSignal ¶ added in v1.60.1
type KLineShapeSignal struct {
FullBodyThreshold float64 `json:"fullBodyThreshold"`
}
type MarketOrderHedgeExecutor ¶ added in v1.63.0
type MarketOrderHedgeExecutor struct {
*HedgeMarket
// contains filtered or unexported fields
}
type MarketOrderHedgeExecutorConfig ¶ added in v1.63.0
type MarketOrderHedgeExecutorConfig struct {
BaseHedgeExecutorConfig
MaxOrderQuantity fixedpoint.Value `json:"maxOrderQuantity,omitempty"` // max order quantity for market order hedge
}
type MutexFloat64 ¶ added in v1.61.0
type MutexFloat64 struct {
// contains filtered or unexported fields
}
func (*MutexFloat64) Get ¶ added in v1.61.0
func (m *MutexFloat64) Get() float64
func (*MutexFloat64) Set ¶ added in v1.61.0
func (m *MutexFloat64) Set(v float64)
type OrderBookBestPriceVolumeSignal ¶ added in v1.60.1
type OrderBookBestPriceVolumeSignal struct {
RatioThreshold fixedpoint.Value `json:"ratioThreshold"`
MinVolume fixedpoint.Value `json:"minVolume"`
MinQuoteVolume fixedpoint.Value `json:"minQuoteVolume"`
// contains filtered or unexported fields
}
func (*OrderBookBestPriceVolumeSignal) Bind ¶ added in v1.60.1
func (s *OrderBookBestPriceVolumeSignal) Bind(ctx context.Context, session *bbgo.ExchangeSession, symbol string) error
func (*OrderBookBestPriceVolumeSignal) CalculateSignal ¶ added in v1.60.1
func (s *OrderBookBestPriceVolumeSignal) CalculateSignal(ctx context.Context) (float64, error)
func (*OrderBookBestPriceVolumeSignal) SetStreamBook ¶ added in v1.61.0
func (s *OrderBookBestPriceVolumeSignal) SetStreamBook(book *types.StreamOrderBook)
type PositionExposure ¶ added in v1.63.0
type PositionExposure struct {
// contains filtered or unexported fields
}
func (*PositionExposure) Close ¶ added in v1.63.0
func (m *PositionExposure) Close(delta fixedpoint.Value)
func (*PositionExposure) Cover ¶ added in v1.63.0
func (m *PositionExposure) Cover(delta fixedpoint.Value)
func (*PositionExposure) EmitClose ¶ added in v1.63.0
func (m *PositionExposure) EmitClose(d fixedpoint.Value)
func (*PositionExposure) EmitCover ¶ added in v1.63.0
func (m *PositionExposure) EmitCover(d fixedpoint.Value)
func (*PositionExposure) GetUncovered ¶ added in v1.63.0
func (m *PositionExposure) GetUncovered() fixedpoint.Value
func (*PositionExposure) IsClosed ¶ added in v1.63.0
func (m *PositionExposure) IsClosed() bool
func (*PositionExposure) OnClose ¶ added in v1.63.0
func (m *PositionExposure) OnClose(cb func(d fixedpoint.Value))
func (*PositionExposure) OnCover ¶ added in v1.63.0
func (m *PositionExposure) OnCover(cb func(d fixedpoint.Value))
func (*PositionExposure) Open ¶ added in v1.63.0
func (m *PositionExposure) Open(delta fixedpoint.Value)
type ProfitStats ¶ added in v1.17.0
type ProfitStats struct {
*types.ProfitStats
MakerExchange types.ExchangeName `json:"makerExchange"`
AccumulatedMakerVolume fixedpoint.Value `json:"accumulatedMakerVolume,omitempty"`
AccumulatedMakerBidVolume fixedpoint.Value `json:"accumulatedMakerBidVolume,omitempty"`
AccumulatedMakerAskVolume fixedpoint.Value `json:"accumulatedMakerAskVolume,omitempty"`
TodayMakerVolume fixedpoint.Value `json:"todayMakerVolume,omitempty"`
TodayMakerBidVolume fixedpoint.Value `json:"todayMakerBidVolume,omitempty"`
TodayMakerAskVolume fixedpoint.Value `json:"todayMakerAskVolume,omitempty"`
// contains filtered or unexported fields
}
func (*ProfitStats) AddTrade ¶ added in v1.17.0
func (s *ProfitStats) AddTrade(trade types.Trade)
func (*ProfitStats) ResetToday ¶ added in v1.17.0
func (s *ProfitStats) ResetToday()
type Quote ¶ added in v1.60.1
type Quote struct {
BestBidPrice, BestAskPrice fixedpoint.Value
BidMargin, AskMargin fixedpoint.Value
// BidLayerPips is the price pips between each layer
BidLayerPips, AskLayerPips fixedpoint.Value
}
type SessionBinder ¶ added in v1.60.1
type SignalConfig ¶ added in v1.60.1
type SignalConfig struct {
Weight float64 `json:"weight"`
BollingerBandTrendSignal *BollingerBandTrendSignal `json:"bollingerBandTrend,omitempty"`
OrderBookBestPriceSignal *OrderBookBestPriceVolumeSignal `json:"orderBookBestPrice,omitempty"`
DepthRatioSignal *DepthRatioSignal `json:"depthRatio,omitempty"`
KLineShapeSignal *KLineShapeSignal `json:"klineShape,omitempty"`
TradeVolumeWindowSignal *TradeVolumeWindowSignal `json:"tradeVolumeWindow,omitempty"`
}
func (*SignalConfig) Get ¶ added in v1.61.0
func (c *SignalConfig) Get() SignalProvider
type SignalMargin ¶ added in v1.61.0
type SignalNumber ¶ added in v1.60.1
type SignalNumber float64
type SignalProvider ¶ added in v1.60.1
type SpreadMaker ¶ added in v1.62.0
type SpreadMaker struct {
Enabled bool `json:"enabled"`
MinProfitRatio fixedpoint.Value `json:"minProfitRatio"`
MaxQuoteAmount fixedpoint.Value `json:"maxQuoteAmount"`
MaxOrderLifespan types.Duration `json:"maxOrderLifespan"`
SignalThreshold float64 `json:"signalThreshold"`
ReverseSignalOrderCancel bool `json:"reverseSignalOrderCancel"`
MakerOnly bool `json:"makerOnly"`
// contains filtered or unexported fields
}
func (*SpreadMaker) Bind ¶ added in v1.62.0
func (c *SpreadMaker) Bind(ctx context.Context, session *bbgo.ExchangeSession, symbol string) error
func (*SpreadMaker) Defaults ¶ added in v1.62.0
func (c *SpreadMaker) Defaults() error
type State ¶
type State struct {
CoveredPosition fixedpoint.Value `json:"coveredPosition,omitempty"`
// Deprecated:
Position *types.Position `json:"position,omitempty"`
// Deprecated:
ProfitStats ProfitStats `json:"profitStats,omitempty"`
}
type Strategy ¶
type Strategy struct {
Environment *bbgo.Environment
Symbol string `json:"symbol"`
// SourceSymbol allows subscribing to a different symbol for price/book
SourceSymbol string `json:"sourceSymbol,omitempty"`
// SourceExchange session name
SourceExchange string `json:"sourceExchange"`
// MakerExchange session name
MakerExchange string `json:"makerExchange"`
UpdateInterval types.Duration `json:"updateInterval"`
HedgeInterval types.Duration `json:"hedgeInterval"`
OrderCancelWaitTime types.Duration `json:"orderCancelWaitTime"`
SubscribeFeeTokenMarkets bool `json:"subscribeFeeTokenMarkets"`
EnableSignalMargin bool `json:"enableSignalMargin"`
SignalConfigList []SignalConfig `json:"signals"`
SignalReverseSideMargin *SignalMargin `json:"signalReverseSideMargin,omitempty"`
SignalTrendSideMarginDiscount *SignalMargin `json:"signalTrendSideMarginDiscount,omitempty"`
// Margin is the default margin for the quote
Margin fixedpoint.Value `json:"margin"`
BidMargin fixedpoint.Value `json:"bidMargin"`
AskMargin fixedpoint.Value `json:"askMargin"`
// MinMargin is the minimum margin protection for signal margin
MinMargin *fixedpoint.Value `json:"minMargin"`
UseDepthPrice bool `json:"useDepthPrice"`
DepthQuantity fixedpoint.Value `json:"depthQuantity"`
SourceDepthLevel types.Depth `json:"sourceDepthLevel"`
MakerOnly bool `json:"makerOnly"`
// EnableDelayHedge enables the delay hedge feature
EnableDelayHedge bool `json:"enableDelayHedge"`
// MaxHedgeDelayDuration is the maximum delay duration to hedge the position
MaxDelayHedgeDuration types.Duration `json:"maxHedgeDelayDuration"`
DelayHedgeSignalThreshold float64 `json:"delayHedgeSignalThreshold"`
DelayedHedge *DelayedHedge `json:"delayedHedge,omitempty"`
SpreadMaker *SpreadMaker `json:"spreadMaker,omitempty"`
EnableBollBandMargin bool `json:"enableBollBandMargin"`
BollBandInterval types.Interval `json:"bollBandInterval"`
BollBandMargin fixedpoint.Value `json:"bollBandMargin"`
BollBandMarginFactor fixedpoint.Value `json:"bollBandMarginFactor"`
// MinMarginLevel is the minimum margin level to trigger the hedge
MinMarginLevel fixedpoint.Value `json:"minMarginLevel"`
StopHedgeQuoteBalance fixedpoint.Value `json:"stopHedgeQuoteBalance"`
StopHedgeBaseBalance fixedpoint.Value `json:"stopHedgeBaseBalance"`
// Quantity is used for fixed quantity of the first layer
Quantity fixedpoint.Value `json:"quantity"`
// QuantityMultiplier is the factor that multiplies the quantity of the previous layer
QuantityMultiplier fixedpoint.Value `json:"quantityMultiplier"`
// QuantityScale helps user to define the quantity by layer scale
QuantityScale *bbgo.LayerScale `json:"quantityScale,omitempty"`
// MaxExposurePosition defines the unhedged quantity of stop
MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"`
MaxHedgeAccountLeverage fixedpoint.Value `json:"maxHedgeAccountLeverage"`
MaxHedgeQuoteQuantityPerOrder fixedpoint.Value `json:"maxHedgeQuoteQuantityPerOrder"`
DisableHedge bool `json:"disableHedge"`
NotifyTrade bool `json:"notifyTrade"`
NotifyIgnoreSmallAmountProfitTrade fixedpoint.Value `json:"notifyIgnoreSmallAmountProfitTrade"`
EnableArbitrage bool `json:"enableArbitrage"`
// RecoverTrade tries to find the missing trades via the REStful API
RecoverTrade bool `json:"recoverTrade"`
RecoverTradeScanPeriod types.Duration `json:"recoverTradeScanPeriod"`
MaxQuoteQuotaRatio fixedpoint.Value `json:"maxQuoteQuotaRatio,omitempty"`
NumLayers int `json:"numLayers"`
// Pips is the pips of the layer prices
Pips fixedpoint.Value `json:"pips"`
// ProfitFixerConfig is the profit fixer configuration
ProfitFixerConfig *common.ProfitFixerConfig `json:"profitFixer,omitempty"`
UseSandbox bool `json:"useSandbox,omitempty"`
SandboxExchangeBalances map[string]fixedpoint.Value `json:"sandboxExchangeBalances,omitempty"`
SyntheticHedge *SyntheticHedge `json:"syntheticHedge,omitempty"`
CircuitBreaker *circuitbreaker.BasicCircuitBreaker `json:"circuitBreaker"`
// persistence fields
Position *types.Position `json:"position,omitempty" persistence:"position"`
ProfitStats *ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"`
// contains filtered or unexported fields
}
func (*Strategy) CrossRun ¶
func (s *Strategy) CrossRun( ctx context.Context, _ bbgo.OrderExecutionRouter, sessions map[string]*bbgo.ExchangeSession, ) error
func (*Strategy) CrossSubscribe ¶
func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession)
func (*Strategy) Initialize ¶ added in v1.55.0
func (*Strategy) InstanceID ¶ added in v1.33.0
func (*Strategy) PrintConfig ¶ added in v1.61.0
type StreamBookSetter ¶ added in v1.61.0
type StreamBookSetter interface {
SetStreamBook(book *types.StreamOrderBook)
}
type SyntheticHedge ¶ added in v1.63.0
type SyntheticHedge struct {
// SyntheticHedge is a strategy that uses synthetic hedging to manage risk
Enabled bool `json:"enabled"`
Source *HedgeMarketConfig `json:"source"`
Fiat *HedgeMarketConfig `json:"fiat"`
// contains filtered or unexported fields
}
SyntheticHedge is a strategy that uses synthetic hedging to manage risk SourceSymbol could be something like binance.BTCUSDT FiatSymbol could be something like max.USDTTWD
func (*SyntheticHedge) GetQuotePrices ¶ added in v1.63.0
func (s *SyntheticHedge) GetQuotePrices() (fixedpoint.Value, fixedpoint.Value, bool)
func (*SyntheticHedge) Hedge ¶ added in v1.63.0
func (s *SyntheticHedge) Hedge( _ context.Context, uncoveredPosition fixedpoint.Value, ) error
Hedge is the main function to perform the synthetic hedging: 1) use the snapshot price as the source average cost 2) submit the hedge order to the source exchange 3) query trades from of the hedge order. 4) build up the source hedge position for the average cost. 5) submit fiat hedge order to the fiat market to convert the quote. 6) merge the positions.
func (*SyntheticHedge) InitializeAndBind ¶ added in v1.63.0
func (s *SyntheticHedge) InitializeAndBind(sessions map[string]*bbgo.ExchangeSession, strategy *Strategy) error
InitializeAndBind not a good way to initialize the synthetic hedge with the strategy instance but we need to build the trade collector to update the profit and position
type TradeVolumeWindowSignal ¶ added in v1.60.2
type TradeVolumeWindowSignal struct {
Threshold fixedpoint.Value `json:"threshold"`
Window types.Duration `json:"window"`
// contains filtered or unexported fields
}
func (*TradeVolumeWindowSignal) Bind ¶ added in v1.60.2
func (s *TradeVolumeWindowSignal) Bind(ctx context.Context, session *bbgo.ExchangeSession, symbol string) error
func (*TradeVolumeWindowSignal) CalculateSignal ¶ added in v1.60.2
func (s *TradeVolumeWindowSignal) CalculateSignal(_ context.Context) (float64, error)