Ejemplo n.º 1
0
		/// <summary>
		/// Отправить сообщение.
		/// </summary>
		/// <param name="message">Сообщение.</param>
		protected override void OnSendInMessage(Message message)
		{
			switch (message.Type)
			{
				case MessageTypes.Reset:
				{
					_accountIds.Clear();

					if (_streamigClient != null)
					{
						try
						{
							StreamingClientDispose();
						}
						catch (Exception ex)
						{
							SendOutError(ex);
						}

						_streamigClient = null;
					}

					_restClient = null;

					SendOutMessage(new ResetMessage());

					break;
				}

				case MessageTypes.Connect:
				{
					if (_restClient != null)
						throw new InvalidOperationException(LocalizedStrings.Str1619);

					if (_streamigClient != null)
						throw new InvalidOperationException(LocalizedStrings.Str1619);

					_restClient = new OandaRestClient(Server, Token);
					
					_streamigClient = new OandaStreamingClient(Server, Token, GetAccountId);
					_streamigClient.NewError += SendOutError;
					_streamigClient.NewTransaction += SessionOnNewTransaction;
					_streamigClient.NewPrice += SessionOnNewPrice;

					SendOutMessage(new ConnectMessage());

					break;
				}

				case MessageTypes.Disconnect:
				{
					if (_restClient == null)
						throw new InvalidOperationException(LocalizedStrings.Str1856);

					if (_streamigClient == null)
						throw new InvalidOperationException(LocalizedStrings.Str1856);

					StreamingClientDispose();
					_streamigClient = null;

					_restClient = null;

					SendOutMessage(new DisconnectMessage());

					break;
				}

				case MessageTypes.PortfolioLookup:
				{
					ProcessPortfolioLookupMessage((PortfolioLookupMessage)message);
					break;
				}

				case MessageTypes.Portfolio:
				{
					ProcessPortfolioMessage((PortfolioMessage)message);
					break;
				}

				case MessageTypes.OrderStatus:
				{
					ProcessOrderStatusMessage();
					break;
				}

				case MessageTypes.Time:
				{
					//var timeMsg = (TimeMessage)message;
					//Session.RequestHeartbeat(new HeartbeatRequest(timeMsg.TransactionId), () => { }, CreateErrorHandler("RequestHeartbeat"));
					break;
				}

				case MessageTypes.OrderRegister:
				{
					ProcessOrderRegisterMessage((OrderRegisterMessage)message);
					break;
				}

				case MessageTypes.OrderCancel:
				{
					ProcessCancelMessage((OrderCancelMessage)message);
					break;
				}

				case MessageTypes.OrderReplace:
				{
					ProcessOrderReplaceMessage((OrderReplaceMessage)message);
					break;
				}

				case MessageTypes.SecurityLookup:
				{
					ProcessSecurityLookupMessage((SecurityLookupMessage)message);
					break;
				}

				case MessageTypes.MarketData:
				{
					ProcessMarketDataMessage((MarketDataMessage)message);
					break;
				}
			}
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Отправить сообщение.
        /// </summary>
        /// <param name="message">Сообщение.</param>
        protected override void OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                _accountIds.Clear();

                if (_streamigClient != null)
                {
                    try
                    {
                        StreamingClientDispose();
                    }
                    catch (Exception ex)
                    {
                        SendOutError(ex);
                    }

                    _streamigClient = null;
                }

                _restClient = null;

                SendOutMessage(new ResetMessage());

                break;
            }

            case MessageTypes.Connect:
            {
                if (_restClient != null)
                {
                    throw new InvalidOperationException(LocalizedStrings.Str1619);
                }

                if (_streamigClient != null)
                {
                    throw new InvalidOperationException(LocalizedStrings.Str1619);
                }

                _restClient = new OandaRestClient(Server, Token);

                _streamigClient                 = new OandaStreamingClient(Server, Token, GetAccountId);
                _streamigClient.NewError       += SendOutError;
                _streamigClient.NewTransaction += SessionOnNewTransaction;
                _streamigClient.NewPrice       += SessionOnNewPrice;

                SendOutMessage(new ConnectMessage());

                break;
            }

            case MessageTypes.Disconnect:
            {
                if (_restClient == null)
                {
                    throw new InvalidOperationException(LocalizedStrings.Str1856);
                }

                if (_streamigClient == null)
                {
                    throw new InvalidOperationException(LocalizedStrings.Str1856);
                }

                StreamingClientDispose();
                _streamigClient = null;

                _restClient = null;

                SendOutMessage(new DisconnectMessage());

                break;
            }

            case MessageTypes.PortfolioLookup:
            {
                ProcessPortfolioLookupMessage((PortfolioLookupMessage)message);
                break;
            }

            case MessageTypes.Portfolio:
            {
                ProcessPortfolioMessage((PortfolioMessage)message);
                break;
            }

            case MessageTypes.OrderStatus:
            {
                ProcessOrderStatusMessage();
                break;
            }

            case MessageTypes.Time:
            {
                //var timeMsg = (TimeMessage)message;
                //Session.RequestHeartbeat(new HeartbeatRequest(timeMsg.TransactionId), () => { }, CreateErrorHandler("RequestHeartbeat"));
                break;
            }

            case MessageTypes.OrderRegister:
            {
                ProcessOrderRegisterMessage((OrderRegisterMessage)message);
                break;
            }

            case MessageTypes.OrderCancel:
            {
                ProcessCancelMessage((OrderCancelMessage)message);
                break;
            }

            case MessageTypes.OrderReplace:
            {
                ProcessOrderReplaceMessage((OrderReplaceMessage)message);
                break;
            }

            case MessageTypes.SecurityLookup:
            {
                ProcessSecurityLookupMessage((SecurityLookupMessage)message);
                break;
            }

            case MessageTypes.MarketData:
            {
                ProcessMarketDataMessage((MarketDataMessage)message);
                break;
            }
            }
        }