Exemplo n.º 1
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;
     }
 }
Exemplo n.º 2
0
        public void Connect()
        {
            // 查看有多少种连接
            int j = 0;

            foreach (var cc in ConnectionConfigList)
            {
                // 建立多个连接
                for (int i = 0; i < cc.SessionLimit; ++i)
                {
                    XApi api = new XApi(cc.LibPath);
                    api.Server = cc.Server;
                    api.User   = cc.User;
                    api.Log    = LogManager.GetLogger(string.Format("{0}.{1}.{2}.{3}", api.Server.BrokerID, api.User.UserID, j, i));

                    api.MaxSubscribedInstrumentsCount = cc.SubscribePerSession;

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

                    api.Connect();

                    XApiList.Add(api);
                }
                ++j;
            }
        }
Exemplo n.º 3
0
        public XApiCom()
        {
            MessageQueue = new ConcurrentQueue <QueueData>();

            api = new XApi();

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

            api.OnRtnDepthMarketData = OnRtnDepthMarketData_callback;
            //base.OnRtnQuoteRequest = OnRtnQuoteRequest_callback;

            api.OnRspQryInstrument       = OnRspQryInstrument_callback;
            api.OnRspQryTradingAccount   = OnRspQryTradingAccount_callback;
            api.OnRspQryInvestorPosition = OnRspQryInvestorPosition_callback;
            //base.OnRspQrySettlementInfo = OnRspQrySettlementInfo_callback;

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

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

            //base.OnRspQryHistoricalTicks = OnRspQryHistoricalTicks_callback;
            //base.OnRspQryHistoricalBars = OnRspQryHistoricalBars_callback;

            //base.OnRspQryInvestor = OnRspQryInvestor_callback;

            InitializeComponent();
        }
Exemplo n.º 4
0
        static void test_CTP_Main(string[] args)
        {
            //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\CTP\x86\QuantBox_CTP_Trade.dll");

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

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

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

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

            api.ReqQuery(QueryType.ReqQryInstrument, ref query);

            Thread.Sleep(300 * 1000);

            api.Dispose();

            Thread.Sleep(5 * 1000);
        }
Exemplo n.º 5
0
        static void test_Tdx_Main(string[] args)
        {
            api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\Tdx\x86\QuantBox_Tdx_Trade.dll");

            api.Server.BrokerID       = "";
            api.Server.Address        = @"D:\new_hbzq_qq\Login.lua";
            api.Server.ExtInfoChar128 = @"D:\new_hbzq_qq\";

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

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

            api.Connect();

            Console.ReadKey();

            Console.ReadKey();

            api.Dispose();

            Console.ReadKey();

            Console.ReadKey();
        }
Exemplo n.º 6
0
 //
 public override void Login()
 {
     if (mTdApi == null)
     {
         mTdApi = new XApi(mdPath);
         mTdApi.Server.AppID    = ConfigUtil.AppId;
         mTdApi.Server.AuthCode = ConfigUtil.AuthCode;
         mTdApi.Server.Address  = ConfigUtil.TdServer;
         mTdApi.Server.BrokerID = ConfigUtil.TdBroker;
         mTdApi.User.UserID     = ConfigUtil.TdInvestor;
         mTdApi.User.Password   = ConfigUtil.TdPassword;
         //
         mTdApi.Server.PrivateTopicResumeType = ResumeType.Quick;
         mTdApi.OnRspQryInstrument            = _onRspQryInstrument;
         mTdApi.OnRspQryInvestorPosition      = _OnRspQryInvestorPosition;
         mTdApi.OnRtnOrder             = _onRtnOrder;
         mTdApi.OnRtnTrade             = _onRtnTrade;
         mTdApi.OnRspQrySettlementInfo =
             (object sender, ref SettlementInfoClass settlementInfo, int size1, bool bIsLast) => {
             LogUtil.SysLog("结算确认:" + settlementInfo.Content);
         };
         mTdApi.OnConnectionStatus = _onConnectionStatus;
     }
     else if (mTdApi.IsConnected)
     {
         return;
     }
     mTdApi.ReconnectInterval = 60;
     mTdApi.Connect();
 }
Exemplo n.º 7
0
 public Plugin_MarketTrader_CnFutures()
 {
     //string dllPath = Assembly.GetExecutingAssembly().Location;
     //FileInfo f = new FileInfo(dllPath);
     //string path = f.DirectoryName + tradePath;
     api_Trade = new XApi(tradePath);
 }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
        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)
                    {
                        XApi api = ConnectToApi(item);
                        assign(item, api);
                    }
                    else
                    {
                        DisconnectToApi(item);
                    }
                }

                // 这个地方也会导致行情接收不到,所以一定要等完全连接成功后才订阅行情
                base.Status = ProviderStatus.Connecting;
            }
        }
