Skip to content

Commit

Permalink
bbgo: integrate priceSolver into the session struct
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 14, 2024
1 parent 7d94e46 commit 97c5db3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/bbgo/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/c9s/bbgo/pkg/envvar"
"github.com/c9s/bbgo/pkg/exchange/retry"
"github.com/c9s/bbgo/pkg/metrics"
"github.com/c9s/bbgo/pkg/pricesolver"
"github.com/c9s/bbgo/pkg/util/templateutil"

exchange2 "github.com/c9s/bbgo/pkg/exchange"
Expand Down Expand Up @@ -150,6 +151,8 @@ type ExchangeSession struct {
initializedSymbols map[string]struct{}

logger log.FieldLogger

priceSolver *pricesolver.SimplePriceSolver
}

func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession {
Expand Down Expand Up @@ -304,8 +307,11 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
return ErrEmptyMarketInfo
}

logger.Infof("%d markets loaded", len(markets))
session.markets = markets

session.priceSolver = pricesolver.NewSimplePriceResolver(markets)

if feeRateProvider, ok := session.Exchange.(types.ExchangeDefaultFeeRates); ok {
defaultFeeRates := feeRateProvider.DefaultFeeRates()
if session.MakerFeeRate.IsZero() {
Expand All @@ -327,11 +333,15 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
}

if session.UseHeikinAshi {
// replace the existing market data stream
session.MarketDataStream = &types.HeikinAshiStream{
StandardStreamEmitter: session.MarketDataStream.(types.StandardStreamEmitter),
}
}

session.priceSolver.BindStream(session.UserDataStream)
session.priceSolver.BindStream(session.MarketDataStream)

// query and initialize the balances
if !session.PublicOnly {
if len(session.PrivateChannels) > 0 {
Expand Down

0 comments on commit 97c5db3

Please sign in to comment.