private void UnsubscribeSymbol(OKExSymbol symbol, OKExSubscriptionType type) { if (symbol.InstrumentType == OKExInstrumentType.Index) { return; } if (!this.subscriberCache.TryGetValue(symbol.OKExInstrumentId, out var okexSubscriber)) { return; } var channelArgs = new List <OKExChannelRequest>(); okexSubscriber.RemoveChannel(type); if (symbol.TryGetChannelName(type, out string channelName)) { channelArgs.Add(new OKExChannelRequest() { ChannelName = channelName, InstrumentId = symbol.OKExInstrumentId }); } if (!okexSubscriber.ContainsAnyMainSubscription()) { okexSubscriber.RemoveChannel(OKExSubscriptionType.Ticker); if (symbol.TryGetChannelName(OKExSubscriptionType.Ticker, out channelName)) { channelArgs.Add(new OKExChannelRequest() { ChannelName = channelName, InstrumentId = symbol.OKExInstrumentId }); } if (symbol.InstrumentType != OKExInstrumentType.Spot) { okexSubscriber.RemoveChannel(OKExSubscriptionType.OpenInterest); if (symbol.TryGetChannelName(OKExSubscriptionType.OpenInterest, out channelName)) { channelArgs.Add(new OKExChannelRequest() { ChannelName = channelName, InstrumentId = symbol.OKExInstrumentId }); } } this.subscriberCache.Remove(symbol.OKExInstrumentId); } if (channelArgs.Count > 0) { this.publicWebsocket.RemoveFromQueue(channelArgs.ToArray()); } }
private void SubscribeSymbol(OKExSymbol symbol, OKExSubscriptionType type) { if (symbol.InstrumentType == OKExInstrumentType.Index) { return; } if (!this.subscriberCache.TryGetValue(symbol.OKExInstrumentId, out var okexSubscriber)) { this.subscriberCache[symbol.OKExInstrumentId] = okexSubscriber = new OKExGeneralSubscriber(symbol); } var args = new List <OKExChannelRequest>(); if (okexSubscriber.SubscriptionCount == 0) { okexSubscriber.AddSubscription(OKExSubscriptionType.Ticker); if (symbol.TryGetChannelName(OKExSubscriptionType.Ticker, out string channelName)) { args.Add(new OKExChannelRequest() { ChannelName = channelName, InstrumentId = symbol.OKExInstrumentId }); } if (okexSubscriber.Symbol.InstrumentType != OKExInstrumentType.Spot) { okexSubscriber.AddSubscription(OKExSubscriptionType.OpenInterest); if (symbol.TryGetChannelName(OKExSubscriptionType.OpenInterest, out channelName)) { args.Add(new OKExChannelRequest() { ChannelName = channelName, InstrumentId = symbol.OKExInstrumentId }); } } } if (!okexSubscriber.ContainsSubscription(type)) { okexSubscriber.AddSubscription(type); if (symbol.TryGetChannelName(type, out string channelName)) { args.Add(new OKExChannelRequest() { ChannelName = channelName, InstrumentId = symbol.OKExInstrumentId }); } if (args.Count > 0) { this.publicWebsocket.AddRequestToQueue(args.ToArray()); } } }
internal void RemoveChannel(OKExSubscriptionType subscriptionType) { this.channelsCache.Remove(subscriptionType); }
internal bool ContainsSubscription(OKExSubscriptionType subscriptionType) { return(this.channelsCache.Contains(subscriptionType)); }
internal void AddSubscription(OKExSubscriptionType subscriptionType) { this.channelsCache.Add(subscriptionType); }