コード例 #1
0
ファイル: StrategyQTP.cs プロジェクト: wsjiabao/autodz
        private int messageInterval = 40;       // 30s
        #endregion

        #region Public methods

        public StrategyQTP(TStrategy s, RiskM t, NLog log)
        {
            strategyT = s;

            t.SetStrategy(this);
            risk = t;
            
            this.log = log;

            monitors = new Dictionary<string, Monitor>();
        }
コード例 #2
0
ファイル: CRUD.cs プロジェクト: wsjiabao/autodz
        public static TStrategy GetTStrategy(string id, NLog log)
        {
            TStrategy t = new TStrategy();

            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    SqlCommand command = new SqlCommand(string.Format("SELECT * FROM Strategy WHERE Id={0}", id), connection);
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        t.Id = (int)reader["Id"];
                        t.Name = (string)reader["Name"];
                        t.GMID = (string)reader["GMID"];
                        t.RiskMClass = (string)reader["RiskMClass"];
                        t.PoolId = (int)reader["PoolId"];
                        t.Args = (string)reader["Args"];
                        t.MDMode = (int)reader["MDMode"];
                    }
                    command.Connection.Close();
                }

                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    SqlCommand command = new SqlCommand("SELECT * FROM Login", connection);
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        t.UserName = (string)reader["UserName"];
                        t.Password = (string)reader["Password"];
                    }
                    command.Connection.Close();
                }

                t.Instruments = GetTInstruments(t.PoolId);
                t.Positions = GetTPositions(t.Id);
            }
            catch 
            {
                log.WriteError("Read TStrategies");
            }

            return t;
        }
コード例 #3
0
ファイル: StrategyFactory.cs プロジェクト: wsjiabao/autodz
        public static StrategyQTP CreateFromDB(string id, NLog nlog)
        {
            // Read config file
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            CRUD.ConnectionString = config.ConnectionStrings.ConnectionStrings["QTP_DB"].ConnectionString.ToString();

            TStrategy t = CRUD.GetTStrategy(id, nlog);

            Assembly assembly = Assembly.LoadFrom(@"QTP.Domain.dll");
            Type type = assembly.GetType(string.Format("QTP.Domain.{0}", t.RiskMClass));

            RiskM trader = (RiskM)Activator.CreateInstance(type);

            StrategyQTP s = new StrategyQTP(t, trader, nlog);
            
            return s;
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: wsjiabao/autodz
        static void Main(string[] args)
        {
            // process args of program
            if (args.Length == 0)
            {
                System.Console.WriteLine("[错误] 无运行参数");
                System.Console.Read();
                return;
            }

            // Open NLog file
            NLog nlog = new NLog();
            if (!nlog.Open(args[0]))
            {
                System.Console.WriteLine("[错误] 打开日志文件失败");
                System.Console.Read();
                return;
            }

            // 设置中断命令处理程序(即清理并停止策略循环运行)。
            SetConsoleCtrlHandler(new HandlerRoutine(ConsoleCtrlCheck), true);

            // Create Strategy
            currentStrategy = StrategyFactory.CreateFromDB(args[0], nlog);
            if (currentStrategy == null)
            {
                System.Console.WriteLine("[错误] 未能创建策略类");
                System.Console.Read();
                return;
            }

            // Start it
            currentStrategy.Start();

            System.Console.WriteLine("策略已停止运行");
            System.Console.Read();
        }