private void DailySettlementThread(object param)
        {
            object[]                  paramArray = (object[])param;
            IWebSocketConnection      socket     = (IWebSocketConnection)paramArray[0];
            WebSocketSubscribeMessage subscrMsg  = (WebSocketSubscribeMessage)paramArray[1];
            bool subscResp = false;

            try
            {
                while (true)
                {
                    DailySettlementPrice dailySettl = DailySettlementPrices.Where(x => x.Symbol == subscrMsg.ServiceKey).FirstOrDefault();
                    if (dailySettl != null)
                    {
                        DoSend <DailySettlementPrice>(socket, dailySettl);
                        Thread.Sleep(3000);//3 seconds
                        if (!subscResp)
                        {
                            ProcessSubscriptionResponse(socket, "FP", subscrMsg.ServiceKey, subscrMsg.UUID);
                            Thread.Sleep(2000);
                            subscResp = true;
                        }
                    }
                    else
                    {
                        DoLog(string.Format("Daily Settlement 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);
            }
        }
Esempio n. 2
0
        private static void ProcessSubscribe(string[] param)
        {
            if (JWTToken == null)
            {
                DoLog("Missing authentication token in memory!. User not logged");
                return;
            }

            if (param.Length >= 2)
            {
                WebSocketSubscribeMessage subscribe = new WebSocketSubscribeMessage()
                {
                    Msg              = "Subscribe",
                    Sender           = 0,
                    UUID             = "APIClientUUID",
                    UserId           = UserId,
                    SubscriptionType = "S",
                    JsonWebToken     = JWTToken,
                    Service          = param[1],
                    ServiceKey       = param.Length == 3 ? param[2] : "*"
                };

                string strMsg = JsonConvert.SerializeObject(subscribe, Newtonsoft.Json.Formatting.None,
                                                            new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                });

                DoSend(strMsg);
            }
            else
            {
                DoLog(string.Format("Missing mandatory parameters for logout message"));
            }
        }
        protected void ProcessCreditLimitUpdatesThread(object param)
        {
            DoLog(string.Format("Starting ProcessCreditLimitUpdatesThread thread"), MessageType.Information);

            object[]                  parameters = (object[])param;
            IWebSocketConnection      socket     = (IWebSocketConnection)parameters[0];
            WebSocketSubscribeMessage subscrMsg  = (WebSocketSubscribeMessage)parameters[1];

            string firmId = subscrMsg.ServiceKey;

            if (subscrMsg.ServiceKey.Contains("@"))
            {
                firmId = subscrMsg.ServiceKey.Split(new string[] { "@" }, StringSplitOptions.RemoveEmptyEntries)[0];
            }

            DoLog(string.Format("Getting account record for firmId {0}", firmId), MessageType.Information);
            AccountRecord accRecord = AccountRecords.Where(x => x.EPFirmId == firmId).FirstOrDefault();

            DoLog(string.Format("Account record for firmId {0} {1} found", firmId, accRecord != null? "do": "not"), MessageType.Information);

            if (accRecord == null)
            {
                return;
            }

            double maxNotional = accRecord.MaxNotional;
            double creditLimit = accRecord.CreditLimit;

            while (true)
            {
                Thread.Sleep(10000);
                TimeSpan elapsed = DateTime.Now - new DateTime(1970, 1, 1);

                creditLimit += 1000d;
                maxNotional += 10000;

                CreditLimitUpdate climUpd = new CreditLimitUpdate();
                climUpd.Active      = true;
                climUpd.CreditLimit = creditLimit;
                climUpd.FirmId      = accRecord.EPFirmId;
                climUpd.MaxNotional = maxNotional;
                climUpd.Msg         = "CreditLimitUpdate";
                climUpd.RouteId     = accRecord.RouteId;
                climUpd.Sender      = 0;
                climUpd.Time        = Convert.ToInt64(elapsed.TotalMilliseconds);


                DoLog(string.Format("Sending Credit Limit Update New MaxLimit:{0} New MaxNotional:{1}", creditLimit, maxNotional), MessageType.Information);
                DoSend <CreditLimitUpdate>(socket, climUpd);
            }
        }
 protected void ProcessCreditLimitUpdates(IWebSocketConnection socket, WebSocketSubscribeMessage subscrMsg)
 {
     if (!ProcessCreditLimitUpdatesThreads.ContainsKey(subscrMsg.ServiceKey))
     {
         ProcessSubscriptionResponse(socket, "Cm", subscrMsg.ServiceKey, subscrMsg.UUID);
         Thread CreditLimitUpdateThread = new Thread(ProcessCreditLimitUpdatesThread);
         CreditLimitUpdateThread.Start(new object[] { socket, subscrMsg });
         ProcessCreditLimitUpdatesThreads.Add(subscrMsg.ServiceKey, CreditLimitUpdateThread);
     }
     else
     {
         DoLog(string.Format("Double subscription for service Cm for symbol {0}...", subscrMsg.ServiceKey), MessageType.Information);
         ProcessSubscriptionResponse(socket, "Cm", subscrMsg.ServiceKey, subscrMsg.UUID, false, "Already subscribed");
     }
 }
 protected void ProcessOficialFixingPrice(IWebSocketConnection socket, WebSocketSubscribeMessage subscrMsg)
 {
     EvalDailyOfficialFixingPriceWarnings(subscrMsg.ServiceKey);
     if (!ProcessDailyOfficialFixingPriceThreads.ContainsKey(subscrMsg.ServiceKey))
     {
         lock (tLock)
         {
             Thread ProcessDailyOfficialFixingPriceThread = new Thread(DailyOfficialFixingPriceThread);
             ProcessDailyOfficialFixingPriceThread.Start(new object[] { socket, subscrMsg });
             ProcessDailyOfficialFixingPriceThreads.Add(subscrMsg.ServiceKey, ProcessDailyOfficialFixingPriceThread);
         }
     }
     else
     {
         DoLog(string.Format("Double subscription for service FP for symbol {0}...", subscrMsg.ServiceKey), MessageType.Information);
         ProcessSubscriptionResponse(socket, "FP", subscrMsg.ServiceKey, subscrMsg.UUID, false, "Double subscription");
     }
 }
        protected void ProcessUserRecord(IWebSocketConnection socket, WebSocketSubscribeMessage subscrMsg)
        {
            if (subscrMsg.ServiceKey != "*")
            {
                UserRecord userRecord = UserRecords.Where(x => x.UserId == subscrMsg.ServiceKey).FirstOrDefault();

                if (userRecord != null)
                {
                    DoSend <UserRecord>(socket, userRecord);
                }
            }
            else
            {
                foreach (UserRecord userRecord in UserRecords)
                {
                    DoSend <UserRecord>(socket, userRecord);
                }
            }
            ProcessSubscriptionResponse(socket, "TB", subscrMsg.ServiceKey, subscrMsg.UUID);
        }
        protected void ProcessCreditRecordUpdates(IWebSocketConnection socket, WebSocketSubscribeMessage subscrMsg)
        {
            if (subscrMsg.ServiceKey != "*")
            {
                if (subscrMsg.ServiceKey.EndsWith("@*"))
                {
                    subscrMsg.ServiceKey = subscrMsg.ServiceKey.Replace("@*", "");
                }

                DGTLBackendMock.Common.DTO.Account.CreditRecordUpdate creditRecordUpdate = CreditRecordUpdates.Where(x => x.FirmId == subscrMsg.ServiceKey).FirstOrDefault();

                if (creditRecordUpdate != null)
                {
                    DoSend <DGTLBackendMock.Common.DTO.Account.CreditRecordUpdate>(socket, creditRecordUpdate);
                }
            }


            ProcessSubscriptionResponse(socket, "CU", subscrMsg.ServiceKey, subscrMsg.UUID);
        }
Esempio n. 8
0
        private static void DoSubscribe(string service, string serviceKey)
        {
            WebSocketSubscribeMessage subscribe = new WebSocketSubscribeMessage()
            {
                Msg              = "Subscribe",
                Sender           = 0,
                UUID             = "OrderBookPOCUUID",
                UserId           = ClientLoginResponse.UserId,
                SubscriptionType = "S",
                JsonWebToken     = ClientLoginResponse.JsonWebToken,
                Service          = service,
                ServiceKey       = serviceKey
            };

            string strMsg = JsonConvert.SerializeObject(subscribe, Newtonsoft.Json.Formatting.None,
                                                        new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            DoSend(strMsg);
        }
Esempio n. 9
0
        private static void RequestSecurityMasterList()
        {
            WebSocketSubscribeMessage subscribe = new WebSocketSubscribeMessage()
            {
                Msg              = "Subscribe",
                Sender           = 0,
                UserId           = ClientLoginResponse.UserId,
                UUID             = "SecurityListPOCUUID",
                SubscriptionType = "S",
                JsonWebToken     = ClientLoginResponse.JsonWebToken,
                Service          = "TA",
                ServiceKey       = "*"
            };

            string strMsg = JsonConvert.SerializeObject(subscribe, Newtonsoft.Json.Formatting.None,
                                                        new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            DoSend(strMsg);
        }
        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);
            }
        }
        protected void ProcessPlatformStatus(IWebSocketConnection socket, WebSocketSubscribeMessage subscrMsg)
        {
            bool doLogout = false;

            if (PlatformStatus.cState == PlatformStatus._STATE_SEND_CLIENT_LOGOUT)
            {
                DoLog(string.Format("Sending state open because of status 7 <will send ClientLogoutResponse>"), MessageType.Information);
                PlatformStatus.cState = PlatformStatus._STATE_OPEN;
                doLogout = true;
            }
            else
            {
                DoLog(string.Format("Senting platform status {0}", PlatformStatus.cState), MessageType.Information);
            }



            DoSend <PlatformStatus>(socket, PlatformStatus);
            ProcessSubscriptionResponse(socket, "PS", subscrMsg.ServiceKey, subscrMsg.UUID, true);

            if (doLogout)
            {
                PlatformStatus.cState = PlatformStatus._STATE_SEND_CLIENT_LOGOUT;
                DoLog(string.Format("Sleeping before Returning ClientLogoutResponse..."), MessageType.Information);
                Thread.Sleep(10 * 1000);
                DoLog(string.Format("Returning ClientLogoutResponse..."), MessageType.Information);
                ClientLogoutResponse logout = new ClientLogoutResponse()
                {
                    Msg     = "ClientLogoutResponse",
                    Sender  = 0,
                    Time    = 0,
                    UserId  = subscrMsg.UserId,
                    ReLogin = false
                };

                DoSend <ClientLogoutResponse>(socket, logout);
                DoLog(string.Format(" ClientLogoutResponse sent..."), MessageType.Information);
            }
        }
        protected void ProcessAccountRecord(IWebSocketConnection socket, WebSocketSubscribeMessage subscrMsg)
        {
            string prevServiceKey = subscrMsg.ServiceKey;

            if (subscrMsg.ServiceKey != "*")
            {
                if (subscrMsg.ServiceKey.EndsWith("@*"))
                {
                    subscrMsg.ServiceKey = subscrMsg.ServiceKey.Replace("@*", "");
                }

                AccountRecordsFirmId = subscrMsg.ServiceKey;

                List <AccountRecord> accountRecords = AccountRecords.Where(x => x.EPFirmId == subscrMsg.ServiceKey).ToList();

                accountRecords.ForEach(x => DoSend <AccountRecord>(socket, x));
            }
            else
            {
                AccountRecords.ToList().ForEach(x => DoSend <AccountRecord>(socket, x));
            }

            ProcessSubscriptionResponse(socket, "TD", prevServiceKey, subscrMsg.UUID);
        }