private void assign(ApiItem item,XApi api)
 {
     if ((item.UseType & ApiType.MarketData) == ApiType.MarketData)
     {
         _MdApi = api;
     }
     if ((item.UseType & ApiType.Trade) == ApiType.Trade)
     {
         _TdApi = api;
     }
     if ((item.UseType & ApiType.QuoteRequest) == ApiType.QuoteRequest)
     {
         _QuoteRequestApi = api;
     }
     if ((item.UseType & ApiType.Level2) == ApiType.Level2)
     {
         _L2Api = api;
     }
     if ((item.UseType & ApiType.HistoricalData) == ApiType.HistoricalData)
     {
         _HdApi = api;
     }
     if ((item.UseType & ApiType.Instrument) == ApiType.Instrument)
     {
         _ItApi = api;
     }
     if ((item.UseType & ApiType.Query) == ApiType.Query)
     {
         _QueryApi = api;
     }
 }
Beispiel #2
0
 private void assign(ApiItem item, XApi api)
 {
     if ((item.UseType & ApiType.MarketData) == ApiType.MarketData)
     {
         _MdApi = api;
     }
     if ((item.UseType & ApiType.Trade) == ApiType.Trade)
     {
         _TdApi = api;
     }
     if ((item.UseType & ApiType.QuoteRequest) == ApiType.QuoteRequest)
     {
         _QuoteRequestApi = api;
     }
     if ((item.UseType & ApiType.Level2) == ApiType.Level2)
     {
         _L2Api = api;
     }
     if ((item.UseType & ApiType.HistoricalData) == ApiType.HistoricalData)
     {
         _HdApi = api;
     }
     if ((item.UseType & ApiType.Instrument) == ApiType.Instrument)
     {
         _ItApi = api;
     }
     if ((item.UseType & ApiType.Query) == ApiType.Query)
     {
         _QueryApi = 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);
            }
        }
Beispiel #4
0
 private void DisconnectToApi(ApiItem item)
 {
     lock (this)
     {
         if (item.Api != null)
         {
             item.Api.Dispose();
             item.Api = null;
         }
     }
 }
        private void DisconnectToApi(ApiItem item)
        {
            if (item.Api != null)
            {
                // 直接销毁
                _DisconnectToApi(item.Api);

                // 立即断开连接后,登录时自动查资金与持仓的功能在线程中还在运行,会报错
                assign(item, null);

                item.Api = null;
            }
        }
Beispiel #6
0
        private void DisconnectToApi(ApiItem item)
        {
            if (item.Api != null)
            {
                // 直接销毁
                _DisconnectToApi(item.Api);

                //// 在线程中销毁
                //Task task = Task.Factory.StartNew(
                //    ()=> { _DisconnectToApi(item.Api); }
                //    );

                item.Api = null;
            }
        }
Beispiel #7
0
        private XApi ConnectToApi(ApiItem item)
        {
            //lock (this)
            {
                DisconnectToApi(item);

                XApi api = item.Api;

                if (api == null)
                {
                    api      = new XApi(PathHelper.MakeAbsolutePath(item.DllPath));
                    item.Api = api;
                }

                api.Server = ServerList[item.Server].ToStruct();
                if (item.UserList.Count > 0)
                {
                    foreach (var it in item.UserList)
                    {
                        api.UserList.Add(it.ToStruct());
                    }
                }
                else
                {
                    api.User = UserList[item.User].ToStruct();
                }

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

                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;

                api.Connect();

                return(api);
            }
        }
 private void DisconnectToApi(ApiItem item)
 {
     lock(this)
     {
         if (item.Api != null)
         {
             item.Api.Dispose();
             item.Api = null;
         }
     }
 }
        private XApi ConnectToApi(ApiItem item)
        {
            lock(this)
            {
                DisconnectToApi(item);
                
                XApi api = item.Api;

                if (api == null)
                {
                    api = new XApi(Helper.MakeAbsolutePath(item.DllPath));
                    item.Api = api;
                }

                api.Server = ServerList[item.Server].ToStruct();
                if(item.UserList.Count>0)
                {
                    foreach(var it in item.UserList)
                    {
                        api.UserList.Add(it.ToStruct());
                    }
                }
                else
                {
                    api.User = UserList[item.User].ToStruct();
                }

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

                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;

                api.Connect();

                return api;
            }
        }