Пример #1
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);
        }
Пример #2
0
        private void QueryAccountPositionInstrument_Logined()
        {
            ReqQueryField query = default(ReqQueryField);

            query.PortfolioID1 = DefaultPortfolioID1;
            query.PortfolioID2 = DefaultPortfolioID2;
            query.PortfolioID3 = DefaultPortfolioID3;
            query.Business     = DefaultBusiness;

            // 查持仓,查资金
            if (IsApiConnected(_QueryApi))
            {
                _QueryApi.ReqQuery(QueryType.ReqQryTradingAccount, ref query);
                _QueryApi.ReqQuery(QueryType.ReqQryInvestorPosition, ref query);
            }

            // 查合约
            if (IsApiConnected(_ItApi))
            {
                _ItApi.ReqQuery(QueryType.ReqQryInstrument, ref query);
            }
        }
Пример #3
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();
        }
Пример #4
0
        private void OnConnectionStatus_Done(object sender, ConnectionStatus status)
        {
            bool bCheckOk = true;

            foreach (var item in ApiList)
            {
                if (item.UseType > 0)
                {
                    if (!IsApiConnected(item.Api))
                    {
                        bCheckOk = false;
                        break;
                    }
                }
            }

            if (bCheckOk)
            {
                base.Status = ProviderStatus.Connected;

                ReqQueryField query = default(ReqQueryField);
                query.PortfolioID1 = DefaultPortfolioID1;
                query.PortfolioID2 = DefaultPortfolioID2;
                query.PortfolioID3 = DefaultPortfolioID3;
                query.Business     = DefaultBusiness;

                // 查持仓,查资金
                if (_QueryApi != null)
                {
                    _QueryApi.ReqQuery(QueryType.ReqQryTradingAccount, ref query);
                    _QueryApi.ReqQuery(QueryType.ReqQryInvestorPosition, ref query);
                }

                // 查合约
                if (_ItApi != null)
                {
                    _ItApi.ReqQuery(QueryType.ReqQryInstrument, ref query);
                }
            }
        }
Пример #5
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);
            ReqQueryField query = default(ReqQueryField);

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

            Thread.Sleep(300 * 1000);

            api.Dispose();

            Thread.Sleep(5 * 1000);
        }
Пример #6
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();
        }
Пример #7
0
        public void ReqQuery(string type)
        {
            QueryType obj = Enum <QueryType> .Parse(type);

            api.ReqQuery(obj, ref _Query);
        }
Пример #8
0
 public void ReqQuery(XAPI.QueryType type)
 {
     api.ReqQuery(type, ref _Query);
 }
Пример #9
0
        public override void QueryInstrument()
        {
            ReqQueryField query = new ReqQueryField();

            mTdApi.ReqQuery(QueryType.ReqQryInstrument, query);
        }
Пример #10
0
 public void QueryInstruments(string[] instruments)
 {
     XAPI.ReqQueryField field = new XAPI.ReqQueryField();
     api_Trade.ReqQuery(XAPI.QueryType.ReqQryInstrument, ref field);
 }
Пример #11
0
        void _Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            _Timer.Enabled = false;

            do
            {
                // 列表为空,表示不处理。这时没有自动重连
                if (SessionTimeList == null || SessionTimeList.Count == 0)
                {
                    break;
                }

                bool bTryConnect = true;

                foreach (var st in SessionTimeList.ToList())
                {
                    // 如果当前时间在交易范围内,要开启重连
                    // 如果当前时间不在交易范围内,要主动断开
                    TimeSpan ts = e.SignalTime.TimeOfDay;
                    if (ts < st.SessionStart)
                    {
                        // 停
                        bTryConnect = false;
                    }
                    else if (ts <= st.SessionEnd)
                    {
                        // 启动
                        bTryConnect = true;
                        break;
                    }
                    else
                    {
                        // 停
                        bTryConnect = false;
                    }
                }

                if (bTryConnect)
                {
                    // 没有连接要连上,有连接要设置时间
                    if (!IsConnected || (!IsConnected && !IsDisconnected))
                    {
                        xlog.Info("当前[{0}]在交易时段,主动连接", e.SignalTime.TimeOfDay);
                        _Connect(false);
                    }

                    foreach (var item in ApiList)
                    {
                        if (item.UseType > 0 && item.Api != null)
                        {
                            item.Api.ReconnectInterval = _ReconnectInterval;
                        }
                    }
                }
                else
                {
                    foreach (var item in ApiList)
                    {
                        if (item.Api != null)
                        {
                            item.Api.ReconnectInterval = 0;
                        }
                    }

                    if (IsConnected || (!IsConnected && !IsDisconnected))
                    {
                        xlog.Info("当前[{0}]在非交易时段,主动断开连接", e.SignalTime.TimeOfDay);
                        // 要断开连接
                        _Disconnect(false);
                    }
                }
            }while(false);

            // 查询持仓和资金
            if (IsApiConnected(_QueryApi))
            {
                _QueryAccountCount -= (int)_Timer.Interval / 1000;
                if (_QueryAccountCount <= 0)
                {
                    ReqQueryField query = default(ReqQueryField);

                    query.PortfolioID1 = DefaultPortfolioID1;
                    query.PortfolioID2 = DefaultPortfolioID2;
                    query.PortfolioID3 = DefaultPortfolioID3;
                    query.Business     = DefaultBusiness;

                    _QueryApi.ReqQuery(QueryType.ReqQryTradingAccount, ref query);
                    _QueryAccountCount = _QueryAccountInterval;
                }

                _QueryPositionCount -= (int)_Timer.Interval / 1000;
                if (_QueryPositionCount <= 0)
                {
                    ReqQueryField query = default(ReqQueryField);

                    query.PortfolioID1 = DefaultPortfolioID1;
                    query.PortfolioID2 = DefaultPortfolioID2;
                    query.PortfolioID3 = DefaultPortfolioID3;
                    query.Business     = DefaultBusiness;

                    _QueryApi.ReqQuery(QueryType.ReqQryInvestorPosition, ref query);
                    _QueryPositionCount = _QueryPositionInterval;
                }
            }

            _Timer.Enabled = true;
        }