Skip to content

Commit

Permalink
assign CircuitBreakLossThreshold to MaximumTotalLoss and delete circu…
Browse files Browse the repository at this point in the history
…itBreakEMA
  • Loading branch information
narumiruna committed Nov 28, 2024
1 parent 1a8820d commit 22cbace
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 26 deletions.
5 changes: 1 addition & 4 deletions config/fixedmaker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ exchangeStrategies:

positionHardLimit: 1500
maxPositionQuantity: 1500
circuitBreakLossThreshold: -0.15
circuitBreakEMA:
interval: 1m
window: 14
circuitBreakLossThreshold: 0.15

inventorySkew:
inventoryRangeMultiplier: 1.0
Expand Down
7 changes: 1 addition & 6 deletions config/scmaker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@ exchangeStrategies:
## maxExposure controls how much balance should be used for placing the maker orders
maxExposure: 10_000

## circuitBreakEMA is used for calculating the price for circuitBreak
circuitBreakEMA:
interval: 1m
window: 14

## circuitBreakLossThreshold is the maximum loss threshold for realized+unrealized PnL
circuitBreakLossThreshold: -10.0
circuitBreakLossThreshold: 10.0

## positionHardLimit is the maximum position limit
positionHardLimit: 500.0
Expand Down
5 changes: 1 addition & 4 deletions config/xfixedmaker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ crossExchangeStrategies:
positionHardLimit: 200
maxPositionQuantity: 0.005

circuitBreakLossThreshold: -10
circuitBreakEMA:
interval: 1m
window: 14
circuitBreakLossThreshold: 10

inventorySkew:
inventoryRangeMultiplier: 1.0
Expand Down
14 changes: 9 additions & 5 deletions pkg/strategy/common/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import (
)

type RiskController struct {
PositionHardLimit fixedpoint.Value `json:"positionHardLimit"`
MaxPositionQuantity fixedpoint.Value `json:"maxPositionQuantity"`
CircuitBreakLossThreshold fixedpoint.Value `json:"circuitBreakLossThreshold"`
CircuitBreakEMA types.IntervalWindow `json:"circuitBreakEMA"`
PositionHardLimit fixedpoint.Value `json:"positionHardLimit"`
MaxPositionQuantity fixedpoint.Value `json:"maxPositionQuantity"`
CircuitBreakLossThreshold fixedpoint.Value `json:"circuitBreakLossThreshold"`

positionRiskControl *riskcontrol.PositionRiskControl
circuitBreakRiskControl *circuitbreaker.BasicCircuitBreaker
Expand Down Expand Up @@ -81,7 +80,12 @@ func (s *Strategy) Initialize(

if !s.CircuitBreakLossThreshold.IsZero() {
log.Infof("circuitBreakLossThreshold is configured, setting up CircuitBreakRiskControl...")
s.circuitBreakRiskControl = circuitbreaker.NewBasicCircuitBreaker(strategyID, instanceID, market.Symbol)
s.circuitBreakRiskControl = &circuitbreaker.BasicCircuitBreaker{
Enabled: true,
MaximumTotalLoss: s.CircuitBreakLossThreshold,
HaltDuration: types.Duration(24 * time.Hour),
}
s.circuitBreakRiskControl.SetMetricsInfo(strategyID, instanceID, market.Symbol)

s.OrderExecutor.TradeCollector().OnProfit(func(trade types.Trade, profit *types.Profit) {
if profit != nil && s.circuitBreakRiskControl != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/strategy/fixedmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ func (s *Strategy) Validate() error {

func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})

if !s.CircuitBreakLossThreshold.IsZero() {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.CircuitBreakEMA.Interval})
}
}

func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
Expand Down
3 changes: 0 additions & 3 deletions pkg/strategy/xfixedmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {
return
}
tradingSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
if !s.CircuitBreakLossThreshold.IsZero() {
tradingSession.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.CircuitBreakEMA.Interval})
}

referenceSession, ok := sessions[s.ReferenceExchange]
if !ok {
Expand Down

0 comments on commit 22cbace

Please sign in to comment.