Esempio n. 1
0
 static public List <CodeList> ReadCodeLists()
 {
     using (var db = new CodeListDbContext())
     {
         return(db.CodeLists.ToList());
     }
 }
Esempio n. 2
0
 static public List <Price> ReadPrices()
 {
     using (var db = new CodeListDbContext())
     {
         return(db.Prices.Include("CodeList").ToList());
     }
 }
Esempio n. 3
0
 static public List <TradeIndex> ReadTradeIndexs()
 {
     using (var db = new CodeListDbContext())
     {
         return(db.TradeIndexs.Include("Price").ToList());
     }
 }
        static void NewMain()
        {
            int               errorSleep = 1000;
            int               sleepTime  = 1000;
            List <CodeList>   codeListList;
            List <Price>      priceList;
            List <TradeIndex> tradeIndexList;

            List <FinanceData> financeDataList = new List <FinanceData>();

            using (var db = new CodeListDbContext())
            {
                codeListList   = db.CodeLists.ToList();
                priceList      = db.Prices.ToList();
                tradeIndexList = db.TradeIndexs.ToList();
            }

            for (int code = 1300; code <= 9999; code++)
            {
                try
                {
                    bool pageCheck;
                    var  yahoo = new YahooFinance.YahooFinance(code, out pageCheck);

                    if (pageCheck == false)
                    {
                        Console.WriteLine("{0} は存在しません。", code);
                        System.Threading.Thread.Sleep(errorSleep);
                        continue;
                    }
                    FinanceData financeData = new FinanceData();

                    var codeList = yahoo.MakeCodeList();
                    //codeListが存在しない場合(現状 空ページorETF)
                    if (codeList == null)
                    {
                        Console.WriteLine("{0} はETFか存在しません。", code);
                        System.Threading.Thread.Sleep(errorSleep);
                        continue;
                    }
                    //1301の日付が今日じゃない場合、飛ばす
                    if (codeList.date != DateTime.Now.Date && codeList.code == 1301)
                    {
                        Console.WriteLine("今日の日付ではありません 停止します(確認待ち)");
                        Console.ReadLine();
                        return;
                    }
                    //codeList追加
                    financeData.codeList = codeList;

                    //Price追加
                    var price = yahoo.MakePrice(codeList);
                    if (price == null)
                    {
                        Console.WriteLine("{0} はPrice情報がありません", code);
                        financeDataList.Add(financeData);
                        ExportLog(financeData);
                        System.Threading.Thread.Sleep(errorSleep);
                        continue;
                    }
                    financeData.price = price;

                    //TradeIndex追加
                    var tradeIndex = yahoo.MakeTradeIndex(price); // ETFは取得しない
                    if (tradeIndex == null)
                    {
                        Console.WriteLine("{0} はtradeIndex情報がありません", code);
                        financeDataList.Add(financeData);
                        ExportLog(financeData);
                        System.Threading.Thread.Sleep(errorSleep);
                        continue;
                    }
                    financeData.tradeIndex = tradeIndex;
                }
                catch (System.Net.WebException e)
                {
                    Console.WriteLine("10分待機 {0} に コード:{1} で {2}", DateTime.Now, code, e);
                    System.Threading.Thread.Sleep(600000);
                    code--;
                    continue;
                }
                catch
                {
                    Console.WriteLine("{0} で異常終了 確認待ち", code);
                    Console.ReadLine();
                }
            }
        }