Exemplo n.º 10
0
        public Plugin_MarketData_CnFutures()
        {
            string path = quotePath;

            //string path = ScConfig.Instance.ScPath + quotePath;
            //string dllPath = Assembly.GetExecutingAssembly().Location;
            //FileInfo f = new FileInfo(dllPath);
            //string path = f.DirectoryName + quotePath;
            this.api_Quote      = new XApi(path);
            this.openTimeGetter = new OpenTimeGetter();
        }
Exemplo n.º 11
0
        static void test_Linux_Main(string[] args)
        {
            //Queue queue = new Queue(@"libQuantBox_Queue.so");
            //Queue queue2 = new Queue(@"libQuantBox_Queue.so");

            //ApiManager.QueuePath = @"/home/hetao/works/QuantBox_XAPI/bin/Debug/libQuantBox_Queue.so";
            //XApi api = ApiManager.CreateApi(@"/home/hetao/works/QuantBox_XAPI/bin/Debug/libQuantBox_CTP_Quote.so");
            //XApi api2 = ApiManager.CreateApi(@"/home/hetao/works/QuantBox_XAPI/bin/Debug/libQuantBox_CTP_Trade.so");

            //ApiManager.QueuePath = @"libQuantBox_Queue.so";
            XApi api  = new XApi(@"libQuantBox_CTP_Quote.so");
            XApi api2 = new XApi(@"libQuantBox_CTP_Trade.so");

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

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

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

            api2.Server.BrokerID = "1017";
            api2.Server.Address  = "tcp://ctpmn1-front1.citicsf.com:51205";
            api2.Server.PrivateTopicResumeType = ResumeType.Quick;

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


            api2.OnConnectionStatus     = OnConnectionStatus2;
            api2.OnRspQryInstrument     = OnRspQryInstrument;
            api2.OnRspQryTradingAccount = OnRspQryTradingAccount;
            api2.OnRspQrySettlementInfo = OnRspQrySettlementInfo;
            api2.OnRtnOrder             = OnRtnOrder;
            api2.OnRtnError             = OnRtnError;
            api2.OnRtnTrade             = OnRtnTrade;

            api.Connect();
            api2.Connect();

            api.Subscribe("IF1412", "");

            Console.ReadKey();

            Thread.Sleep(10000);
            Console.WriteLine(123);
            api.Dispose();
            api2.Dispose();
        }
Exemplo n.º 12
0
        public void Connect()
        {
            XApi api = new XApi(ConnectionConfig.LibPath);

            api.Server = ConnectionConfig.Server;
            api.User   = ConnectionConfig.User;

            api.Log = LogManager.GetLogger(string.Format("{0}.{1}", api.Server.BrokerID, api.User.UserID));
            api.MaxSubscribedInstrumentsCount = ConnectionConfig.SubscribePerSession;

            api.OnConnectionStatus = OnConnectionStatus;
            api.OnRspQryInstrument = OnRspQryInstrument;

            api.Connect();

            XApiList.Add(api);
        }
        public void InitGraphics()
        {
            var colorFormat  = new ColorFormat(32);
            var graphicsMode = new GraphicsMode(colorFormat, 24, 8);

            var display      = GdkApi.gdk_x11_display_get_xdisplay(Control.Display.Handle);
            var screen       = Control.Screen.Number;
            var windowHandle = GdkApi.gdk_x11_drawable_get_xid(Control.GdkWindow.Handle);
            var rootWindow   = GdkApi.gdk_x11_drawable_get_xid(Control.RootWindow.Handle);

            IntPtr visualInfo;

            if (graphicsMode.Index.HasValue)
            {
                var xVisualInfo = new XVisualInfo
                {
                    VisualID = graphicsMode.Index.Value
                };
                int dummy;
                visualInfo = XApi.XGetVisualInfo(display, (IntPtr)XVisualInfoMask.ID, ref xVisualInfo, out dummy);
            }
            else
            {
                visualInfo = GlxApi.glXChooseVisual(display, Control.Screen.Number, new[] {
                    GlxApi.GLX_RGBA,
                    GlxApi.GLX_DOUBLEBUFFER,
                    GlxApi.GLX_RED_SIZE, 8,
                    GlxApi.GLX_GREEN_SIZE, 8,
                    GlxApi.GLX_BLUE_SIZE, 8,
                    GlxApi.GLX_ALPHA_SIZE, 8,
                    GlxApi.GLX_DEPTH_SIZE, 24,
                    GlxApi.GLX_STENCIL_SIZE, 8,
                    GlxApi.GLX_NONE
                });
            }

            windowInfo = Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo);

            graphicsContext = new GraphicsContext(graphicsMode, windowInfo);
            graphicsContext.MakeCurrent(windowInfo);
            graphicsContext.LoadAll();
            graphicsContext.SwapInterval = 1;
        }
