strategy: rename callBackRatio to callbackRatio

This commit is contained in:
Andy Cheng 2022-01-28 15:47:12 +08:00
parent a9b48ff138
commit 41c3b860b0
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28
3 changed files with 12 additions and 12 deletions

View File

@ -72,7 +72,7 @@ exchangeStrategies:
minQuoteAssetBalance: 2000.0 minQuoteAssetBalance: 2000.0
#trailingStopTarget: #trailingStopTarget:
# callBackRatio: 0.015 # callbackRatio: 0.015
# minimumProfitPercentage: 0.02 # minimumProfitPercentage: 0.02
targets: targets:

View File

@ -39,7 +39,7 @@ This strategy uses K-lines with high volume as support and buys the target asset
profit. profit.
- `trailingStopTarget` - `trailingStopTarget`
- Use trailing stop to take profit - Use trailing stop to take profit
- `callBackRatio` - `callbackRatio`
- Callback ratio of the trailing stop - Callback ratio of the trailing stop
- `minimumProfitPercentage` - `minimumProfitPercentage`
- The minimum profit ratio of the trailing stop. The trailing stop is triggered when the profit is higher than the minimum. - The minimum profit ratio of the trailing stop. The trailing stop is triggered when the profit is higher than the minimum.

View File

@ -79,7 +79,7 @@ func (stop *PercentageTargetStop) GenerateOrders(market types.Market, pos *types
} }
type TrailingStopTarget struct { type TrailingStopTarget struct {
TrailingStopCallBackRatio fixedpoint.Value `json:"callBackRatio"` TrailingStopCallbackRatio fixedpoint.Value `json:"callbackRatio"`
MinimumProfitPercentage fixedpoint.Value `json:"minimumProfitPercentage"` MinimumProfitPercentage fixedpoint.Value `json:"minimumProfitPercentage"`
} }
@ -88,7 +88,7 @@ type TrailingStopControl struct {
market types.Market market types.Market
marginSideEffect types.MarginOrderSideEffectType marginSideEffect types.MarginOrderSideEffectType
trailingStopCallBackRatio fixedpoint.Value trailingStopCallbackRatio fixedpoint.Value
minimumProfitPercentage fixedpoint.Value minimumProfitPercentage fixedpoint.Value
CurrentHighestPrice fixedpoint.Value CurrentHighestPrice fixedpoint.Value
@ -96,13 +96,13 @@ type TrailingStopControl struct {
} }
func (control *TrailingStopControl) IsHigherThanMin(minTargetPrice float64) bool { func (control *TrailingStopControl) IsHigherThanMin(minTargetPrice float64) bool {
targetPrice := control.CurrentHighestPrice.Float64() * (1 - control.trailingStopCallBackRatio.Float64()) targetPrice := control.CurrentHighestPrice.Float64() * (1 - control.trailingStopCallbackRatio.Float64())
return targetPrice >= minTargetPrice return targetPrice >= minTargetPrice
} }
func (control *TrailingStopControl) GenerateStopOrder(quantity float64) types.SubmitOrder { func (control *TrailingStopControl) GenerateStopOrder(quantity float64) types.SubmitOrder {
targetPrice := control.CurrentHighestPrice.Float64() * (1 - control.trailingStopCallBackRatio.Float64()) targetPrice := control.CurrentHighestPrice.Float64() * (1 - control.trailingStopCallbackRatio.Float64())
orderForm := types.SubmitOrder{ orderForm := types.SubmitOrder{
Symbol: control.symbol, Symbol: control.symbol,
@ -377,13 +377,13 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.orderStore = bbgo.NewOrderStore(s.Symbol) s.orderStore = bbgo.NewOrderStore(s.Symbol)
s.orderStore.BindStream(session.UserDataStream) s.orderStore.BindStream(session.UserDataStream)
if s.TrailingStopTarget.TrailingStopCallBackRatio != 0 { if s.TrailingStopTarget.TrailingStopCallbackRatio != 0 {
s.trailingStopControl = &TrailingStopControl{ s.trailingStopControl = &TrailingStopControl{
symbol: s.Symbol, symbol: s.Symbol,
market: s.Market, market: s.Market,
marginSideEffect: s.MarginOrderSideEffect, marginSideEffect: s.MarginOrderSideEffect,
CurrentHighestPrice: fixedpoint.NewFromInt(0), CurrentHighestPrice: fixedpoint.NewFromInt(0),
trailingStopCallBackRatio: s.TrailingStopTarget.TrailingStopCallBackRatio, trailingStopCallbackRatio: s.TrailingStopTarget.TrailingStopCallbackRatio,
minimumProfitPercentage: s.TrailingStopTarget.MinimumProfitPercentage, minimumProfitPercentage: s.TrailingStopTarget.MinimumProfitPercentage,
} }
} }
@ -396,7 +396,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.tradeCollector = bbgo.NewTradeCollector(s.Symbol, s.state.Position, s.orderStore) s.tradeCollector = bbgo.NewTradeCollector(s.Symbol, s.state.Position, s.orderStore)
if s.TrailingStopTarget.TrailingStopCallBackRatio != 0 { if s.TrailingStopTarget.TrailingStopCallbackRatio != 0 {
// Update trailing stop when the position changes // Update trailing stop when the position changes
s.tradeCollector.OnPositionUpdate(func(position *types.Position) { s.tradeCollector.OnPositionUpdate(func(position *types.Position) {
if position.Base.Float64() > 0 { // Update order if we have a position if position.Base.Float64() > 0 { // Update order if we have a position
@ -451,7 +451,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
highPriceF := kline.GetHigh() highPriceF := kline.GetHigh()
highPrice := fixedpoint.NewFromFloat(highPriceF) highPrice := fixedpoint.NewFromFloat(highPriceF)
if s.TrailingStopTarget.TrailingStopCallBackRatio > 0 { if s.TrailingStopTarget.TrailingStopCallbackRatio > 0 {
if s.state.Position.Base.Float64() <= 0 { // Without a position if s.state.Position.Base.Float64() <= 0 { // Without a position
// Update trailing orders with current high price // Update trailing orders with current high price
s.trailingStopControl.CurrentHighestPrice = highPrice s.trailingStopControl.CurrentHighestPrice = highPrice
@ -582,7 +582,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.Notify("%s position is saved", s.Symbol, s.state.Position) s.Notify("%s position is saved", s.Symbol, s.state.Position)
} }
if s.TrailingStopTarget.TrailingStopCallBackRatio == 0 { // submit fixed target orders if s.TrailingStopTarget.TrailingStopCallbackRatio == 0 { // submit fixed target orders
var targetOrders []types.SubmitOrder var targetOrders []types.SubmitOrder
for _, target := range s.Targets { for _, target := range s.Targets {
targetPrice := closePrice.Float64() * (1.0 + target.ProfitPercentage) targetPrice := closePrice.Float64() * (1.0 + target.ProfitPercentage)
@ -623,7 +623,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
defer wg.Done() defer wg.Done()
// Cancel trailing stop order // Cancel trailing stop order
if s.TrailingStopTarget.TrailingStopCallBackRatio > 0 { if s.TrailingStopTarget.TrailingStopCallbackRatio > 0 {
if err := s.cancelOrder(s.trailingStopControl.OrderID, ctx, session); err != nil { if err := s.cancelOrder(s.trailingStopControl.OrderID, ctx, session); err != nil {
log.WithError(err).Errorf("Can not cancel the trailing stop order!") log.WithError(err).Errorf("Can not cancel the trailing stop order!")
} }