Merge pull request #1452 from c9s/refactor/strategy/common

This commit is contained in:
c9s 2023-12-13 18:49:44 +08:00 committed by GitHub
commit 4a54611d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 10 additions and 19 deletions

View File

@ -20,7 +20,7 @@ func init() {
}
type Strategy struct {
*common.Strategy
common.Strategy
Environment *bbgo.Environment
Market types.Market
@ -62,7 +62,6 @@ func (s *Strategy) Defaults() error {
}
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
s.Strategy = &common.Strategy{}
s.Strategy.Initialize(ctx, s.Environment, session, s.Market, ID, s.InstanceID())
atr := session.Indicators(s.Symbol).ATR(s.Interval, s.Window)

View File

@ -26,7 +26,7 @@ func init() {
}
type Strategy struct {
*common.Strategy
common.Strategy
Environment *bbgo.Environment
Market types.Market
@ -101,7 +101,6 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
}
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
s.Strategy = &common.Strategy{}
s.Strategy.Initialize(ctx, s.Environment, session, s.Market, ID, s.InstanceID())
instanceID := s.InstanceID()

View File

@ -23,7 +23,7 @@ func init() {
// Fixed spread market making strategy
type Strategy struct {
*common.Strategy
common.Strategy
Environment *bbgo.Environment
Market types.Market
@ -77,7 +77,6 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
}
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
s.Strategy = &common.Strategy{}
s.Strategy.Initialize(ctx, s.Environment, session, s.Market, ID, s.InstanceID())
s.activeOrderBook = bbgo.NewActiveOrderBook(s.Symbol)

View File

@ -32,7 +32,7 @@ func init() {
// - place enough total liquidity amount on the order book, for example, 20k USDT value liquidity on both sell and buy
// - ensure the spread by placing the orders from the mid price (or the last trade price)
type Strategy struct {
*common.Strategy
common.Strategy
Environment *bbgo.Environment
Market types.Market
@ -81,7 +81,6 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
}
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
s.Strategy = &common.Strategy{}
s.Strategy.Initialize(ctx, s.Environment, session, s.Market, ID, s.InstanceID())
s.orderGenerator = &LiquidityOrderGenerator{

View File

@ -23,7 +23,7 @@ func init() {
}
type Strategy struct {
*common.Strategy
common.Strategy
Environment *bbgo.Environment
Market types.Market
@ -67,7 +67,6 @@ func (s *Strategy) Validate() error {
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {}
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
s.Strategy = &common.Strategy{}
s.Strategy.Initialize(ctx, s.Environment, session, s.Market, s.ID(), s.InstanceID())
session.UserDataStream.OnStart(func() {

View File

@ -9,7 +9,7 @@ import (
"github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/indicator/v2"
indicatorv2 "github.com/c9s/bbgo/pkg/indicator/v2"
"github.com/c9s/bbgo/pkg/strategy/common"
"github.com/c9s/bbgo/pkg/types"
)
@ -21,7 +21,7 @@ func init() {
}
type Strategy struct {
*common.Strategy
common.Strategy
Environment *bbgo.Environment
Market types.Market
@ -49,7 +49,6 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
}
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
s.Strategy = &common.Strategy{}
s.Strategy.Initialize(ctx, s.Environment, session, s.Market, ID, s.InstanceID())
fastRsi := session.Indicators(s.Symbol).RSI(types.IntervalWindow{Interval: s.Interval, Window: s.FastWindow})

View File

@ -34,7 +34,7 @@ func init() {
// Strategy scmaker is a stable coin market maker
type Strategy struct {
*common.Strategy
common.Strategy
Environment *bbgo.Environment
Market types.Market
@ -88,7 +88,6 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
}
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
s.Strategy = &common.Strategy{}
s.Strategy.Initialize(ctx, s.Environment, session, s.Market, ID, s.InstanceID())
s.book = types.NewStreamBook(s.Symbol)

View File

@ -30,7 +30,7 @@ func init() {
}
type Strategy struct {
*common.Strategy
common.Strategy
Environment *bbgo.Environment
Market types.Market
@ -235,7 +235,6 @@ func (s *Strategy) placeWallOrders(ctx context.Context, orderExecutor bbgo.Order
}
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
s.Strategy = &common.Strategy{}
s.Strategy.Initialize(ctx, s.Environment, session, s.Market, ID, s.InstanceID())
// initial required information

View File

@ -23,7 +23,7 @@ func init() {
// Fixed spread market making strategy
type Strategy struct {
*common.Strategy
common.Strategy
Environment *bbgo.Environment
@ -109,7 +109,6 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
}
s.market = market
s.Strategy = &common.Strategy{}
s.Strategy.Initialize(ctx, s.Environment, tradingSession, s.market, ID, s.InstanceID())
s.orderPriceRiskControl = NewOrderPriceRiskControl(