Beispiel #1
0
 private static void OnStreamData(object sender, IStreamData data)
 {
     if (data.Topic == ETopic.Blockheight)
     {
         Blockheight blockheight = (Blockheight)data;
         Console.WriteLine(blockheight.BlockHeight);
         Log.Information($"BlockHeight: {blockheight.BlockHeight}");
     }
     else if (data.Topic == ETopic.AllTickers)
     {
         AllTickersData allTickersData = (AllTickersData)data;
         Console.WriteLine(allTickersData.AllTickers[0].Symbol);
     }
     else if (data.Topic == ETopic.AllMiniTickers)
     {
         AllMiniTickersData allMiniTickersData = (AllMiniTickersData)data;
         Console.WriteLine(allMiniTickersData.AllMiniTickers[0].Symbol);
     }
 }
Beispiel #2
0
        private Task OnReceive(string message)
        {
            var         jObject    = JObject.Parse(message);
            string      stream     = jObject.Value <string>("stream");
            IStreamData streamData = null;

            if (stream == websocket.stream.Topic.ToTopic(ETopic.Orders))
            {
                streamData = new OrdersData {
                    Orders = JsonConvert.DeserializeObject <Payload <List <Order> > >(message).Data
                };
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.Accounts))
            {
                streamData = new AccountsData {
                    Accounts = JsonConvert.DeserializeObject <Payload <List <Account> > >(message).Data
                };
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.Transfers))
            {
                streamData = JsonConvert.DeserializeObject <Payload <TransfersData> >(message).Data;
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.Trades))
            {
                streamData = new TradesData {
                    Trades = JsonConvert.DeserializeObject <Payload <List <Trade> > >(message).Data
                };
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.MarketDiff))
            {
                streamData = JsonConvert.DeserializeObject <Payload <MarketDiff> >(message).Data;
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.MarketDepth))
            {
                streamData = JsonConvert.DeserializeObject <Payload <MarketDepth> >(message).Data;
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.KLine))
            {
                streamData = JsonConvert.DeserializeObject <Payload <KLine> >(message).Data;
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.Ticker))
            {
                streamData = JsonConvert.DeserializeObject <Payload <Ticker> >(message).Data;
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.AllTickers))
            {
                streamData = new AllTickersData {
                    AllTickers = JsonConvert.DeserializeObject <Payload <List <Ticker> > >(message).Data
                };
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.MiniTicker))
            {
                streamData = JsonConvert.DeserializeObject <Payload <MiniTicker> >(message).Data;
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.AllMiniTickers))
            {
                streamData = new AllMiniTickersData {
                    AllMiniTickers = JsonConvert.DeserializeObject <Payload <List <MiniTicker> > >(message).Data
                };
            }
            else if (stream == websocket.stream.Topic.ToTopic(ETopic.Blockheight))
            {
                streamData = JsonConvert.DeserializeObject <Payload <Blockheight> >(message).Data;
            }
            else
            {
                throw new WebSocketException($"Unhandled topic stream: {stream}");
            }
            StreamData(this, streamData);
            return(Task.CompletedTask);
        }