private void ProcessMarketDataMessage(MarketDataMessage message) { _sessionHolder.Requests.Enqueue(new LuaRequest { MessageType = message.Type, DataType = message.DataType, SecurityId = new SecurityId { SecurityCode = message.SecurityId.SecurityCode, BoardCode = _sessionHolder.GetSecurityClass(message.SecurityId) }, IsSubscribe = message.IsSubscribe, TransactionId = message.TransactionId }); var result = (MarketDataMessage)message.Clone(); result.OriginalTransactionId = message.TransactionId; _fixServer.SendInMessage(result); }
/// <summary> /// Создать <see cref="LuaFixServer"/>. /// </summary> public LuaFixServer() { _sessionHolder = new LuaSession(new MillisecondIncrementalIdGenerator()) { Path = SystemProcess.GetCurrentProcess().MainModule.FileName }; _fixServer = new FixServerEx((l, p) => { if (Login.IsEmpty() || (l.CompareIgnoreCase(Login) && p == Password)) { _prevLevel1.Clear(); return(Tuple.Create(TimeSpan.FromMilliseconds(100), FixClientRoles.Admin)); } return(null); }); _fixServer.NewOutMessage += message => { _sessionHolder.AddDebugLog("In. {0}", message); switch (message.Type) { case MessageTypes.CandlePnF: case MessageTypes.CandleRange: case MessageTypes.CandleRenko: case MessageTypes.CandleTick: case MessageTypes.CandleTimeFrame: case MessageTypes.CandleVolume: throw new NotSupportedException(); case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; ProcessMarketDataMessage(mdMsg); break; } case MessageTypes.SecurityLookup: { var secMsg = (SecurityLookupMessage)message; var securityId = new SecurityId { SecurityCode = secMsg.SecurityId.SecurityCode, BoardCode = !secMsg.SecurityId.BoardCode.IsEmpty() ? _sessionHolder.GetSecurityClass(secMsg.SecurityId) : null }; _sessionHolder.Requests.Enqueue(new LuaRequest { MessageType = MessageTypes.SecurityLookup, TransactionId = secMsg.TransactionId, SecurityId = securityId, Value = secMsg.UnderlyingSecurityCode }); break; } case MessageTypes.OrderPairReplace: case MessageTypes.Portfolio: case MessageTypes.Position: throw new NotSupportedException(); case MessageTypes.PortfolioLookup: var pfMsg = (PortfolioLookupMessage)message; _sessionHolder.Requests.Enqueue(new LuaRequest { MessageType = MessageTypes.PortfolioLookup, TransactionId = pfMsg.TransactionId }); break; case MessageTypes.OrderStatus: var statusMsg = (OrderStatusMessage)message; _sessionHolder.Requests.Enqueue(new LuaRequest { MessageType = MessageTypes.OrderStatus, TransactionId = statusMsg.TransactionId }); break; case MessageTypes.OrderRegister: case MessageTypes.OrderReplace: case MessageTypes.OrderCancel: case MessageTypes.OrderGroupCancel: var orderMsg = (OrderMessage)message; ProcessOrderMessage(orderMsg); break; default: throw new ArgumentOutOfRangeException(); } }; _logManager.Application = new QuikNativeApp(); _logManager.Sources.Add(_sessionHolder); _logManager.Sources.Add(_fixServer); LogFile = "StockSharp.QuikLua.log"; var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var logFileName = Path.Combine(path, LogFile); _logManager.Listeners.Add(new FileLogListener(logFileName)); }