protected void DailyOfficialFixingPriceThread(object param) { object[] paramArray = (object[])param; IWebSocketConnection socket = (IWebSocketConnection)paramArray[0]; WebSocketSubscribeMessage subscrMsg = (WebSocketSubscribeMessage)paramArray[1]; bool subscResp = false; try { while (true) { OfficialFixingPrice officialFixingPrice = OfficialFixingPrices.Where(x => x.Symbol == subscrMsg.ServiceKey).FirstOrDefault(); if (officialFixingPrice != null) { //officialFixingPrice.Price += Convert.ToDecimal( DateTime.Now.Second )/ 100; DoLog(string.Format("Returning fixing price for symbol {0}:{1}...", subscrMsg.ServiceKey, officialFixingPrice.Price), MessageType.Information); DoSend <OfficialFixingPrice>(socket, officialFixingPrice); Thread.Sleep(3000);//3 seconds if (!subscResp) { ProcessSubscriptionResponse(socket, "FD", subscrMsg.ServiceKey, subscrMsg.UUID); Thread.Sleep(2000); subscResp = true; return; } } else { DoLog(string.Format("Official Fixing Price not found for symbol {0}...", subscrMsg.ServiceKey), MessageType.Information); break; } } } catch (Exception ex) { DoLog(string.Format("Critical error processing daily settlement price message: {0}...", ex.Message), MessageType.Error); } }
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 } }