Esempio n. 5
0
        static public void newMain()
        {
            int errorSleep = 1000;
            int sleepTime  = 1000;
            List <FinanceData> financeDataList = new List <FinanceData>();

            for (int code = 1300; code <= 9999; code++)
            {
                try
                {
                    bool pageCheck;
                    var  yahoo = new YahooFinance.YahooFinance(code, out pageCheck);
                    if (pageCheck == false)
                    {
                        Console.WriteLine("{0} は存在しません。", code);
                        System.Threading.Thread.Sleep(errorSleep);
                        continue;
                    }
                    var codeList = yahoo.MakeCodeList();
                    //codeListが存在しない場合(現状 空ページorETF)
                    if (codeList == null)
                    {
                        Console.WriteLine("{0} はETFか存在しません。", code);
                        System.Threading.Thread.Sleep(errorSleep);
                        continue;
                    }
                    //1301の日付が今日じゃない場合、飛ばす
                    if (codeList.date != DateTime.Now.Date && codeList.code == 1301)
                    {
                        Console.WriteLine("今日の日付ではありません 停止します(確認待ち)");
                        Console.ReadLine();
                        return;
                    }
                    //ファイナンスデータを入れる
                    FinanceData financeData = new FinanceData()
                    {
                        codeList = codeList
                    };

                    var price = yahoo.MakePrice(codeList);
                    if (price == null)
                    {
                        Console.WriteLine("{0} はPrice情報がありません", code);
                        //ファイナンスデータを入れる
                        financeDataList.Add(financeData);
                        System.Threading.Thread.Sleep(errorSleep);
                        continue;
                    }
                    //ファイナンスデータを入れる
                    financeData.price = price;

                    if (price.codeList.sector == "ETF")
                    {
                        Console.WriteLine("{0} はETF、tradeIndex情報がありません", code);
                        //ファイナンスデータを入れる
                        financeDataList.Add(financeData);
                        System.Threading.Thread.Sleep(errorSleep);
                        continue;
                    }

                    var tradeIndex = yahoo.MakeTradeIndex(price); // ETFは取得しない
                    if (tradeIndex == null)
                    {
                        Console.WriteLine("{0} はtradeIndex情報がありません", code);
                        //ファイナンスデータを入れる
                        financeDataList.Add(financeData);
                        System.Threading.Thread.Sleep(errorSleep);
                        continue;
                    }
                    //ファイナンスデータを入れる
                    financeData.tradeIndex = tradeIndex;
                    //ファイナンスデータを入れる
                    financeDataList.Add(financeData);
                    Console.WriteLine("{0} 完了", code);
                    System.Threading.Thread.Sleep(sleepTime);
                }
                catch (Exception e)
                {
                    Console.WriteLine("10分待機 {0} に コード:{1} で {2}", DateTime.Now, code, e);
                    System.Threading.Thread.Sleep(600000);
                    code--;
                    continue;
                }
            }

            //ここにDB登録を書く
            using (var db = new CodeListDbContext())
            {
                List <CodeList> codeListList = db.CodeLists.ToList();

                foreach (var finance in financeDataList)
                {
                    var codeList = codeListList.Where(x => x.code == finance.codeList.code).FirstOrDefault();

                    if (codeList == null)
                    {
                        if (finance.tradeIndex != null)
                        {
                            db.TradeIndexs.Add(finance.tradeIndex);
                            continue;
                        }
                        if (finance.price != null)
                        {
                            db.Prices.Add(finance.price);
                            continue;
                        }
                        db.CodeLists.Add(finance.codeList);
                    }
                    codeList.date          = finance.codeList.date;
                    finance.price.codeList = codeList;
                    if (finance.tradeIndex != null)
                    {
                        db.TradeIndexs.Add(finance.tradeIndex);
                        continue;
                    }
                    if (finance.price != null)
                    {
                        db.Prices.Add(finance.price);
                        continue;
                    }
                    db.CodeLists.Add(finance.codeList);
                }
                db.SaveChanges();
            }
        }
