예제 #1
0
        private void ExecuteBeforeClose(object o)
        {
            Task taskA = new Task(() => _marketFeed.Dispose());

            taskA.Start();

            while (marketConnectionUp)
            {
                Thread.Sleep(1000);
            }

            log.Info("VolManager closed");
        }
예제 #2
0
        public void Start()
        {
            // Check if closing snapshot batch as run
            if (_dbManager.TestClosePrice(Option.PreviousWeekDay(DateTime.Today)))
            {
                log.Error("Close price already inserted");
                IsRunning = false;
                return;
            }

            _marketFeed.Connect(_ttlogin, _ttPassword, ConnectionStatusHandler, PriceUpdateHandler, null);

            _delay = DateTime.Now.AddSeconds(_delayTime);
            while (DateTime.Now < _delay)
            {
                Thread.Sleep(1000);
            }

            var histoCollection = new List <HistoricalPrice>();

            DateTime previousDay = Option.PreviousWeekDay(DateTime.Today);

            foreach (var instru in _instruCollection)
            {
                double closePrice;
                if (_instrumentPriceSafeDico.TryGetValue(instru.TtCode, out closePrice) && closePrice != 0)
                {
                    histoCollection.Add(new HistoricalPrice()
                    {
                        AsOfDate = previousDay, ClosePrice = closePrice, InstrumentId = instru.Id
                    });
                }
                else
                {
                    log.Info($"Close missing instrument: {instru.TtCode}");
                }
            }

            _dbManager.AddClosePrice(histoCollection);
            _marketFeed.Dispose();
        }
예제 #3
0
        /// <summary>
        /// 1) Retreive all instruments from TTAPI
        /// 2) Retreive all instruments from Database
        /// 3) Insert the delta into Database
        /// 4) Create default vol parameters for new maturity
        /// </summary>
        public void Start()
        {
            //Check Database connection
            if (!_dbManager.TestConnection())
            {
                Console.WriteLine("Enable to access to database. Check VPN connection");
                Console.ReadLine();
                IsRunning = false;
                return;
            }

            _marketFeed.Connect(_ttlogin, _ttPassword, ConnectionStatusHandler, null, DataUpdateHandler);
            Instrument[] instruCollection = _dbManager.GetAllInstruments(DateTime.Today);

            //wait 30sec to receive all the instruments info from MarketFeed
            _delay = DateTime.Now.AddSeconds(_delayTime);
            while (DateTime.Now < _delay)
            {
                Thread.Sleep(1000);
            }

            // remove from InstruInfoSafeDico instruments already present in DB
            foreach (var instru in instruCollection)
            {
                if (_instruInfoSafeDico.ContainsKey(instru.Id))
                {
                    Instrument suppresedInstru;
                    _instruInfoSafeDico.TryRemove(instru.Id, out suppresedInstru);
                }
            }

            // insert new instruments into DB
            List <Instrument> Newinstru = _instruInfoSafeDico.Values.ToList();

            if (Newinstru.Any())
            {
                _dbManager.AddInstruments(Newinstru);
            }

            // load db vol parameters
            Dictionary <string, VolParam> volParamDico = LoadVolParams();

            string[]   optionList   = _dbManager.GetOptionProductNames();
            DateTime[] maturityList = _dbManager.GetAvailableMaturity(DateTime.Today);

            foreach (var option in optionList)
            {
                foreach (var maturity in maturityList)
                {
                    string key = option + "_" + maturity.ToString("MMyyyy");
                    if (!volParamDico.ContainsKey(key))
                    {
                        // create default vol parameters if no params exist
                        var volParam = new VolParam()
                        {
                            A = 0, B = 0, Sigma = 0, Rho = 0, M = 0, MaturityDate = maturity, ProductId = option
                        };
                        _dbManager.AddVolParameter(volParam);
                    }
                }
            }

            _marketFeed.Dispose();
        }