Exemplo n.º 14
0
        static void test_LTS_Main(string[] args)
        {
            XApi api  = new XApi("QuantBox_LTS_Quote.dll");
            XApi api2 = new XApi("QuantBox_C2LTS_Trade.dll");

            api.Server.BrokerID = "2010";
            api.Server.Address  = "tcp://211.144.195.163:44513";

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

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

            api2.Server.BrokerID = "2010";
            api2.Server.Address  = "tcp://211.144.195.163:44505";

            api2.User.UserID   = "0020090001134";
            api2.User.Password = "******";

            api2.OnConnectionStatus     = OnConnectionStatus2;
            api2.OnRspQryInstrument     = OnRspQryInstrument;
            api2.OnRspQryTradingAccount = OnRspQryTradingAccount;
            api2.OnRspQrySettlementInfo = OnRspQrySettlementInfo;
            api2.OnRtnOrder             = OnRtnOrder;
            api2.OnRtnError             = OnRtnError;
            api2.OnRtnTrade             = OnRtnTrade;

            api.Connect();
            api2.Connect();

            Console.ReadKey();

            ReqQueryField query = new ReqQueryField();

            api2.ReqQuery(QueryType.ReqQryInstrument, query);

            Console.ReadKey();

            api.Dispose();
            api2.Dispose();
            //queue.Dispose();
        }
Exemplo n.º 15
0
        static void Test_Linux_Main(string[] args)
        {
            XApi api  = new XApi(@"libQuantBox_CTP_Quote.so");
            XApi api2 = new XApi(@"libQuantBox_CTP_Trade.so");

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

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

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

            api2.Server.BrokerID = "1017";
            api2.Server.Address  = "tcp://ctpmn1-front1.citicsf.com:51205";
            api2.Server.PrivateTopicResumeType = ResumeType.Quick;

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


            api2.OnConnectionStatus     = OnConnectionStatus2;
            api2.OnRspQryInstrument     = OnRspQryInstrument;
            api2.OnRspQryTradingAccount = OnRspQryTradingAccount;
            api2.OnRspQrySettlementInfo = OnRspQrySettlementInfo;
            api2.OnRtnOrder             = OnRtnOrder;
            api2.OnRtnError             = OnRtnError;
            api2.OnRtnTrade             = OnRtnTrade;

            api.Connect();
            api2.Connect();

            api.Subscribe("IF1502;IF1503", "");

            Console.ReadKey();

            Thread.Sleep(10000);
            Console.WriteLine(123);
            api.Dispose();
            api2.Dispose();
        }
Exemplo n.º 16
0
        static void test_CTP_Main(string[] args)
        {
            //ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\QuantBox_Queue.dll";
            api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\QuantBox_CTP_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.Connect();

            Thread.Sleep(5 * 1000);

            api.Dispose();
        }
Exemplo n.º 17
0
        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.OnFilterSubscribe    = OnFilterSubscribe;

            api.Connect();
            Thread.Sleep(10 * 1000);
            api.ReqQryInstrument("", "");

            Thread.Sleep(300 * 1000);

            api.Dispose();

            Thread.Sleep(5 * 1000);
        }
Exemplo n.º 18
0
        private void init()
        {
            Config config = ConfigUtils.Config;
            //
            string mdPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CTP_Quote_x86.dll");

            mMdApi = new XApi(mdPath);
            mMdApi.Server.Address       = config.MyMdAccount.Server;
            mMdApi.Server.BrokerID      = config.MyMdAccount.Broker;
            mMdApi.User.UserID          = config.MyMdAccount.Investor;
            mMdApi.User.Password        = config.MyMdAccount.Password;
            mMdApi.OnRtnDepthMarketData = _onRtnDepthMarketData;
            //
            string tdPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CTP_Trade_x86.dll");

            mTdApi = new XApi(tdPath);
            mTdApi.Server.Address  = config.MyTdAccount.Server;
            mTdApi.Server.BrokerID = config.MyTdAccount.Broker;
            mTdApi.User.UserID     = config.MyTdAccount.Investor;
            mTdApi.User.Password   = config.MyTdAccount.Password;
        }
