private void OrderAction(string lastInfo) { //拆解最后一条,生成orderInsert,发单 string[] arrayInfos = lastInfo.Split('|'); InsertOrder orderInsert = new InsertOrder(); orderInsert.StockCode = arrayInfos[0].Trim(); orderInsert.OrderSide = (TrdCommon.TrdSide)Convert.ToDouble(arrayInfos[1].Trim()); orderInsert.OrderType = (TrdCommon.OrderType)Convert.ToDouble(arrayInfos[2].Trim()); orderInsert.Shares = Convert.ToDouble(arrayInfos[3].Trim()); orderInsert.Price = Convert.ToDouble(arrayInfos[4].Trim()); //调用trd下单 TrdPlaceOrder.Request.Builder req = TrdPlaceOrder.Request.CreateBuilder(); TrdPlaceOrder.C2S.Builder cs = TrdPlaceOrder.C2S.CreateBuilder(); Common.PacketID.Builder packetID = Common.PacketID.CreateBuilder().SetConnID(trd.GetConnectID()).SetSerialNo(0); //设置参与的账户--真实模拟市场--参与的市场(美港A股等) TrdCommon.TrdHeader.Builder trdHeader = TrdCommon.TrdHeader.CreateBuilder().SetAccID(m_st.accID).SetTrdEnv((int)TrdCommon.TrdEnv.TrdEnv_Real).SetTrdMarket((int)TrdCommon.TrdMarket.TrdMarket_US); //设置下单的参数 cs.SetPacketID(packetID).SetHeader(trdHeader).SetTrdSide((int)orderInsert.OrderSide).SetOrderType((int)orderInsert.OrderType).SetCode(orderInsert.StockCode).SetQty(orderInsert.Shares).SetPrice(orderInsert.Price).SetAdjustPrice(true); req.SetC2S(cs); uint serialNo = trd.PlaceOrder(req.Build()); }
private void Button_PlaceOrder_Click(object sender, EventArgs e) { //trd未初始化直接返回 if (trd == null) { return; } //创建发单对象 //BUY-SELL-SELLSHORT买卖开平 InsertOrder orderInsert = this.CreateInsertOrder(); //调用trd下单 TrdPlaceOrder.Request.Builder req = TrdPlaceOrder.Request.CreateBuilder(); TrdPlaceOrder.C2S.Builder cs = TrdPlaceOrder.C2S.CreateBuilder(); Common.PacketID.Builder packetID = Common.PacketID.CreateBuilder().SetConnID(trd.GetConnectID()).SetSerialNo(0); //设置参与的账户--真实模拟市场--参与的市场(美港A股等) TrdCommon.TrdHeader.Builder trdHeader = TrdCommon.TrdHeader.CreateBuilder().SetAccID(m_st.accID).SetTrdEnv((int)TrdCommon.TrdEnv.TrdEnv_Real).SetTrdMarket((int)TrdCommon.TrdMarket.TrdMarket_US); //设置下单的参数 cs.SetPacketID(packetID).SetHeader(trdHeader).SetTrdSide((int)orderInsert.OrderSide).SetOrderType((int)orderInsert.OrderType).SetCode(orderInsert.StockCode).SetQty(orderInsert.Shares).SetPrice(orderInsert.Price).SetAdjustPrice(true); req.SetC2S(cs); uint serialNo = trd.PlaceOrder(req.Build()); }
/// <summary> /// 创建交易单 /// </summary> /// <returns></returns> private InsertOrder CreateInsertOrder() { InsertOrder order = new InsertOrder(); order.StockCode = this.TextBox_StockCode.Text; order.Shares = Convert.ToDouble(this.textBox_Shres.Text); order.Price = Convert.ToDouble(this.textBox_Price.Text); order.OrderType = (TrdCommon.OrderType) this.comboBox_OrderType.SelectedIndex; order.OrderSide = (TrdCommon.TrdSide) this.comboBox_OrderSide.SelectedIndex; return(order); }