add accessor to MarketDataStore

This commit is contained in:
c9s 2020-10-18 12:27:11 +08:00
parent 7d7828a556
commit 168cb355fc
2 changed files with 15 additions and 10 deletions

View File

@ -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) {

View File

@ -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{