Exemplo n.º 1
0
 public override CommonDataProvider GetData(string symbols, DataCycle dataCycle, DateTime startTime, DateTime endTime)
 {
     byte[] bs = DownloadBinary(symbols, "http://subscribe.easychart.net/member/datafeed.aspx?f=BinaryHistory&AddWhenNoSymbol=1&Symbol=" + symbols);
     if (bs != null)
     {
         CommonDataProvider cdp = new CommonDataProvider(null);
         cdp.LoadByteBinary(bs);
         cdp.SetStringData("Code", symbols.ToUpper());
         return(cdp);
     }
     return(null);
 }
Exemplo n.º 2
0
        public override IDataProvider GetData(string Code, int Count)
        {
            ddm.DownloadRealTimeQuote = this.DownloadRealTimeQuote;
            CommonDataProvider cdp = (CommonDataProvider)ddm[Code, Count];

            if (!cdp.HasData)
            {
                EasyStockChartDataFeed df = new EasyStockChartDataFeed();
                try
                {
                    byte[] bs = df.BinaryHistory(Code, true);
                    if (bs != null)
                    {
                        cdp.LoadByteBinary(bs);
                        DBDataManager.UpdateForNewSymbol(Code, cdp, Config.SaveInServerDataManager);
                    }
                }
                catch
                {
                }
            }
            return(cdp);
        }
Exemplo n.º 3
0
        public override IDataProvider GetData(string Code, int Count)
        {
            Code = Code.Trim();
            Hashtable          htList = GetSymbolListHashtable();
            string             s      = (string)htList[Code];
            CommonDataProvider cdpn   = new CommonDataProvider(this);


            byte[]   bs = new byte[] {};
            string[] ss = null;

            if (s != null)
            {
                ss = s.Split(',');
                if (ss[3] != "")
                {
                    string r = (string)htList[ss[3]];
                    if (r != null)
                    {
                        ss = r.Split(',');
                    }
                }
                if (Count > 0)
                {
                    // Load data from file
                    bs = LoadHisDataFromFile(Code, Count * DataPacket.PacketByteSize);
                    if (DownloadRealTimeQuote)
                    {
                        try
                        {
                            DataPacket dp = DataPacket.DownloadFromYahoo(Code);

                            if (dp != null && !dp.IsZeroValue)
                            {
                                bs = CommonDataProvider.MergeOneQuote(bs, dp);
                            }
                        }
                        catch
                        {
                        }
                    }

                    cdpn.LoadByteBinary(bs);

                    // Update data from yahoo
                    if (AutoYahooToDB)
                    {
                        string   FileName = GetHisDataFile(Code);
                        DateTime d        = new DateTime(1900, 1, 1);
                        try
                        {
                            d = File.GetLastWriteTime(FileName);                            // GetLastAccessTime(FileName);
                        }
                        catch
                        {
                        }
                        DateTime d1 = DateTime.Now.Date;
                        DateTime d2 = d.Date;
                        TimeSpan ts = d1 - d2;
                        if (ts.TotalDays > 0)
                        {
                            YahooDataManager   ydm      = new YahooDataManager();
                            CommonDataProvider cdpDelta = (CommonDataProvider)ydm[Code, ts.Days + 5];
                            cdpDelta.Adjusted = false;
                            if (cdpDelta.Count > 0)
                            {
                                double[] dd1 = cdpDelta["DATE"];
                                double[] dd2 = cdpn["DATE"];
                                if (cdpn.Count == 0 || (int)dd2[dd2.Length - 1] < (int)dd1[dd1.Length - 1])
                                {
                                    cdpn.Merge(cdpDelta);
                                    Impersonate.ChangeToAdmin();
                                    Utils.UpdateRealtime(Code, cdpn);
                                }
                            }
                            cdpn.SaveBinary(FileName);
                        }
                    }
                }
            }
            else
            {
                try
                {
                    // Download data from yahoo
                    if (AutoYahooToDB)
                    {
                        YahooDataManager ydm = new YahooDataManager();
                        cdpn = (CommonDataProvider)ydm[Code];
                        if (cdpn.Count > 0)
                        {
                            UpdateForNewSymbol(Code, cdpn, true);
                        }
                        else
                        {
                            throw new Exception("Invalid Quote : " + Code);
                        }
                    }
                    else
                    {
                        cdpn.LoadByteBinary(bs);
                    }
                }
                catch (Exception e)
                {
                    Tools.Log(e.Message);
                    cdpn.LoadByteBinary(bs);
                }
            }
            //cdpn = TrimToEndTime(cdpn);

            cdpn.SetStringData("Code", Code);
            if (ss != null && ss.Length > 2)
            {
                cdpn.SetStringData("Code", ss[0]);
                cdpn.SetStringData("Name", ss[1]);
                cdpn.SetStringData("Exchange", ss[2]);
            }
            return(cdpn);
        }