mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +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/mirrormaker"
|
||||
_ "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/trailingstop"
|
||||
_ "github.com/c9s/bbgo/pkg/strategy/xpuremaker"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package sat
|
||||
package support
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -11,8 +11,8 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
// sat -- support and targets
|
||||
const ID = "supportAndTargets"
|
||||
// support -- support and targets
|
||||
const ID = "support"
|
||||
|
||||
var log = logrus.WithField("strategy", ID)
|
||||
|
||||
|
@ -23,6 +23,7 @@ func init() {
|
|||
type Target struct {
|
||||
ProfitPercentage float64 `json:"profitPercentage"`
|
||||
QuantityPercentage float64 `json:"quantityPercentage"`
|
||||
MarginOrderSideEffect types.MarginOrderSideEffectType `json:"marginOrderSideEffect"`
|
||||
}
|
||||
|
||||
type Strategy struct {
|
||||
|
@ -31,6 +32,7 @@ type Strategy struct {
|
|||
MovingAverageWindow int `json:"movingAverageWindow"`
|
||||
Quantity fixedpoint.Value `json:"quantity"`
|
||||
MinVolume fixedpoint.Value `json:"minVolume"`
|
||||
MarginOrderSideEffect types.MarginOrderSideEffectType `json:"marginOrderSideEffect"`
|
||||
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())
|
||||
|
||||
quantity := s.Quantity.Float64()
|
||||
_, err := orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
|
||||
|
||||
orderForm := types.SubmitOrder{
|
||||
Symbol: s.Symbol,
|
||||
Market: market,
|
||||
Side: types.SideTypeBuy,
|
||||
Type: types.OrderTypeMarket,
|
||||
Quantity: quantity,
|
||||
MarginSideEffect: s.MarginOrderSideEffect,
|
||||
}
|
||||
|
||||
// This is for Long position.
|
||||
MarginSideEffect: types.SideEffectTypeMarginBuy,
|
||||
})
|
||||
_, err := orderExecutor.SubmitOrders(ctx, orderForm)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("submit order error")
|
||||
return
|
||||
|
@ -120,8 +123,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
|||
Price: targetPrice,
|
||||
Quantity: targetQuantity,
|
||||
|
||||
// This is for Long position.
|
||||
MarginSideEffect: types.SideEffectTypeAutoRepay,
|
||||
MarginSideEffect: target.MarginOrderSideEffect,
|
||||
TimeInForce: "GTC",
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user