public void ParallelTokenBucketTest() { var client = new ETradeClient(_consumerToken); var tokens = new[] { new { client, consumerToken = _consumerToken, accessToken = _accessToken }, new { client, consumerToken = _consumerToken, accessToken = _accessToken }, new { client, consumerToken = _consumerToken, accessToken = _accessToken }, new { client, consumerToken = _consumerToken, accessToken = _accessToken } }; var accounts = new ConcurrentBag<Account>(); var sw = new Stopwatch(); sw.Start(); Parallel.ForEach( tokens, t => accounts.Add(t.client.GetAccount()) ); sw.Stop(); Assert.IsNotNull(accounts); }
public void ExecuteOrdersTest() { var client = new ETradeClient(_consumerToken); const int accountId = 30049872; var orders = new List <Order> { new Order { IsSale = false, Price = 1d, Quantity = 1, Symbol = "IBM" }, new Order { IsSale = true, Price = 1d, Quantity = 1, Symbol = "MSFT" } }; var response = client.ExecuteOrders(accountId, orders); Assert.IsNotNull(response); Assert.IsTrue(response.Any()); }
public void ParallelTokenBucketTest() { var client = new ETradeClient(_consumerToken); var tokens = new[] { new { client, consumerToken = _consumerToken, accessToken = _accessToken }, new { client, consumerToken = _consumerToken, accessToken = _accessToken }, new { client, consumerToken = _consumerToken, accessToken = _accessToken }, new { client, consumerToken = _consumerToken, accessToken = _accessToken } }; var accounts = new ConcurrentBag <Account>(); var sw = new Stopwatch(); sw.Start(); Parallel.ForEach( tokens, t => accounts.Add(t.client.GetAccount()) ); sw.Stop(); Assert.IsNotNull(accounts); }
public void GetOAuthUserActionUriTest() { var client = new ETradeClient(_consumerToken); var userActionUri = client.GetUserAuthorizationUrl(); Assert.IsNotNull(userActionUri); }
public StocksRepository(Common.OAuthToken consumerToken, Common.OAuthToken accessToken = null, bool productionMode = false) { var cToken = new ConsumerToken { Token = consumerToken.Token, TokenSecret = consumerToken.Secret }; var aToken = accessToken != null ? new AccessToken { Token = accessToken.Token, TokenSecret = accessToken.Secret } : null; _etradeClient = new ETradeClient(cToken, aToken, productionMode); }
/// <summary> /// Отправить входящее сообщение. /// </summary> /// <param name="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; } } }
public void ExecuteOrdersTest() { var client = new ETradeClient(_consumerToken); const int accountId = 30049872; var orders = new List<Order> { new Order { IsSale = false, Price = 1d, Quantity = 1, Symbol = "IBM" }, new Order { IsSale = true, Price = 1d, Quantity = 1, Symbol = "MSFT" } }; var response = client.ExecuteOrders(accountId, orders); Assert.IsNotNull(response); Assert.IsTrue(response.Any()); }