mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-23 15:25:14 +00:00
bbgo: add partial option to the trailingStop
This commit is contained in:
parent
1ea52e03c6
commit
e7de96ca3c
|
@ -19,8 +19,13 @@ type TrailingStop2 struct {
|
||||||
ActivationRatio fixedpoint.Value `json:"activationRatio,omitempty"`
|
ActivationRatio fixedpoint.Value `json:"activationRatio,omitempty"`
|
||||||
|
|
||||||
// ClosePosition is a percentage of the position to be closed
|
// ClosePosition is a percentage of the position to be closed
|
||||||
|
// Deprecated: please use Partial instead
|
||||||
ClosePosition fixedpoint.Value `json:"closePosition,omitempty"`
|
ClosePosition fixedpoint.Value `json:"closePosition,omitempty"`
|
||||||
|
|
||||||
|
// Partial is a percentage of the position to be closed
|
||||||
|
// 50% means you will close halt the position
|
||||||
|
Partial fixedpoint.Value `json:"partial,omitempty"`
|
||||||
|
|
||||||
// MinProfit is the percentage of the minimum profit ratio.
|
// MinProfit is the percentage of the minimum profit ratio.
|
||||||
// Stop order will be activated only when the price reaches above this threshold.
|
// Stop order will be activated only when the price reaches above this threshold.
|
||||||
MinProfit fixedpoint.Value `json:"minProfit,omitempty"`
|
MinProfit fixedpoint.Value `json:"minProfit,omitempty"`
|
||||||
|
@ -177,9 +182,15 @@ func (s *TrailingStop2) triggerStop(price fixedpoint.Value) error {
|
||||||
Notify("[TrailingStop] %s stop loss triggered. price: %f callback rate: %f", s.Symbol, price.Float64(), s.CallbackRate.Float64())
|
Notify("[TrailingStop] %s stop loss triggered. price: %f callback rate: %f", s.Symbol, price.Float64(), s.CallbackRate.Float64())
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
p := fixedpoint.One
|
p := fixedpoint.One
|
||||||
|
|
||||||
|
// this is for legacy
|
||||||
if !s.ClosePosition.IsZero() {
|
if !s.ClosePosition.IsZero() {
|
||||||
p = s.ClosePosition
|
p = s.ClosePosition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !s.Partial.IsZero() {
|
||||||
|
p = s.Partial
|
||||||
|
}
|
||||||
|
|
||||||
return s.orderExecutor.ClosePosition(ctx, p, "trailingStop")
|
return s.orderExecutor.ClosePosition(ctx, p, "trailingStop")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user