mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
Merge pull request #667 from c9s/strategy/pivot
This commit is contained in:
commit
2d461582ea
|
@ -4,7 +4,6 @@ sessions:
|
||||||
envVarPrefix: binance
|
envVarPrefix: binance
|
||||||
# futures: true
|
# futures: true
|
||||||
|
|
||||||
|
|
||||||
exchangeStrategies:
|
exchangeStrategies:
|
||||||
- on: binance
|
- on: binance
|
||||||
pivotshort:
|
pivotshort:
|
||||||
|
@ -14,6 +13,7 @@ exchangeStrategies:
|
||||||
pivotLength: 120
|
pivotLength: 120
|
||||||
|
|
||||||
entry:
|
entry:
|
||||||
|
immediate: true
|
||||||
catBounceRatio: 1%
|
catBounceRatio: 1%
|
||||||
quantity: 1000
|
quantity: 1000
|
||||||
numLayers: 3
|
numLayers: 3
|
||||||
|
@ -22,15 +22,14 @@ exchangeStrategies:
|
||||||
exit:
|
exit:
|
||||||
takeProfitPercentage: 13%
|
takeProfitPercentage: 13%
|
||||||
stopLossPercentage: 0.5%
|
stopLossPercentage: 0.5%
|
||||||
shadowTPRatio: 13%
|
shadowTakeProfitRatio: 3%
|
||||||
# marginOrderSideEffect: repay
|
# marginOrderSideEffect: repay
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
backtest:
|
backtest:
|
||||||
sessions:
|
sessions:
|
||||||
- binance
|
- binance
|
||||||
startTime: "2022-04-01"
|
startTime: "2022-05-25"
|
||||||
endTime: "2022-06-03"
|
endTime: "2022-06-03"
|
||||||
symbols:
|
symbols:
|
||||||
- GMTUSDT
|
- GMTUSDT
|
||||||
|
|
|
@ -24,6 +24,7 @@ type IntervalWindowSetting struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Entry struct {
|
type Entry struct {
|
||||||
|
Immediate bool `json:"immediate"`
|
||||||
CatBounceRatio fixedpoint.Value `json:"catBounceRatio"`
|
CatBounceRatio fixedpoint.Value `json:"catBounceRatio"`
|
||||||
Quantity fixedpoint.Value `json:"quantity"`
|
Quantity fixedpoint.Value `json:"quantity"`
|
||||||
NumLayers fixedpoint.Value `json:"numLayers"`
|
NumLayers fixedpoint.Value `json:"numLayers"`
|
||||||
|
@ -33,7 +34,7 @@ type Entry struct {
|
||||||
type Exit struct {
|
type Exit struct {
|
||||||
TakeProfitPercentage fixedpoint.Value `json:"takeProfitPercentage"`
|
TakeProfitPercentage fixedpoint.Value `json:"takeProfitPercentage"`
|
||||||
StopLossPercentage fixedpoint.Value `json:"stopLossPercentage"`
|
StopLossPercentage fixedpoint.Value `json:"stopLossPercentage"`
|
||||||
ShadowTPRatio fixedpoint.Value `json:"shadowTPRatio"`
|
ShadowTPRatio fixedpoint.Value `json:"shadowTakeProfitRatio"`
|
||||||
MarginSideEffect types.MarginOrderSideEffectType `json:"marginOrderSideEffect"`
|
MarginSideEffect types.MarginOrderSideEffectType `json:"marginOrderSideEffect"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,14 +81,17 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
||||||
//session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: types.Interval1d})
|
//session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: types.Interval1d})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) placeOrder(ctx context.Context, price fixedpoint.Value, qty fixedpoint.Value, orderExecutor bbgo.OrderExecutor) {
|
func (s *Strategy) placeOrder(ctx context.Context, marketPrice fixedpoint.Value, limitPrice fixedpoint.Value, currentPrice fixedpoint.Value, qty fixedpoint.Value, orderExecutor bbgo.OrderExecutor) {
|
||||||
submitOrder := types.SubmitOrder{
|
submitOrder := types.SubmitOrder{
|
||||||
Symbol: s.Symbol,
|
Symbol: s.Symbol,
|
||||||
Side: types.SideTypeSell,
|
Side: types.SideTypeSell,
|
||||||
Type: types.OrderTypeLimit,
|
Type: types.OrderTypeLimit,
|
||||||
Price: price,
|
Price: limitPrice,
|
||||||
Quantity: qty,
|
Quantity: qty,
|
||||||
}
|
}
|
||||||
|
if s.Entry.Immediate && marketPrice.Compare(currentPrice) <= 0 {
|
||||||
|
submitOrder.Type = types.OrderTypeMarket
|
||||||
|
}
|
||||||
if s.session.Margin {
|
if s.session.Margin {
|
||||||
submitOrder.MarginSideEffect = s.Entry.MarginSideEffect
|
submitOrder.MarginSideEffect = s.Entry.MarginSideEffect
|
||||||
}
|
}
|
||||||
|
@ -279,19 +283,19 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
if futuresMode {
|
if futuresMode {
|
||||||
//log.Infof("futures mode on")
|
//log.Infof("futures mode on")
|
||||||
if q.Mul(p).Compare(quoteBalance.Available) <= 0 {
|
if q.Mul(p).Compare(quoteBalance.Available) <= 0 {
|
||||||
s.placeOrder(ctx, p, q, orderExecutor)
|
s.placeOrder(ctx, lastLow, p, kline.Close, q, orderExecutor)
|
||||||
s.tradeCollector.Process()
|
s.tradeCollector.Process()
|
||||||
}
|
}
|
||||||
} else if s.Environment.IsBackTesting() {
|
} else if s.Environment.IsBackTesting() {
|
||||||
//log.Infof("spot backtest mode on")
|
//log.Infof("spot backtest mode on")
|
||||||
if q.Compare(baseBalance.Available) <= 0 {
|
if q.Compare(baseBalance.Available) <= 0 {
|
||||||
s.placeOrder(ctx, p, q, orderExecutor)
|
s.placeOrder(ctx, lastLow, p, kline.Close, q, orderExecutor)
|
||||||
s.tradeCollector.Process()
|
s.tradeCollector.Process()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//log.Infof("spot mode on")
|
//log.Infof("spot mode on")
|
||||||
if q.Compare(baseBalance.Available) <= 0 {
|
if q.Compare(baseBalance.Available) <= 0 {
|
||||||
s.placeOrder(ctx, p, q, orderExecutor)
|
s.placeOrder(ctx, lastLow, p, kline.Close, q, orderExecutor)
|
||||||
s.tradeCollector.Process()
|
s.tradeCollector.Process()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user