Exemple #1
0
        public int SendQuote(
            int QuoteRef,
            string szInstrument,
            double AskPrice,
            double BidPrice,
            int AskVolume,
            int BidVolume,
            TThostFtdcOffsetFlagType AskOffsetFlag,
            TThostFtdcOffsetFlagType BidOffsetFlag,
            TThostFtdcHedgeFlagType AskHedgeFlag,
            TThostFtdcHedgeFlagType BidHedgeFlag)
        {
            if (null == IntPtrKey || IntPtr.Zero == IntPtrKey)
            {
                return(0);
            }

            return(TraderApi.TD_SendQuote(
                       IntPtrKey,
                       QuoteRef,
                       szInstrument,
                       AskPrice,
                       BidPrice,
                       AskVolume,
                       BidVolume,
                       AskOffsetFlag,
                       BidOffsetFlag,
                       AskHedgeFlag,
                       BidHedgeFlag));
        }
Exemple #2
0
 public static extern int TD_SendQuote(
     IntPtr pTraderApi,
     int QuoteRef,
     string szInstrument,
     double AskPrice,
     double BidPrice,
     int AskVolume,
     int BidVolume,
     TThostFtdcOffsetFlagType AskOffsetFlag,
     TThostFtdcOffsetFlagType BidOffsetFlag,
     TThostFtdcHedgeFlagType AskHedgeFlag,
     TThostFtdcHedgeFlagType BidHedgeFlag);
        private void Send(QuoteOrderItem item)
        {
            if (item == null)
            {
                return;
            }

            SingleOrder AskOrder = item.Sell.Order;
            SingleOrder BidOrder = item.Buy.Order;

            string symbol = item.Buy.Order.Symbol;

            double AskPrice  = AskOrder.Price;
            double BidPrice  = BidOrder.Price;
            int    AskVolume = (int)AskOrder.OrderQty;
            int    BidVolume = (int)BidOrder.OrderQty;

            TThostFtdcOffsetFlagType AskOffsetFlag = CTPAPI.ToCTP(item.Sell.OpenClose);
            TThostFtdcOffsetFlagType BidOffsetFlag = CTPAPI.ToCTP(item.Buy.OpenClose);

            TThostFtdcHedgeFlagType AskHedgeFlag = HedgeFlagType;
            TThostFtdcHedgeFlagType BidHedgeFlag = HedgeFlagType;

            int nRet = 0;

#if CTP
            nRet = TraderApi.TD_SendQuote(m_pTdApi,
                                          -1,
                                          symbol,
                                          AskPrice,
                                          BidPrice,
                                          AskVolume,
                                          BidVolume,
                                          AskOffsetFlag,
                                          BidOffsetFlag,
                                          AskHedgeFlag,
                                          BidHedgeFlag);
#endif
            if (nRet > 0)
            {
                orderMap.CreateNewOrder(string.Format("{0}:{1}:{2}", _RspUserLogin.FrontID, _RspUserLogin.SessionID, nRet), item);
            }
        }
Exemple #4
0
        /// <summary>
        /// TThostFtdcOffsetFlagType枚举型转为Offset枚举型
        /// </summary>
        /// <param name="tfoft">TThostFtdcOffsetFlagType枚举型</param>
        /// <returns></returns>
        public static Offset TThostFtdcOffsetFlagType_To_Offset(TThostFtdcOffsetFlagType tfoft)
        {
            Offset offset = Offset.Open;

            switch (tfoft)
            {
            case TThostFtdcOffsetFlagType.THOST_FTDC_OF_Open:
                break;

            case TThostFtdcOffsetFlagType.THOST_FTDC_OF_Close:
                offset = Offset.Close;
                break;

            case TThostFtdcOffsetFlagType.THOST_FTDC_OF_ForceClose:
                offset = Offset.ForceClose;
                break;

            case TThostFtdcOffsetFlagType.THOST_FTDC_OF_CloseToday:
                offset = Offset.CloseToday;
                break;

            case TThostFtdcOffsetFlagType.THOST_FTDC_OF_CloseYesterday:
                offset = Offset.CloseYesterday;
                break;

            case TThostFtdcOffsetFlagType.THOST_FTDC_OF_ForceOff:
                offset = Offset.ForceOff;
                break;

            case TThostFtdcOffsetFlagType.THOST_FTDC_OF_LocalForceClose:
                offset = Offset.LocalForceClose;
                break;

            default:
                break;
            }
            return(offset);
        }
