/// <summary> /// 返回交易模块编号 /// </summary> /// <param name="field"></param> /// <returns></returns> public static string GetModelID(object field) { //委托单 if (field is CZQThostFtdcInputOrderField) { CZQThostFtdcInputOrderField ctpOrder = (CZQThostFtdcInputOrderField)field; return(GetModelIDByOrderRef(ctpOrder.OrderRef)); } //撤单 if (field is CZQThostFtdcOrderActionField) { CZQThostFtdcOrderActionField ctpOrder = (CZQThostFtdcOrderActionField)field; return(GetModelIDByOrderRef(ctpOrder.OrderRef)); } //订单 if (field is CZQThostFtdcOrderField) { CZQThostFtdcOrderField ctpOrder = (CZQThostFtdcOrderField)field; return(GetModelIDByOrderRef(ctpOrder.OrderRef)); } //成交单 if (field is CZQThostFtdcTradeField) { CZQThostFtdcTradeField ctpOrder = (CZQThostFtdcTradeField)field; return(GetModelIDByOrderRef(ctpOrder.OrderRef)); } throw new Exception("unknow field:" + field.ToString(), null); }
public CZQThostFtdcInputOrderActionField DeleteOrder(CZQThostFtdcInputOrderField order) { //撤单时,会引发报单时间小于登录时间的报单回报, //因此需要关闭过滤 FLag this.filterRestart = false; CZQThostFtdcInputOrderActionField orderAction = new CZQThostFtdcInputOrderActionField(); orderAction.BrokerID = order.BrokerID; orderAction.InvestorID = order.InvestorID; orderAction.FrontID = this.FrontID; orderAction.SessionID = this.SessionID; orderAction.OrderRef = order.OrderRef; orderAction.InstrumentID = order.InstrumentID; orderAction.ActionFlag = CTPStockActionFlagType.Delete; //CTPWrapper.TraderReqOrderAction(this._instance, orderAction, CreateRequestID()); InvokeAPI(CTPStockRequestAction.OrderActionAction, orderAction); return(orderAction); }
private void OnErrRtnOrderInsert(IntPtr pTraderApi, ref CZQThostFtdcInputOrderField pInputOrder, ref CZQThostFtdcRspInfoField pRspInfo) { SingleOrder order; string strKey = string.Format("{0}:{1}:{2}", _RspUserLogin.FrontID, _RspUserLogin.SessionID, pInputOrder.OrderRef); if (_OrderRef2Order.TryGetValue(strKey, out order)) { tdlog.Error("交易所回应:{0},{1},开平{2},价{3},原量{4},引用{5},{6}#{7}", pInputOrder.InstrumentID, pInputOrder.Direction, pInputOrder.CombOffsetFlag, pInputOrder.LimitPrice, pInputOrder.VolumeTotalOriginal, pInputOrder.OrderRef, pRspInfo.ErrorID, pRspInfo.ErrorMsg); order.Text = string.Format("{0}|{1}#{2}", order.Text.Substring(0, Math.Min(order.Text.Length, 64)), pRspInfo.ErrorID, pRspInfo.ErrorMsg); EmitRejected(order, order.Text); //没得办法,这样全撤了状态就唯一了 Dictionary <string, CZQThostFtdcOrderField> _Ref2Action; if (_Orders4Cancel.TryGetValue(order, out _Ref2Action)) { lock (_Ref2Action) { _Ref2Action.Remove(strKey); if (0 == _Ref2Action.Count()) { _Orders4Cancel.Remove(order); return; } Cancel(order); } } } }
private void OnRspOrderInsert_callback(IntPtr pTraderApi, ref CZQThostFtdcInputOrderField pInputOrder, ref CZQThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (null != OnRspOrderInsert) { OnRspOrderInsert(this, new OnRspOrderInsertArgs(pTraderApi, ref pInputOrder, ref pRspInfo, nRequestID, bIsLast)); } }
private void OnErrRtnOrderInsert_callback(IntPtr pTraderApi, ref CZQThostFtdcInputOrderField pInputOrder, ref CZQThostFtdcRspInfoField pRspInfo) { if (null != OnErrRtnOrderInsert) { OnErrRtnOrderInsert(this, new OnErrRtnOrderInsertArgs(pTraderApi, ref pInputOrder, ref pRspInfo)); } }
public OnRspOrderInsertArgs(IntPtr pTraderApi, ref CZQThostFtdcInputOrderField pInputOrder, ref CZQThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { this.pTraderApi = pTraderApi; this.pInputOrder = pInputOrder; this.pRspInfo = pRspInfo; this.nRequestID = nRequestID; this.bIsLast = bIsLast; }
public static string GetOrderUniqueKey(CTPStockTrader trader, object field) { //委托单 if (field is CZQThostFtdcInputOrderField) { CZQThostFtdcInputOrderField ctpOrder = (CZQThostFtdcInputOrderField)field; return(string.Format("{0:X}_{1:X}_{2}", trader.FrontID, trader.SessionID, ctpOrder.OrderRef.Trim())); } //撤单 if (field is CZQThostFtdcOrderActionField) { CZQThostFtdcOrderActionField ctpOrder = (CZQThostFtdcOrderActionField)field; return(string.Format("{0:X}_{1:X}_{2}", ctpOrder.FrontID, ctpOrder.SessionID, ctpOrder.OrderRef.Trim())); } throw new Exception("Unknow type : " + field.GetType().ToString()); }
public CZQThostFtdcInputOrderField InsertOrder(string exchangeID, string symbolCode, CTPStockDirectionType direct, double price, int volume) { CTPStockOffsetFlagType flag = CTPStockOffsetFlagType.Open; switch (direct) { case CTPStockDirectionType.Buy: case CTPStockDirectionType.ETFPur: case CTPStockDirectionType.MarginTrade: case CTPStockDirectionType.RepayMargin: case CTPStockDirectionType.DirectRepayMargin: flag = CTPStockOffsetFlagType.Open; break; case CTPStockDirectionType.Sell: case CTPStockDirectionType.ETFRed: case CTPStockDirectionType.ShortSell: case CTPStockDirectionType.RepayStock: case CTPStockDirectionType.DirectRepayStock: flag = CTPStockOffsetFlagType.Close; break; case CTPStockDirectionType.TransferSecurities: flag = CTPStockOffsetFlagType.Open; break; default: break; } CZQThostFtdcInputOrderField order = CreateInputOrder(exchangeID, symbolCode, direct, flag, price, volume); SendInsertOrder(order); return(order); }
public static string GetUserKey(object field) { //委托单 if (field is CZQThostFtdcInputOrderField) { CZQThostFtdcInputOrderField ctpOrder = (CZQThostFtdcInputOrderField)field; return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID)); } //撤单 if (field is CZQThostFtdcOrderActionField) { CZQThostFtdcOrderActionField ctpOrder = (CZQThostFtdcOrderActionField)field; return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID)); } //预埋单 if (field is CZQThostFtdcParkedOrderField) { CZQThostFtdcParkedOrderField ctpOrder = (CZQThostFtdcParkedOrderField)field; return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID)); } //删除预埋单 if (field is CZQThostFtdcRemoveParkedOrderField) { CZQThostFtdcRemoveParkedOrderField ctpOrder = (CZQThostFtdcRemoveParkedOrderField)field; return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID)); } //预埋撤单 if (field is CZQThostFtdcParkedOrderActionField) { CZQThostFtdcRemoveParkedOrderField ctpOrder = (CZQThostFtdcRemoveParkedOrderField)field; return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID)); } //删除预埋撤单 if (field is CZQThostFtdcRemoveParkedOrderActionField) { CZQThostFtdcRemoveParkedOrderActionField ctpOrder = (CZQThostFtdcRemoveParkedOrderActionField)field; return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID)); } //订单 if (field is CZQThostFtdcOrderField) { CZQThostFtdcOrderField ctpOrder = (CZQThostFtdcOrderField)field; return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID)); } //成交单 if (field is CZQThostFtdcTradeField) { CZQThostFtdcTradeField ctpData = (CZQThostFtdcTradeField)field; return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID)); } //持仓 if (field is CZQThostFtdcInvestorPositionField) { CZQThostFtdcInvestorPositionField ctpData = (CZQThostFtdcInvestorPositionField)field; return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID)); } //持仓明细 if (field is CZQThostFtdcInvestorPositionDetailField) { CZQThostFtdcInvestorPositionDetailField ctpData = (CZQThostFtdcInvestorPositionDetailField)field; return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID)); } //持仓明细 if (field is CZQThostFtdcInvestorPositionCombineDetailField) { CZQThostFtdcInvestorPositionCombineDetailField ctpData = (CZQThostFtdcInvestorPositionCombineDetailField)field; return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID)); } //资金账户 if (field is CZQThostFtdcTradingAccountField) { CZQThostFtdcTradingAccountField ctpData = (CZQThostFtdcTradingAccountField)field; return(GetUserKey(ctpData.AccountID, ctpData.BrokerID)); } throw new Exception("unknow type : " + field.GetType().FullName); }
private CZQThostFtdcInputOrderField CreateInputOrder(string exchangeID, string symbolCode, CTPStockDirectionType direct, CTPStockOffsetFlagType flag, double price, int volume, string orderRef = "") { CZQThostFtdcInputOrderField order = new CZQThostFtdcInputOrderField(); order.BrokerID = this.BrokerID; order.InvestorID = this.InvestorID; //合约 order.ExchangeID = exchangeID; order.InstrumentID = symbolCode; if (string.IsNullOrEmpty(orderRef)) { order.OrderRef = System.Threading.Interlocked.Increment(ref this.currentOrderRef).ToString(); } else { order.OrderRef = orderRef; } //限价单 order.OrderPriceType = CTPStockOrderPriceType.LimitPrice; //方向 order.Direction = direct; //开平仓 order.CombOffsetFlag = new byte[] { (byte)flag, 0, 0, 0, 0 }; //投机/套保 order.CombHedgeFlag = new byte[] { (byte)CTPStockHedgeFlagType.Speculation, 0, 0, 0, 0 }; ///价格 order.LimitPrice = price.ToString(); ///数量: 1 order.VolumeTotalOriginal = volume; ///有效期类型: 当日有效 order.TimeCondition = CTPStockTimeConditionType.GFD; ///GTD日期 // TThostFtdcDateType GTDDate; ///成交量类型: 任何数量 order.VolumeCondition = CTPStockVolumeConditionType.AV; ///最小成交量: 1 order.MinVolume = 1; ///触发条件: 立即 order.ContingentCondition = CTPStockContingentConditionType.Immediately; ///强平原因: 非强平 order.ForceCloseReason = CTPStockForceCloseReasonType.NotForceClose; ///自动挂起标志: 是 order.IsAutoSuspend = true; ///用户强评标志: 否 order.UserForceClose = false; //条件单处理内容 //if (parameter.OrderType == OrderType.ConditionOrder) //{ // //条件触发价 // order.StopPrice = (double)parameter.ConditionPrice; // //报价方式 // if (order.OrderPriceType != CTPStockOrderPriceType.LimitPrice) // { // order.LimitPrice = "0"; // } //} return(order); }
private int SendInsertOrder(CZQThostFtdcInputOrderField order) { //return CTPWrapper.TraderReqOrderInsert(this._instance, order, CreateRequestID()); Trace.WriteLine(string.Format("{0} [{1}]:{2},{3},{4}", this.wallTimeStopwatch.ElapsedMilliseconds, this.UserKey, "SendInsertOrder", order.OrderRef, order.RequestID)); return(InvokeAPI(CTPStockRequestAction.OrderInsertAction, order)); }
public OnErrRtnOrderInsertArgs(IntPtr pTraderApi, ref CZQThostFtdcInputOrderField pInputOrder, ref CZQThostFtdcRspInfoField pRspInfo) { this.pTraderApi = pTraderApi; this.pInputOrder = pInputOrder; this.pRspInfo = pRspInfo; }