mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
Use configuration instead of kine fixed interval
This commit is contained in:
parent
4f57c5b842
commit
151722664f
|
@ -30,6 +30,10 @@ type ProtectiveStopLoss struct {
|
|||
// PlaceStopOrder places the stop order on exchange and lock the balance
|
||||
PlaceStopOrder bool `json:"placeStopOrder"`
|
||||
|
||||
// Interval is the time resolution to update the stop order
|
||||
// KLine per Interval will be used for updating the stop order
|
||||
Interval types.Interval `json:"interval,omitempty"`
|
||||
|
||||
session *ExchangeSession
|
||||
orderExecutor *GeneralOrderExecutor
|
||||
stopLossPrice fixedpoint.Value
|
||||
|
@ -37,8 +41,8 @@ type ProtectiveStopLoss struct {
|
|||
}
|
||||
|
||||
func (s *ProtectiveStopLoss) Subscribe(session *ExchangeSession) {
|
||||
// use 1m kline to handle roi stop
|
||||
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: types.Interval1m})
|
||||
// use kline to handle roi stop
|
||||
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
|
||||
}
|
||||
|
||||
func (s *ProtectiveStopLoss) shouldActivate(position *types.Position, closePrice fixedpoint.Value) bool {
|
||||
|
@ -131,8 +135,8 @@ func (s *ProtectiveStopLoss) Bind(session *ExchangeSession, orderExecutor *Gener
|
|||
s.stopLossPrice = fixedpoint.Zero
|
||||
}
|
||||
}
|
||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, f))
|
||||
session.MarketDataStream.OnKLine(types.KLineWith(s.Symbol, types.Interval1m, f))
|
||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.Interval, f))
|
||||
session.MarketDataStream.OnKLine(types.KLineWith(s.Symbol, s.Interval, f))
|
||||
|
||||
if !IsBackTesting && enableMarketTradeStop {
|
||||
session.MarketDataStream.OnMarketTrade(func(trade types.Trade) {
|
||||
|
|
|
@ -11,14 +11,17 @@ type RoiStopLoss struct {
|
|||
Symbol string
|
||||
Percentage fixedpoint.Value `json:"percentage"`
|
||||
CancelActiveOrders bool `json:"cancelActiveOrders"`
|
||||
// Interval is the time resolution to update the stop order
|
||||
// KLine per Interval will be used for updating the stop order
|
||||
Interval types.Interval `json:"interval,omitempty"`
|
||||
|
||||
session *ExchangeSession
|
||||
orderExecutor *GeneralOrderExecutor
|
||||
}
|
||||
|
||||
func (s *RoiStopLoss) Subscribe(session *ExchangeSession) {
|
||||
// use 1m kline to handle roi stop
|
||||
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: types.Interval1m})
|
||||
// use kline to handle roi stop
|
||||
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
|
||||
}
|
||||
|
||||
func (s *RoiStopLoss) Bind(session *ExchangeSession, orderExecutor *GeneralOrderExecutor) {
|
||||
|
@ -30,8 +33,8 @@ func (s *RoiStopLoss) Bind(session *ExchangeSession, orderExecutor *GeneralOrder
|
|||
s.checkStopPrice(kline.Close, position)
|
||||
}
|
||||
|
||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, f))
|
||||
session.MarketDataStream.OnKLine(types.KLineWith(s.Symbol, types.Interval1m, f))
|
||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.Interval, f))
|
||||
session.MarketDataStream.OnKLine(types.KLineWith(s.Symbol, s.Interval, f))
|
||||
|
||||
if !IsBackTesting && enableMarketTradeStop {
|
||||
session.MarketDataStream.OnMarketTrade(func(trade types.Trade) {
|
||||
|
|
|
@ -13,13 +13,17 @@ type RoiTakeProfit struct {
|
|||
Percentage fixedpoint.Value `json:"percentage"`
|
||||
CancelActiveOrders bool `json:"cancelActiveOrders"`
|
||||
|
||||
// Interval is the time resolution to update the stop order
|
||||
// KLine per Interval will be used for updating the stop order
|
||||
Interval types.Interval `json:"interval,omitempty"`
|
||||
|
||||
session *ExchangeSession
|
||||
orderExecutor *GeneralOrderExecutor
|
||||
}
|
||||
|
||||
func (s *RoiTakeProfit) Subscribe(session *ExchangeSession) {
|
||||
// use 1m kline to handle roi stop
|
||||
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: types.Interval1m})
|
||||
// use kline to handle roi stop
|
||||
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
|
||||
}
|
||||
|
||||
func (s *RoiTakeProfit) Bind(session *ExchangeSession, orderExecutor *GeneralOrderExecutor) {
|
||||
|
@ -27,7 +31,7 @@ func (s *RoiTakeProfit) Bind(session *ExchangeSession, orderExecutor *GeneralOrd
|
|||
s.orderExecutor = orderExecutor
|
||||
|
||||
position := orderExecutor.Position()
|
||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) {
|
||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.Interval, func(kline types.KLine) {
|
||||
closePrice := kline.Close
|
||||
if position.IsClosed() || position.IsDust(closePrice) || position.IsClosing() {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user