private void idSendOrderButton_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(idSymbolCodeComboBox.Text) == false) { string symbolCode = idSymbolCodeComboBox.Text; double price = Convert.ToDouble(idPriceNumericUpDown.Value); int volume = Convert.ToInt32(this.idVolumeNumericUpDown.Value); CTPDirectionType direction = (CTPDirectionType)this.idDirectionComboBox.SelectedItem; CTPOffsetFlagType offset = (CTPOffsetFlagType)this.idOffsetComboBox.SelectedItem; trader.InsertOrder(symbolCode, price, direction, volume, offset); } }
public static string DirectionTypeString(CTPDirectionType tyep) { return(tyep == CTPDirectionType.Buy ? "买入" : "卖出"); }
public CThostFtdcParkedOrderField InsertParkedOrder(string symbolCode, double price, CTPDirectionType direct, int volume, CTPOffsetFlagType flag, string orderRef) { CThostFtdcParkedOrderField order = new CThostFtdcParkedOrderField(); order.BrokerID = this.BrokerID; order.InvestorID = this.InvestorID; //合约 order.InstrumentID = symbolCode; order.OrderRef = orderRef; //currentOrderRef++; //限价单 order.OrderPriceType = CTPOrderPriceType.LimitPrice; //方向 order.Direction = direct; //开平仓 order.CombOffsetFlag = new byte[] { (byte)flag, 0, 0, 0, 0 }; //投机/套保 order.CombHedgeFlag = new byte[] { (byte)CTPHedgeFlagType.Speculation, 0, 0, 0, 0 }; ///价格 order.LimitPrice = price; ///数量: 1 order.VolumeTotalOriginal = volume; ///有效期类型: 当日有效 order.TimeCondition = CTPTimeConditionType.GFD; ///GTD日期 // TThostFtdcDateType GTDDate; ///成交量类型: 任何数量 order.VolumeCondition = CTPVolumeConditionType.AV; ///最小成交量: 1 order.MinVolume = 1; ///触发条件: 立即 order.ContingentCondition = CTPContingentConditionType.ParkedOrder; ///止损价 // TThostFtdcPriceType StopPrice; ///强平原因: 非强平 order.ForceCloseReason = CTPForceCloseReasonType.NotForceClose; ///自动挂起标志: 是 order.IsAutoSuspend = true; ///业务单元 // TThostFtdcBusinessUnitType BusinessUnit; ///请求编号 // TThostFtdcorderuestIDType orderuestID; ///用户强评标志: 否 order.UserForceClose = false; order.Status = CTPParkedOrderStatusType.NotSend; //order.UserType = UserType.Investor; //CTPWrapper.TraderReqParkedOrderInsert(this._instance, order, CreateRequestID()); InvokeAPI(CTPRequestAction.ParkedOrderInsertAction, order); return order; }
public CThostFtdcInputOrderField InsertOrder(string symbolCode, double price, CTPDirectionType direct, int volume, CTPOffsetFlagType flag,string orderRef = "") { CThostFtdcInputOrderField order = new CThostFtdcInputOrderField(); order.BrokerID = this.BrokerID; order.InvestorID = this.InvestorID; //合约 order.InstrumentID = symbolCode; if (string.IsNullOrEmpty(orderRef)) { order.OrderRef = this.IncrementOrderRef().ToString(); } else { order.OrderRef = orderRef; } //限价单 order.OrderPriceType = CTPOrderPriceType.LimitPrice; //方向 order.Direction = direct; //开平仓 order.CombOffsetFlag = new byte[] { (byte)flag, 0, 0, 0, 0 }; //投机/套保 order.CombHedgeFlag = new byte[] { (byte)CTPHedgeFlagType.Speculation, 0, 0, 0, 0 }; //套利合约 if (this.instrumentDictionary.ContainsKey(symbolCode)) { if (this.instrumentDictionary[symbolCode].ProductClass == CTPProductClassType.Combination) { //开平仓 order.CombOffsetFlag = new byte[] { (byte)flag, (byte)flag, 0, 0, 0 }; //投机/套保 order.CombHedgeFlag = new byte[] { (byte)CTPHedgeFlagType.Speculation, (byte)CTPHedgeFlagType.Speculation, 0, 0, 0 }; } } ///价格 order.LimitPrice = price; ///数量: 1 order.VolumeTotalOriginal = volume; ///有效期类型: 当日有效 order.TimeCondition = CTPTimeConditionType.GFD; ///GTD日期 // TThostFtdcDateType GTDDate; ///成交量类型: 任何数量 order.VolumeCondition = CTPVolumeConditionType.AV; ///最小成交量: 1 order.MinVolume = 1; ///触发条件: 立即 order.ContingentCondition = CTPContingentConditionType.Immediately; ///强平原因: 非强平 order.ForceCloseReason = CTPForceCloseReasonType.NotForceClose; ///自动挂起标志: 是 order.IsAutoSuspend = true; ///用户强评标志: 否 order.UserForceClose = false; SendInsertOrder(order); return order; }