Beispiel #1
0
        // TODO: Fix MarketSpeed Inserterの動作確認。.
        /// <summary>
        /// MarketSpeedから取得したデータの挿入
        /// </summary>
        /// <param name="path"></param>
        private void MSInserter(string path)
        {
            var sepapath = path.Split('\\');

            if (sepapath.Count() < 1)
            {
                return;
            }

            string   filename = sepapath[sepapath.Count() - 1];
            DateTime date;
            string   datestr = filename.Substring(0, 12);

            try
            {
                date = new DateTime(int.Parse(datestr.Substring(0, 4)), int.Parse(datestr.Substring(4, 2)), int.Parse(datestr.Substring(6, 2)), int.Parse(datestr.Substring(8, 2)), int.Parse(datestr.Substring(10, 2)), 0);
            }
            catch
            {
                return;
            }

            using (StreamReader sr = new StreamReader(path, Encoding.GetEncoding(932)))
            {
                double counter = 0;
                string line    = "";
                while ((line = sr.ReadLine()) != null)
                {
                    counter++;

                    if (counter <= 1)
                    {
                        continue;
                    }

                    var sepa = line.Split(',');

                    if (sepa[0].Length != 4)
                    {
                        continue;
                        throw new Exception("不明な銘柄コードが検出されました。\r\n" + "銘柄コード:" + sepa[0]);
                    }

                    StockDataFull.StockDataFullDataTable dt = new StockDataFull.StockDataFullDataTable();

                    var row = dt.NewRow() as StockDataFull.StockDataFullRow;

                    StockDataConverter.ConvertToDBFormat("", "銘柄コード", sepa[0], row);
                    StockDataConverter.ConvertToDBFormat("", "市場コード", sepa[1], row);
                    StockDataConverter.ConvertToDBFormat("", "銘柄名称", sepa[2], row);
                    StockDataConverter.ConvertToDBFormat("", "市場名称", sepa[3], row);
                    StockDataConverter.ConvertToDBFormat("", "市場部名称", sepa[4], row);
                    StockDataConverter.ConvertToDBFormat("", "市場部略称", sepa[5], row);
                    StockDataConverter.ConvertToDBFormat("", "現在日付", sepa[6], row);
                    StockDataConverter.ConvertToDBFormat("", "現在値", sepa[7], row);
                    StockDataConverter.ConvertToDBFormat("", "前日比", sepa[8], row);
                    StockDataConverter.ConvertToDBFormat("", "前日比率", sepa[9], row);
                    StockDataConverter.ConvertToDBFormat("", "前日終値", sepa[10], row);
                    StockDataConverter.ConvertToDBFormat("", "前日日付", sepa[11], row);
                    StockDataConverter.ConvertToDBFormat("", "出来高", sepa[12], row);
                    StockDataConverter.ConvertToDBFormat("", "売買代金", sepa[13], row);
                    StockDataConverter.ConvertToDBFormat("", "出来高加重平均", sepa[14], row);
                    StockDataConverter.ConvertToDBFormat("", "始値", sepa[15], row);
                    StockDataConverter.ConvertToDBFormat("", "高値", sepa[16], row);
                    StockDataConverter.ConvertToDBFormat("", "安値", sepa[17], row);
                    StockDataConverter.ConvertToDBFormat("", "始値時刻", sepa[18], row);
                    StockDataConverter.ConvertToDBFormat("", "高値時刻", sepa[19], row);
                    StockDataConverter.ConvertToDBFormat("", "安値時刻", sepa[20], row);
                    StockDataConverter.ConvertToDBFormat("", "前場出来高", sepa[21], row);
                    StockDataConverter.ConvertToDBFormat("", "信用貸借区分", sepa[22], row);
                    StockDataConverter.ConvertToDBFormat("", "逆日歩", sepa[23], row);
                    StockDataConverter.ConvertToDBFormat("", "逆日歩更新日付", sepa[24], row);
                    StockDataConverter.ConvertToDBFormat("", "信用売残", sepa[25], row);
                    StockDataConverter.ConvertToDBFormat("", "信用売残前週比", sepa[26], row);
                    StockDataConverter.ConvertToDBFormat("", "信用買残", sepa[27], row);
                    StockDataConverter.ConvertToDBFormat("", "信用買残前週比", sepa[28], row);
                    StockDataConverter.ConvertToDBFormat("", "信用倍率", sepa[29], row);
                    StockDataConverter.ConvertToDBFormat("", "証金コード", sepa[30], row);
                    StockDataConverter.ConvertToDBFormat("", "証金残更新日付", sepa[31], row);
                    StockDataConverter.ConvertToDBFormat("", "新規貸株", sepa[32], row);
                    StockDataConverter.ConvertToDBFormat("", "新規融資", sepa[33], row);
                    StockDataConverter.ConvertToDBFormat("", "返済貸株", sepa[34], row);
                    StockDataConverter.ConvertToDBFormat("", "返済融資", sepa[35], row);
                    StockDataConverter.ConvertToDBFormat("", "残高貸株", sepa[36], row);
                    StockDataConverter.ConvertToDBFormat("", "残高融資", sepa[37], row);
                    StockDataConverter.ConvertToDBFormat("", "残高差引", sepa[38], row);
                    StockDataConverter.ConvertToDBFormat("", "前日比貸株", sepa[39], row);
                    StockDataConverter.ConvertToDBFormat("", "前日比融資", sepa[40], row);
                    StockDataConverter.ConvertToDBFormat("", "前日比差引", sepa[41], row);
                    StockDataConverter.ConvertToDBFormat("", "回転日数", sepa[42], row);
                    StockDataConverter.ConvertToDBFormat("", "貸借倍率", sepa[43], row);
                    StockDataConverter.ConvertToDBFormat("", "単位株数", sepa[44], row);
                    StockDataConverter.ConvertToDBFormat("", "配当", sepa[45], row);
                    StockDataConverter.ConvertToDBFormat("", "配当落日", sepa[46], row);
                    StockDataConverter.ConvertToDBFormat("", "権利落日", sepa[47], row);
                    StockDataConverter.ConvertToDBFormat("", "PER", sepa[48], row);
                    StockDataConverter.ConvertToDBFormat("", "PBR", sepa[49], row);
                    StockDataConverter.ConvertToDBFormat("", "年初来高値", sepa[50], row);
                    StockDataConverter.ConvertToDBFormat("", "年初来安値", sepa[51], row);
                    StockDataConverter.ConvertToDBFormat("", "年初来高値日付", sepa[52], row);
                    StockDataConverter.ConvertToDBFormat("", "年初来安値日付", sepa[53], row);
                    StockDataConverter.ConvertToDBFormat("", "上場来高値", sepa[54], row);
                    StockDataConverter.ConvertToDBFormat("", "上場来安値", sepa[55], row);
                    StockDataConverter.ConvertToDBFormat("", "上場来高値日付", sepa[56], row);
                    StockDataConverter.ConvertToDBFormat("", "上場来安値日付", sepa[57], row);

                    try
                    {
                        StartInsert
                        (
                            date,
                            row.銘柄コード,
                            row.市場コード,
                            row.Is銘柄名称Null() ? null : row.銘柄名称,
                            row.Is市場名称Null() ? null : row.市場名称,
                            row.Is市場部名称Null() ? null : row.市場部名称,
                            row.Is市場部略称Null() ? null : row.市場部略称,
                            row.現在日付,
                            row.Is現在値Null() ? (double?)null : row.現在値,
                            row.Is前日比Null() ? (double?)null : row.前日比,
                            row.Is前日比率Null() ? (double?)null : row.前日比率,
                            row.Is前日終値Null() ? (double?)null : row.前日終値,
                            row.Is前日日付Null() ? (DateTime?)null : row.前日日付,
                            row.Is出来高Null() ? (double?)null : row.出来高,
                            row.Is売買代金Null() ? (double?)null : row.売買代金,
                            row.Is出来高加重平均Null() ? (double?)null : row.出来高加重平均,
                            row.Is始値Null() ? (double?)null : row.始値,
                            row.Is高値Null() ? (double?)null : row.高値,
                            row.Is安値Null() ? (double?)null : row.安値,
                            row.Is始値時刻Null() ? (DateTime?)null : row.始値時刻,
                            row.Is高値時刻Null() ? (DateTime?)null : row.高値時刻,
                            row.Is安値時刻Null() ? (DateTime?)null : row.安値時刻,
                            row.Is前場出来高Null() ? (double?)null : row.前場出来高,
                            row.Is信用貸借区分Null() ? null : row.信用貸借区分,
                            row.Is逆日歩Null() ? (double?)null : row.逆日歩,
                            row.Is逆日歩更新日付Null() ? (DateTime?)null : row.逆日歩更新日付,
                            row.Is信用売残Null() ? (double?)null : row.信用売残,
                            row.Is信用売残前週比Null() ? (double?)null : row.信用売残前週比,
                            row.Is信用買残Null() ? (double?)null : row.信用買残,
                            row.Is信用買残前週比Null() ? (double?)null : row.信用買残前週比,
                            row.Is信用倍率Null() ? (double?)null : row.信用倍率,
                            row.Is証金コードNull() ? null : row.証金コード,
                            row.Is証金残更新日付Null() ? (DateTime?)null : row.証金残更新日付,
                            row.Is新規貸株Null() ? (double?)null : row.新規貸株,
                            row.Is新規融資Null() ? (double?)null : row.新規融資,
                            row.Is返済貸株Null() ? (double?)null : row.返済貸株,
                            row.Is返済融資Null() ? (double?)null : row.返済融資,
                            row.Is残高貸株Null() ? (double?)null : row.残高貸株,
                            row.Is残高融資Null() ? (double?)null : row.残高融資,
                            row.Is残高差引Null() ? (double?)null : row.残高差引,
                            row.Is前日比貸株Null() ? (double?)null : row.前日比貸株,
                            row.Is前日比融資Null() ? (double?)null : row.前日比融資,
                            row.Is前日比差引Null() ? (double?)null : row.前日比差引,
                            row.Is回転日数Null() ? (double?)null : row.回転日数,
                            row.Is貸借倍率Null() ? (double?)null : row.貸借倍率,
                            row.Is単位株数Null() ? (double?)null : row.単位株数,
                            row.Is配当Null() ? (double?)null : row.配当,
                            row.Is配当落日Null() ? (DateTime?)null : row.配当落日,
                            row.Is権利落日Null() ? (DateTime?)null : row.権利落日,
                            row.IsPERNull() ? (double?)null : row.PER,
                            row.IsPBRNull() ? (double?)null : row.PBR,
                            row.Is年初来高値Null() ? (double?)null : row.年初来高値,
                            row.Is年初来安値Null() ? (double?)null : row.年初来安値,
                            row.Is年初来高値日付Null() ? (DateTime?)null : row.年初来高値日付,
                            row.Is年初来安値日付Null() ? (DateTime?)null : row.年初来安値日付,
                            row.Is上場来高値Null() ? (double?)null : row.場来高値,
                            row.Is上場来安値Null() ? (double?)null : row.場来安値,
                            row.Is上場来高値日付Null() ? (DateTime?)null : row.場来高値日付,
                            row.Is上場来安値日付Null() ? (DateTime?)null : row.場来安値日付

                        );
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }



                    System.Diagnostics.Debug.WriteLine(string.Format("銘柄:{0}.{1}  {2}  現在値:{3}", row.銘柄コード, row.市場コード, row.Is銘柄名称Null() ? "DBNull" : row.銘柄名称.ToString(), row.Is現在値Null() ? "DBNull" : row.現在値.ToString()));
                }
            }

            string destipath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Path.Combine(HSTStockDataStream.Properties.Settings.Default.InsertCompleteFolderPathFromDesktop, filename));

            File.Move(path, destipath);
            StockDataデータ挿入履歴Inserter(date, DateTime.Now);
        }
