Skip to content

Commit

Permalink
strategy: rename callBackRatio to callbackRatio
Browse files Browse the repository at this point in the history
  • Loading branch information
andycheng123 committed Feb 6, 2022
1 parent a9b48ff commit 41c3b86
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config/support.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ exchangeStrategies:
minQuoteAssetBalance: 2000.0

#trailingStopTarget:
# callBackRatio: 0.015
# callbackRatio: 0.015
# minimumProfitPercentage: 0.02

targets:
Expand Down
2 changes: 1 addition & 1 deletion doc/strategy/support.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This strategy uses K-lines with high volume as support and buys the target asset
profit.
- `trailingStopTarget`
- Use trailing stop to take profit
- `callBackRatio`
- `callbackRatio`
- Callback ratio of the trailing stop
- `minimumProfitPercentage`
- The minimum profit ratio of the trailing stop. The trailing stop is triggered when the profit is higher than the minimum.
Expand Down
20 changes: 10 additions & 10 deletions pkg/strategy/support/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (stop *PercentageTargetStop) GenerateOrders(market types.Market, pos *types
}

type TrailingStopTarget struct {
TrailingStopCallBackRatio fixedpoint.Value `json:"callBackRatio"`
TrailingStopCallbackRatio fixedpoint.Value `json:"callbackRatio"`
MinimumProfitPercentage fixedpoint.Value `json:"minimumProfitPercentage"`
}

Expand All @@ -88,21 +88,21 @@ type TrailingStopControl struct {
market types.Market
marginSideEffect types.MarginOrderSideEffectType

trailingStopCallBackRatio fixedpoint.Value
trailingStopCallbackRatio fixedpoint.Value
minimumProfitPercentage fixedpoint.Value

CurrentHighestPrice fixedpoint.Value
OrderID uint64
}

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
}

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{
Symbol: control.symbol,
Expand Down Expand Up @@ -377,13 +377,13 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.orderStore = bbgo.NewOrderStore(s.Symbol)
s.orderStore.BindStream(session.UserDataStream)

if s.TrailingStopTarget.TrailingStopCallBackRatio != 0 {
if s.TrailingStopTarget.TrailingStopCallbackRatio != 0 {
s.trailingStopControl = &TrailingStopControl{
symbol: s.Symbol,
market: s.Market,
marginSideEffect: s.MarginOrderSideEffect,
CurrentHighestPrice: fixedpoint.NewFromInt(0),
trailingStopCallBackRatio: s.TrailingStopTarget.TrailingStopCallBackRatio,
trailingStopCallbackRatio: s.TrailingStopTarget.TrailingStopCallbackRatio,
minimumProfitPercentage: s.TrailingStopTarget.MinimumProfitPercentage,
}
}
Expand All @@ -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)

if s.TrailingStopTarget.TrailingStopCallBackRatio != 0 {
if s.TrailingStopTarget.TrailingStopCallbackRatio != 0 {
// Update trailing stop when the position changes
s.tradeCollector.OnPositionUpdate(func(position *types.Position) {
if position.Base.Float64() > 0 { // Update order if we have a position
Expand Down Expand Up @@ -451,7 +451,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
highPriceF := kline.GetHigh()
highPrice := fixedpoint.NewFromFloat(highPriceF)

if s.TrailingStopTarget.TrailingStopCallBackRatio > 0 {
if s.TrailingStopTarget.TrailingStopCallbackRatio > 0 {
if s.state.Position.Base.Float64() <= 0 { // Without a position
// Update trailing orders with current high price
s.trailingStopControl.CurrentHighestPrice = highPrice
Expand Down Expand Up @@ -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)
}

if s.TrailingStopTarget.TrailingStopCallBackRatio == 0 { // submit fixed target orders
if s.TrailingStopTarget.TrailingStopCallbackRatio == 0 { // submit fixed target orders
var targetOrders []types.SubmitOrder
for _, target := range s.Targets {
targetPrice := closePrice.Float64() * (1.0 + target.ProfitPercentage)
Expand Down Expand Up @@ -623,7 +623,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
defer wg.Done()

// 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 {
log.WithError(err).Errorf("Can not cancel the trailing stop order!")
}
Expand Down

0 comments on commit 41c3b86

Please sign in to comment.