mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
add accessor to MarketDataStore
This commit is contained in:
parent
7d7828a556
commit
168cb355fc
|
@ -102,7 +102,7 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
|
|||
|
||||
session.LastPrices[symbol] = currentPrice
|
||||
|
||||
session.MarketDataStores[symbol] = store.NewMarketDataStore(symbol)
|
||||
session.marketDataStores[symbol] = store.NewMarketDataStore(symbol)
|
||||
}
|
||||
|
||||
log.Infof("querying balances...")
|
||||
|
@ -121,7 +121,7 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
|
|||
// update last prices
|
||||
stream.OnKLineClosed(func(kline types.KLine) {
|
||||
session.LastPrices[kline.Symbol] = kline.Close
|
||||
session.MarketDataStores[kline.Symbol].AddKLine(kline)
|
||||
session.marketDataStores[kline.Symbol].AddKLine(kline)
|
||||
})
|
||||
|
||||
stream.OnTrade(func(trade *types.Trade) {
|
||||
|
|
|
@ -30,21 +30,26 @@ type ExchangeSession struct {
|
|||
// map: symbol -> []trade
|
||||
Trades map[string][]types.Trade
|
||||
|
||||
MarketDataStores map[string]*store.MarketDataStore
|
||||
marketDataStores map[string]*store.MarketDataStore
|
||||
}
|
||||
|
||||
func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession {
|
||||
return &ExchangeSession{
|
||||
Name: name,
|
||||
Exchange: exchange,
|
||||
Subscriptions: make(map[types.Subscription]types.Subscription),
|
||||
Markets: make(map[string]types.Market),
|
||||
Trades: make(map[string][]types.Trade),
|
||||
LastPrices: make(map[string]float64),
|
||||
MarketDataStores: make(map[string]*store.MarketDataStore),
|
||||
Name: name,
|
||||
Exchange: exchange,
|
||||
Subscriptions: make(map[types.Subscription]types.Subscription),
|
||||
Markets: make(map[string]types.Market),
|
||||
Trades: make(map[string][]types.Trade),
|
||||
LastPrices: make(map[string]float64),
|
||||
marketDataStores: make(map[string]*store.MarketDataStore),
|
||||
}
|
||||
}
|
||||
|
||||
func (session *ExchangeSession) MarketDataStore(symbol string) (s *store.MarketDataStore, ok bool) {
|
||||
s, ok = session.marketDataStores[symbol]
|
||||
return s, ok
|
||||
}
|
||||
|
||||
// Subscribe save the subscription info, later it will be assigned to the stream
|
||||
func (session *ExchangeSession) Subscribe(channel types.Channel, symbol string, options types.SubscribeOptions) *ExchangeSession {
|
||||
sub := types.Subscription{
|
||||
|
|
Loading…
Reference in New Issue
Block a user