private static void ProcessEvent(WebSocketMessage msg) { if (msg is ClientLoginResponse) { ClientLoginResponse loginResp = (ClientLoginResponse)msg; if (loginResp.JsonWebToken != null) { ClientLoginResponse = loginResp; } Thread publishOrderBookThread = new Thread(PublishOrderBookThread); publishOrderBookThread.Start(); DoLog(string.Format("Client successfully logged with token {0}", loginResp.JsonWebToken)); SubscribeLastSales(); SubscribeQuotes(); Thread.Sleep(1000); SubscribeOrderBook(); } else if (msg is DepthOfBook) { DepthOfBook depthOfBookDelta = (DepthOfBook)msg; ProcessDepthOfBook(depthOfBookDelta); } else if (msg is LastSale) { LastSale lastSale = (LastSale)msg; DoLog(string.Format("Received last sale for symbol {1}: {0}", lastSale.LastPrice, lastSale.Symbol)); } else if (msg is Quote) { Quote quote = (Quote)msg; DoLog(string.Format("Received quote for symbol {4}: Bid {0}-{1} -- Ask {2}-{3}", quote.BidSize, quote.Bid, quote.AskSize, quote.Ask, quote.Symbol)); } }
private static void ProcessEvent(WebSocketMessage msg) { if (msg is ClientLoginResponse) { ClientLoginResponse loginResp = (ClientLoginResponse)msg; if (loginResp.JsonWebToken != null) { ClientLoginResponse = loginResp; } DoLog(string.Format("Client successfully logged with token {0}", loginResp.JsonWebToken)); //3- Subscribe market data for Security //Market data will be delivered through many services, for the moment we will use // LS - LastSales will have all the information regarding the trades that took place (high, low, last, etc.) // LQ - QuoteService will tell us the the best offers (best buy and sell) that we have for a security. // It is what fills the red/green holders that we can see in the image! // When we select a Product (SPOT) and Pair (XBT-USD) in the combos, we will have to fill the instrument holder (story 74) // ---> In that context we only need the Quote (LQ) service // Only when we CLICK that instrument we will need the trades service (LS) to fill the header // ---> Then we can make this call //Of course, every time we subscribe to some security , we will have to ususcribe to another one. // That will be covered in the spec document RequestMarketData(Security); } else if (msg is LastSale) { //4.1 LastSale event arrived! We update the security in memory with the following fields LastSale lastSale = (LastSale)msg; lock (Security) { Security.MarketData.LastTradeDateTime = lastSale.GetLastTime(); Security.MarketData.MDTradeSize = lastSale.LastShares; Security.MarketData.Trade = lastSale.LastPrice; Security.MarketData.NominalVolume = lastSale.Volume; Security.MarketData.TradingSessionHighPrice = lastSale.High; Security.MarketData.TradingSessionLowPrice = lastSale.Low; Security.MarketData.OpeningPrice = lastSale.Open; Security.MarketData.NetChgPrevDay = lastSale.Change; } MarketDataRefresh(); } else if (msg is Quote) { //4.2 Quote event arrived! We update the security in memory with the following fields Quote quote = (Quote)msg; lock (Security) { Security.MarketData.BestBidPrice = quote.Bid; Security.MarketData.BestBidSize = quote.BidSize; Security.MarketData.BestAskPrice = quote.Ask; Security.MarketData.BestAskSize = quote.AskSize; } MarketDataRefresh(); } else if (msg is DailySettlementPrice) { //4.3 DailySettlementPrice event arrived! We update the security in memory with the following fields DailySettlementPrice DSP = (DailySettlementPrice)msg; lock (Security) { Security.MarketData.SettlementPrice = DSP.Price; } MarketDataRefresh(); } else if (msg is OfficialFixingPrice) { //4.4 DailySettlementPrice event arrived! We update the security in memory with the following fields OfficialFixingPrice fixingPrice = (OfficialFixingPrice)msg; lock (Security) { Security.MarketData.FIXPrice = fixingPrice.Price; } MarketDataRefresh(); } else if (msg is SubscriptionResponse) { SubscriptionResponse subscrResp = (SubscriptionResponse)msg; //We have to process this message to be sure that the subscription was fully processed } }