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())); } }
//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(); }
//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(); }
public void UnsubscribeQuotes(string symbol) { WebSocketSubscriptionRequest request = new WebSocketSubscriptionRequest() { op = "unsubscribe", args = new string[] { string.Format("{0}:{1}", _QUOTE, symbol) } }; InvokeWebSocket(request).Wait(); }
public void SubscribeTrades(string symbol) { WebSocketSubscriptionRequest request = new WebSocketSubscriptionRequest() { op = "subscribe", args = new string[] { string.Format("{0}:{1}", _TRADE, symbol) } }; InvokeWebSocket(request).Wait(); }
public void UnsubscribeOrderBookL2(string symbol) { WebSocketSubscriptionRequest request = new WebSocketSubscriptionRequest() { op = "unsubscribe", args = new string[] { string.Format("{0}:{1}", _ORDERBOOK_L2, symbol) } }; InvokeWebSocket(request).Wait(); }