Exemple #5
0
		/// <summary>
		/// 预埋单录入请求
		/// </summary>
		/// <param name="InstrumentID"></param>
		/// <param name="OffsetFlag"></param>
		/// <param name="Direction"></param>
		/// <param name="Price"></param>
		/// <param name="Volume"></param>
		public int ParkedOrderInsert(string InstrumentID, TThostFtdcOffsetFlagType OffsetFlag, TThostFtdcDirectionType Direction, double Price, int Volume)
		{
			CThostFtdcParkedOrderField tmp = new CThostFtdcParkedOrderField();
			tmp.BrokerID = this.BrokerID;
			tmp.BusinessUnit = null;
			tmp.ContingentCondition = TThostFtdcContingentConditionType.ParkedOrder;
			tmp.ForceCloseReason = TThostFtdcForceCloseReasonType.NotForceClose;
			tmp.InvestorID = this.InvestorID;
			tmp.IsAutoSuspend = (int)TThostFtdcBoolType.No;
			tmp.MinVolume = 1;
			tmp.OrderPriceType = TThostFtdcOrderPriceTypeType.LimitPrice;
			tmp.OrderRef = (++this.MaxOrderRef).ToString();
			tmp.TimeCondition = TThostFtdcTimeConditionType.GFD;
			tmp.UserForceClose = (int)TThostFtdcBoolType.No;
			tmp.UserID = this.InvestorID;
			tmp.VolumeCondition = TThostFtdcVolumeConditionType.AV;
			tmp.CombHedgeFlag_0 = TThostFtdcHedgeFlagType.Speculation;

			tmp.InstrumentID = InstrumentID;
			tmp.CombOffsetFlag_0 = OffsetFlag;
			tmp.Direction = Direction;
			tmp.LimitPrice = Price;
			tmp.VolumeTotalOriginal = Volume;
			return reqParkedOrderInsert(ref tmp);
		}
Exemple #6
0
 public static extern int TD_SendQuote(
     IntPtr pTraderApi,
     int QuoteRef,
     string szInstrument,
     string szExchange,
     double AskPrice,
     double BidPrice,
     int AskVolume,
     int BidVolume,
     TThostFtdcOffsetFlagType AskOffsetFlag,
     TThostFtdcOffsetFlagType BidOffsetFlag,
     TThostFtdcHedgeFlagType AskHedgeFlag,
     TThostFtdcHedgeFlagType BidHedgeFlag);
Exemple #7
0
        public int SendQuote(
            int QuoteRef,
            string szInstrument,
            string szExchange,
            double AskPrice,
            double BidPrice,
            int AskVolume,
            int BidVolume,
            TThostFtdcOffsetFlagType AskOffsetFlag,
            TThostFtdcOffsetFlagType BidOffsetFlag,
            TThostFtdcHedgeFlagType AskHedgeFlag,
            TThostFtdcHedgeFlagType BidHedgeFlag)
        {
            if (null == IntPtrKey || IntPtr.Zero == IntPtrKey)
            {
                return 0;
            }

            return TraderApi.TD_SendQuote(
                IntPtrKey,
                QuoteRef,
                szInstrument,
                szExchange,
                AskPrice,
                BidPrice,
                AskVolume,
                BidVolume,
                AskOffsetFlag,
                BidOffsetFlag,
                AskHedgeFlag,
                BidHedgeFlag);
        }
