private void Send(SPOrderItem item) { if (item == null) { return; } SingleOrder order = item.Leg[0].Order; SingleOrder order2 = item.Leg[1].Order; string symbol = item.GetSymbol(); double price = order.Price - order2.Price; int qty = (int)order.OrderQty; // 是否要做价格调整? byte[] bytes = { (byte)CTPAPI.ToCTP(item.Leg[0].OpenClose), (byte)CTPAPI.ToCTP(item.Leg[1].OpenClose) }; string szCombOffsetFlag = System.Text.Encoding.Default.GetString(bytes, 0, bytes.Length); byte[] bytes2 = { (byte)HedgeFlagType, (byte)HedgeFlagType }; string szCombHedgeFlag = System.Text.Encoding.Default.GetString(bytes2, 0, bytes2.Length); TThostFtdcDirectionType Direction = order.Side == Side.Buy ? TThostFtdcDirectionType.Buy : TThostFtdcDirectionType.Sell; TThostFtdcOrderPriceTypeType OrderPriceType = TThostFtdcOrderPriceTypeType.LimitPrice; TThostFtdcTimeConditionType TimeCondition = TThostFtdcTimeConditionType.GFD; TThostFtdcContingentConditionType ContingentCondition = TThostFtdcContingentConditionType.Immediately; TThostFtdcVolumeConditionType VolumeCondition = TThostFtdcVolumeConditionType.AV; int nRet = 0; #if CTP nRet = TraderApi.TD_SendOrder(m_pTdApi, -1, symbol, Direction, szCombOffsetFlag, szCombHedgeFlag, qty, price, OrderPriceType, TimeCondition, ContingentCondition, 0, VolumeCondition); #endif if (nRet > 0) { orderMap.CreateNewOrder(string.Format("{0}:{1}:{2}", _RspUserLogin.FrontID, _RspUserLogin.SessionID, nRet), item); } }
public SPOrderItem Add(SingleOrder order, TextSP t) { if (item == null || item.IsDone()) { item = new SPOrderItem(t); } item.Add(order, t); if (item.IsDone()) { return item; } return null; }
public SPOrderItem Add(SingleOrder order, TextSP t) { if (item == null || item.IsDone()) { item = new SPOrderItem(t); } item.Add(order, t); if (item.IsDone()) { return(item); } return(null); }
private void Send(NewOrderSingle order) { if (!_bTdConnected) { EmitError(-1, -1, "交易服务器没有连接,无法报单"); tdlog.Error("交易服务器没有连接,无法报单"); return; } // 表示特殊的Json格式 if (order.Text.StartsWith("{") && order.Text.EndsWith("}")) { TextParameter parameter = JsonConvert.DeserializeObject <TextParameter>(order.Text); switch (parameter.Type) { case EnumGroupType.COMMON: { TextCommon t = JsonConvert.DeserializeObject <TextCommon>(order.Text); CommonOrderItem item = CommonOrderCombiner.Add(order as SingleOrder, t); Send(item); } break; case EnumGroupType.QUOTE: { TextQuote t = JsonConvert.DeserializeObject <TextQuote>(order.Text); QuoteOrderItem item = QuoteOrderCombiner.Add(order as SingleOrder, t); } break; case EnumGroupType.SP: { TextSP t = JsonConvert.DeserializeObject <TextSP>(order.Text); SPOrderItem item = SPOrderCombiner.Add(order as SingleOrder, t); Send(item); } break; case EnumGroupType.SPC: { TextSPC t = JsonConvert.DeserializeObject <TextSPC>(order.Text); SPCOrderItem item = SPCOrderCombiner.Add(order as SingleOrder, t); Send(item); } break; case EnumGroupType.SPD: { TextSPD t = JsonConvert.DeserializeObject <TextSPD>(order.Text); SPDOrderItem item = SPDOrderCombiner.Add(order as SingleOrder, t); Send(item); } break; } } else { // 无法识别的格式,直接发送报单,只开仓 TextCommon t = new TextCommon() { Type = EnumGroupType.COMMON, OpenClose = EnumOpenClose.OPEN }; CommonOrderItem item = CommonOrderCombiner.Add(order as SingleOrder, t); Send(item); } }