예제 #1
0
        static void test_CTP_Main2(string[] args)
        {
            Type type = Type.GetType("XAPI.Callback.XApi, XAPI_CSharp");
            var  a    = (IXApi)Activator.CreateInstance(type, @"d:\Users\Kan\Documents\GitHub\XAPI3\bin\Debug64\x64\CTP_SE\CTP_SE_Trade_x64.dll");

            api = a;

            api.OnConnectionStatus     = OnConnectionStatus;
            api.OnRtnDepthMarketData   = OnRtnDepthMarketData;
            api.OnRspQryInstrument     = OnRspQryInstrument;
            api.OnRspQrySettlementInfo = OnRspQrySettlementInfo;

            api.Connect(
                @"d:\Users\Kan\Documents\GitHub\XAPI3\bin\Debug64\x64\CTP_SE\td_1.json",
                @"d:\Users\Kan\Documents\GitHub\XAPI3\bin\Debug64\x64\CTP_SE\td_2.json",
                Path.GetTempPath());
            Thread.Sleep(3 * 1000);

            Console.ReadKey();
            Thread.Sleep(1000 * 1000);

            api.Dispose();

            Thread.Sleep(5 * 1000);
        }
예제 #2
0
        static void test_KingstarGold_Main(string[] args)
        {
            api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\KingstarGold\QuantBox_KingstarGold.dll");

            api.Server.BrokerID = "";
            api.Server.Address  = "tcp://124.74.239.38:18961";

            api.User.UserID   = "9843010200773696";
            api.User.Password = "******";

            api.OnConnectionStatus   = OnConnectionStatus;
            api.OnRtnDepthMarketData = OnRtnDepthMarketData;

            api.Connect();

            Console.ReadKey();
            api.Subscribe("IF1411", "");

            Console.ReadKey();

            api.Dispose();

            Console.ReadKey();

            Console.ReadKey();
        }
예제 #3
0
        static void test_CTP_Main(string[] args)
        {
            Type type = Type.GetType("XAPI.Callback.XApi, XAPI_CSharp");
            var  a    = (IXApi)Activator.CreateInstance(type, @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\x86\CTP\CTP_Quote_x86.dll");

            api = a;

            api.Server.BrokerID = "9999";
            api.Server.Address  = "tcp://180.168.146.187:10010";
            api.Server.PrivateTopicResumeType = ResumeType.Undefined;

            api.User.UserID   = "037505";
            api.User.Password = "******";

            api.OnConnectionStatus     = OnConnectionStatus;
            api.OnRtnDepthMarketData   = OnRtnDepthMarketData;
            api.OnRspQryInstrument     = OnRspQryInstrument;
            api.OnRspQrySettlementInfo = OnRspQrySettlementInfo;

            api.Connect();
            Thread.Sleep(3 * 1000);
            api.Subscribe("IF000;IF_WI;IF_IH_1803;IF888", "");

            Console.ReadKey();
            Thread.Sleep(1000 * 1000);

            api.Dispose();

            Thread.Sleep(5 * 1000);
        }
        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);
            }
        }
        private void _Connect(bool bFromUI)
        {
            lock (this)
            {
                // 已经连接了,没有必要再连
                if (IsConnected)
                {
                    return;
                }

                // 要求再连一次,所以还是先断开已有的比较好
                if (base.Status == ProviderStatus.Connecting || base.Status == ProviderStatus.Disconnecting)
                {
                    _Disconnect(bFromUI);
                }

                if (bFromUI)
                {
                    xlog.Info("人工尝试连接...");
                }
                else
                {
                    xlog.Info("插件尝试连接...");
                }

                // 连接前清理一下
                Clear();

                // 如果已经连接过一次,取消一个功能,再连,会再连上
                _TdApi           = null;
                _MdApi           = null;
                _L2Api           = null;
                _QuoteRequestApi = null;
                _HdApi           = null;
                _ItApi           = null;
                _QueryApi        = null;

                foreach (var item in ApiList)
                {
                    if (item.UseType > 0)
                    {
                        IXApi api = ConnectToApi(item);
                        assign(item, api);
                    }
                    else
                    {
                        DisconnectToApi(item);
                    }
                }

                // 这个地方也会导致行情接收不到,所以一定要等完全连接成功后才订阅行情
                base.Status = ProviderStatus.Connecting;
            }
        }
