mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
pivotshort: bind supportTakeProfit method
This commit is contained in:
parent
278fbb7b51
commit
81f9639c85
|
@ -48,7 +48,6 @@ func (s *SupportTakeProfit) Subscribe(session *bbgo.ExchangeSession) {
|
||||||
|
|
||||||
func (s *SupportTakeProfit) updateSupportPrice(closePrice fixedpoint.Value) bool {
|
func (s *SupportTakeProfit) updateSupportPrice(closePrice fixedpoint.Value) bool {
|
||||||
supportPrices := findPossibleSupportPrices(closePrice.Float64(), 0.05, s.pivot.Lows)
|
supportPrices := findPossibleSupportPrices(closePrice.Float64(), 0.05, s.pivot.Lows)
|
||||||
|
|
||||||
if len(supportPrices) == 0 {
|
if len(supportPrices) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -58,12 +57,14 @@ func (s *SupportTakeProfit) updateSupportPrice(closePrice fixedpoint.Value) bool
|
||||||
currentBuyPrice := s.currentSupportPrice.Mul(one.Add(s.Ratio))
|
currentBuyPrice := s.currentSupportPrice.Mul(one.Add(s.Ratio))
|
||||||
|
|
||||||
if s.currentSupportPrice.IsZero() {
|
if s.currentSupportPrice.IsZero() {
|
||||||
|
log.Infof("setup next support take profit price at %f", nextSupportPrice.Float64())
|
||||||
s.currentSupportPrice = nextSupportPrice
|
s.currentSupportPrice = nextSupportPrice
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// the close price is already lower than the support price, than we should update
|
// the close price is already lower than the support price, than we should update
|
||||||
if closePrice.Compare(currentBuyPrice) < 0 || nextSupportPrice.Compare(s.currentSupportPrice) > 0 {
|
if closePrice.Compare(currentBuyPrice) < 0 || nextSupportPrice.Compare(s.currentSupportPrice) > 0 {
|
||||||
|
log.Infof("setup next support take profit price at %f", nextSupportPrice.Float64())
|
||||||
s.currentSupportPrice = nextSupportPrice
|
s.currentSupportPrice = nextSupportPrice
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -106,7 +107,9 @@ func (s *SupportTakeProfit) Bind(session *bbgo.ExchangeSession, orderExecutor *b
|
||||||
Type: types.OrderTypeLimitMaker,
|
Type: types.OrderTypeLimitMaker,
|
||||||
Price: buyPrice,
|
Price: buyPrice,
|
||||||
Quantity: quantity,
|
Quantity: quantity,
|
||||||
|
Tag: "supportTakeProfit",
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("can not submit orders: %+v", createdOrders)
|
log.WithError(err).Errorf("can not submit orders: %+v", createdOrders)
|
||||||
}
|
}
|
||||||
|
@ -240,6 +243,10 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
s.BreakLow.Bind(session, s.orderExecutor)
|
s.BreakLow.Bind(session, s.orderExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, m := range s.SupportTakeProfit {
|
||||||
|
m.Bind(session, s.orderExecutor)
|
||||||
|
}
|
||||||
|
|
||||||
bbgo.OnShutdown(func(ctx context.Context, wg *sync.WaitGroup) {
|
bbgo.OnShutdown(func(ctx context.Context, wg *sync.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user