public AlterDiceSocketClient(string clientName, SocketClientOptions exchangeOptions, AuthenticationProvider authenticationProvider) : base(clientName, exchangeOptions, authenticationProvider) { //_socketIo = IO.Socket("https://socket.alterdice.com"); //_socketIo.Connect(); _socketIo = new SocketIO("https://socket.alterdice.com/"); _socketIo.OnConnected += _socketIo_OnConnected; _socketIo.OnError += _socketIo_OnError; _socketIo.OnReceivedEvent += _socketIo_OnReceivedEvent; _socketIo.OnDisconnected += _socketIo_OnDisconnected; _socketIo.On("hi", response => { string text = response.GetValue <string>(); Console.WriteLine(text); }); _socketIo.OnConnected += async(sender, e) => { await _socketIo.EmitAsync("hi", ".net core"); Console.WriteLine(e.ToString()); }; _socketIo.On("message", (data) => { Console.WriteLine(data.ToString()); var t = JsonConvert.DeserializeObject <List <List <AlterDiceSocketOrderBookUpdateEvent> > >(data.ToString()); OnOrderBookUpdate?.Invoke(t[0][0]); }); _socketIo.ConnectAsync().GetAwaiter().GetResult(); }
public async Task SubscribeOrderBook(string symbol) { if (!String.IsNullOrWhiteSpace(symbol) && !_subscriptions.ContainsKey(symbol)) { await _wampChannelOpenTask; var subscriber = new OrderBookSubscriber(); subscriber.OnOrderBookUpdate += (s, e) => OnOrderBookUpdate?.Invoke(this, e); var topic = _wampChannel.RealmProxy.TopicContainer.GetTopicByUri(symbol); var obj = await topic.Subscribe(subscriber, new SubscribeOptions()); _subscriptions[symbol] = obj; } }
private void OnOrderBookMessage(SocketIOResponse eventData) { try { var data = JsonConvert.DeserializeObject <List <AlterDiceSocketOrderBookUpdateEvent> >(eventData.GetValue(0).ToString()); foreach (var update in data) { OnOrderBookUpdate?.Invoke(update); } } catch (Exception ex) { log.Write(LogLevel.Error, $"can not process event {eventData.ToString()}: {ex.Message}"); } }
public void Event <TMessage>(IWampFormatter <TMessage> formatter, long publicationId, EventDetails details, TMessage[] arguments, IDictionary <string, TMessage> argumentsKeywords) { if (arguments == null) { return; } foreach (var arg in arguments) { var token = arg as JToken; var type = (OrderBookItemType)Enum.Parse(typeof(OrderBookItemType), token.Value <string>("type"), true); var item = type == OrderBookItemType.NewTrade ? token.SelectToken("data").ToObject <OrderBookTrade>() : token.SelectToken("data").ToObject <OrderBookItem>(); item.Symbol = CurrencyPair.Parse(details.Topic); item.Type = type; OnOrderBookUpdate?.Invoke(this, item); } }
public async Task <CallResult <UpdateSubscription> > SubscribeAsync <TParams>(HitBtcSocketSubscribeBaseRequest <TParams> subscribeRequest) { var dataHandler = new Action <string>(data => { var token = JToken.Parse(data); var method = (string)token["method"]; HitBtcSocketEvent responseType; if (!mappedResponses.TryGetValue(method, out responseType)) { log.Write(LogVerbosity.Warning, $"Unknown response method [{method}] update catched at data {data}"); return; } switch (responseType) { case HitBtcSocketEvent.OrderBookUpdated: { var result = Deserialize <HitBtcSocketOrderBookEvent>(token, false); if (result.Success) { OnOrderBookUpdate?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.OrderbookFullSnapshot: { var result = Deserialize <HitBtcSocketOrderBookEvent>(token, false); if (result.Success) { OnOrderBookSnapshot?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.TradesSnapshot: { var result = Deserialize <HitBtcSocketTradesEvent>(token, false); if (result.Success) { OnTradesSnapshot?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.TradesUpdated: { var result = Deserialize <HitBtcSocketTradesEvent>(token, false); if (result.Success) { OnTradesUpdate?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.TickerUpdated: { var result = Deserialize <HitBtcSocketTickerEvent>(token, false); if (result.Success) { OnTickerUpdate?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.CandlesSnapshot: { var result = Deserialize <HitBtcSocketCandlesEvent>(token, false); if (result.Success) { OnCandlesSnapshot?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.CandlesUpdated: { var result = Deserialize <HitBtcSocketCandlesEvent>(token, false); if (result.Success) { OnCandlesUpdate?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.ActiveOrdersSnapshot: { var result = Deserialize <HitBtcSocketActiveOrdersReportEvent>(token, false); if (result.Success) { OnActiveOrdersSnapshot?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.OrderUpdated: { var result = Deserialize <HitBtcSocketOrderReportEvent>(token, false); if (result.Success) { OnOrderUpdate?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.MarginOrdersSnapshot: { var result = Deserialize <HitBtcSocketMarginActiveOrdersReportEvent>(token, false); if (result.Success) { OnMarginActiveOrdersSnapshot?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.MarginOrderUpdated: { var result = Deserialize <HitBtcSocketMarginOrderReportEvent>(token, false); if (result.Success) { OnMarginOrderUpdate?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.MarginAccountsSnapshot: { var result = Deserialize <HitBtcSocketMarginAccountsEvent>(token, false); if (result.Success) { OnMarginAccountsSnapshot?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.MarginAccountUpdated: { var result = Deserialize <HitBtcSocketMarginAccountReportEvent>(token, false); if (result.Success) { OnMarginAccountUpdate?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } case HitBtcSocketEvent.TransactionUpdated: { var result = Deserialize <HitBtcSocketAccountTransactionEvent>(token, false); if (result.Success) { OnAccountTransactionUpdate?.Invoke(result.Data); } else { log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from stream: " + result.Error); } break; } default: log.Write(LogVerbosity.Warning, $"Catched unknown method update: {data}"); break; } }); return(await Subscribe(BaseAddress + subscribeRequest.EndpointSuffix, subscribeRequest, null, subscribeRequest.EndpointSuffix != MarketDataUrlSuffix, dataHandler)); }