Beispiel #2
0
        public static StockDataFull.StockDataFullDataTable GetStockDatas(List <string> topicslist, List <string> itemslist)
        {
            ResetMSandRSS();
            StockDataFull.StockDataFullDataTable dt = new StockDataFull.StockDataFullDataTable();
            int counter = 0;

            try
            {
                foreach (var topic in topicslist)
                {
                    // DateTime start = DateTime.Now;

                    int errorcounter = 0;
                    StockDataFull.StockDataFullRow row = dt.NewRow() as StockDataFull.StockDataFullRow;
                    using (DdeClient client = new DdeClient("RSS", topic))
                    {
                        foreach (var item in itemslist)
                        {
                            // System.Diagnostics.Debug.WriteLine(item);
                            counter++;
                            string            name  = null;
                            NDde.DdeException ddeex = null;

                            for (int i = 0; i < 5; i++)
                            {
                                try
                                {
                                    name = Request(topic, item, client);
                                }
                                catch (NDde.DdeException e)
                                {
                                    errorcounter++;

                                    if (errorcounter == 5)
                                    {
                                        ddeex = e;
                                        //continue;
                                        break;
                                    }

                                    if (e.Message.Contains("The client failed to request") || e.Message.Contains("The client failed to connect"))
                                    {
                                        // 最後は例外入れる
                                        if (i == 4)
                                        {
                                            ddeex = e;
                                            // continue;
                                            break;
                                        }
                                        continue;
                                    }
                                    else
                                    {
                                        ddeex = e;
                                        //continue;
                                        break;
                                    }
                                }

                                break;
                            }

                            if (ddeex != null)
                            {
                                // throw ddeex;
                                break;
                            }

                            if (name == null)
                            {
                                //continue;
                                break;
                                // throw new Exception("Request中に予期せぬ例外が発生しました。");
                            }

                            StockDataConverter.ConvertToDBFormat(topic, item, name, row);
                        }
                    }

                    try
                    {
                        dt.AddStockDataFullRow(row);
                    }
                    catch
                    {
                        continue;
                    }


                    #region DebugWriteline
                    System.Diagnostics.Debug.WriteLine(
                        string.Format
                        (
                            "count:{58} 銘柄コード:{0},市場コード:{1},銘柄名称:{2},市場名称:{3},市場部名称:{4},市場部略称:{5},現在日付:{6},現在値:{7},前日比:{8},前日比率:{9},前日終値:{10},前日日付:{11},出来高:{12},売買代金:{13},出来高加重平均:{14},始値:{15},高値:{16},安値:{17},始値時刻:{18},高値時刻:{19},安値時刻:{20},前場出来高:{21},信用貸借区分:{22},逆日歩:{23},逆日歩更新日付:{24},信用売残:{25},信用売残前週比:{26},信用買残:{27},信用買残前週比:{28},信用倍率:{29},証金コード:{30},証金残更新日付:{31},新規貸株:{32},新規融資:{33},返済貸株:{34},返済融資:{35},残高貸株:{36},残高融資:{37},残高差引:{38},前日比貸株:{39},前日比融資:{40},前日比差引:{41},回転日数:{42},貸借倍率:{43},単位株数:{44},配当:{45},配当落日:{46},権利落日:{47},PER:{48},PBR:{49},年初来高値:{50},年初来安値:{51},年初来高値日付:{52},年初来安値日付:{53},上場来高値:{54},上場来安値:{55},上場来高値日付:{56},上場来安値日付{57}",
                            row.銘柄コード.ToString(),
                            row.市場コード.ToString(),
                            row.Is銘柄名称Null() ? "DBnull" : row.銘柄名称.ToString(),
                            row.Is市場名称Null() ? "DBnull" : row.市場名称.ToString(),
                            row.Is市場部名称Null() ? "DBnull" : row.市場部名称.ToString(),
                            row.Is市場部略称Null() ? "DBnull" : row.市場部略称.ToString(),
                            row.現在日付.ToString(),
                            row.Is現在値Null() ? "DBnull" : row.現在値.ToString(),
                            row.Is前日比Null() ? "DBnull" : row.前日比.ToString(),
                            row.Is前日比率Null() ? "DBnull" : row.前日比率.ToString(),
                            row.Is前日終値Null() ? "DBnull" : row.前日終値.ToString(),
                            row.Is前日日付Null() ? "DBnull" : row.前日日付.ToString(),
                            row.Is出来高Null() ? "DBnull" : row.出来高.ToString(),
                            row.Is売買代金Null() ? "DBnull" : row.売買代金.ToString(),
                            row.Is出来高加重平均Null() ? "DBnull" : row.出来高加重平均.ToString(),
                            row.Is始値Null() ? "DBnull" : row.始値.ToString(),
                            row.Is高値Null() ? "DBnull" : row.高値.ToString(),
                            row.Is安値Null() ? "DBnull" : row.安値.ToString(),
                            row.Is始値時刻Null() ? "DBnull" : row.始値時刻.ToString(),
                            row.Is高値時刻Null() ? "DBnull" : row.高値時刻.ToString(),
                            row.Is安値時刻Null() ? "DBnull" : row.安値時刻.ToString(),
                            row.Is前場出来高Null() ? "DBnull" : row.前場出来高.ToString(),
                            row.Is信用貸借区分Null() ? "DBnull" : row.信用貸借区分.ToString(),
                            row.Is逆日歩Null() ? "DBnull" : row.逆日歩.ToString(),
                            row.Is逆日歩更新日付Null() ? "DBnull" : row.逆日歩更新日付.ToString(),
                            row.Is信用売残Null() ? "DBnull" : row.信用売残.ToString(),
                            row.Is信用売残前週比Null() ? "DBnull" : row.信用売残前週比.ToString(),
                            row.Is信用買残Null() ? "DBnull" : row.信用買残.ToString(),
                            row.Is信用買残前週比Null() ? "DBnull" : row.信用買残前週比.ToString(),
                            row.Is信用倍率Null() ? "DBnull" : row.信用倍率.ToString(),
                            row.Is証金コードNull() ? "DBnull" : row.証金コード.ToString(),
                            row.Is証金残更新日付Null() ? "DBnull" : row.証金残更新日付.ToString(),
                            row.Is新規貸株Null() ? "DBnull" : row.新規貸株.ToString(),
                            row.Is新規融資Null() ? "DBnull" : row.新規融資.ToString(),
                            row.Is返済貸株Null() ? "DBnull" : row.返済貸株.ToString(),
                            row.Is返済融資Null() ? "DBnull" : row.返済融資.ToString(),
                            row.Is残高貸株Null() ? "DBnull" : row.残高貸株.ToString(),
                            row.Is残高融資Null() ? "DBnull" : row.残高融資.ToString(),
                            row.Is残高差引Null() ? "DBnull" : row.残高差引.ToString(),
                            row.Is前日比貸株Null() ? "DBnull" : row.前日比貸株.ToString(),
                            row.Is前日比融資Null() ? "DBnull" : row.前日比融資.ToString(),
                            row.Is前日比差引Null() ? "DBnull" : row.前日比差引.ToString(),
                            row.Is回転日数Null() ? "DBnull" : row.回転日数.ToString(),
                            row.Is貸借倍率Null() ? "DBnull" : row.貸借倍率.ToString(),
                            row.Is単位株数Null() ? "DBnull" : row.単位株数.ToString(),
                            row.Is配当Null() ? "DBnull" : row.配当.ToString(),
                            row.Is配当落日Null() ? "DBnull" : row.配当落日.ToString(),
                            row.Is権利落日Null() ? "DBnull" : row.権利落日.ToString(),
                            row.IsPERNull() ? "DBnull" : row.PER.ToString(),
                            row.IsPBRNull() ? "DBnull" : row.PBR.ToString(),
                            row.Is年初来高値Null() ? "DBnull" : row.年初来高値.ToString(),
                            row.Is年初来安値Null() ? "DBnull" : row.年初来安値.ToString(),
                            row.Is年初来高値日付Null() ? "DBnull" : row.年初来高値日付.ToString(),
                            row.Is年初来安値日付Null() ? "DBnull" : row.年初来安値日付.ToString(),
                            row.Is上場来高値Null() ? "DBnull" : row.場来高値.ToString(),
                            row.Is上場来安値Null() ? "DBnull" : row.場来安値.ToString(),
                            row.Is上場来高値日付Null() ? "DBnull" : row.場来高値日付.ToString(),
                            row.Is上場来安値日付Null() ? "DBnull" : row.場来安値日付.ToString(),
                            counter
                        )


                        );

                    #endregion


                    //DateTime end = DateTime.Now;
                    //var span = end - start;
                    //System.Diagnostics.Debug.WriteLine(span.TotalSeconds);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(dt);
        }