private async Task OpenStreamAsync <T>(BinanceStreamNameInfo info) where T : BinanceEvent { IBinanceStream stream; string streamName = info.BuildStreamFullName(); lock (this.streamsCacheLocker) { if (this.streamsCache.ContainsKey(streamName)) { throw new ArgumentException($"Stream with name \"{streamName}\" already exist"); } var tStream = new BinanceStream <T>(this.socketBaseEndpoint, streamName); tStream.Opened += this.Stream_Opened; tStream.Closed += this.Stream_Closed; tStream.Error += this.Stream_Error; tStream.EventReceived += this.Stream_EventReceived; tStream.Initialize(); stream = tStream; this.streamsCache.Add(streamName, stream); } await stream.OpenAsync(); }
private async Task CloseStreamAsync(BinanceStreamNameInfo info) { IBinanceStream stream; string streamName = info.BuildStreamFullName(); lock (this.streamsCacheLocker) { if (!this.streamsCache.TryGetValue(streamName, out stream)) { throw new ArgumentException($"Stream with name \"{streamName}\" not found"); } this.streamsCache.Remove(streamName); } await stream.CloseAsync(); }