예제 #1
0
        /*
         * 上海证券交易所证券代码分配规则
         * http://www.docin.com/p-417422186.html
         *
         * http://wenku.baidu.com/view/f2e9ddf77c1cfad6195fa706.html
         */
        private string GetSecurityType(CThostFtdcInstrumentField inst)
        {
            string securityType = FIXSecurityType.NoSecurityType;

            switch (inst.ProductClass)
            {
            case TThostFtdcProductClassType.Futures:
                securityType = FIXSecurityType.Future;
                break;

            case TThostFtdcProductClassType.Combination:
                securityType = FIXSecurityType.MultiLegInstrument;    //此处是否理解上有不同
                break;

            case TThostFtdcProductClassType.Options:
                securityType = FIXSecurityType.Option;
                break;

#if CTPZQ
            case TThostFtdcProductClassType.StockA:
            case TThostFtdcProductClassType.StockB:
                securityType = GetSecurityTypeStock(inst.ProductID, inst.InstrumentID);
                break;

            case TThostFtdcProductClassType.ETF:
            case TThostFtdcProductClassType.ETFPurRed:
                securityType = GetSecurityTypeETF(inst.ProductID, inst.InstrumentID);
                break;
#endif
            default:
                securityType = FIXSecurityType.NoSecurityType;
                break;
            }
            return(securityType);
        }
예제 #2
0
        private void OnRspQryInstrument(IntPtr pTraderApi, ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            if (0 == pRspInfo.ErrorID)
            {
#if CTP
                _dictInstruments[pInstrument.InstrumentID] = pInstrument;
#else
                //比较无语,测试平台上会显示很多无效数据,有关期货的还会把正确的数据给覆盖,所以临时这样处理
                if (pInstrument.ProductClass != TThostFtdcProductClassType.Futures)
                {
                    string symbol = GetYahooSymbol(pInstrument.InstrumentID, pInstrument.ExchangeID);
                    _dictInstruments[symbol] = pInstrument;

                    // 行情中可能没有交易所信息,这个容器用于容错处理
                    _dictInstruments2[pInstrument.InstrumentID] = symbol;
                }
#endif

                if (bIsLast)
                {
                    tdlog.Info("合约列表已经接收完成,共{0}条", _dictInstruments.Count);
                }
            }
            else
            {
                tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspQryInstrument:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
                EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInstrument:" + pRspInfo.ErrorMsg);
            }
        }
예제 #3
0
 public OnRspQryInstrumentArgs(ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.pInstrument = pInstrument;
     this.pRspInfo    = pRspInfo;
     this.nRequestID  = nRequestID;
     this.bIsLast     = bIsLast;
 }
예제 #4
0
 private void OnRspQryInstrument_callback(object sender, ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspQryInstrument)
     {
         OnRspQryInstrument(this, new OnRspQryInstrumentArgs(ref pInstrument, ref pRspInfo, nRequestID, bIsLast));
     }
 }
예제 #5
0
 public void FireOnRspQryInstrument(CThostFtdcInstrumentField pInstrument)
 {
     if (null != OnRspQryInstrument)
     {
         OnRspQryInstrument(pInstrument);
     }
 }
