Пример #1
0
        protected override void DoRunLoopSubscriptions(string resp)
        {
            WebSocketSubscriptionEvent eventSubscr = JsonConvert.DeserializeObject <WebSocketSubscriptionEvent>(resp);

            if (ResponseRequestSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
            {
                if (eventSubscr.table == _ORDER && EventSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
                {
                    WebSocketExecutionReportEvent execReportEvent = JsonConvert.DeserializeObject <WebSocketExecutionReportEvent>(resp);

                    WebSocketSubscriptionEvent subscrEvent = EventSubscriptions[eventSubscr.GetSubscriptionEvent()];

                    subscrEvent.RunEvent(execReportEvent);
                }
                else if (eventSubscr.table == _EXECUTIONS && EventSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
                {
                    WebSocketExecutionReportEvent execReportEvent = JsonConvert.DeserializeObject <WebSocketExecutionReportEvent>(resp);

                    WebSocketSubscriptionEvent subscrEvent = EventSubscriptions[eventSubscr.GetSubscriptionEvent()];

                    subscrEvent.RunEvent(execReportEvent);
                }
                else
                {
                    //Log what we are receiving here because we are getting events that we didn't expect
                }
            }
        }
Пример #2
0
        public void OnEvent(string resp)
        {
            WebSocketResponseMessage wsResp = wsResp = JsonConvert.DeserializeObject <WebSocketResponseMessage>(resp);

            lock (tSubscrLock)
            {
                if (wsResp.IsResponse())//We have the response to a subscription
                {
                    WebSocketSubscriptionResponse requestRespSubscr = JsonConvert.DeserializeObject <WebSocketSubscriptionResponse>(resp);

                    if (ResponseRequestSubscriptions.ContainsKey(requestRespSubscr.GetSubscriptionEvent()))
                    {
                        WebSocketSubscriptionResponse requestRespEvent = ResponseRequestSubscriptions[requestRespSubscr.GetSubscriptionEvent()];

                        requestRespEvent.RunSubscritionEvent(requestRespSubscr);
                    }
                }
                else if (resp.Contains("error"))
                {
                    WebSocketErrorMessage wsError = JsonConvert.DeserializeObject <WebSocketErrorMessage>(resp);

                    if (wsError.request != null)
                    {
                        foreach (string ev in wsError.request.args)
                        {
                            string[] fields = ev.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

                            string key    = fields[0];
                            string symbol = fields.Length > 1 ? fields[1] : null;

                            WebSocketSubscriptionEvent subscrEvent = EventSubscriptions[key];

                            if (subscrEvent != null)
                            {
                                wsError.Symbol = symbol;
                                subscrEvent.RunEvent(wsError);
                            }
                        }
                    }
                    else
                    {
                        ProcessSubscriptionEvent(resp);
                    }
                }
                else //We have an event from a subscription
                {
                    ProcessSubscriptionEvent(resp);
                }
            }
        }
Пример #3
0
        protected override void DoRunLoopSubscriptions(string resp)
        {
            WebSocketSubscriptionEvent eventSubscr = JsonConvert.DeserializeObject <WebSocketSubscriptionEvent>(resp);

            if (ResponseRequestSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
            {
                if (eventSubscr.table == _ORDERBOOK_L2 && EventSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
                {
                    WebSocketOrderBookL2Event orderBookL2Event = JsonConvert.DeserializeObject <WebSocketOrderBookL2Event>(resp);

                    WebSocketSubscriptionEvent subscrEvent = EventSubscriptions[eventSubscr.GetSubscriptionEvent()];

                    subscrEvent.RunEvent(orderBookL2Event);
                }
                else if (eventSubscr.table == _TRADE && EventSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
                {
                    WebSocketTradeEvent tradeEvent = JsonConvert.DeserializeObject <WebSocketTradeEvent>(resp);

                    WebSocketSubscriptionEvent subscrEvent = EventSubscriptions[eventSubscr.GetSubscriptionEvent()];

                    subscrEvent.RunEvent(tradeEvent);
                }
                else if (eventSubscr.table == _QUOTE && EventSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
                {
                    WebSocketQuoteEvent quoteEvent = JsonConvert.DeserializeObject <WebSocketQuoteEvent>(resp);

                    WebSocketSubscriptionEvent subscrEvent = EventSubscriptions[eventSubscr.GetSubscriptionEvent()];

                    subscrEvent.RunEvent(quoteEvent);
                }
                else if (eventSubscr.table == _1_DAY_TRADE_BINS && EventSubscriptions.ContainsKey(eventSubscr.GetSubscriptionEvent()))
                {
                    //TODO: I have to ask BitMex why aren't they retrieveing high and low for the 1 day bin
                    //and they are for the 1 hour bin
                }
                else
                {
                    //Log what we are receiving here because we are getting events that we didn't expect
                }
            }
        }