예제 #6
0
 public XTradingApi(string path)
 {
     if (XApiHelper.IsManagedAssembly(path))
     {
         FileType  = XApiFileType.Managed;
         _instance = ManagedManager.GetInstance(path);
     }
     else
     {
         FileType  = XApiFileType.Managed;
         _instance = new Nactive.XApi(path);
     }
     _api = (IXApi)_instance;
     _api.RegisterSpi(this);
 }
예제 #7
0
파일: Program.cs 프로젝트: yuxi214/heiwuqi
        static void Test_CTP_Main2(string[] args)
        {
            Type type = Type.GetType("XAPI.Callback.XApi, XApi_CSharp");
            var  a    = (IXApi)Activator.CreateInstance(type, @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\x86\CTP\CTP_Quote_x86.dll");

            //api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\x86\QuantBox_CTP_Quote.dll");

            //api.Server.BrokerID = "1017";
            //api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51213";
            //api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\x86\CTP\CTP_Trade_x86.dll");
            api = a;

            api.Server.BrokerID = "9999";
            api.Server.Address  = "tcp://180.168.146.187:10010";
            api.Server.PrivateTopicResumeType = ResumeType.Undefined;

            api.User.UserID   = "037505";
            api.User.Password = "******";

            api.OnConnectionStatus     = OnConnectionStatus;
            api.OnRtnDepthMarketData   = OnRtnDepthMarketData;
            api.OnRspQryInstrument     = OnRspQryInstrument;
            api.OnRspQrySettlementInfo = OnRspQrySettlementInfo;

            api.Connect();
            Thread.Sleep(3 * 1000);
            api.Subscribe("IF1802;au1806;au000;IF000", "");

            Console.ReadKey();
            api.Unsubscribe("au1806", "");
            Console.ReadKey();
            api.Unsubscribe("au000", "");
            Console.ReadKey();
            api.Unsubscribe("au1806", "");
            Console.ReadKey();


            api.Subscribe("au1806;au000", "");
            Console.ReadKey();
            api.Unsubscribe("au000", "");
            Console.ReadKey();
            Thread.Sleep(1000 * 1000);

            api.Dispose();

            Thread.Sleep(5 * 1000);
        }
예제 #8
0
파일: Program.cs 프로젝트: wzugang/XAPI2
        static void test_KingstarStock_Main(string[] args)
        {
            //ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\QuantBox_CTP_Trade.dll";
            api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\KingstarStock\x86\QuantBox_KingstarStock_Trade.dll");

            api.Server.BrokerID = "1017";
            api.Server.Address  = "tcp://ctpmn1-front1.citicsf.com:51205";

            api.User.UserID   = "00000015";
            api.User.Password = "******";

            api.OnConnectionStatus   = OnConnectionStatus;
            api.OnRtnDepthMarketData = OnRtnDepthMarketData;
            api.OnRtnError           = OnRtnError;

            api.Connect();

            Thread.Sleep(5 * 1000);

            api.Dispose();
        }
예제 #9
0
파일: Program.cs 프로젝트: wzugang/XAPI2
        static void test_TongShi_Main(string[] args)
        {
            api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\TongShi\x86\QuantBox_TongShi_Quote.dll");

            api.Server.Address = "D:\\Scengine\\Stock.dll";

            api.OnConnectionStatus   = OnConnectionStatus;
            api.OnRtnDepthMarketData = OnRtnDepthMarketData;

            api.Connect();
            Thread.Sleep(10 * 1000);
            ReqQueryField query = new ReqQueryField();

            api.ReqQuery(QueryType.ReqQryInstrument, query);

            Thread.Sleep(300 * 1000);

            api.Dispose();

            Thread.Sleep(5 * 1000);
        }
 private void _DisconnectToApi(IXApi api)
 {
     try
     {
         if (api != null)
         {
             // 断开连接可能卡死
             api.ReconnectInterval = 0;
             api.Disconnect();
             api.Dispose();
             api = null;
         }
     }
     catch (Exception ex)
     {
         xlog.Error(ex.Message);
     }
     finally
     {
         api = null;
     }
 }
예제 #11
0
파일: Program.cs 프로젝트: yuxi214/heiwuqi
        static void Test_Tdx_Main(string[] args)
        {
            api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\x86\Tdx\Tdx_Trade_x86.dll");


            api.Server.Address        = @"D:\tc_yhzq_v6\Login.lua";
            api.Server.ExtInfoChar128 = @"D:\tc_yhzq_v6\";
            api.User.UserID           = "16206";
            api.User.Password         = "******";

            api.Server.Address        = @"D:\new_gjzq_v6\Login.lua";
            api.Server.ExtInfoChar128 = @"D:\new_gjzq_v6\";
            api.User.UserID           = "31244679";
            api.User.Password         = "******";

            api.OnConnectionStatus   = OnConnectionStatus;
            api.OnRtnDepthMarketData = OnRtnDepthMarketData;

            api.Connect();

            Console.ReadKey();
            Console.WriteLine("回车后开始查持仓");
            Console.ReadKey();

            ReqQueryField query = new ReqQueryField()
            {
                Int32ID = -1
            };

            api.ReqQuery(QueryType.ReqQryInvestorPosition, query);

            // api.Dispose();

            Console.ReadKey();

            Console.WriteLine("回车后退出");
            Console.ReadKey();
        }
예제 #12
0
        static void test_CTP_Main(string[] args)
        {
            Type type = Type.GetType("XAPI.Callback.XApi, XAPI_CSharp");
            var  a    = (IXApi)Activator.CreateInstance(type, @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\x86\CTP\CTP_Trade_x86.dll");

            //api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\x86\QuantBox_CTP_Quote.dll");

            //api.Server.BrokerID = "1017";
            //api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51213";
            //api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\x86\CTP\CTP_Trade_x86.dll");
            api = a;

            api.Server.BrokerID = "9999";
            api.Server.Address  = "tcp://218.202.237.33:10002";
            api.Server.PrivateTopicResumeType = ResumeType.Undefined;

            api.User.UserID   = "037505";
            api.User.Password = "******";

            api.OnConnectionStatus     = OnConnectionStatus;
            api.OnRtnDepthMarketData   = OnRtnDepthMarketData;
            api.OnRspQryInstrument     = OnRspQryInstrument;
            api.OnRspQrySettlementInfo = OnRspQrySettlementInfo;

            api.Connect();
            Thread.Sleep(5 * 1000);
            //api.Subscribe("IF1502", "");
            ReqQueryField query = new ReqQueryField();

            query.DateStart = 20161124;
            api.ReqQuery(QueryType.ReqQrySettlementInfo, query);

            Thread.Sleep(10 * 1000);

            api.Dispose();

            Thread.Sleep(5 * 1000);
        }
예제 #13
0
        public static IXApi CreateInstance(string typeName = "XAPI.Callback.XApi, XAPI_CSharp", string c_dll_path = "")
        {
            //Type type = Type.GetType("XAPI.Callback.XApi, XAPI_CSharp");
            //var api = (IXApi)Activator.CreateInstance(type, @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\x86\CTP\CTP_Trade_x86.dll");
            //return api;
            Type type = Type.GetType(typeName);

            if (type == null)
            {
                return(null);
            }
            IXApi api = null;

            if (string.IsNullOrEmpty(c_dll_path))
            {
                api = (IXApi)Activator.CreateInstance(type);
            }
            else
            {
                api = (IXApi)Activator.CreateInstance(type, c_dll_path);
            }
            return(api);
        }
예제 #14
0
 public void Dispose()
 {
     _api?.Release();
     _api = null;
 }
예제 #15
0
 public XTradingApi(IXApi api, XApiFileType type = XApiFileType.Managed)
 {
     FileType = type;
     _api     = api;
     _api.RegisterSpi(this);
 }
 private bool IsApiConnected(IXApi api)
 {
     return(api != null && api.IsConnected);
 }
예제 #17
0
 public void Dispose()
 {
     _api?.Release();
     _api = null;
     GC.SuppressFinalize(this);
 }
예제 #18
0
 public XTradingApi(IXApi api)
 {
     _api = api;
     _api.RegisterSpi(this);
 }
예제 #19
0
 public static Logger GetLog(this IXApi api)
 {
     return(api.Log as Logger);
 }