예제 #6
0
        private void CTPOnRspQryInstrument(ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
        {
            var field = new InstrumentField
            {
                //ExchangeID = pInstrument.ExchangeID,
                InstrumentID = pInstrument.InstrumentID,
                PriceTick    = pInstrument.PriceTick,
                ProductClass = pInstrument.ProductClass == TThostFtdcProductClassType.THOST_FTDC_PC_Futures ? ProductClassType.Futures :
                               pInstrument.ProductClass == TThostFtdcProductClassType.THOST_FTDC_PC_Options ? ProductClassType.Options :
                               pInstrument.ProductClass == TThostFtdcProductClassType.THOST_FTDC_PC_Combination ? ProductClassType.Combination :
                               pInstrument.ProductClass == TThostFtdcProductClassType.THOST_FTDC_PC_SpotOption ? ProductClassType.SpotOption : ProductClassType.Futures,
                ProductID      = pInstrument.ProductID,
                VolumeMultiple = pInstrument.VolumeMultiple,
                MaxOrderVolume = pInstrument.MaxLimitOrderVolume,
            };
            Exchange exc;

            if (Enum.TryParse(pInstrument.ExchangeID, out exc))
            {
                field.ExchangeID = exc;
            }
            DicInstrumentField.TryAdd(pInstrument.InstrumentID, field);
            if (bIsLast)
            {
                //查询流控
                _tIsLogin = new Thread(qryPosiAccount);
                _tIsLogin.Start();
                //Thread.Sleep(1100);
                //_t.ReqQryTradingAccount(_broker, _investor);
            }
        }
예제 #7
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public InstrumentField(CThostFtdcInstrumentField instrumentField)
        {
            this._if = instrumentField;
            Regex r     = new Regex(@"\d");
            int   index = r.Match(_if.InstrumentID).Index;

            _baseCode = _if.InstrumentID.Substring(0, index);
            Notify("");
        }
예제 #8
0
 /// <summary>
 /// 查询合约回报
 /// </summary>
 private void CTradeApi_OnRspQryInstrument(ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (pRspInfo.ErrorID == 0)
     {
         CThostFtdcInstrumentField tmpInstrument = pInstrument;
         this._DictInstrumentField.AddOrUpdate(pInstrument.InstrumentID, new InstrumentField(pInstrument),
                                               (k, v) => { v.CThostFtdcInstrumentFieldInstance = tmpInstrument; return(v); });
     }
     _isQryInstrumentCompleted = bIsLast;
 }
예제 #9
0
 private void OnRspQryInstrument(IntPtr pTraderApi, ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (0 == pRspInfo.ErrorID)
     {
         _dictInstruments[pInstrument.InstrumentID] = pInstrument;
         if (bIsLast)
         {
             tdlog.Info("合约列表已经接收完成,共{0}条", _dictInstruments.Count);
         }
     }
     else
     {
         tdlog.Error("nRequestID:{0},ErrorID:{1},OnRspQryInstrument:{2}", nRequestID, pRspInfo.ErrorID, pRspInfo.ErrorMsg);
         EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInstrument:" + pRspInfo.ErrorMsg);
     }
 }
예제 #10
0
 private void OnRspQryInstrument(IntPtr pTraderApi, ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (0 == pRspInfo.ErrorID)
     {
         _dictInstruments[pInstrument.InstrumentID] = pInstrument;
         if (bIsLast)
         {
             Console.WriteLine(string.Format("TdApi:{0},合约列表已经接收完成",
                                             Clock.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")));
         }
     }
     else
     {
         EmitError(nRequestID, pRspInfo.ErrorID, "OnRspQryInstrument:" + pRspInfo.ErrorMsg);
     }
 }
예제 #11
0
        /*
         * 上海证券交易所证券代码分配规则
         * http://www.docin.com/p-417422186.html
         *
         * http://wenku.baidu.com/view/f2e9ddf77c1cfad6195fa706.html
         */
        private string GetSecurityType(CThostFtdcInstrumentField inst)
        {
            string securityType = FIXSecurityType.CommonStock;

            try
            {
                switch (inst.ProductClass)
                {
                case TThostFtdcProductClassType.Futures:
                    securityType = FIXSecurityType.Future;
                    break;

                case TThostFtdcProductClassType.Combination:
                    securityType = FIXSecurityType.MultiLegInstrument;    //此处是否理解上有不同
                    break;

                case TThostFtdcProductClassType.Options:
                    securityType = FIXSecurityType.FutureOption;
                    break;

#if CTPZQ
                case TThostFtdcProductClassType.StockA:
                case TThostFtdcProductClassType.StockB:
                    securityType = GetSecurityTypeStock(inst.ProductID, inst.InstrumentID);
                    break;

                case TThostFtdcProductClassType.ETF:
                case TThostFtdcProductClassType.ETFPurRed:
                    securityType = GetSecurityTypeETF(inst.ProductID, inst.InstrumentID);
                    break;
#endif
                default:
                    securityType = FIXSecurityType.CommonStock;
                    break;
                }
                return(securityType);
            }
            catch (Exception ex)
            {
                tdlog.Warn("合约:{0},字段内容:{1}", inst.InstrumentID, ex.Message);
            }

            return(securityType);
        }
 public override void OnRspQryInstrument(CThostFtdcInstrumentField pInstrument, CThostFtdcRspInfoField pRspInfo, int nRequestID,
                                         bool bIsLast)
 {
     _callbackApi.OnRspQryInstrument(pInstrument, pRspInfo, nRequestID, bIsLast);
 }
예제 #13
0
 private static int SortCThostFtdcInstrumentField(CThostFtdcInstrumentField a1, CThostFtdcInstrumentField a2)
 {
     return(a1.InstrumentID.CompareTo(a2.InstrumentID));
 }
예제 #14
0
 private void OnRspQryInstrument_3(ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     OnRspQryInstrument_1(this, ref pInstrument, ref pRspInfo, nRequestID, bIsLast);
 }
예제 #15
0
 private void OnRspQryInstrument_3(IntPtr pTraderApi, ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     OnRspQryInstrument_1(this, pTraderApi, ref pInstrument, ref pRspInfo, nRequestID, bIsLast);
 }
예제 #16
0
 private void OnRspQryInstrument_callback(IntPtr pTraderApi, ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     if (null != OnRspQryInstrument)
     {
         OnRspQryInstrument(this, new OnRspQryInstrumentArgs(pTraderApi, ref pInstrument, ref pRspInfo, nRequestID, bIsLast));
     }
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(CThostFtdcInstrumentField obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
예제 #18
0
 public void SetNativeValue(CThostFtdcInstrumentField nativeValue)
 {
     this.nativeValue = nativeValue;
 }
예제 #19
0
 private void CTPOnRspQryClassifiedInstrument(ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     CTPOnRspQryInstrument(ref pInstrument, ref pRspInfo, nRequestID, bIsLast);
 }
예제 #20
0
 void OnRspQryInstrument(CThostFtdcInstrumentField pInstrument)
 {
     Console.WriteLine("==合约列表");
     Console.WriteLine(pInstrument.LongMarginRatio);
     Console.WriteLine(pInstrument.ShortMarginRatio);
 }
예제 #21
0
파일: EventArgs.cs 프로젝트: vcfriend/CTP
 public OnRspQryInstrumentArgs(IntPtr pTraderApi, ref CThostFtdcInstrumentField pInstrument, ref CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast)
 {
     this.pTraderApi = pTraderApi;
     this.pInstrument = pInstrument;
     this.pRspInfo = pRspInfo;
     this.nRequestID = nRequestID;
     this.bIsLast = bIsLast;
 }
 ///请求查询合约响应
 public void OnRspQryInstrument(CThostFtdcInstrumentField pInstrument, CThostFtdcRspInfoField pRspInfo,
                                int nRequestID, bool bIsLast)
 {
     Console.WriteLine("OnRspQryInstrument");
 }