mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
strategy: fix fixedpoint.Value compare to 0 problem
This commit is contained in:
parent
16f811f48f
commit
a9b48ff138
|
@ -377,7 +377,7 @@ 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.Float64() != 0 {
|
||||
if s.TrailingStopTarget.TrailingStopCallBackRatio != 0 {
|
||||
s.trailingStopControl = &TrailingStopControl{
|
||||
symbol: s.Symbol,
|
||||
market: s.Market,
|
||||
|
@ -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.Float64() != 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
|
||||
|
@ -408,7 +408,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
|
||||
// Calculate minimum target price
|
||||
var minTargetPrice = 0.0
|
||||
if s.trailingStopControl.minimumProfitPercentage.Float64() > 0 {
|
||||
if s.trailingStopControl.minimumProfitPercentage > 0 {
|
||||
minTargetPrice = position.AverageCost.Float64() * (1 + s.trailingStopControl.minimumProfitPercentage.Float64())
|
||||
}
|
||||
|
||||
|
@ -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.Float64() > 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
|
||||
|
@ -467,7 +467,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
|
||||
// Calculate minimum target price
|
||||
var minTargetPrice = 0.0
|
||||
if s.trailingStopControl.minimumProfitPercentage.Float64() > 0 {
|
||||
if s.trailingStopControl.minimumProfitPercentage > 0 {
|
||||
minTargetPrice = s.state.Position.AverageCost.Float64() * (1 + s.trailingStopControl.minimumProfitPercentage.Float64())
|
||||
}
|
||||
|
||||
|
@ -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.Float64() == 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)
|
||||
|
@ -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.Float64() > 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!")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user