mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
xmaker: integrate circuitbreaker
This commit is contained in:
parent
92ad80f2f8
commit
14fff8dbad
|
@ -116,7 +116,7 @@ type BasicCircuitBreaker struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBasicCircuitBreaker(strategyID, strategyInstance string) *BasicCircuitBreaker {
|
func NewBasicCircuitBreaker(strategyID, strategyInstance string) *BasicCircuitBreaker {
|
||||||
return &BasicCircuitBreaker{
|
b := &BasicCircuitBreaker{
|
||||||
MaximumConsecutiveLossTimes: 8,
|
MaximumConsecutiveLossTimes: 8,
|
||||||
MaximumHaltTimes: 3,
|
MaximumHaltTimes: 3,
|
||||||
MaximumHaltTimesExceededPanic: false,
|
MaximumHaltTimesExceededPanic: false,
|
||||||
|
@ -125,6 +125,8 @@ func NewBasicCircuitBreaker(strategyID, strategyInstance string) *BasicCircuitBr
|
||||||
strategyInstance: strategyInstance,
|
strategyInstance: strategyInstance,
|
||||||
metricsLabels: prometheus.Labels{"strategy": strategyID, "strategyInstance": strategyInstance},
|
metricsLabels: prometheus.Labels{"strategy": strategyID, "strategyInstance": strategyInstance},
|
||||||
}
|
}
|
||||||
|
b.updateMetrics()
|
||||||
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BasicCircuitBreaker) getMetricsLabels() prometheus.Labels {
|
func (b *BasicCircuitBreaker) getMetricsLabels() prometheus.Labels {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/core"
|
"github.com/c9s/bbgo/pkg/core"
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
"github.com/c9s/bbgo/pkg/indicator"
|
"github.com/c9s/bbgo/pkg/indicator"
|
||||||
|
"github.com/c9s/bbgo/pkg/risk/circuitbreaker"
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
"github.com/c9s/bbgo/pkg/util"
|
"github.com/c9s/bbgo/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -98,6 +99,8 @@ type Strategy struct {
|
||||||
|
|
||||||
state *State
|
state *State
|
||||||
|
|
||||||
|
CircuitBreaker *circuitbreaker.BasicCircuitBreaker `json:"circuitBreaker"`
|
||||||
|
|
||||||
// persistence fields
|
// persistence fields
|
||||||
Position *types.Position `json:"position,omitempty" persistence:"position"`
|
Position *types.Position `json:"position,omitempty" persistence:"position"`
|
||||||
ProfitStats *ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"`
|
ProfitStats *ProfitStats `json:"profitStats,omitempty" persistence:"profit_stats"`
|
||||||
|
@ -630,6 +633,14 @@ func (s *Strategy) tradeRecover(ctx context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Strategy) Defaults() error {
|
||||||
|
if s.CircuitBreaker == nil {
|
||||||
|
s.CircuitBreaker = circuitbreaker.NewBasicCircuitBreaker(ID, s.InstanceID())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Strategy) Validate() error {
|
func (s *Strategy) Validate() error {
|
||||||
if s.Quantity.IsZero() || s.QuantityScale == nil {
|
if s.Quantity.IsZero() || s.QuantityScale == nil {
|
||||||
return errors.New("quantity or quantityScale can not be empty")
|
return errors.New("quantity or quantityScale can not be empty")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user