mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
improve support strategy
This commit is contained in:
parent
bea750ca97
commit
0c9ca851e5
|
@ -8,7 +8,7 @@ import (
|
||||||
_ "github.com/c9s/bbgo/pkg/strategy/grid"
|
_ "github.com/c9s/bbgo/pkg/strategy/grid"
|
||||||
_ "github.com/c9s/bbgo/pkg/strategy/mirrormaker"
|
_ "github.com/c9s/bbgo/pkg/strategy/mirrormaker"
|
||||||
_ "github.com/c9s/bbgo/pkg/strategy/pricealert"
|
_ "github.com/c9s/bbgo/pkg/strategy/pricealert"
|
||||||
_ "github.com/c9s/bbgo/pkg/strategy/sat"
|
_ "github.com/c9s/bbgo/pkg/strategy/support"
|
||||||
_ "github.com/c9s/bbgo/pkg/strategy/swing"
|
_ "github.com/c9s/bbgo/pkg/strategy/swing"
|
||||||
_ "github.com/c9s/bbgo/pkg/strategy/trailingstop"
|
_ "github.com/c9s/bbgo/pkg/strategy/trailingstop"
|
||||||
_ "github.com/c9s/bbgo/pkg/strategy/xpuremaker"
|
_ "github.com/c9s/bbgo/pkg/strategy/xpuremaker"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package sat
|
package support
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -11,8 +11,8 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/types"
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// sat -- support and targets
|
// support -- support and targets
|
||||||
const ID = "supportAndTargets"
|
const ID = "support"
|
||||||
|
|
||||||
var log = logrus.WithField("strategy", ID)
|
var log = logrus.WithField("strategy", ID)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ func init() {
|
||||||
type Target struct {
|
type Target struct {
|
||||||
ProfitPercentage float64 `json:"profitPercentage"`
|
ProfitPercentage float64 `json:"profitPercentage"`
|
||||||
QuantityPercentage float64 `json:"quantityPercentage"`
|
QuantityPercentage float64 `json:"quantityPercentage"`
|
||||||
|
MarginOrderSideEffect types.MarginOrderSideEffectType `json:"marginOrderSideEffect"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Strategy struct {
|
type Strategy struct {
|
||||||
|
@ -31,6 +32,7 @@ type Strategy struct {
|
||||||
MovingAverageWindow int `json:"movingAverageWindow"`
|
MovingAverageWindow int `json:"movingAverageWindow"`
|
||||||
Quantity fixedpoint.Value `json:"quantity"`
|
Quantity fixedpoint.Value `json:"quantity"`
|
||||||
MinVolume fixedpoint.Value `json:"minVolume"`
|
MinVolume fixedpoint.Value `json:"minVolume"`
|
||||||
|
MarginOrderSideEffect types.MarginOrderSideEffectType `json:"marginOrderSideEffect"`
|
||||||
Targets []Target `json:"targets"`
|
Targets []Target `json:"targets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,16 +94,17 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
log.Infof("found support: close price %f is under EMA %f, volume %f > minimum volume %f", closePrice, ema.Last(), kline.Volume, s.MinVolume.Float64())
|
log.Infof("found support: close price %f is under EMA %f, volume %f > minimum volume %f", closePrice, ema.Last(), kline.Volume, s.MinVolume.Float64())
|
||||||
|
|
||||||
quantity := s.Quantity.Float64()
|
quantity := s.Quantity.Float64()
|
||||||
_, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
|
|
||||||
|
orderForm := types.SubmitOrder{
|
||||||
Symbol: s.Symbol,
|
Symbol: s.Symbol,
|
||||||
Market: market,
|
Market: market,
|
||||||
Side: types.SideTypeBuy,
|
Side: types.SideTypeBuy,
|
||||||
Type: types.OrderTypeMarket,
|
Type: types.OrderTypeMarket,
|
||||||
Quantity: quantity,
|
Quantity: quantity,
|
||||||
|
MarginSideEffect: s.MarginOrderSideEffect,
|
||||||
|
}
|
||||||
|
|
||||||
// This is for Long position.
|
_, err := orderExecutor.SubmitOrders(ctx, orderForm)
|
||||||
MarginSideEffect: types.SideEffectTypeMarginBuy,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("submit order error")
|
log.WithError(err).Error("submit order error")
|
||||||
return
|
return
|
||||||
|
@ -120,8 +123,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
Price: targetPrice,
|
Price: targetPrice,
|
||||||
Quantity: targetQuantity,
|
Quantity: targetQuantity,
|
||||||
|
|
||||||
// This is for Long position.
|
MarginSideEffect: target.MarginOrderSideEffect,
|
||||||
MarginSideEffect: types.SideEffectTypeAutoRepay,
|
|
||||||
TimeInForce: "GTC",
|
TimeInForce: "GTC",
|
||||||
})
|
})
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user