Exemple #8
0
 public int SendOrder(
     int OrderRef,
     string szInstrument,
     TThostFtdcDirectionType Direction,
     TThostFtdcOffsetFlagType OffsetFlag,
     TThostFtdcHedgeFlagType HedgeFlag,
     int VolumeTotalOriginal,
     double LimitPrice,
     TThostFtdcOrderPriceTypeType OrderPriceType,
     TThostFtdcTimeConditionType TimeCondition,
     TThostFtdcContingentConditionType ContingentCondition,
     double StopPrice,
     TThostFtdcVolumeConditionType VolumeCondition)
 {
     if (null == IntPtrKey || IntPtr.Zero == IntPtrKey)
     {
         return 0;
     }
     char szOffsetFlag = (char) OffsetFlag;
     char hedgeFlag = (char) HedgeFlag;
     return TraderApi.TD_SendOrder(
        IntPtrKey,
        OrderRef,
        szInstrument,
        Direction,
        szOffsetFlag.ToString(),
        hedgeFlag.ToString(),
        VolumeTotalOriginal,
        LimitPrice,
        OrderPriceType,
        TimeCondition,
        ContingentCondition,
        StopPrice,
        VolumeCondition);
 }
        //构造平仓单:对手价限价单(OrderOffsetFlag 平今平昨)
        public OrderField ClosePositionOrder(string InstrumentID, int VolumeToClose,
                                             TThostFtdcPosiDirectionType OrderDirection, TThostFtdcOffsetFlagType OrderOffsetFlag,
                                             TThostFtdcOrderPriceTypeType OrderPriceType)
        {
            DepthMarketData dmd;

            this._dicStrategyDmds.TryGetValue(InstrumentID, out dmd);
            OrderField of = new OrderField();

            of.InstrumentID   = InstrumentID;
            of.OrderPriceType = OrderPriceType;
            of.CombOffsetFlag = new String((char)OrderOffsetFlag, 1);
            if (OrderDirection == TThostFtdcPosiDirectionType.THOST_FTDC_PD_Long)
            {
                of.LimitPrice = dmd.BidPrice1;
                of.Direction  = TThostFtdcDirectionType.THOST_FTDC_D_Sell;
            }
            else
            {
                of.LimitPrice = dmd.AskPrice1;
                of.Direction  = TThostFtdcDirectionType.THOST_FTDC_D_Buy;
            }
            of.VolumeTotalOriginal = VolumeToClose;//确保是正数
            return(of);
        }
Exemple #10
0
 /// <summary>
 /// 开平仓:市价单
 /// </summary>
 /// <param name="InstrumentID">合约代码</param>
 /// <param name="OffsetFlag">平仓:仅上期所平今时使用CloseToday/其它情况均使用Close</param>
 /// <param name="Direction">买卖</param>
 /// <param name="Price">价格</param>
 /// <param name="Volume">手数</param>
 public int OrderInsert(string InstrumentID, TThostFtdcOffsetFlagType OffsetFlag, TThostFtdcDirectionType Direction, int Volume)
 {
     return m_Api.SendOrder(
         ++this.MaxOrderRef,
         InstrumentID,
         Direction,
         OffsetFlag,
         TThostFtdcHedgeFlagType.Speculation,
         Volume,
         0,
         TThostFtdcOrderPriceTypeType.AnyPrice,
         TThostFtdcTimeConditionType.IOC,
         TThostFtdcContingentConditionType.Immediately,
         0,
         TThostFtdcVolumeConditionType.AV);
 }
Exemple #11
0
        /// <summary>
        /// 开平仓:限价单
        /// </summary>
        /// <param name="InstrumentID">合约代码</param>
        /// <param name="OffsetFlag">平仓:仅上期所平今时使用CloseToday/其它情况均使用Close</param>
        /// <param name="Direction">买卖</param>
        /// <param name="Price">价格</param>
        /// <param name="Volume">手数</param>
        public int OrderInsert(string InstrumentID, TThostFtdcOffsetFlagType OffsetFlag, TThostFtdcDirectionType Direction, double Price, int Volume)
        {
            var priceType = TThostFtdcOrderPriceTypeType.LimitPrice;
            var conditionType = TThostFtdcTimeConditionType.GFD;
            if (Price < 0.01)
            {
                priceType = TThostFtdcOrderPriceTypeType.AnyPrice;
                conditionType = TThostFtdcTimeConditionType.IOC;
            }

            return m_Api.SendOrder(
                ++this.MaxOrderRef,
                InstrumentID,
                Direction,
                OffsetFlag,
                TThostFtdcHedgeFlagType.Speculation,
                Volume,
                Price,
                priceType,
                conditionType,
                TThostFtdcContingentConditionType.Immediately,
                0,
                TThostFtdcVolumeConditionType.AV);
        }