private void MakeOrder(Side side, OrdType ordType) { Instrument instrument = (this.dgvQuotes.SelectedRows[0] as QuoteViewRow).Instrument; byte route = (byte)0; if (this.executionProvider is IMultiRouteExecutionProvider) { route = this.SelectedRoute; } OrderMiniBlotterForm orderMiniBlotterForm = new OrderMiniBlotterForm(); orderMiniBlotterForm.Init(instrument, ordType, side, route); if (orderMiniBlotterForm.ShowDialog((IWin32Window)this) == DialogResult.OK) { SingleOrder singleOrder = null; switch (ordType) { case OrdType.Market: singleOrder = new MarketOrder(this.executionProvider, this.portfolio, instrument, side, (double)orderMiniBlotterForm.Qty); break; case OrdType.Limit: singleOrder = new LimitOrder(this.executionProvider, this.portfolio, instrument, side, (double)orderMiniBlotterForm.Qty, orderMiniBlotterForm.LimitPrice); break; case OrdType.Stop: singleOrder = new StopOrder(this.executionProvider, this.portfolio, instrument, side, (double)orderMiniBlotterForm.Qty, orderMiniBlotterForm.StopPrice); break; case OrdType.StopLimit: singleOrder = new StopLimitOrder(this.executionProvider, this.portfolio, instrument, side, (double)orderMiniBlotterForm.Qty, orderMiniBlotterForm.LimitPrice, orderMiniBlotterForm.StopPrice); break; } ((NewOrderSingle)singleOrder).TimeInForce = orderMiniBlotterForm.TimeInForce; ((FIXNewOrderSingle)singleOrder).Route = (int)orderMiniBlotterForm.Route; singleOrder.Persistent = this.portfolio.Persistent; if (!((IProvider)this.executionProvider).IsConnected) { bool flag = false; if (MessageBox.Show(this, "Cannot send the order, because provider is not connected." + Environment.NewLine + "Do you want to connect to " + ((IProvider)this.executionProvider).Name + "?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { flag = true; ((IProvider)this.executionProvider).Connect(15000); } if (flag && !((IProvider)this.marketDataProvider).IsConnected) { MessageBox.Show(this, "Unable to connect to " + this.marketDataProvider.Name, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } if (((IProvider)this.executionProvider).IsConnected) { singleOrder.Send(); } if ((int)orderMiniBlotterForm.Route > 0) { this.SelectedRoute = orderMiniBlotterForm.Route; } } orderMiniBlotterForm.Dispose(); }
private void MakeOrder(Side side, OrdType ordType) { Instrument instrument = (this.dgvQuotes.SelectedRows[0] as QuoteViewRow).Instrument; byte route = (byte)0; if (this.executionProvider is IMultiRouteExecutionProvider) route = this.SelectedRoute; OrderMiniBlotterForm orderMiniBlotterForm = new OrderMiniBlotterForm(); orderMiniBlotterForm.Init(instrument, ordType, side, route); if (orderMiniBlotterForm.ShowDialog((IWin32Window)this) == DialogResult.OK) { SingleOrder singleOrder = null; switch (ordType) { case OrdType.Market: singleOrder = new MarketOrder(this.executionProvider, this.portfolio, instrument, side, (double)orderMiniBlotterForm.Qty); break; case OrdType.Limit: singleOrder = new LimitOrder(this.executionProvider, this.portfolio, instrument, side, (double)orderMiniBlotterForm.Qty, orderMiniBlotterForm.LimitPrice); break; case OrdType.Stop: singleOrder = new StopOrder(this.executionProvider, this.portfolio, instrument, side, (double)orderMiniBlotterForm.Qty, orderMiniBlotterForm.StopPrice); break; case OrdType.StopLimit: singleOrder = new StopLimitOrder(this.executionProvider, this.portfolio, instrument, side, (double)orderMiniBlotterForm.Qty, orderMiniBlotterForm.LimitPrice, orderMiniBlotterForm.StopPrice); break; } ((NewOrderSingle)singleOrder).TimeInForce = orderMiniBlotterForm.TimeInForce; ((FIXNewOrderSingle)singleOrder).Route = (int)orderMiniBlotterForm.Route; singleOrder.Persistent = this.portfolio.Persistent; if (!((IProvider)this.executionProvider).IsConnected) { bool flag = false; if (MessageBox.Show(this, "Cannot send the order, because provider is not connected." + Environment.NewLine + "Do you want to connect to " + ((IProvider)this.executionProvider).Name + "?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { flag = true; ((IProvider)this.executionProvider).Connect(15000); } if (flag && !((IProvider)this.marketDataProvider).IsConnected) { MessageBox.Show(this, "Unable to connect to " + this.marketDataProvider.Name, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } if (((IProvider)this.executionProvider).IsConnected) singleOrder.Send(); if ((int)orderMiniBlotterForm.Route > 0) this.SelectedRoute = orderMiniBlotterForm.Route; } orderMiniBlotterForm.Dispose(); }
public void Init(Instrument instrument, OrdType ordType, Side side, byte route) { this.Text = string.Format("{0} - {1} {2}", instrument, side, ordType); int decimalPlaces = PriceFormatHelper.GetDecimalPlaces(instrument); Decimal num1 = (Decimal)Math.Pow(0.1, (double)decimalPlaces); this.nudLimitPrice.DecimalPlaces = decimalPlaces; this.nudStopPrice.DecimalPlaces = decimalPlaces; this.nudLimitPrice.Increment = num1; this.nudStopPrice.Increment = num1; this.nudLimitPrice.Enabled = false; this.nudStopPrice.Enabled = false; switch (ordType) { case OrdType.Market: switch (side) { case Side.Buy: this.nudLimitPrice.Value = (Decimal)instrument.Quote.Ask; this.nudStopPrice.Value = (Decimal)instrument.Quote.Ask; break; case Side.Sell: this.nudLimitPrice.Value = (Decimal)instrument.Quote.Bid; this.nudStopPrice.Value = (Decimal)instrument.Quote.Bid; break; default: throw new NotSupportedException("Not supported order side - " + ((object)side).ToString()); } this.cbxTIFs.BeginUpdate(); this.cbxTIFs.Items.Clear(); foreach (OpenQuant.API.TimeInForce timeInForce in Enum.GetValues(typeof(OpenQuant.API.TimeInForce))) { this.cbxTIFs.Items.Add((object)timeInForce); } this.cbxTIFs.SelectedItem = (object)OpenQuant.API.TimeInForce.Day; this.cbxTIFs.EndUpdate(); if ((int)route > 0) { OrderMiniBlotterForm orderMiniBlotterForm = this; int num2 = orderMiniBlotterForm.Height + 32; orderMiniBlotterForm.Height = num2; Button button1 = this.btnSend; int num3 = button1.Top + 32; button1.Top = num3; Button button2 = this.btnCancel; int num4 = button2.Top + 32; button2.Top = num4; GroupBox groupBox = this.groupBox1; int num5 = groupBox.Height + 32; groupBox.Height = num5; Label label = new Label(); label.AutoSize = false; label.TextAlign = ContentAlignment.MiddleLeft; label.Location = new Point(16, 144); label.Size = new Size(70, 20); label.Text = "Route"; this.groupBox1.Controls.Add((Control)label); this.cbxRoutes = new ComboBox(); this.cbxRoutes.DropDownStyle = ComboBoxStyle.DropDownList; this.cbxRoutes.Location = new Point(104, 144); this.cbxRoutes.Size = new Size(98, 21); this.cbxRoutes.Sorted = true; this.groupBox1.Controls.Add((Control)this.cbxRoutes); this.cbxRoutes.BeginUpdate(); this.cbxRoutes.Items.Clear(); IEnumerator enumerator = ((ProviderList)ProviderManager.ExecutionProviders).GetEnumerator(); try { while (enumerator.MoveNext()) { IExecutionProvider iexecutionProvider = (IExecutionProvider)enumerator.Current; RouteItem routeItem = new RouteItem(iexecutionProvider.Name, iexecutionProvider.Id); this.cbxRoutes.Items.Add((object)routeItem); if ((int)((IProvider)iexecutionProvider).Id == (int)route) { this.cbxRoutes.SelectedItem = (object)routeItem; } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } if (this.cbxRoutes.Items.Count > 0 && this.cbxRoutes.SelectedItem == null) { this.cbxRoutes.SelectedIndex = 0; } this.cbxRoutes.EndUpdate(); break; } else { this.cbxRoutes = (ComboBox)null; break; } case OrdType.Limit: this.nudLimitPrice.Enabled = true; goto case OrdType.Market; case OrdType.Stop: this.nudStopPrice.Enabled = true; goto case OrdType.Market; case OrdType.StopLimit: this.nudLimitPrice.Enabled = true; this.nudStopPrice.Enabled = true; goto case OrdType.Market; default: throw new NotSupportedException("Not supported order type - " + ordType.ToString()); } }