public Task<int> PlaceOrder(OrderParams orderParams, CancellationToken cancellationToken) { Contract.Requires((orderParams.OrderType != OrderType.Limit && orderParams.OrderType != OrderType.Limit) || (orderParams.OrderType == OrderType.Limit && orderParams.LimitPrice.HasValue) || (orderParams.OrderType == OrderType.Stop && orderParams.StopPrice.HasValue)); return null; }
public async Task<int> PlaceOrder(OrderParams orderParams, CancellationToken cancellationToken) { using (var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(this.internalCancelationTokenSource.Token, cancellationToken)) { var orderId = this.idsDispenser.NextOrderId(); var request = RequestPlaceOrderMessage.Default; request.Account = this.AccountId; request.Action = orderParams.OrderAction.ToStringAction(); request.TotalQuantity = orderParams.Quantity; request.ContractId = orderParams.Contract.ContractId; request.Symbol = orderParams.Contract.Symbol; request.SecType = orderParams.Contract.SecurityType.ToString(); request.Expity = orderParams.Contract.Expiry; request.Strike = orderParams.Contract.Strike; request.Right = orderParams.Contract.RightString; request.Multiplier = orderParams.Contract.AdditionalContractInfo.Multiplier; request.Exchange = orderParams.Contract.AdditionalContractInfo.Exchange; request.PrimaryExchange = orderParams.Contract.AdditionalContractInfo.PrimaryExchange; request.Currency = orderParams.Contract.AdditionalContractInfo.Currency; request.LocalSymbol = orderParams.Contract.LocalSymbol; request.TradingClass = orderParams.Contract.AdditionalContractInfo.TradingClass; request.OrderType = orderParams.OrderType.ToOrderString(); request.OrderId = orderId; request.Transmit = true; // ReSharper disable PossibleInvalidOperationException // Relations between order type and prices fields checked in contracts if (orderParams.OrderType == OrderType.Limit) { request.LimitPrice = (double)orderParams.LimitPrice.Value; } if (orderParams.OrderType == OrderType.Stop) { request.AuxPrice = (double)orderParams.StopPrice.Value; } // ReSharper restore PossibleInvalidOperationException return await this.factory.CreatePlaceOrderOperation(request, this.ordersStorage, cancellationTokenSource.Token); } }
public Task<int> PlaceOrder(OrderParams orderParams, CancellationToken cancellationToken) { return this.dispatcher.Dispatch( () => this.internalAccount.PlaceOrder(orderParams, cancellationToken)); }
private async void PlaceOrder(OrderAction action) { if (this.SelectedOrderType == OrderType.Limit && !this.LimitPrice.HasValue) { this.SetFieldError(true, "LimitPrice"); return; } if (this.SelectedOrderType == OrderType.Stop && !this.StopPrice.HasValue) { this.SetFieldError(true, "StopPrice"); return; } this.cancellationTokenSource = new CancellationTokenSource(); var searchRequest = new SearchRequest{NumberOfResults = 1}; if (this.Ticker.Length == 7 && this.Ticker[3] == '.') { searchRequest.LocalSymbol = this.Ticker; searchRequest.SecurityType = SecurityType.CASH; } else { searchRequest.Symbol = this.Ticker; } Contract contract; try { contract = (await this.client.FindContracts(searchRequest, this.cancellationTokenSource.Token)).First(); } catch (IbException) { this.SetFieldError(true, "Ticker"); return; } try { var orderParams = new OrderParams { Contract = contract, LimitPrice = this.LimitPrice, OrderAction = action, OrderType = this.SelectedOrderType, Quantity = this.Quantity, StopPrice = this.StopPrice, }; var account = this.client.Accounts.First(acc => acc.AccountId == this.SelectedAccount); await account.PlaceOrder(orderParams, this.cancellationTokenSource.Token); } catch (IbException) { } }