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/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)
|
||||||
|
|
||||||
|
@ -21,17 +21,19 @@ 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 {
|
||||||
Symbol string `json:"symbol"`
|
Symbol string `json:"symbol"`
|
||||||
Interval types.Interval `json:"interval"`
|
Interval types.Interval `json:"interval"`
|
||||||
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"`
|
||||||
Targets []Target `json:"targets"`
|
MarginOrderSideEffect types.MarginOrderSideEffectType `json:"marginOrderSideEffect"`
|
||||||
|
Targets []Target `json:"targets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) ID() string {
|
func (s *Strategy) ID() string {
|
||||||
|
@ -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{
|
|
||||||
Symbol: s.Symbol,
|
|
||||||
Market: market,
|
|
||||||
Side: types.SideTypeBuy,
|
|
||||||
Type: types.OrderTypeMarket,
|
|
||||||
Quantity: quantity,
|
|
||||||
|
|
||||||
// This is for Long position.
|
orderForm := types.SubmitOrder{
|
||||||
MarginSideEffect: types.SideEffectTypeMarginBuy,
|
Symbol: s.Symbol,
|
||||||
})
|
Market: market,
|
||||||
|
Side: types.SideTypeBuy,
|
||||||
|
Type: types.OrderTypeMarket,
|
||||||
|
Quantity: quantity,
|
||||||
|
MarginSideEffect: s.MarginOrderSideEffect,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := orderExecutor.SubmitOrders(ctx, orderForm)
|
||||||
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