Esempio n. 1
0
 private void ShowMin1Bar()
 {
     if (curSymbol == "")
     {
         MessageBox.Show("请选择证券!");
     }
     else
     {
         List <Bar>   bars = TradeDataAccessor.GetMin1Bars(curSymbol);
         BarDataTable bdt  = new BarDataTable();
         foreach (Bar bar in bars)
         {
             DataRow dr = bdt.NewRow();
             dr["BeginTime"] = bar.BeginTime;
             dr["EndTime"]   = bar.EndTime;
             dr["LastClose"] = bar.LastClose;
             dr["Open"]      = bar.Open;
             dr["High"]      = bar.High;
             dr["Low"]       = bar.Low;
             dr["Close"]     = bar.Close;
             dr["Volume"]    = bar.Volume;
             dr["Amount"]    = bar.Amount;
             dr["Size"]      = bar.Size;
             bdt.Rows.Add(dr);
         }
         RefreshData(this.dataGridView1, bdt);
     }
 }
Esempio n. 2
0
        private void DownloadDailyBar()
        {
            string text = "当前进度:开始下载日线.....";

            RefreshLabel(this.lblDisplay, text);
            GMCollector gmc             = new GMCollector();
            string      beginTimeString = Utils.DateTimeToString(this.DtpBeginTime.Value);
            string      endTimeString   = Utils.DateTimeToString(this.DtpEndTime.Value);
            int         i = 0;

            foreach (var item in this.CmbSymbol.Items)
            {
                string symbol = item.ToString();
                text = string.Format("当前进度:下载<{0}>的日线", symbol);
                RefreshLabel(this.lblDisplay, text);
                List <Bar> bars = gmc.HistoryBars(symbol, 86400, beginTimeString, endTimeString);
                if (bars.Count > 0)
                {
                    TradeDataAccessor.StoreDay1Bars(symbol, bars);
                }
                i++;
                RefreshProgressBar(this.PgbDisplay, i);
            }
            text = "当前进度:日线下载完毕。";
            RefreshLabel(this.lblDisplay, text);
        }
Esempio n. 3
0
        private void LoadInstruments()
        {
            RefreshLabel(lblDisplay, "当前进度:正在读取证券信息......");
            instruments = TradeDataAccessor.GetInstruments();
            List <string> symbols = instruments.Select(i => i.Symbol).OrderBy(i => i).ToList();

            RefreshComboBox(this.CmbSymbol, symbols);
            RefreshLabel(lblDisplay, "当前进度:读取证券信息完毕。");
        }
Esempio n. 4
0
 static void Main()
 {
     try
     {
         TradeDataAccessor.SetRedisConnectString(Properties.Settings.Default.RedisConnString);
         TradeDataAccessor.SetInfluxConnectParameters(Properties.Settings.Default.InfluxUrl,
                                                      Properties.Settings.Default.InfluxUser, Properties.Settings.Default.InfluxPassword);
         TradeDataAccessor.DatabaseInit();
         GMCollector.SetToken(Properties.Settings.Default.GMToken);
     }catch (Exception e)
     {
         Program.ErrorMsg = e.Message;
     }
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new MainForm());
 }
Esempio n. 5
0
        public override bool Execute(CancellationToken token)
        {
            foreach (string symbol in this.symbols)
            {
                token.ThrowIfCancellationRequested();
                string     beginTime  = this.lastTimes[symbol];
                string     endTime    = Utils.DateTimeToString(DateTime.Now);
                object[]   parameters = new object[] { symbol, 60, beginTime, endTime };
                List <Bar> data       = (List <Bar>) this.invokeMethod(parameters);

                if (data.Count > 0)
                {
                    this.lastTimes[symbol] = Utils.DateTimeToString(data.Last().BeginTime);
                    TradeDataAccessor.BatchStoreMin1Bars(symbol, data);
                }
            }
            Console.WriteLine("{0}:在 {1} 时请求完一遍分线", this.Name, DateTime.Now);
            return(true);
        }
