Ejemplo n.º 1
0
        private IXApi CheckApi(string typeName, string dllPath)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                TypeName = "XAPI.Callback.XApi, XAPI_CSharp";
                return(null);
            }
            var api = XApiHelper.CreateInstance(typeName, dllPath);

            try
            {
                Type    = api.GetApiTypes;
                Name    = api.GetApiName;
                Version = api.GetApiVersion;

                // 取公共部分
                UseType = UseType & Type;
            }
            catch (Exception ex)
            {
                api     = null;
                Type    = ApiType.None;
                Name    = ex.Message;
                Version = "请使用depends检查一下是否缺少依赖";
                UseType = ApiType.None;
            }
            return(api);
        }
        private IXApi ConnectToApi(ApiItem item)
        {
            //lock (this)
            {
                DisconnectToApi(item);

                IXApi api = item.Api;

                if (api == null)
                {
                    api      = XApiHelper.CreateInstance(item.TypeName, item.DllPath);
                    item.Api = api;
                }

                string szServerPath = ServerList[item.Server].Path;
                string szUserPath   = UserList[item.User].Path;
                string szUserLabel  = UserList[item.User].Label;

                // 更新Log名字,这样在日志中可以进行识别
                api.Log = LogManager.GetLogger(string.Format("{0}.{1}.{2}", Name, item.LogPrefix, szUserLabel));

                if (api.IsConnected)
                {
                    return(api);
                }

                api.OnConnectionStatus = OnConnectionStatus_callback;
                api.OnRtnError         = OnRtnError_callback;
                api.OnLog = OnLog_callback;

                api.OnRtnDepthMarketData = OnRtnDepthMarketData_callback;

                api.OnRspQryInstrument       = OnRspQryInstrument_callback;
                api.OnRspQryTradingAccount   = OnRspQryTradingAccount_callback;
                api.OnRspQryInvestor         = OnRspQryInvestor_callback;
                api.OnRspQryInvestorPosition = OnRspQryInvestorPosition_callback;

                api.OnRspQryOrder = OnRspQryOrder_callback;
                api.OnRspQryTrade = OnRspQryTrade_callback;
                api.OnRspQryQuote = OnRspQryQuote_callback;

                api.OnRtnOrder = OnRtnOrder_callback;
                api.OnRtnTrade = OnRtnTrade_callback;
                api.OnRtnQuote = OnRtnQuote_callback;

                api.OnRtnQuoteRequest = OnRtnQuoteRequest_callback;

                api.OnRspQryHistoricalTicks = OnRspQryHistoricalTicks_callback;
                api.OnRspQryHistoricalBars  = OnRspQryHistoricalBars_callback;

                api.OnRspQrySettlementInfo = OnRspQrySettlementInfo_callback;
                api.OnRtnInstrumentStatus  = OnRtnInstrumentStatus_callback;

                api.Connect(szServerPath, szUserPath, Path.GetTempPath());

                return(api);
            }
        }