private void buttonCancelAll_Click(object sender, EventArgs e) { if (this.TrElement.Security.NotIsNull()) { Trader.CancelAllOrder(this.TrElement.Security); } }
private void buttonOrdersCancelAll_Click(object sender, EventArgs e) { if (CreateOrderSec != null) { Common.Ext.NewThread(() => { Trader.CancelAllOrder(CreateOrderSec); }); } }
/*private void InitFormCreateOrders() * { * try * { * this.OnTimer2s += () => * { * if (CreateOrderSec != null) * { * var pos = Trader.Objects.Positions.FirstOrDefault(p => p.Sec == CreateOrderSec); * OrdersLastPrice.GuiAsync(() => * { * if (CreateOrderSec != null) * if (CreateOrderSec.LastTrade != null) * OrdersLastPrice.Text = CreateOrderSec.LastTrade.Price.ToString(); * if (pos != null) * { * labelPosSec.Text = pos.Data.CurrentNet.ToString(); * labelOrdersCountOrder.Text = pos.Data.OrdersBuy.ToString() + " / " + pos.Data.OrdersSell.ToString(); * } * else * { * labelPosSec.Text = "0"; * labelOrdersCountOrder.Text = "0"; * } * }); * } * }; * * OrdersSetPrice.InitWheelDecimal(); * OrdersSetVolume.InitWheelDecimal(); * * textBoxOrderFindSec.TextChanged += (sen, e) => * { * var textBox_fs = (TextBox)sen; * string secCode = textBox_fs.Text; * this.SelectSecurity(secCode); * }; * } * catch (Exception ee) * { * MessageBox.Show(ee.ToString()); * } * }*/ /// <summary> /// Переключатель на нужный инструмент /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /*private void labelOrdersClass_Click(object sender, EventArgs e) * { * try * { * if (CreateOrderSec != null) * { * * if (labelOrdersClass.Tag == null) labelOrdersClass.Tag = 0; * int index = (int)labelOrdersClass.Tag; * var listSec = Trader.Objects.Securities.Where(s => s.Code == CreateOrderSec.Code).ToArray(); * if (listSec.Length > 0) * { * if (index >= listSec.Length) index = 0; * var classSec = listSec.ElementAt(index); * this.SelectSecurity(CreateOrderSec.Code, classSec.Class.Code); * index++; * labelOrdersClass.Tag = index; * } * } * } * catch (Exception ee) * { * MessageBox.Show(ee.ToString()); * } * }*/ /// <summary> /// Осуществляет поиск и подстановку значений в формы нужно инструмента. /// </summary> /// <param name="secCode"></param> /*private void SelectSecurity(string secCode, string secClass = "") * { * try * { * Securities sec = null; * if (secClass != "") * { * sec = this.SearchSecurity(secCode, secClass); * } * else * { * sec = this.SearchSecurity(secCode); * } * if (sec != null) * { * CreateOrderSec = sec; * * labelOrdersSec.Text = CreateOrderSec.Code; * labelOrdersClass.Text = CreateOrderSec.Class.Code; * if (CreateOrderSec.LastTrade != null) * { * OrdersLastPrice.Text = CreateOrderSec.LastTrade.Price.ToString(); * OrdersSetPrice.Value = CreateOrderSec.LastTrade.Price; * } * } * else * { * labelOrdersSec.Text = "---"; * labelOrdersClass.Text = secClass; * OrdersLastPrice.Text = "0"; * OrdersSetPrice.Value = 0; * } * } * catch (Exception ee) * { * MessageBox.Show(ee.ToString()); * } * }*/ /*private void dataGridViewOrders_SelectionChanged(object sender, EventArgs e) * { * try * { * var dataGrid = (DataGridView)sender; * DataGridViewRow selectRow = null; * foreach (var r in dataGrid.SelectedRows) * selectRow = (DataGridViewRow)r; * if (selectRow != null) * { * CreateOrderSec = (Securities)selectRow.Cells[3].Value; * OrdersSetPrice.DecimalPlaces = CreateOrderSec.Scale; * OrdersSetPrice.Increment = CreateOrderSec.Params.MinPriceStep; * OrdersSetPrice.Value = Convert.ToDecimal(selectRow.Cells[5].Value); * OrdersSetVolume.Value = Convert.ToDecimal(selectRow.Cells[6].Value); * * textBoxOrderFindSec.Text = CreateOrderSec.Code; * } * } * catch (Exception ee) * { * MessageBox.Show(ee.ToString()); * } * }*/ /*private void buttonOrderCreateBuy_Click(object sender, EventArgs e) * { * try * { * if (CreateOrderSec != null && OrdersSetPrice.Value > 0 && OrdersSetVolume.Value > 0) * { * Common.Ext.NewThread(() => * { * Trader.CreateOrder(new Order() * { * Price = OrdersSetPrice.Value, * Volume = Convert.ToInt32(OrdersSetVolume.Value), * Direction = OrderDirection.Buy, * Sec = CreateOrderSec * }); * }); * } * } * catch (Exception ee) * { * MessageBox.Show(ee.ToString()); * } * }*/ /*private void buttonOrderCreateSell_Click(object sender, EventArgs e) * { * try * { * if (CreateOrderSec != null && OrdersSetPrice.Value > 0 && OrdersSetVolume.Value > 0) * { * Common.Ext.NewThread(() => * { * Trader.CreateOrder(new Order() * { * Price = OrdersSetPrice.Value, * Volume = Convert.ToInt32(OrdersSetVolume.Value), * Direction = OrderDirection.Sell, * Sec = CreateOrderSec * }); * }); * } * } * catch (Exception ee) * { * MessageBox.Show(ee.ToString()); * } * }*/ /* private void OrdersLastPrice_Click(object sender, EventArgs e) * { * OrdersSetPrice.Value = Convert.ToDecimal(OrdersLastPrice.Text); * }*/ private void ButtonOrdersCancelAll_Click(object sender, EventArgs e) { if (CreateOrderSec != null) { MThread.InitThread(() => { Trader.CancelAllOrder(CreateOrderSec); }); } }
public void LoopControl(bool ReCalculate = false) { if (checkBoxMCActivate.Checked) { var pos = GetPositionForControl(); if (pos.NotIsNull() && pos.CurrentVolume > 0) { var sOrders = GetStopOrdersForControl(); if (ReCalculate || !CheckStopOrdersForControls(sOrders)) { foreach (var sOrd in sOrders) { Trader.CancelStopOrder(sOrd); } return; } if (sOrders.NotIsNull() && sOrders.Count() == 0) ///*&& (!CheckStopOrdersForControls(sOrders)*/) { //Защита от большого числа заявок if (sOrders.Count() > 2) { ShowTransReply("Контроль риска. Стоп-заявки не снимаются."); return; } var lastMyTrade = GetLastMyTradeForControl(pos.Data.CurrentNet); decimal Price = 0; if (lastMyTrade.NotIsNull()) { //Если выбран, то берем цену из поля цены if (checkBoxMCSetPrice.Checked) { Price = numericUpDownMCPriceLastTrade.Value; } else { Price = numericUpDownMCPriceLastTrade.Value = lastMyTrade.Trade.Price; } } else { ShowTransReply("Контроль риска. Не удалось получить последнюю сделку."); return; } if (Price > 0 && numericUpDownMCStopTiks.Value > 0 && numericUpDownMCTakeProfitTiks.Value > 0) { var newStopOrder = GetStopOrderControl(pos.Data.CurrentNet, Price); var takePos = getCurrectPosByPercent(pos); var newTakeProfit = GetTakeProfitOrderControl(pos.Data.CurrentNet, takePos, Price); if (newStopOrder.NotIsNull() && checkBoxMCStopLoss.Checked) { Trader.CreateStopOrder(newStopOrder, StopOrderType.StopLimit); } if (newTakeProfit.NotIsNull() && checkBoxMCTakeProfit.Checked) { Trader.CreateStopOrder(newTakeProfit, StopOrderType.TakeProfit); } } else { ShowTransReply("Контроль риска. Одно из значений равно 0."); return; } } } else { var sOrders = GetStopOrdersForControl(); foreach (var sOrd in sOrders) { Trader.CancelStopOrder(sOrd); Trader.CancelAllOrder(Securities); Trader.CancelAllStopOrder(Securities); } //Снимаем флаг фиксации цены, чтобы при последующих ордерах не выставлялось не корректно. checkBoxMCSetPrice.Checked = false; } } }