Esempio n. 6
0
        private void ShowQuotation()
        {
            Dictionary <string, Tick> currentTicks = TradeDataAccessor.GetCurrentTicks();

            QuotationDataTable qdt = new QuotationDataTable();

            foreach (Instrument inst in this.instruments)
            {
                DataRow dr = qdt.NewRow();
                dr["Symbol"]     = inst.Symbol;
                dr["LastClose"]  = inst.LastClose;
                dr["UpperLimit"] = inst.UpperLimit;
                dr["LowerLimit"] = inst.LowerLimit;
                dr["AdjFactor"]  = inst.AdjFactor;
                dr["CreatedAt"]  = inst.CreatedAt;
                if (currentTicks.TryGetValue(inst.Symbol, out Tick tick))
                {
                    dr["Open"]      = tick.Open;
                    dr["High"]      = tick.High;
                    dr["Low"]       = tick.Low;
                    dr["Price"]     = tick.Price;
                    dr["Volume"]    = tick.Volume;
                    dr["Amount"]    = tick.Amount;
                    dr["CumVolume"] = tick.CumVolume;
                    dr["CumAmount"] = tick.CumAmount;
                    dr["BuyOrSell"] = tick.BuyOrSell;
                    for (int i = 0; i < tick.Quotes.Length; i++)
                    {
                        dr["BidPrice" + i.ToString()]  = tick.Quotes[i].BidPrice;
                        dr["BidVolume" + i.ToString()] = tick.Quotes[i].BidVolume;
                        dr["AskPrice" + i.ToString()]  = tick.Quotes[i].AskPrice;
                        dr["AskVolume" + i.ToString()] = tick.Quotes[i].AskVolume;
                    }
                    dr["DateTime"] = Utils.DateTimeToString(tick.DateTime);
                    dr["Source"]   = tick.Source;
                }
                qdt.Rows.Add(dr);
            }
            this.RefreshData(this.dataGridView1, qdt);
            this.ChangeColumnStyle(this.dataGridView1.Columns[35]);
        }
        public override bool Execute(CancellationToken token)
        {
            string beginTime = Utils.DateTimeToString((DateTime)this.dataDate);
            string endTime   = Utils.DateTimeToString(((DateTime)this.dataDate).Date.AddDays(1));

            foreach (string symbol in this.symbols)
            {
                token.ThrowIfCancellationRequested();
                object[]   parameters = new object[] { symbol, 60, beginTime, endTime };
                List <Bar> data       = (List <Bar>) this.invokeMethod(parameters);
                if (data.Count > 0)
                {
                    TradeDataAccessor.StoreMin1Bars(symbol, data);
                    Console.WriteLine("{0}:{1} 得到数据 {2} 条", this.Name, symbol, data.Count);
                }
                else
                {
                    Console.WriteLine("{0}:{1} 没有数据", this.Name, symbol);
                }
            }
            return(true);
        }
Esempio n. 8
0
        public override bool Execute(CancellationToken token)
        {
            int batchSize = 50;
            IEnumerable <string> remains = this.symbols;
            IEnumerable <string> currents;

            do
            {
                token.ThrowIfCancellationRequested();
                currents = remains.Take(batchSize);
                object[] parameters            = new object[] { currents };
                Dictionary <string, Tick> data = (Dictionary <string, Tick>) this.invokeMethod(parameters);
                int lost = currents.Count() - data.Count;
                if (lost > 0)
                {
                    Console.WriteLine("{0}:丢失数据 {1} 条", this.Name, lost);
                }
                TradeDataAccessor.StoreCurrentTicks(data);
                remains = remains.Skip(batchSize);
            } while (currents.Count() == batchSize);
            return(true);
        }
