Пример #1
0
        public void Init(getNow getNow)
        {
            Assembly     thisAssem     = typeof(Trader).Assembly;
            AssemblyName thisAssemName = thisAssem.GetName();
            Version      ver           = thisAssemName.Version;

            _getNow = getNow;
            DateTime now = getNow();

            Log.Instance.WriteEntry("Midax " + ver + " service initialized", EventLogEntryType.Information);

            var timerStart = new System.Threading.Timer(startSignalCallback);
            var timerStop  = new System.Threading.Timer(stopSignalCallback);

            // Figure how much time until PUBLISHING_STOP_TIME
            _startTime = Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_START_TIME"]);
            DateTime stopTime          = Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"]);
            DateTime closePositionTime = Config.ParseDateTimeLocal(Config.Settings["TRADING_STOP_TIME"]);

            if (!Config.Settings.ContainsKey("TRADING_CLOSING_TIME"))
            {
                _disconnectClosePositions = false;
            }

            // If it's already past PUBLISHING_STOP_TIME, wait until PUBLISHING_STOP_TIME tomorrow
            int msUntilStartTime = 10;

            if (now > _startTime)
            {
                if (now > stopTime)
                {
                    var nextDay = _startTime.AddDays(1.0);
                    stopTime         = stopTime.AddDays(1.0);
                    msUntilStartTime = (int)((nextDay - now).TotalMilliseconds);
                }
            }
            else
            {
                msUntilStartTime = (int)((_startTime - now).TotalMilliseconds);
            }
            int msUntilStopTime = (int)((stopTime - now).TotalMilliseconds);

            Log.Instance.WriteEntry(string.Format("Next scheduling in {0}h{1}mn", msUntilStartTime / (3600 * 1000),
                                                  (msUntilStartTime - 3600 * 1000 * (msUntilStartTime / (3600 * 1000))) / (60 * 1000)), EventLogEntryType.Information);

            // Set the timers to elapse only once, at their respective scheduled times
            timerStart.Change(msUntilStartTime, Timeout.Infinite);
            timerStop.Change(msUntilStopTime, Timeout.Infinite);
        }
Пример #2
0
        public void Init(getNow getNow)
        {
            Assembly thisAssem = typeof(Trader).Assembly;
            AssemblyName thisAssemName = thisAssem.GetName();
            Version ver = thisAssemName.Version;
            _getNow = getNow;
            DateTime now = getNow();

            Log.Instance.WriteEntry("Midax " + ver + " service initialized", EventLogEntryType.Information);

            var timerStart = new System.Threading.Timer(startSignalCallback);
            var timerStop = new System.Threading.Timer(stopSignalCallback);

            // Figure how much time until PUBLISHING_STOP_TIME
            _startTime = Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_START_TIME"]);
            DateTime stopTime = Config.ParseDateTimeLocal(Config.Settings["PUBLISHING_STOP_TIME"]);

            // If it's already past PUBLISHING_STOP_TIME, wait until PUBLISHING_STOP_TIME tomorrow
            int msUntilStartTime = 10;
            if (now > _startTime)
            {
                if (now > stopTime)
                {
                    var nextDay = _startTime.AddDays(1.0);
                    stopTime = stopTime.AddDays(1.0);
                    msUntilStartTime = (int)((nextDay - now).TotalMilliseconds);
                }
            }
            else
                msUntilStartTime = (int)((_startTime - now).TotalMilliseconds);
            int msUntilStopTime = (int)((stopTime - now).TotalMilliseconds);

            Log.Instance.WriteEntry(string.Format("Next scheduling in {0}h{1}mn", msUntilStartTime / (3600 * 1000),
                (msUntilStartTime - 3600 * 1000 * (msUntilStartTime / (3600 * 1000))) / (60 * 1000)), EventLogEntryType.Information);

            // Set the timers to elapse only once, at their respective scheduled times
            timerStart.Change(msUntilStartTime, Timeout.Infinite);
            timerStop.Change(msUntilStopTime, Timeout.Infinite);
        }