Example #1
0
        public WebsocketClient(Network network)
        {
            var networkEnv = BinanceEnvironment.GetEnvironment(network);

            _ws = new WebSocket(networkEnv.WssApiAddress);
            _ws.SslConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12;
            _ws.EmitOnPing = true;

            _ws.OnMessage += _ws_OnMessage;
            _ws.OnError   += _ws_OnError;

            BlockHeight          = new BlockHeight(this);
            AllMiniTicker        = new AllMiniTicker(this);
            IndividualMiniTicker = new IndividualMiniTicker(this);
            AllTicker            = new AllTicker(this);
            IndividualTicker     = new IndividualTicker(this);
            Klines    = new Klines(this);
            BookDepth = new BookDepth(this);
            DiffDepth = new DiffDepth(this);
            Trades    = new Trades(this);
            Transfer  = new Transfer(this);
            Account   = new Account(this);
            Orders    = new Orders(this);
        }
Example #2
0
 private void _ws_OnMessage(object sender, MessageEventArgs e)
 {
     //Pre-parsing message. Doesn't fully deserialize now to dynamic to improve performance
     if (e.Data.StartsWith("{\"stream\":\"orders\""))
     {
         Orders.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"trades\""))
     {
         Trades.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"accounts\""))
     {
         Account.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"marketDiff\""))
     {
         DiffDepth.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"marketDepth\""))
     {
         BookDepth.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"blockheight\""))
     {
         BlockHeight.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"allMiniTickers\""))
     {
         AllMiniTicker.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"miniTicker\""))
     {
         IndividualMiniTicker.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"allTickers\""))
     {
         AllTicker.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"ticker\""))
     {
         IndividualTicker.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"kline_"))
     {
         Klines.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"transfers\""))
     {
         Transfer.ProcessRecievedMessage(e.Data);
     }
     else if (e.Data.StartsWith("{\"stream\":\"transfers\""))
     {
         Transfer.ProcessRecievedMessage(e.Data);
     }
     else if (!string.IsNullOrWhiteSpace(e.Data))
     {
         //We might received an error text from backend, have to raise attention if so.
         if (e.Data.Contains("error"))
         {
             throw new WebSocketConnectionException(string.Format("Websocket DEX backend sent error message: {0}", e.Data));
         }
     }
 }