Esempio n. 9
0
        public override bool Execute(CancellationToken token)
        {
            DateTime curDay = DateTime.Today;

            Console.WriteLine("当前日期:{0}", curDay.ToLongDateString());
            DateTime tradeDay = gmc.GetNextTradingDate("SHSE", curDay.AddDays(-1));

            if (curDay == tradeDay)
            {
                List <Instrument> insts = new List <Instrument>();
                foreach (string market in this.config.Markets.Split(','))
                {
                    insts.AddRange(gmc.GetInstruments(market, "stock"));
                }
                TradeDataAccessor.StoreInstruments(insts).Wait();
                List <string> symbols = insts.Where(e => e.IsSuspended == false).Select(e => e.Symbol).ToList();
                Console.WriteLine("市场<{0}>今日开市证券:{1}只", config.Markets, symbols.Count);
                foreach (DataJobConfig dataJobConfig in config.DataJobConfigs)
                {
                    if (dataJobConfig.SubJobs != null && dataJobConfig.SubJobs.Count > 0)
                    {
                        List <IJob> jobQueue = new List <IJob>();
                        foreach (DataJobConfig subDataJobConfig in dataJobConfig.SubJobs)
                        {
                            int   i           = 0;
                            float weightTotal = 0;
                            foreach (DataCollector dataCollector in subDataJobConfig.DataCollectors)
                            {
                                weightTotal += dataCollector.Weight;
                                int      count      = (int)Math.Round(symbols.Count * weightTotal) - i;
                                object[] parameters = new object[] { dataCollector.MothedName, dataCollector.ClassName, symbols.GetRange(i, count), curDay };
                                i = i + count;
                                Type type = Type.GetType(subDataJobConfig.ClassName, (aName) => Assembly.LoadFrom(aName.Name),
                                                         (assem, name, ignore) => assem == null ? Type.GetType(name, false, ignore) : assem.GetType(name, false, ignore));
                                Job job = (Job)Activator.CreateInstance(type, parameters);
                                jobQueue.Add(job);
                            }
                        }
                        jobSche.Add(jobQueue, buildTrigger(dataJobConfig));
                    }
                    else
                    {
                        int   i           = 0;
                        float weightTotal = 0;
                        foreach (DataCollector dataCollector in dataJobConfig.DataCollectors)
                        {
                            weightTotal += dataCollector.Weight;
                            int      count      = (int)Math.Round(symbols.Count * weightTotal) - i;
                            object[] parameters = new object[] { dataCollector.MothedName, dataCollector.ClassName, symbols.GetRange(i, count), curDay };
                            i = i + count;
                            Type type = Type.GetType(dataJobConfig.ClassName, (aName) => Assembly.LoadFrom(aName.Name),
                                                     (assem, name, ignore) => assem == null ? Type.GetType(name, false, ignore) : assem.GetType(name, false, ignore));
                            Job job = (Job)Activator.CreateInstance(type, parameters);
                            jobSche.Add(job, buildTrigger(dataJobConfig), dataJobConfig.MaxTaskNumber);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("今天不是交易日。");
            }

            return(true);
        }
Esempio n. 10
0
 private void BtnClearRedis_Click(object sender, EventArgs e)
 {
     TradeDataAccessor.ClearRedis();
 }
Esempio n. 11
0
        static void Main(string[] args)
        {
            //string[] testSymbols = new string[] { "SZSE.002434", "SZSE.888888", "SHSE.603186", "SHSE.000001" };
            ////腾讯数据测试
            //Console.WriteLine("tencent testing....");
            //TencentCollector tc = new TencentCollector();
            //Dictionary<string, Tick> data = tc.Current(testSymbols);
            //foreach (KeyValuePair<string, Tick> kvp in data)
            //{
            //    Console.WriteLine("{0}:{1}", kvp.Key, kvp.Value);
            //}
            //Console.ReadKey();
            //Console.WriteLine();
            ////List<Trade> data1 = tc.LastDayTrades("SZSE.002361");
            ////foreach (Trade trade in data1)
            ////{
            ////    Console.WriteLine(trade.ToString());
            ////}
            ////Console.ReadKey();
            ////Console.WriteLine();
            ////掘金数据测试
            //Console.WriteLine("gm testing....");
            //GMCollector gc = new GMCollector();
            //data = gc.Current(testSymbols);
            //foreach (KeyValuePair<string, Tick> kvp in data)
            //{
            //    Console.WriteLine("{0}:{1}", kvp.Key, kvp.Value);
            //}
            //Console.WriteLine();
            ////data1 = gc.HistoryTrades("SZSE.002361", "2019-01-18 11:26:50");
            ////foreach (Trade trade in data1)
            ////{
            ////    Console.WriteLine(trade.ToString());
            ////}
            ////Console.ReadKey();
            ////Console.WriteLine();
            //Console.WriteLine("neteasy testing....");
            //NeteasyCollector nc = new NeteasyCollector();
            //data = nc.Current(testSymbols);
            //foreach (KeyValuePair<string, Tick> kvp in data)
            //{
            //    Console.WriteLine("{0}:{1}", kvp.Key, kvp.Value);
            //}
            //Console.WriteLine();
            //Console.WriteLine("sina testing....");
            //SinaCollector sc = new SinaCollector();
            //data = sc.Current(testSymbols);
            //foreach (KeyValuePair<string, Tick> kvp in data)
            //{
            //    Console.WriteLine("{0}:{1}", kvp.Key, kvp.Value);
            //}

            //Console.WriteLine("eastmoney testing....");
            //EastMoneyCollector ec = new EastMoneyCollector();
            ////data1 = ec.LastDayTrades("SZSE.002361");
            ////foreach (Trade trade in data1)
            ////{
            ////    Console.WriteLine(trade.ToString());
            ////}
            ////data = ec.Current(testSymbols);
            //foreach (KeyValuePair<string, Tick> kvp in data)
            //{
            //    Console.WriteLine("{0}:{1}", kvp.Key, kvp.Value);
            //}
            //Console.WriteLine();
            //Console.ReadKey();
            //Console.WriteLine();
            //RedisHelper.Set("test1", 123);
            //RedisHelper.Set("test2", 456);
            //RedisHelper.Set("test3", 789);
            //RedisHelper.Set("sr", 321);


            //foreach (var key in RedisHelper.GetKeys( "*test*"))
            //{
            //    Console.WriteLine(key);
            //}

            //Console.ReadKey();
            //Console.WriteLine();
            //IJob job = new Min1Job("HistoryBars", "TradeDataCollector.SinaCollector", new string[] { "SHSE.600025" }, DateTime.Today);
            // string influxUrl = "http://localhost:8086/";
            // string username = "******";
            // string password = "******";
            // InfluxDbClient _instance = new InfluxDbClient(influxUrl, username, password, InfluxDbVersion.Latest);
            //string query = "select * from \"Bar.60\" where \"Symbol\"='SHSE.600025'" ;
            //var series = _instance.Client.QueryAsync(query, "Finance").Result;
            //Console.WriteLine(series.Count());
            //foreach(var serie in series)
            //{
            //    Console.WriteLine(serie.Values.Count());
            //}
            //Console.ReadKey();
            //IEnumerable<SerieSet> ret = _instance.Serie.GetSeriesAsync("Finance").Result;
            //foreach (SerieSet ss in ret)
            //{
            //    Console.WriteLine(ss.Name);
            //    Console.WriteLine(ss.Series[0].Key);
            //}
            //Console.ReadKey();
            List <Instrument> instruments = TradeDataAccessor.GetInstruments();

            foreach (Instrument inst in instruments)
            {
                Console.WriteLine(inst.Symbol);
            }
            Console.ReadKey();
        }