Beispiel #1
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
                }
            }
        }
Beispiel #2
0
        protected void UpdateQuotes(WebSocketSubscriptionEvent subscrEvent)
        {
            if (subscrEvent is WebSocketErrorMessage)
            {
                ProcessSubscrError((WebSocketErrorMessage)subscrEvent);
                return;
            }

            WebSocketQuoteEvent quotes = (WebSocketQuoteEvent)subscrEvent;

            foreach (Quote quote in quotes.data.OrderBy(x => x.timestamp))
            {
                try
                {
                    if (ActiveSecuritiesQuotes.Values.Where(x => x.Symbol == quote.symbol).FirstOrDefault() != null)
                    {
                        Security sec = ActiveSecuritiesQuotes.Values.Where(x => x.Symbol == quote.symbol).FirstOrDefault();


                        sec.MarketData.BestAskSize  = quote.askSize.HasValue ? (long?)Convert.ToInt64(quote.askSize.Value) : null;
                        sec.MarketData.BestBidSize  = quote.bidSize.HasValue ? (long?)Convert.ToInt64(quote.bidSize.Value) : null;
                        sec.MarketData.BestAskPrice = quote.askPrice;
                        sec.MarketData.BestBidPrice = quote.bidPrice;

                        DoLog(string.Format("@{1}:NEW Quote for symbol {0}", quote.symbol, BitmexConfiguration.Name), Main.Common.Util.Constants.MessageType.Information);

                        MarketDataQuoteWrapper wrapper = new MarketDataQuoteWrapper(sec, GetConfig());
                        OnMessageRcv(wrapper);
                    }
                }
                catch (Exception ex)
                {
                    DoLog(string.Format("@{0}:Error processing quote for symbol {1}:{2}", BitmexConfiguration.Name, quote.symbol, ex.Message), Main.Common.Util.Constants.MessageType.Error);
                }
            }
        }