public LeechPlatform(ITickDispatcher tickDisp, IInstrumTable insTable, IHoldingTable holdTable, IOrderTable orderTable, IAccountTable accountTable, AlorTradeWrapper alorTrade, ILogger logger, IInsStoreBL insStoreBL, ILeechConfig leechConfig) { _tickDisp = tickDisp; _instrumTable = insTable; _holdingTable = holdTable; _orderTable = orderTable; _accountTable = accountTable; _alorTrade = alorTrade; _logger = logger; _insStoreBL = insStoreBL; _leechConfig = leechConfig; _barRows = new List <BarRow>(); _onTimer = null; _onTimerTask = null; _ins_onTick = new Dictionary <int, OnTickDelegate>(); _insID_pm = new Dictionary <int, IPosManager>(); }
public void OnTimer(OnTimerDelegate onTimer) { _onTimer = onTimer; if (_onTimer != null && _onTimerTask == null) { _onTimerTask = Task.Factory.StartNew(() => { DateTime prev = DateTime.MinValue; while (_onTimer != null) { var mskNow = DateTime.Now.AddHours(_leechConfig.CorrectHours); // сразу переходим на время биржи, т.к. в тиках тоже стоит биржевое время, а не местное DateTime t = new DateTime(mskNow.Year, mskNow.Month, mskNow.Day, mskNow.Hour, mskNow.Minute, mskNow.Second).AddSeconds(1); long waitToNextSec = t.Ticks - mskNow.Ticks; if (waitToNextSec > 0) { Thread.Sleep(new TimeSpan(waitToNextSec)); } if (t == prev) { continue; } prev = t; var lastTick = _tickDisp.GetLastTick(); if (lastTick.InsID == 0) { _onTimer(t, 0); } else { int delay = (int)Math.Round(new TimeSpan(t.Ticks - lastTick.Time.Ticks).TotalMilliseconds); _onTimer(t, delay); } } }); } else if (_onTimer == null && _onTimerTask != null) { _onTimerTask = null; } }
public void OnTimer(OnTimerDelegate onTimer) { _onTimer = onTimer; }