Пример #1
0
        private void EvalDailySettlementPriceWarnings(string symbol)
        {
            SecurityMasterRecord security = SecurityMasterRecords.Where(x => x.Symbol == symbol).FirstOrDefault();

            if (security.AssetClass == Security._SPOT)
            {
                //WE shouldn't have this service requested for a spot currency
                DoLog(string.Format("WARNING2 - Daily Settlement Price requested for spot currency! : {0}", symbol), MessageType.Error);
            }
        }
Пример #2
0
        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- Once Logged we request the security master record. We set the request timestamp for timeout calculation
                SecurityMasterRecordRequestStartTime = DateTime.Now;
                SubscriptionTAFinished = false;
                RequestSecurityMasterList();

                //3.1- We launch the thread that will process all the securities once everything is available
                Thread processSecurityMasterRecordThread = new Thread(ProcessSecurityMasterRecordThread);
                processSecurityMasterRecordThread.Start();
            }
            else if (msg is SubscriptionResponse)
            {
                SubscriptionResponse subscrResp = (SubscriptionResponse)msg;
                if (subscrResp.Service == "TA")
                {
                    SubscriptionTAFinished = true;
                }
            }
            else if (msg is SecurityMasterRecord)
            {
                SecurityMasterRecord security = (SecurityMasterRecord)msg;
                //4-Every time we get a security, if the arrival time is less than timeout time, we update the list that hold
                //all the securities
                TimeSpan elapsed = DateTime.Now - SecurityMasterRecordRequestStartTime;
                if (elapsed.TotalSeconds < _SECURITY_MASTER_RECORD_TIMOUT_IN_SECONDS && !SubscriptionTAFinished)
                {
                    SecurityMasterRecords.Add(security);
                }
                else
                {
                    //4.1- Here the security arrive after the timeout. We have to set some warning in the logs to check
                    //     if we have to recalibrate the timeout threshold
                    if (SubscriptionTAFinished)
                    {
                        DoLog(string.Format("TC1-Security Master Record arrived afte subscription response succesfull received!:{0}", security.Symbol));
                    }
                    else if (elapsed.TotalSeconds > _SECURITY_MASTER_RECORD_TIMOUT_IN_SECONDS)
                    {
                        DoLog(string.Format("TC2-Security Master Record arrived after timeout expiration!:{0}", security.Symbol));
                    }
                }
            }
        }
Пример #3
0
        private static void ProcessSecurityList(string secType, string symbol)
        {
            //5.2.1 - As the derivative (contract) traded is also a security, we will show a security list like we did in ProcessPairCombo method
            List <Security> securities = new List <Security>();

            //5.2.2 - Still missing to filter the underlying as we have no field for it!!!
            foreach (SecurityMasterRecord secMasterRecord in SecurityMasterRecords.Where(x => x.AssetClass == secType && x.CurrencyPair == symbol))
            {
                securities.Add(new Security()
                {
                    Symbol = secMasterRecord.Symbol, Description = secMasterRecord.Description
                });
            }

            //5.2.3 - Showing all the derivatives (contracts) available for secType (prodcut) and symbol (pair) selected
            ShowSecurityList(securities, secType, symbol);
        }
Пример #4
0
        protected double GetBaseMargin(string firmId, ClientPosition[] Positions, string symbol = null, DailySettlementPrice[] DSPsToUse = null)
        {
            double acumMargin = 0;

            foreach (SecurityMasterRecord security in SecurityMasterRecords.Where(x => (symbol == null || x.Symbol == symbol)))
            {
                double netContracts = GetNetContracts(firmId, security.Symbol, Positions);

                DailySettlementPrice DSP = DSPsToUse == null?DailySettlementPrices.Where(x => x.Symbol == security.Symbol).FirstOrDefault() : DSPsToUse.Where(x => x.Symbol == security.Symbol).FirstOrDefault();

                if (DSP != null && DSP.Price.HasValue)
                {
                    acumMargin += Math.Abs(netContracts) * DSP.Price.Value * Config.MarginPct;
                }

                DoLog(string.Format("Net Contracts for Security {0} :{1}", security.Symbol, netContracts), zHFT.Main.Common.Util.Constants.MessageType.Information);
            }

            //TODO : implement the calendar spreads margin calculation
            DoLog(string.Format("Base Margin for FirmId {0}:{1}", firmId, acumMargin), zHFT.Main.Common.Util.Constants.MessageType.Information);

            return(acumMargin);
        }