/// <summary> /// Instantiate and connect a new Level 2 data feed. /// </summary> /// <param name="symbol">The symbol to watch.</param> public KlineFeed(string symbol, KlineType type) : base(null, null, null) { Connect().ContinueWith(async(t) => { await SubscribeOne(symbol, type); }); }
/// <summary> /// Unsubscribe from the specified ticker. /// </summary> /// <param name="symbol">The trading pair (symbol) of the ticker to remove.</param> /// <param name="type">The <see cref="KlineType"/> of the ticker to remove.</param> public virtual async Task UnsubscribeOne(string symbol, KlineType type) { if (disposedValue) { throw new ObjectDisposedException(GetType().FullName); } if (!Connected) { return; } SymbolKline sk = SymbolKline.Empty; foreach (var t in activeTickers) { if (t.Symbol == symbol && t.KlineType == type) { sk = t; break; } } if (sk == SymbolKline.Empty) { return; } var topic = $"{Topic}:{sk}"; var e = new FeedMessage() { Type = "unsubscribe", Id = connectId.ToString("d"), Topic = topic, Response = true }; await Send(e); }
/// <summary> /// Subscribe to the specified ticker. /// </summary> /// <param name="symbol">The trading pair (symbol) of the ticker to add.</param> /// <param name="type">The <see cref="KlineType"/> of the ticker to add.</param> /// <returns></returns> public virtual async Task SubscribeOne(string symbol, KlineType type) { if (disposedValue) { throw new ObjectDisposedException(GetType().FullName); } if (!Connected) { await Connect(); } foreach (var t in activeTickers) { if (t.Symbol == symbol && t.KlineType == type) { return; } } var sk = new SymbolKline(symbol, type); activeTickers.Add(sk); var topic = $"{Topic}:{sk}"; var e = new FeedMessage() { Type = "subscribe", Id = connectId.ToString("d"), Topic = topic, Response = true, PrivateChannel = false }; await Send(e); }