Пример #1
0
        public ETradeApi(ETradeClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            _client = client;
        }
Пример #2
0
            protected ETradeModule(string name, ETradeClient client)
            {
                _name  = name;
                Client = client;
                Client.Connection.ConnectionStateChanged += HandleClientState;

                _wakeupTimer.AutoReset = false;
                _wakeupTimer.Enabled   = false;
                _wakeupTimer.Elapsed  += (sender, args) => _wakeupEvt.Set();
            }
Пример #3
0
        public ETradeResponse ExecuteNextPart(ETradeClient client)
        {
            IsDone = false;
            var response = ExecuteNextPartInternal(client.Api);

            IsDone = GetIsDone() || response.Exception != null;

            if (response.Exception != null)
            {
                client.AddWarningLog("Request '{0}' completed with exception: {1}", GetType().Name, response.Exception);
            }

            return(response);
        }
Пример #4
0
		public ETradeConnection(ETradeClient client)
		{
			_client = client;
			_authorizationAction = DefaultAuthorizationAction;
		}
Пример #5
0
 public ETradeConnection(ETradeClient client)
 {
     _client = client;
     _authorizationAction = DefaultAuthorizationAction;
 }
Пример #6
0
		/// <summary>
		/// Send incoming message.
		/// </summary>
		/// <param name="message">Message.</param>
		protected override void OnSendInMessage(Message message)
		{
			switch (message.Type)
			{
				case MessageTypes.Reset:
				{
					if (_client != null)
					{
						try
						{
							DisposeClient();
						}
						catch (Exception ex)
						{
							SendOutError(ex);
						}

						_client = null;
					}

					SendOutMessage(new ResetMessage());

					break;
				}

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

					_client = new ETradeClient
					{
						ConsumerKey = ConsumerKey,
						ConsumerSecret = ConsumerSecret,
						AccessToken = AccessToken,
						Sandbox = Sandbox,
						VerificationCode = VerificationCode,
					};

					_client.ConnectionStateChanged += ClientOnConnectionStateChanged;
					_client.ConnectionError += ClientOnConnectionError;
					_client.Error += SendOutError;

					_client.OrderRegisterResult += ClientOnOrderRegisterResult;
					_client.OrderReRegisterResult += ClientOnOrderRegisterResult;
					_client.OrderCancelResult += ClientOnOrderCancelResult;
					_client.AccountsData += ClientOnAccountsData;
					_client.PositionsData += ClientOnPositionsData;
					_client.OrdersData += ClientOnOrdersData;

					_client.ProductLookupResult += ClientOnProductLookupResult;

					_client.Parent = this;
					_client.Connect();

					break;
				}

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

					DisposeClient();
					_client = null;

					break;
				}

				case MessageTypes.SecurityLookup:
				{
					var lookupMsg = (SecurityLookupMessage)message;
					_client.LookupSecurities(lookupMsg.SecurityId.SecurityCode, lookupMsg.TransactionId);
					break;
				}

				case MessageTypes.OrderRegister:
				{
					var regMsg = (OrderRegisterMessage)message;

					_client.RegisterOrder(
						regMsg.PortfolioName,
						regMsg.SecurityId.SecurityCode,
						regMsg.Side,
						regMsg.Price,
						regMsg.Volume,
						regMsg.TransactionId,
						regMsg.TimeInForce == TimeInForce.MatchOrCancel,
						regMsg.TillDate,
						regMsg.OrderType,
						(ETradeOrderCondition)regMsg.Condition);

					break;
				}

				case MessageTypes.OrderReplace:
				{
					var replaceMsg = (OrderReplaceMessage)message;

					if (replaceMsg.OldOrderId == null)
						throw new InvalidOperationException(LocalizedStrings.Str2252Params.Put(replaceMsg.OldTransactionId));

					SaveOrder(replaceMsg.OldTransactionId, replaceMsg.OldOrderId.Value);

					_client.ReRegisterOrder(
						replaceMsg.OldOrderId.Value,
						replaceMsg.PortfolioName,
						replaceMsg.Price,
						replaceMsg.Volume,
						replaceMsg.TransactionId,
						replaceMsg.TimeInForce == TimeInForce.MatchOrCancel,
						replaceMsg.TillDate,
						replaceMsg.OrderType,
						(ETradeOrderCondition)replaceMsg.Condition);

					break;
				}

				case MessageTypes.OrderCancel:
				{
					var cancelMsg = (OrderCancelMessage)message;

					if (cancelMsg.OrderId == null)
						throw new InvalidOperationException(LocalizedStrings.Str2252Params.Put(cancelMsg.OrderTransactionId));

					_client.CancelOrder(cancelMsg.TransactionId, cancelMsg.OrderId.Value, cancelMsg.PortfolioName);
					break;
				}
			}
		}
Пример #7
0
 public ETradeMarketModule(ETradeClient client) : base("market", client)
 {
 }
Пример #8
0
 public ETradeOrderModule(ETradeClient client) : base("order", client)
 {
 }
Пример #9
0
 public ETradeAccountsModule(ETradeClient client) : base("accounts", client)
 {
 }