예제 #1
0
		/// <summary>
		/// Создать <see cref="LuaFixServer"/>.
		/// </summary>
		public LuaFixServer()
		{
			_requests.Close();
			_securityClassInfo.FillDefault();

			_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 =>
			{
				_fixServer.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()
								? _securityClassInfo.GetSecurityClass(secMsg.SecurityId)
								: null
						};

						_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;
						_requests.Enqueue(new LuaRequest
						{
							MessageType = MessageTypes.PortfolioLookup,
							TransactionId = pfMsg.TransactionId
						});
						break;

					case MessageTypes.OrderStatus:
						var statusMsg = (OrderStatusMessage)message;
						_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();
				}
			};

			_fixServer.TransactionSession.TimeZone = TimeHelper.Moscow;

			_logManager.Application = new QuikNativeApp();

			_logManager.Sources.Add(_fixServer);

			LogFile = "StockSharp.QuikLua.log";
		}