Esempio n. 6
0
        static void oldMain()
        {
            int errorSleep = 1000;
            int sleepTime  = 1000;

            using (var db = new CodeListDbContext())
            {
                List <CodeList>   codeListList   = db.CodeLists.ToList();
                List <Price>      priceList      = db.Prices.ToList();
                List <TradeIndex> tradeIndexList = db.TradeIndexs.ToList();

                for (int code = 1300; code <= 9999; code++)
                {
                    try
                    {
                        bool pageCheck;
                        var  yahoo = new YahooFinance.YahooFinance(code, out pageCheck);

                        if (pageCheck == false)
                        {
                            Console.WriteLine("{0} は存在しません。", code);
                            System.Threading.Thread.Sleep(errorSleep);
                            continue;
                        }
                        var codeList = yahoo.MakeCodeList();
                        //codeListが存在しない場合(現状 空ページorETF)
                        if (codeList == null)
                        {
                            Console.WriteLine("{0} はETFか存在しません。", code);
                            System.Threading.Thread.Sleep(errorSleep);
                            continue;
                        }
                        //1301の日付が今日じゃない場合、飛ばす
                        if (codeList.date != DateTime.Now.Date && codeList.code == 1301)
                        {
                            Console.WriteLine("今日の日付ではありません 停止します(確認待ち)");
                            Console.ReadLine();
                            return;
                        }

                        //コードリストが存在するか確認する
                        CodeList dbCodeList;
                        if (codeListCheck(codeListList, codeList))
                        {
                            dbCodeList = db.CodeLists.Single(x => x.code == codeList.code);

                            dbCodeList.name   = codeList.name;
                            dbCodeList.market = codeList.market;
                            dbCodeList.sector = codeList.sector;
                            dbCodeList.date   = codeList.date;
                        }
                        else
                        {
                            db.CodeLists.Add(codeList);
                            dbCodeList = codeList;
                        }
                        //CodeList更新
                        db.SaveChanges();

                        var price = yahoo.MakePrice(dbCodeList);
                        if (price == null)
                        {
                            Console.WriteLine("{0} はPrice情報がありません", code);
                            System.Threading.Thread.Sleep(errorSleep);
                            continue;
                        }

                        var updatePrice = priceCheck(priceList, price);
                        if (updatePrice == null)
                        {
                            updatePrice = price;
                            db.Prices.Add(updatePrice);
                        }
                        else
                        {
                            var tmpPrice = db.Prices.SingleOrDefault(x => x.id == updatePrice.id);
                            tmpPrice.lastClosePrice = price.lastClosePrice;
                            tmpPrice.closePrice     = price.closePrice;
                            tmpPrice.closePriceDate = price.closePriceDate;
                            tmpPrice.highPrice      = price.highPrice;
                            tmpPrice.highPriceDate  = price.highPriceDate;

                            tmpPrice.limitHighPrice = price.limitHighPrice;
                            tmpPrice.limitLowPrice  = price.limitLowPrice;
                            tmpPrice.lowPrice       = price.lowPrice;
                            tmpPrice.lowPriceDate   = price.lowPriceDate;
                            tmpPrice.openPrice      = price.openPrice;
                            tmpPrice.openPriceDate  = price.openPriceDate;
                            tmpPrice.tradingVolume  = price.tradingVolume;
                            tmpPrice.volume         = price.volume;

                            updatePrice = tmpPrice;
                        }

                        //Price更新
                        db.SaveChanges();

                        var tradeIndex = yahoo.MakeTradeIndex(updatePrice); // ETFは取得しない
                        if (tradeIndex == null)
                        {
                            Console.WriteLine("{0} はtradeIndex情報がありません", code);
                            System.Threading.Thread.Sleep(errorSleep);
                            continue;
                        }

                        var updateTradeIndex = tradeindexCheck(tradeIndexList, tradeIndex);
                        if (updateTradeIndex == null)
                        {
                            updateTradeIndex = tradeIndex;
                            db.TradeIndexs.Add(updateTradeIndex);
                        }
                        else
                        {
                            var tmpTradeIndex = db.TradeIndexs.SingleOrDefault(x => x.id == updateTradeIndex.id);
                            tmpTradeIndex.marginBuy            = tradeIndex.marginBuy;
                            tmpTradeIndex.marginCell           = tradeIndex.marginCell;
                            tmpTradeIndex.marketCapitalization = tradeIndex.marketCapitalization;
                            tmpTradeIndex.minimumPrice         = tradeIndex.minimumPrice;
                            tmpTradeIndex.minimumUnit          = tradeIndex.minimumUnit;
                            tmpTradeIndex.outstandingShares    = tradeIndex.outstandingShares;
                            tmpTradeIndex.price = tradeIndex.price;
                            tmpTradeIndex.ratioMarginBalance = tradeIndex.ratioMarginBalance;
                            tmpTradeIndex.WoWMarginBuy       = tradeIndex.WoWMarginBuy;
                            tmpTradeIndex.WoWMarginCell      = tradeIndex.WoWMarginCell;
                            tmpTradeIndex.yearHighPrice      = tradeIndex.yearHighPrice;
                            tmpTradeIndex.yearLowPrice       = tradeIndex.yearLowPrice;
                            updateTradeIndex = tmpTradeIndex;
                        }
                        //TradeIndex更新
                        db.SaveChanges();

                        Console.WriteLine("{0} 完了", code);
                        System.Threading.Thread.Sleep(sleepTime);
                    }
                    catch (System.Net.WebException e)
                    {
                        Console.WriteLine("10分待機 {0} に コード:{1} で {2}", DateTime.Now, code, e);
                        System.Threading.Thread.Sleep(600000);
                        code--;
                        continue;
                    }
                }
            }
        }