mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 16:55:15 +00:00
pivotshort: add leverage settings
This commit is contained in:
parent
adb96cac39
commit
c4332fcac2
|
@ -27,6 +27,7 @@ type BreakLow struct {
|
||||||
// limit sell price = breakLowPrice * (1 + BounceRatio)
|
// limit sell price = breakLowPrice * (1 + BounceRatio)
|
||||||
BounceRatio fixedpoint.Value `json:"bounceRatio"`
|
BounceRatio fixedpoint.Value `json:"bounceRatio"`
|
||||||
|
|
||||||
|
Leverage fixedpoint.Value `json:"leverage"`
|
||||||
Quantity fixedpoint.Value `json:"quantity"`
|
Quantity fixedpoint.Value `json:"quantity"`
|
||||||
StopEMARange fixedpoint.Value `json:"stopEMARange"`
|
StopEMARange fixedpoint.Value `json:"stopEMARange"`
|
||||||
StopEMA *types.IntervalWindow `json:"stopEMA"`
|
StopEMA *types.IntervalWindow `json:"stopEMA"`
|
||||||
|
@ -170,8 +171,7 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener
|
||||||
// graceful cancel all active orders
|
// graceful cancel all active orders
|
||||||
_ = orderExecutor.GracefulCancel(ctx)
|
_ = orderExecutor.GracefulCancel(ctx)
|
||||||
|
|
||||||
leverage := fixedpoint.NewFromInt(5)
|
quantity, err := useQuantityOrBaseBalance(s.session, s.Market, closePrice, s.Quantity, s.Leverage)
|
||||||
quantity, err := useQuantityOrBaseBalance(s.session, s.Market, closePrice, s.Quantity, leverage)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("quantity calculation error")
|
log.WithError(err).Errorf("quantity calculation error")
|
||||||
}
|
}
|
||||||
|
@ -222,6 +222,10 @@ func useQuantityOrBaseBalance(session *bbgo.ExchangeSession, market types.Market
|
||||||
return quantity, nil
|
return quantity, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if leverage.IsZero() {
|
||||||
|
leverage = fixedpoint.NewFromInt(3)
|
||||||
|
}
|
||||||
|
|
||||||
// quantity is zero, we need to calculate the quantity
|
// quantity is zero, we need to calculate the quantity
|
||||||
baseBalance, _ := session.Account.Balance(market.BaseCurrency)
|
baseBalance, _ := session.Account.Balance(market.BaseCurrency)
|
||||||
quoteBalance, _ := session.Account.Balance(market.QuoteCurrency)
|
quoteBalance, _ := session.Account.Balance(market.QuoteCurrency)
|
||||||
|
|
|
@ -155,7 +155,11 @@ type Strategy struct {
|
||||||
// pivot interval and window
|
// pivot interval and window
|
||||||
types.IntervalWindow
|
types.IntervalWindow
|
||||||
|
|
||||||
|
Leverage fixedpoint.Value `json:"leverage"`
|
||||||
|
Quantity fixedpoint.Value `json:"quantity"`
|
||||||
|
|
||||||
// persistence fields
|
// persistence fields
|
||||||
|
|
||||||
Position *types.Position `persistence:"position"`
|
Position *types.Position `persistence:"position"`
|
||||||
ProfitStats *types.ProfitStats `persistence:"profit_stats"`
|
ProfitStats *types.ProfitStats `persistence:"profit_stats"`
|
||||||
TradeStats *types.TradeStats `persistence:"trade_stats"`
|
TradeStats *types.TradeStats `persistence:"trade_stats"`
|
||||||
|
@ -177,7 +181,6 @@ type Strategy struct {
|
||||||
bbgo.StrategyController
|
bbgo.StrategyController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *Strategy) ID() string {
|
func (s *Strategy) ID() string {
|
||||||
return ID
|
return ID
|
||||||
}
|
}
|
||||||
|
@ -236,6 +239,11 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
s.TradeStats = types.NewTradeStats(s.Symbol)
|
s.TradeStats = types.NewTradeStats(s.Symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.Leverage.IsZero() {
|
||||||
|
// the default leverage is 3x
|
||||||
|
s.Leverage = fixedpoint.NewFromInt(3)
|
||||||
|
}
|
||||||
|
|
||||||
// StrategyController
|
// StrategyController
|
||||||
s.Status = types.StrategyStatusRunning
|
s.Status = types.StrategyStatusRunning
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user