internal OKExTradeItem[] GetTickHistory(OKExSymbol symbol, CancellationToken token, out string error) { var responce = this.SendPublicGetRequest <OKExTradeItem[]>($"{this.settings.RestEndpoint}/api/v5/market/trades?&instId={symbol.OKExInstrumentId}", token); error = responce.Message; return(responce.Data ?? new OKExTradeItem[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()); } }
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()); } } }
public bool TryGetSymbolById(string symbolId, OKExInstrumentType type, out OKExSymbol symbol) { symbol = null; foreach (var item in this.allSymbolsCache) { if (type != OKExInstrumentType.Any && type == item.Key) { return(item.Value.TryGetValue(symbolId, out symbol)); } } return(false); }
internal OKExCandleItem[] GetCandleHistory(OKExSymbol symbol, DateTime?after, OKExCandlePeriod period, OKExHistoryType historyType, CancellationToken token, out string error) { if (period == OKExCandlePeriod.Tick1) { throw new ArgumentException($"Unsupported candle period - {period}"); } // default string endpoint = "/api/v5/market/candles"; if (symbol.InstrumentType == OKExInstrumentType.Index) { endpoint = "/api/v5/market/index-candles"; } else if (historyType == OKExHistoryType.Last) { if (symbol.IsTopCurrency()) { endpoint = "/api/v5/market/history-candles"; } else { endpoint = "/api/v5/market/candles"; } } else if (historyType == OKExHistoryType.Mark) { endpoint = "/api/v5/market/mark-price-candles"; } // var request = $"{this.settings.RestEndpoint}{endpoint}?instId={symbol.OKExInstrumentId}&bar={period.GetEnumMember()}"; if (after.HasValue) { request += $"&after={new DateTimeOffset(after.Value).ToUnixTimeMilliseconds()}"; } // var responce = this.SendPublicGetRequest <OKExCandleItem[]>(request, token); error = responce?.Message; return(responce?.Data ?? new OKExCandleItem[0]); }
internal void UnsubscribeIndexPrice(OKExSymbol symbol) { if (symbol.InstrumentType != OKExInstrumentType.Index) { return; } if (this.indexSubscriberCache.TryGetValue(symbol.OKExInstrumentId, out var subscriber)) { subscriber.RemoveChannel(OKExSubscriptionType.Ticker); this.indexSubscriberCache.Remove(symbol.OKExInstrumentId); if (symbol.TryGetChannelName(OKExSubscriptionType.Ticker, out string channelName)) { this.publicWebsocket.RemoveFromQueue(new OKExChannelRequest() { ChannelName = channelName, InstrumentId = symbol.OKExInstrumentId }); } } }
internal void SubscribeIndexPrice(OKExSymbol symbol) { if (symbol.InstrumentType != OKExInstrumentType.Index) { return; } if (!this.indexSubscriberCache.ContainsKey(symbol.OKExInstrumentId)) { var subscriber = new OKExIndexSubscriber(symbol); subscriber.AddSubscription(OKExSubscriptionType.Ticker); this.indexSubscriberCache[symbol.OKExInstrumentId] = subscriber; if (symbol.TryGetChannelName(OKExSubscriptionType.Ticker, out string channelName)) { this.publicWebsocket.AddRequestToQueue(new OKExChannelRequest() { ChannelName = channelName, InstrumentId = symbol.OKExInstrumentId }); } } }
public OKExIndexSubscriber(OKExSymbol symbol) : base(symbol) { }
public OKExGeneralSubscriber(OKExSymbol symbol) : base(symbol) { }
public void UnsubscribeMark(OKExSymbol symbol) => this.UnsubscribeSymbol(symbol, OKExSubscriptionType.Mark);
public void UnsubscribeLevel2(OKExSymbol symbol) => this.UnsubscribeSymbol(symbol, OKExSubscriptionType.Level2);
public void UnsubscribeQuote(OKExSymbol symbol) => this.UnsubscribeSymbol(symbol, OKExSubscriptionType.Quote);
public void UnsubscribeLast(OKExSymbol symbol) => this.UnsubscribeSymbol(symbol, OKExSubscriptionType.Last);
public OKExSubscriberBase(OKExSymbol symbol) { this.Symbol = symbol; this.channelsCache = new HashSet <OKExSubscriptionType>(); }