mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
pivotshort: add immediate market sell
This commit is contained in:
parent
9dab39849b
commit
af2d88d9a3
|
@ -14,6 +14,7 @@ exchangeStrategies:
|
|||
pivotLength: 120
|
||||
|
||||
entry:
|
||||
immediate: true
|
||||
catBounceRatio: 1%
|
||||
quantity: 1000
|
||||
numLayers: 3
|
||||
|
@ -30,7 +31,7 @@ exchangeStrategies:
|
|||
backtest:
|
||||
sessions:
|
||||
- binance
|
||||
startTime: "2022-04-01"
|
||||
startTime: "2022-05-25"
|
||||
endTime: "2022-06-03"
|
||||
symbols:
|
||||
- GMTUSDT
|
||||
|
|
|
@ -24,6 +24,7 @@ type IntervalWindowSetting struct {
|
|||
}
|
||||
|
||||
type Entry struct {
|
||||
Immediate bool `json:"immediate"`
|
||||
CatBounceRatio fixedpoint.Value `json:"catBounceRatio"`
|
||||
Quantity fixedpoint.Value `json:"quantity"`
|
||||
NumLayers fixedpoint.Value `json:"numLayers"`
|
||||
|
@ -80,14 +81,17 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
|||
//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{
|
||||
Symbol: s.Symbol,
|
||||
Side: types.SideTypeSell,
|
||||
Type: types.OrderTypeLimit,
|
||||
Price: price,
|
||||
Price: limitPrice,
|
||||
Quantity: qty,
|
||||
}
|
||||
if s.Entry.Immediate && marketPrice.Compare(currentPrice) <= 0 {
|
||||
submitOrder.Type = types.OrderTypeMarket
|
||||
}
|
||||
if s.session.Margin {
|
||||
submitOrder.MarginSideEffect = s.Entry.MarginSideEffect
|
||||
}
|
||||
|
@ -279,19 +283,19 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
if futuresMode {
|
||||
//log.Infof("futures mode on")
|
||||
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()
|
||||
}
|
||||
} else if s.Environment.IsBackTesting() {
|
||||
//log.Infof("spot backtest mode on")
|
||||
if q.Compare(baseBalance.Available) <= 0 {
|
||||
s.placeOrder(ctx, p, q, orderExecutor)
|
||||
s.placeOrder(ctx, lastLow, p, kline.Close, q, orderExecutor)
|
||||
s.tradeCollector.Process()
|
||||
}
|
||||
} else {
|
||||
//log.Infof("spot mode on")
|
||||
if q.Compare(baseBalance.Available) <= 0 {
|
||||
s.placeOrder(ctx, p, q, orderExecutor)
|
||||
s.placeOrder(ctx, lastLow, p, kline.Close, q, orderExecutor)
|
||||
s.tradeCollector.Process()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user