示例#1
0
        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());
            }
        }
示例#2
0
        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());
                }
            }
        }
示例#3
0
 internal void RemoveChannel(OKExSubscriptionType subscriptionType)
 {
     this.channelsCache.Remove(subscriptionType);
 }
示例#4
0
 internal bool ContainsSubscription(OKExSubscriptionType subscriptionType)
 {
     return(this.channelsCache.Contains(subscriptionType));
 }
示例#5
0
 internal void AddSubscription(OKExSubscriptionType subscriptionType)
 {
     this.channelsCache.Add(subscriptionType);
 }