Skip to content

Commit

Permalink
core: remove built-in stream book from session
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 14, 2024
1 parent 3d1a481 commit 30b275d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
20 changes: 3 additions & 17 deletions pkg/bbgo/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ type ExchangeSession struct {
// markets defines market configuration of a symbol
markets map[string]types.Market

// orderBooks stores the streaming order book
orderBooks map[string]*types.StreamOrderBook

// startPrices is used for backtest
startPrices map[string]fixedpoint.Value

Expand Down Expand Up @@ -185,10 +182,9 @@ func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession {
Account: &types.Account{},
Trades: make(map[string]*types.TradeSlice),

orderBooks: make(map[string]*types.StreamOrderBook),
markets: make(map[string]types.Market),
startPrices: make(map[string]fixedpoint.Value),
lastPrices: make(map[string]fixedpoint.Value),
markets: make(map[string]types.Market, 100),
startPrices: make(map[string]fixedpoint.Value, 30),
lastPrices: make(map[string]fixedpoint.Value, 30),
positions: make(map[string]*types.Position),
marketDataStores: make(map[string]*MarketDataStore),
standardIndicatorSets: make(map[string]*StandardIndicatorSet),
Expand Down Expand Up @@ -557,9 +553,6 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ
for _, sub := range session.Subscriptions {
switch sub.Channel {
case types.BookChannel:
book := types.NewStreamBook(sub.Symbol, session.ExchangeName)
book.BindStream(session.MarketDataStream)
session.orderBooks[sub.Symbol] = book

case types.KLineChannel:
if sub.Options.Interval == "" {
Expand Down Expand Up @@ -719,12 +712,6 @@ func (session *ExchangeSession) SerialMarketDataStore(
return store, true
}

// OrderBook returns the personal orderbook of a symbol
func (session *ExchangeSession) OrderBook(symbol string) (s *types.StreamOrderBook, ok bool) {
s, ok = session.orderBooks[symbol]
return s, ok
}

func (session *ExchangeSession) StartPrice(symbol string) (price fixedpoint.Value, ok bool) {
price, ok = session.startPrices[symbol]
return price, ok
Expand Down Expand Up @@ -958,7 +945,6 @@ func (session *ExchangeSession) InitExchange(name string, ex types.Exchange) err
session.Account = &types.Account{}
session.Trades = make(map[string]*types.TradeSlice)

session.orderBooks = make(map[string]*types.StreamOrderBook)
session.markets = make(map[string]types.Market)
session.lastPrices = make(map[string]fixedpoint.Value)
session.startPrices = make(map[string]fixedpoint.Value)
Expand Down
4 changes: 3 additions & 1 deletion pkg/strategy/tri/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,9 @@ func (s *Strategy) buildArbMarkets(
m.book = book
m.stream = stream
} else {
book, _ := session.OrderBook(symbol)

book := types.NewStreamBook(symbol, session.ExchangeName)
book.BindStream(session.MarketDataStream)
priceUpdater := func(_ types.SliceOrderBook) {
bestAsk, bestBid, _ := book.BestBidAndAsk()
if bestAsk.Equals(m.bestAsk) && bestBid.Equals(m.bestBid) {
Expand Down

0 comments on commit 30b275d

Please sign in to comment.