void ProcessEvents(TradeWebResponse response) { if (response.events == null) { return; } if (response.events is ExpandoObject) { long LastLogPos = NextLogPos - 1; foreach (KeyValuePair <string, object> @event in response.events) { int key; if (!Int32.TryParse(@event.Key as string, out key)) { continue; } LastLogPos = Math.Max(LastLogPos, key); ProcessEvent(key, @event.Value as ExpandoObject); } //Console.WriteLine("New NextLogPos: " + (LastLogPos + 1)); Interlocked.Exchange(ref NextLogPos, LastLogPos + 1); } else { foreach (var @event in response.events) { Interlocked.Increment(ref NextLogPos); ProcessEvent(0, @event); } } }
void ProcessStatus(TradeWebResponse response) { var trade_status = response.trade_status; switch (trade_status) { case 0: // Trade is ongoing. Status = ETradeTransactionStatus.InProgress; break; case 1: ulong tradeId; ulong.TryParse(response.tradeid, out tradeId); FinishTrade(ETradeTransactionStatus.Finished, (e) => e.tradeId = tradeId); break; case 3: FinishTrade(ETradeTransactionStatus.Cancelled); break; case 4: FinishTrade(ETradeTransactionStatus.TimedOut); break; default: Console.WriteLine("Unknown trade status: " + trade_status); break; } }
void ProcessEvents(TradeWebResponse response) { if (response.events == null) return; if (response.events is ExpandoObject) { long LastLogPos = NextLogPos - 1; foreach (KeyValuePair<string, object> @event in response.events) { int key; if (!Int32.TryParse(@event.Key as string, out key)) continue; LastLogPos = Math.Max(LastLogPos, key); ProcessEvent(key, @event.Value as ExpandoObject); } //Console.WriteLine("New NextLogPos: " + (LastLogPos + 1)); Interlocked.Exchange(ref NextLogPos, LastLogPos + 1); } else { foreach (var @event in response.events) { Interlocked.Increment(ref NextLogPos); ProcessEvent(0, @event); } } }