Exemplo n.º 19
0
 private void _DisconnectToApi(XApi api)
 {
     try
     {
         if (api != null)
         {
             // 断开连接可能卡死
             api.ReconnectInterval = 0;
             api.Disconnect();
             api.Dispose();
             api = null;
         }
     }
     catch (Exception ex)
     {
         xlog.Error(ex.Message);
     }
     finally
     {
         api = null;
     }
 }
Exemplo n.º 20
0
        public XApiCom()
        {
            MessageQueue = new ConcurrentQueue <QueueData>();

            api = new XApi();

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

            api.OnRtnDepthMarketData = OnRtnDepthMarketData_callback;
            //base.OnRtnQuoteRequest = OnRtnQuoteRequest_callback;

            api.OnRspQryInstrument       = OnRspQryInstrument_callback;
            api.OnRspQryTradingAccount   = OnRspQryTradingAccount_callback;
            api.OnRspQryInvestorPosition = OnRspQryInvestorPosition_callback;
            //base.OnRspQrySettlementInfo = OnRspQrySettlementInfo_callback;

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

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

            //base.OnRspQryHistoricalTicks = OnRspQryHistoricalTicks_callback;
            //base.OnRspQryHistoricalBars = OnRspQryHistoricalBars_callback;

            //base.OnRspQryInvestor = OnRspQryInvestor_callback;

            InitializeComponent();


            Console.WriteLine("ReferenceCountedObjectBase contructor.");
            // We increment the global count of objects.
            ManagedCOMLocalServer.InterlockedIncrementObjectsCount();
        }
Exemplo n.º 21
0
 //
 public override void Login()
 {
     if (mMdApi == null)
     {
         mMdApi = new XApi(mdPath);
         mMdApi.Server.AppID    = ConfigUtil.AppId;
         mMdApi.Server.AuthCode = ConfigUtil.AuthCode;
         mMdApi.Server.Address  = ConfigUtil.MdServer;
         mMdApi.Server.BrokerID = ConfigUtil.MdBroker;
         mMdApi.User.UserID     = ConfigUtil.MdInvestor;
         mMdApi.User.Password   = ConfigUtil.MdPassword;
         //
         mMdApi.OnConnectionStatus   = _onConnectionStatus;
         mMdApi.OnRtnError           = _onRtnError;
         mMdApi.OnRtnDepthMarketData = _onRtnDepthMarketData;
     }
     else if (mMdApi.IsConnected)
     {
         return;
     }
     mMdApi.ReconnectInterval = 60;
     mMdApi.Connect();
 }
Exemplo n.º 22
0
        /// <summary>
        /// 连接行情前置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void connectBt_Click(object sender, EventArgs e)
        {
            showInfo("begin");
            showInfo("Initialize api");
            api = new XApi(@"C:\Users\jht\Documents\Visual Studio 2013\Projects\DataApp\DataApp\dll\QuantBox_CTP_Quote.dll");
            showInfo("Initialize server info");
            api.Server.BrokerID = "66666";
            api.Server.Address  = "tcp://ctp1-md9.citicsf.com:41213";

            showInfo("set 回调函数");
            api.OnConnectionStatus   += OnConnectionStatus;
            api.OnRtnDepthMarketData += OnRtnDepthMarketData;

            showInfo("begin connecting");
            api.Connect();


            //Thread.Sleep(3000);
            //showInfo("begin dispose");
            //api.Dispose();

            //Thread.Sleep(5 * 1000);
        }
Exemplo n.º 23
0
        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();

            query.Int32ID = -1;
            api.ReqQuery(QueryType.ReqQryInvestorPosition, ref query);

            // api.Dispose();

            Console.ReadKey();

            Console.WriteLine("回车后退出");
            Console.ReadKey();
        }
 public static Logger GetLog(this XApi api)
 {
     return(api.Log as Logger);
 }
Exemplo n.º 25
0
        private void _Connect(bool bFromUI)
        {
            lock (this)
            {
                if (IsConnected)
                {
                    return;
                }

                if (!IsConnected && !IsDisconnected)
                {
                    _Disconnect(bFromUI);
                }

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

                bool bCheckOk = false;
                foreach (var item in ApiList)
                {
                    if (item.UseType > 0)
                    {
                        bCheckOk = true;
                    }
                }

                if (false == bCheckOk)
                {
                    base.Status = ProviderStatus.Disconnected;
                    return;
                }

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

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

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

                // 这个地方也会导致行情接收不到
                base.Status = ProviderStatus.Connecting;
            }
        }
 private bool IsApiConnected(XApi api)
 {
     return(api != null && api.IsConnected);
 }
Exemplo n.º 27
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);
            }
        }