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)
|
||||
BounceRatio fixedpoint.Value `json:"bounceRatio"`
|
||||
|
||||
Leverage fixedpoint.Value `json:"leverage"`
|
||||
Quantity fixedpoint.Value `json:"quantity"`
|
||||
StopEMARange fixedpoint.Value `json:"stopEMARange"`
|
||||
StopEMA *types.IntervalWindow `json:"stopEMA"`
|
||||
|
@ -170,8 +171,7 @@ func (s *BreakLow) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.Gener
|
|||
// graceful cancel all active orders
|
||||
_ = orderExecutor.GracefulCancel(ctx)
|
||||
|
||||
leverage := fixedpoint.NewFromInt(5)
|
||||
quantity, err := useQuantityOrBaseBalance(s.session, s.Market, closePrice, s.Quantity, leverage)
|
||||
quantity, err := useQuantityOrBaseBalance(s.session, s.Market, closePrice, s.Quantity, s.Leverage)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("quantity calculation error")
|
||||
}
|
||||
|
@ -222,6 +222,10 @@ func useQuantityOrBaseBalance(session *bbgo.ExchangeSession, market types.Market
|
|||
return quantity, nil
|
||||
}
|
||||
|
||||
if leverage.IsZero() {
|
||||
leverage = fixedpoint.NewFromInt(3)
|
||||
}
|
||||
|
||||
// quantity is zero, we need to calculate the quantity
|
||||
baseBalance, _ := session.Account.Balance(market.BaseCurrency)
|
||||
quoteBalance, _ := session.Account.Balance(market.QuoteCurrency)
|
||||
|
|
|
@ -155,7 +155,11 @@ type Strategy struct {
|
|||
// pivot interval and window
|
||||
types.IntervalWindow
|
||||
|
||||
Leverage fixedpoint.Value `json:"leverage"`
|
||||
Quantity fixedpoint.Value `json:"quantity"`
|
||||
|
||||
// persistence fields
|
||||
|
||||
Position *types.Position `persistence:"position"`
|
||||
ProfitStats *types.ProfitStats `persistence:"profit_stats"`
|
||||
TradeStats *types.TradeStats `persistence:"trade_stats"`
|
||||
|
@ -177,7 +181,6 @@ type Strategy struct {
|
|||
bbgo.StrategyController
|
||||
}
|
||||
|
||||
|
||||
func (s *Strategy) ID() string {
|
||||
return ID
|
||||
}
|
||||
|
@ -236,6 +239,11 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
s.TradeStats = types.NewTradeStats(s.Symbol)
|
||||
}
|
||||
|
||||
if s.Leverage.IsZero() {
|
||||
// the default leverage is 3x
|
||||
s.Leverage = fixedpoint.NewFromInt(3)
|
||||
}
|
||||
|
||||
// StrategyController
|
||||
s.Status = types.StrategyStatusRunning
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user