pivotshort: improve useQuantityOrBaseBalance and add bounce short check

This commit is contained in:
c9s 2022-06-26 19:45:37 +08:00
parent 4d862a4286
commit 1557423229
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 34 additions and 25 deletions

View File

@ -130,10 +130,14 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
}
func (s *Strategy) useQuantityOrBaseBalance(quantity fixedpoint.Value) fixedpoint.Value {
balance, hasBalance := s.session.Account.Balance(s.Market.BaseCurrency)
if hasBalance {
if quantity.IsZero() {
if balance, ok := s.session.Account.Balance(s.Market.BaseCurrency); ok {
bbgo.Notify("sell quantity is not set, submitting sell with all base balance: %s", balance.Available.String())
quantity = balance.Available
} else {
quantity = fixedpoint.Min(quantity, balance.Available)
}
}
@ -240,6 +244,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
method.Bind(session, s.orderExecutor)
}
if s.BounceShort != nil && s.BounceShort.Enabled {
session.UserDataStream.OnStart(func() {
lastKLine := s.preloadPivot(s.pivot, store)
@ -271,6 +276,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
}
}
})
}
// Always check whether you can open a short position or not
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {

View File

@ -31,6 +31,9 @@ func (s *TradeStats) Add(pnl fixedpoint.Value) {
s.MostLossTrade = fixedpoint.Min(s.MostLossTrade, pnl)
}
// The win/loss ratio is your wins divided by your losses.
// In the example, suppose for the sake of simplicity that 60 trades were winners, and 40 were losers.
// Your win/loss ratio would be 60/40 = 1.5. That would mean that you are winning 50% more often than you are losing.
if s.NumOfLossTrade == 0 && s.NumOfProfitTrade > 0 {
s.WinningRatio = fixedpoint.One
} else {