/// <summary> /// Subscribes to updates on a specific market /// </summary> /// <param name="marketName">The name of the market to subscribe on</param> /// <param name="onUpdate">The update event handler</param> /// <returns>ApiResult whether subscription was successful. The Result property contains the Stream Id which can be used to unsubscribe the stream again</returns> public async Task <BittrexApiResult <int> > SubscribeToExchangeDeltasAsync(string marketName, Action <BittrexStreamExchangeState> onUpdate) { return(await Task.Run(() => { if (!CheckConnection()) { return ThrowErrorMessage <int>(BittrexErrors.GetError(BittrexErrorKey.CantConnectToServer)); } // send subscribe to bittrex SubscribeToExchangeDeltas(marketName); var registration = new BittrexExchangeDeltasRegistration() { Callback = onUpdate, MarketName = marketName, StreamId = NextStreamId }; lock (registrationLock) { registrations.Add(registration); localRegistrations.Add(registration); } return new BittrexApiResult <int>() { Result = registration.StreamId, Success = true }; }).ConfigureAwait(false)); }
/// <summary> /// Subscribes to updates on a specific market /// </summary> /// <param name="marketName">The name of the market to subscribe on</param> /// <param name="onUpdate">The update event handler</param> /// <returns>ApiResult whether subscription was successful. The Result property contains the Stream Id which can be used to unsubscribe the stream again</returns> public async Task <CallResult <int> > SubscribeToExchangeDeltasAsync(string marketName, Action <BittrexStreamUpdateExchangeState> onUpdate) { log.Write(LogVerbosity.Info, $"Subscribing to exchange deltas for {marketName}"); if (!CheckConnection()) { return(new CallResult <int>(0, new CantConnectError())); } // send subscribe to bittrex await SubscribeToExchangeDeltas(marketName).ConfigureAwait(false); var registration = new BittrexExchangeDeltasRegistration { Callback = onUpdate, MarketName = marketName, StreamId = NextStreamId }; lock (registrationLock) { registrations.Add(registration); localRegistrations.Add(registration); } return(new CallResult <int>(registration.StreamId, null)); }