internal CheckPoint(Guid instrumentId, DateTime checkTime, InstrumentStatus status, DateTime tradeDay) { _instrumentId = instrumentId; _checkTime = checkTime; _status = status; this.TradeDay = tradeDay; }
private void DeleteFromStatusDict(Guid instrumentId) { List <InstrumentStatus> toBeRemoveStatusList = new List <InstrumentStatus>(); foreach (var eachPair in this.StatusDict) { InstrumentStatus status = eachPair.Key; List <Guid> instruments = eachPair.Value; if (instruments.Contains(instrumentId)) { instruments.Remove(instrumentId); } if (instruments.Count == 0) { toBeRemoveStatusList.Add(status); } } foreach (var eachStatus in toBeRemoveStatusList) { this.StatusDict.Remove(eachStatus); } }
private void AddForInstrumentExists(Guid instrumentId, InstrumentStatus status, DateTime checkTime, DateTime tradeDay) { var lastCheckTime = _instrumentLastTimeDict[instrumentId]; var lastStatus = this.GetLastStatus(instrumentId); if (lastStatus == null) { Logger.ErrorFormat("last status can't be found, instrumentId = {0}, status = {1}, checkTime = {2}", instrumentId, status, checkTime); return; } if (status == InstrumentStatus.DayCloseQuotationReceived && lastStatus != InstrumentStatus.DayClose) { Logger.WarnFormat("AddForInstrumentExists when receveid daycloseQuotation, last status should be dayClose instrumentId = {0}, status = {1}, lastStatus = {2}, checkTime = {3}, tradeDay = {4}", instrumentId, status, lastStatus , checkTime, tradeDay); return; } LastTime current = new LastTime(checkTime, tradeDay); if (_instrumentLastTimeDict[instrumentId] < current || (lastCheckTime == current && status == InstrumentStatus.DayClose)) { this.DeleteFromStatusDict(instrumentId); this.AddToStatusDict(instrumentId, status); _instrumentLastTimeDict[instrumentId] = current; } }
/// <summary> /// Creates a new InstrumentInfo /// </summary> public InstrumentInfo(InstrumentStatus status, string hostAddress, string instrumentType, string version, string serialNumber = "", string description = "") { Status = status; HostAddress = hostAddress; InstrumentType = instrumentType; Version = version; SerialNumber = serialNumber; Description = description; }
private void AddToStatusDict(Guid instrumentId, InstrumentStatus status) { List <Guid> instrumentIds; if (!this.StatusDict.TryGetValue(status, out instrumentIds)) { instrumentIds = new List <Guid>(); this.StatusDict.Add(status, instrumentIds); } instrumentIds.Add(instrumentId); }
public void Add(Guid instrumentId, InstrumentStatus status, DateTime checkTime, DateTime tradeDay) { Logger.InfoFormat("addInstrumentStatus id = {0}, status = {1}, checkTime = {2}, tradeDay = {3}", instrumentId, status, checkTime, tradeDay); if (!_instrumentLastTimeDict.ContainsKey(instrumentId)) { _instrumentLastTimeDict.Add(instrumentId, new LastTime(checkTime, tradeDay)); this.AddToStatusDict(instrumentId, status); } else { this.AddForInstrumentExists(instrumentId, status, checkTime, tradeDay); } }
internal void AddInstrumentStatus(Guid instrumentId, InstrumentStatus status, DateTime checkTime, DateTime tradeDay) { _readWriteLock.EnterWriteLock(); try { Logger.InfoFormat("AddInstrumentStatus instrumentId = {0}, status = {1}, checkTime = {2}, tradeDay = {3}", instrumentId, status, checkTime, tradeDay); _builder.Add(instrumentId, status, checkTime, tradeDay); if (status == InstrumentStatus.DayCloseQuotationReceived) { this.OnDayCloseQuotationReceived(instrumentId, tradeDay); } } finally { _readWriteLock.ExitWriteLock(); } }
public InstrumentStateSnapshot(Instrument inst) { action = NC.App.Opstate.Action; ins = new InstrumentStatus(inst); switch (action) { case NCCAction.HVCalibration: hv = new HVStatusSnapshot(inst); break; case NCCAction.Assay: asy = new AssayProcessingStateSnapshot(inst); break; case NCCAction.Discover: //asy = new AssayProcessingStateSnapshot(inst); break; } }
private void AddCheckPoint(Guid instrumentId, DateTime checkTime, InstrumentStatus status, DateTime tradeDay, InstrumentTradingStatusBuilderProxy tradingStatus) { CheckPoint checkPoint = new CheckPoint(instrumentId, checkTime, status, tradeDay); var now = DateTime.Now; Logger.InfoFormat("add check point, {0}", checkPoint.ToString()); if (checkPoint.CheckTime <= now) { tradingStatus.Add(checkPoint.InstrumentId, checkPoint.Status, checkPoint.CheckTime, tradeDay); } else { if (_loadedInstrumentCheckPoints.Contains(new InstrumentCheckTimeKey(instrumentId, checkTime))) { return; } _loadedInstrumentCheckPoints.Add(new InstrumentCheckTimeKey(instrumentId, checkTime)); _checkPointHeap.Add(checkPoint); } }
public override string ToString() { StringBuilder sb = new StringBuilder(200); foreach (var eachPair in this.InstrumentStatus) { StringBuilder instrumentSB = new StringBuilder(); InstrumentStatus status = eachPair.Key; List <InstrumentStatusInfo> instruments = eachPair.Value; if (eachPair.Value.Count == 0) { continue; } foreach (var eachInstrument in instruments) { instrumentSB.Append(eachInstrument); instrumentSB.Append(','); } sb.AppendLine(string.Format("instrumentStatus = {0}, count= {2} instruments = {1}", status, instrumentSB.ToString(0, instrumentSB.Length - 1), instruments.Count)); } return(sb.ToString()); }
internal void ProcessMarketCommand(Protocal.MarketCommand marketCommand) { try { Logger.InfoFormat("ProcessMarketCommand, type= {0}", marketCommand.GetType().Name); if (marketCommand is Protocal.UpdateInstrumentTradingStatusMarketCommand) { List <InstrumentUpdateStatusCommand> broadcastTask = new List <InstrumentUpdateStatusCommand>(); Protocal.UpdateInstrumentTradingStatusMarketCommand updateMarketCommand = marketCommand as Protocal.UpdateInstrumentTradingStatusMarketCommand; Logger.InfoFormat("ProcessMarketCommand, content= {0}", updateMarketCommand); foreach (var instrumentStatus in updateMarketCommand.InstrumentStatus) { foreach (var instrument in instrumentStatus.Value) { InstrumentStatus sendInstrumentStatus = InstrumentStatus.None; switch (instrumentStatus.Key) { case Protocal.TradingInstrument.InstrumentStatus.DayOpen: sendInstrumentStatus = InstrumentStatus.DayOpen; break; case Protocal.TradingInstrument.InstrumentStatus.DayClose: sendInstrumentStatus = InstrumentStatus.DayClose; break; case Protocal.TradingInstrument.InstrumentStatus.SessionOpen: sendInstrumentStatus = InstrumentStatus.SessionOpen; break; case Protocal.TradingInstrument.InstrumentStatus.SessionClose: sendInstrumentStatus = InstrumentStatus.SessionClose; break; default: continue; } broadcastTask.Add(new InstrumentUpdateStatusCommand { InstrumentId = instrument.Id, TradeDay = instrument.TradeDay == null ? DateTime.MaxValue : instrument.TradeDay.Value, Status = sendInstrumentStatus }); } } this._broadcast.BroadcastCommands(this._token, new InstrumentsUpdateStatusCommand[] { new InstrumentsUpdateStatusCommand() { commandCollection = broadcastTask } }); //Protocal.UpdateInstrumentTradingStatusMarketCommand // marketCloseCommand = marketCommand as Protocal.UpdateInstrumentTradingStatusMarketCommand; //Logger.InfoFormat("ProcessMarketCommand, content= {0}", marketCloseCommand); //if (marketCloseCommand.InstrumentStatus.ContainsKey(Protocal.TradingInstrument.InstrumentStatus.DayClose)) //{ // List<InstrumentTradeDayCloseCommand> broadcastTask = new List<InstrumentTradeDayCloseCommand>(); // foreach (var instrumentInfo in marketCloseCommand.InstrumentStatus[Protocal.TradingInstrument.InstrumentStatus.DayClose]) // { // broadcastTask.Add(new InstrumentTradeDayCloseCommand // { // InstrumentId = instrumentInfo.Id, // TradeDay = instrumentInfo.TradeDay // }); // } // Logger.InfoFormat("ProcessMarketCommand, callBrodcast."); // this._broadcast.BroadcastCommands(this._token, broadcastTask.ToArray()); //} } } catch (Exception ex) { Logger.Error(string.Format("ProcessMarketCommand failed at\r\n{0}", ex)); } }
public void Add(Guid instrumentId, InstrumentStatus status, DateTime checkTime, DateTime tradeDay) { _builder.Add(instrumentId, status, checkTime, tradeDay); InstrumentTradingStatusKeeper.Default.AddInstrumentStatus(instrumentId, status, checkTime, tradeDay); }