Beispiel #1
0
        //双击撤单/平仓
        private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;
            }

            var rgv = (DataGridView)sender;
            var row = rgv.CurrentRow;

            if (row == null)
            {
                return;
            }

            if (rgv == this.dataGridViewOrder)
            {
                if (MessageBox.Show(this, "确认撤单操作(Y/N)", "确认", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }

                OrderField of = (OrderField)row.DataBoundItem;
                if (of.Status == OrderStatus.Normal || of.Status == OrderStatus.Partial)
                {
                    _t.ReqOrderAction(of.OrderID);
                }
            }
            else if (rgv == this.dataGridViewPosition)
            {
                if (MessageBox.Show(this, "确认快速平仓操作(Y/N)", "确认", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }

                PositionField pf    = (PositionField)row.DataBoundItem;
                var           dir   = pf.Direction == DirectionType.Buy ? DirectionType.Sell : DirectionType.Buy;
                var           price = dir == DirectionType.Buy ? _q.DicTick[pf.InstrumentID].AskPrice : _q.DicTick[pf.InstrumentID].BidPrice;
                var           lots  = pf.Position;
                if (_t.DicInstrumentField[pf.InstrumentID].ExchangeID == Exchange.SHFE && pf.TdPosition > 0)
                {
                    _t.ReqOrderInsert(pf.InstrumentID, dir, OffsetType.CloseToday, price, pf.TdPosition, 0);
                    lots -= pf.TdPosition;
                }
                if (lots > 0)
                {
                    close(pf, price, lots);
                }
            }
        }
Beispiel #2
0
        private int close(PositionField pf, double price, int lots)
        {
            var volClose = Math.Min(lots, pf.Position);               //可平量
            var rtn      = lots - volClose;
            var dire     = pf.Direction == DirectionType.Buy ? DirectionType.Sell : DirectionType.Buy;

            if (_t.DicInstrumentField[pf.InstrumentID].ExchangeID == Exchange.SHFE && pf.TdPosition > 0)
            {
                var tdClose = Math.Min(pf.TdPosition, volClose);
                _t.ReqOrderInsert(pf.InstrumentID, dire, OffsetType.CloseToday, price, tdClose, 0);
                volClose -= tdClose;
            }
            if (volClose > 0)
            {
                _t.ReqOrderInsert(pf.InstrumentID, dire, OffsetType.Close, price, volClose, 0);
            }
            return(rtn);
        }