Exemplo n.º 1
0
        protected async Task InvokeWebSocket(WebSocketSubscriptionRequest req)
        {
            if (AuthSubscriptionResult.ClientWebSocket.State == WebSocketState.Open)
            {
                try
                {
                    string strReq = JsonConvert.SerializeObject(req, Newtonsoft.Json.Formatting.None,
                                                                new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    });

                    byte[] msgArray = Encoding.ASCII.GetBytes(strReq);

                    ArraySegment <byte> bytesToSend = new ArraySegment <byte>(msgArray);

                    await AuthSubscriptionResult.ClientWebSocket.SendAsync(bytesToSend, WebSocketMessageType.Text, true,
                                                                           CancellationToken.None);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                throw new Exception(string.Format("Not connected to BitMex on subscription channel:{0}", AuthSubscriptionResult.ClientWebSocket.State.ToString()));
            }
        }
Exemplo n.º 2
0
        //We receive an execution report for every of OUR order that were sent to the market
        public void SubscribeExecutions()
        {
            WebSocketSubscriptionRequest request = new WebSocketSubscriptionRequest()
            {
                op   = "subscribe",
                args = new string[] { string.Format("{0}", _EXECUTIONS) }
            };

            InvokeWebSocket(request).Wait();
        }
Exemplo n.º 3
0
        //We receive an execution report for every of OUR order that were sent to the market
        public void SubscribeOrders()
        {
            WebSocketSubscriptionRequest request = new WebSocketSubscriptionRequest()
            {
                op   = "subscribe",
                args = new string[] { string.Format("{0}", _ORDER) }
            };

            InvokeWebSocket(request).Wait();
        }
Exemplo n.º 4
0
        public void UnsubscribeQuotes(string symbol)
        {
            WebSocketSubscriptionRequest request = new WebSocketSubscriptionRequest()
            {
                op   = "unsubscribe",
                args = new string[] { string.Format("{0}:{1}", _QUOTE, symbol) }
            };

            InvokeWebSocket(request).Wait();
        }
Exemplo n.º 5
0
        public void SubscribeTrades(string symbol)
        {
            WebSocketSubscriptionRequest request = new WebSocketSubscriptionRequest()
            {
                op   = "subscribe",
                args = new string[] { string.Format("{0}:{1}", _TRADE, symbol) }
            };

            InvokeWebSocket(request).Wait();
        }
Exemplo n.º 6
0
        public void UnsubscribeOrderBookL2(string symbol)
        {
            WebSocketSubscriptionRequest request = new WebSocketSubscriptionRequest()
            {
                op   = "unsubscribe",
                args = new string[] { string.Format("{0}:{1}", _ORDERBOOK_L2, symbol) }
            };

            InvokeWebSocket(request).Wait();
        }