public void AutoOrdersLoopControl() { MThread.InitThread(() => { foreach (var ord in ObjAutoOrders.ToArray) { var sec = GetSecCodeAndClass(ord.SecAndCode); if (sec.NotIsNull()) { Order order = null; if (ord.CondAutoOrder == AutoOrders.CondAutoOrder.MoreOrEquals) { if (sec.LastPrice >= ord.PriceCondition) { order = new Order() { Sec = sec, Direction = ord.Direction, Price = ord.Price, Volume = (int)ord.Volume, ClientCode = ord.Comment }; } } else if (ord.CondAutoOrder == AutoOrders.CondAutoOrder.LessOrEquals) { if (sec.LastPrice <= ord.PriceCondition) { order = new Order() { Sec = sec, Direction = ord.Direction, Price = ord.Price, Volume = (int)ord.Volume, ClientCode = ord.Comment }; } } if (order.NotIsNull()) { ObjAutoOrders.Delete(ord); Trader.CreateOrder(order); SignalView.GSMSignaler.SendSignalCall(); textBoxLogSign.GuiAsync(() => { textBoxLogSign.Text = DateTime.Now.ToString() + " AutoOrder: " + order.Sec.Shortname + "(" + order.Sec.Code + ")" + ", Price: " + order.Price + " (" + order.Volume + ")" + ", " + (order.IsBuy() ? "BUY" : "SELL") + ", " + order.ClientCode + "\r\n" + textBoxLogSign.Text; }); } } } }); }
private void buttonExitPos_Click(object sender, EventArgs e) { if (this.TrElement.Security.NotIsNull()) { var pos = Trader.Objects.Positions.FirstOrDefault(p => p.Sec == this.TrElement.Security); if (pos != null) { if (pos.Data.CurrentNet != 0) { var codeClient = comboBoxCodeClient.SelectedText; Common.Ext.NewThread(() => { OrderDirection?direction = pos.Data.CurrentNet > 0 ? OrderDirection.Sell : OrderDirection.Buy; decimal Price = 0; decimal LastPrice = this.TrElement.Security.Params.LastPrice == 0 ? this.TrElement.Security.LastTrade.Price : this.TrElement.Security.Params.LastPrice; if (direction == OrderDirection.Sell) { Price = LastPrice - this.TrElement.Security.Params.MinPriceStep * 5; } else { Price = LastPrice + this.TrElement.Security.Params.MinPriceStep * 5; } int Volume = pos.Data.CurrentNet < 0 ? pos.Data.CurrentNet * -1 : pos.Data.CurrentNet; Trader.CreateOrder(new Order() { Sec = this.TrElement.Security, Direction = direction, Price = Price, Volume = Volume }, codeClient); }); } else { UpdateTransReply("По данному инструменту нет позиций."); } } } }
private void buttonSell_Click(object sender, EventArgs e) { if (this.TrElement.Security != null) { if (numericUpDownVolume.Value > 0) { Trader.CreateOrder(new Order() { Sec = this.TrElement.Security, Direction = OrderDirection.Sell, Price = numericUpDownPrice.Value, Volume = Convert.ToInt32(numericUpDownVolume.Value), }, comboBoxCodeClient.SelectedText); } else { UpdateTransReply("Объем не может быть 0 или отрицательным значением."); } } }
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()); } }
/// <summary> Кликеры по таблице стакана </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridViewDepth_Click(object sender, EventArgs e) { if (this.TrElement.Security.IsNull()) { return; } var MouseEvent = (MouseEventArgs)e; var dataGrid = (DataGridView)sender; dataGrid.ClearSelection(); var hti = dataGrid.HitTest(MouseEvent.X, MouseEvent.Y); int indexRow = hti.RowIndex; int indexCol = hti.ColumnIndex; if (indexRow < 0 || indexCol < 0) { return; } DataGridViewCell cell = dataGrid.Rows[indexRow].Cells[indexCol]; if (MouseEvent.Button == MouseButtons.Left) { if (cell.Tag != null) { int Volume = Convert.ToInt32(numericUpDownVolume.Value); if (Volume == 0) { UpdateTransReply("Не указан объем!"); } if (cell.Tag.GetType().ToString().Contains("StructClickDepth")) { var data = (StructClickDepth)cell.Tag; OrderDirection?direction = null; if (data.Flag == "buy") { direction = OrderDirection.Buy; } if (data.Flag == "sell") { direction = OrderDirection.Sell; } var codeClient = comboBoxCodeClient.SelectedText; Common.Ext.NewThread(() => { Trader.CreateOrder(new Order() { Sec = this.TrElement.Security, Direction = direction, Price = data.Price, Volume = Volume }, codeClient); }); } } } if (MouseEvent.Button == MouseButtons.Right) { if (cell.Tag != null) { if (cell.Tag.GetType().ToString().Contains("StructClickDepth")) { var data = (StructClickDepth)cell.Tag; if (data.Flag == "buy" || data.Flag == "sell") { Common.Ext.NewThread(() => { var ords = Trader.Objects.Orders.Where(o => o.Sec == this.TrElement.Security && o.Price == data.Price && o.Status == OrderStatus.ACTIVE); if (ords.NotIsNull()) { foreach (var ord in ords) { Trader.CancelOrder(ord.Sec, ord.OrderNumber); } } }); } } } } }