core: add Initialize() method to the converter interface

This commit is contained in:
c9s 2024-08-08 17:37:58 +08:00
parent df8d52adda
commit 1ad2bc5f34
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 12 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import "github.com/c9s/bbgo/pkg/types"
type Converter interface {
OrderConverter
TradeConverter
Initialize() error
}
// OrderConverter converts the order to another order
@ -29,6 +30,10 @@ func NewDynamicConverter(orderConverter OrderConvertFunc, tradeConverter TradeCo
return &DynamicConverter{orderConverter: orderConverter, tradeConverter: tradeConverter}
}
func (c *DynamicConverter) Initialize() error {
return nil
}
func (c *DynamicConverter) ConvertOrder(order types.Order) (types.Order, error) {
return c.orderConverter(order)
}
@ -47,6 +52,10 @@ func NewSymbolConverter(fromSymbol, toSymbol string) *SymbolConverter {
return &SymbolConverter{FromSymbol: fromSymbol, ToSymbol: toSymbol}
}
func (c *SymbolConverter) Initialize() error {
return nil
}
func (c *SymbolConverter) ConvertOrder(order types.Order) (types.Order, error) {
if order.Symbol == c.FromSymbol {
order.Symbol = c.ToSymbol

View File

@ -12,6 +12,7 @@ import (
"golang.org/x/time/rate"
"github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/core"
"github.com/c9s/bbgo/pkg/exchange/retry"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/strategy/common"
@ -147,6 +148,8 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize(
type Strategy struct {
*CrossExchangeMarketMakingStrategy
*core.ConverterManager
Environment *bbgo.Environment
Symbol string `json:"symbol"`