Example #1
0
        public override IDataProvider GetData(string Code, int Count)
        {
            string str = GetFileName(Code);

            byte[]             bs1 = new byte[0];
            CommonDataProvider commonDataProvider = new CommonDataProvider(this);

            if (File.Exists(str))
            {
                commonDataProvider.LoadBinary(str);
            }
            else
            {
                commonDataProvider.LoadBinary(bs1);
            }
            if (SymbolTable != null)
            {
                DataRow dataRow = (DataRow)SymbolTable[Code];
                if (dataRow != null)
                {
                    commonDataProvider.SetStringData("Code", Code);
                    commonDataProvider.SetStringData("Name", dataRow["Name"].ToString());
                    commonDataProvider.SetStringData("Exchange", dataRow["Exchange"].ToString());
                }
            }
            IDataProvider iDataProvider = commonDataProvider;

            return(iDataProvider);
        }
Example #2
0
        public CommonDataProvider LoadCSV(StreamReader sr)
        {
            //string Date = sr.ReadLine();
            string s = sr.ReadToEnd().Trim();

            string[] ss = s.Split('\n');

            int N = ss.Length;

            double[] CLOSE  = new double[N];
            double[] VOLUME = new double[N];
            double[] DATE   = new double[N];

            DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
            NumberFormatInfo   nfi  = NumberFormatInfo.InvariantInfo;

            for (int i = 0; i < N; i++)
            {
                string[] sss = ss[i].Split(',');
                DATE[i]   = DateTime.ParseExact(sss[0], "yyyyMMddHHmmss", dtfi).ToOADate();
                CLOSE[i]  = double.Parse(sss[1], nfi);
                VOLUME[i] = double.Parse(sss[2], nfi);
            }

            CommonDataProvider cdp = new CommonDataProvider(this);

            cdp.LoadBinary("DATE", DATE);
            cdp.LoadBinary("CLOSE", CLOSE);
            cdp.LoadBinary("VOLUME", VOLUME);
            return(cdp);
        }
        public override IDataProvider GetData(string Code, int Count)
        {
            try
            {
                CommonDataProvider cdp = new CommonDataProvider(this);
                DbParam[]          dps = new DbParam[] {
                    new DbParam("@Q1", DbType.DateTime, StartTime),
                    new DbParam("@Q2", DbType.DateTime, EndTime),
                };
                BaseDb bd = DB.Open(false);
                try
                {
                    DataTable dt = bd.GetDataTable("select Tick,tstamp from " + Code + "_tick where tstamp>=? and tstamp<=? order by tstamp", dps);

                    dps[1].Value = ((DateTime)dps[0].Value).AddSeconds(-1);
                    dps[0].Value = ((DateTime)dps[0].Value).AddDays(-30);
                    DataRow drr = bd.GetFirstRow("select Tick from " + Code + "_tick where tstamp>=? and tstamp<=? order by tstamp desc", dps);

                    if (dt.Rows.Count > 0)
                    {
                        cdp.SetStringData("LastTradeTime", ((DateTime)dt.Rows[dt.Rows.Count - 1]["tstamp"]).ToString());
                    }
                    if (drr != null)
                    {
                        cdp.SetStringData("LastPrice", drr[0].ToString());
                    }

                    if (dt.Rows.Count == 0)
                    {
                        dt.Rows.Add(new object[] { Single.NaN, StartTime });
                    }
                    double[] CLOSE  = new double[dt.Rows.Count];
                    double[] VOLUME = new double[dt.Rows.Count];
                    double[] DATE   = new double[dt.Rows.Count];

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        CLOSE[i]  = ToDouble(dt.Rows[i]["Tick"]);
                        VOLUME[i] = 0;
                        DATE[i]   = ((DateTime)dt.Rows[i]["tstamp"]).ToOADate();
                    }
                    cdp.LoadBinary("CLOSE", CLOSE);
                    cdp.LoadBinary("DATE", DATE);
                    cdp.LoadBinary("VOLUME", VOLUME);
                }
                finally
                {
                    bd.Close();
                }
                return(cdp);
            }
            catch
            {
            }
            return(base.GetData(Code, Count));
        }
Example #4
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = new CommonDataProvider(this);

            cdp.SetStringData("Code", Code);
            DataTable dt = DB.GetDataTable("SELECT top " + Count + " * FROM WEBCHARTX_DATA where Symbol='" + Code + "' ORDER BY Store_Date");

            double[] OPEN   = new double[dt.Rows.Count];
            double[] HIGH   = new double[dt.Rows.Count];
            double[] LOW    = new double[dt.Rows.Count];
            double[] CLOSE  = new double[dt.Rows.Count];
            double[] VOLUME = new double[dt.Rows.Count];
            double[] AMOUNT = new double[dt.Rows.Count];
            double[] DATE   = new double[dt.Rows.Count];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                OPEN[i]   = ToDecimalDouble(dt.Rows[i]["Open_Price"]);
                HIGH[i]   = ToDecimalDouble(dt.Rows[i]["HIGHT_PRICE"]);
                LOW[i]    = ToDecimalDouble(dt.Rows[i]["LOW_PRICE"]);
                CLOSE[i]  = ToDecimalDouble(dt.Rows[i]["CLOSE_PRICE"]);
                VOLUME[i] = ToInt(dt.Rows[i]["VOLUME"]);
                DATE[i]   = ((DateTime)dt.Rows[i]["STORE_DATE"]).ToOADate();
            }
            cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
            return(cdp);
        }
Example #5
0
        public CommonDataProvider GetCachedHistoricalData(string Symbol)
        {
            string CacheRoot = Environment.CurrentDirectory + "\\Cache\\";

            if (!Directory.Exists(CacheRoot))
            {
                Directory.CreateDirectory(CacheRoot);
            }
            string             Cache = CacheRoot + Symbol + ".dat";
            CommonDataProvider cdp   = null;

            if (Symbol != "")
            {
                if (File.Exists(Cache) && File.GetLastWriteTime(Cache).Date == DateTime.Now.Date)
                {
                    cdp = new CommonDataProvider(null);
                    cdp.LoadBinary(Cache);
                    cdp.SetStringData("Code", Symbol.ToUpper());
                }
                else
                {
                    cdp = GetHistoricalData(Symbol);
                    if (cdp != null && cdp.Count > 0)
                    {
                        cdp.SaveBinary(Cache);
                    }
                }
            }
            return(cdp);
        }
Example #6
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = new CommonDataProvider(this);

            cdp.SetStringData("Code", Code);
            string s = FormulaHelper.Root + "Data\\" + Code + ".txt";

            if (File.Exists(s))
            {
                using (StreamReader sr = File.OpenText(s))
                {
                    string   r  = sr.ReadToEnd();
                    string[] ss = r.Trim().Split('\n');

                    int      N      = ss.Length;
                    double[] CLOSE  = new double[N];
                    double[] VOLUME = new double[N];
                    double[] DATE   = new double[N];

                    for (int i = 0; i < ss.Length; i++)
                    {
                        int      j   = N - i - 1;
                        string[] sss = ss[i].Split(' ');
                        DATE[j]   = DateTime.ParseExact(sss[0], "yyyy.MM.dd", DateTimeFormatInfo.InvariantInfo).ToOADate();
                        CLOSE[j]  = double.Parse(sss[2]);
                        VOLUME[j] = 0;
                    }
                    cdp.LoadBinary(new double[][] { CLOSE, CLOSE, CLOSE, CLOSE, VOLUME, DATE });
                    return(cdp);
                }
            }
            return(base.GetData(Code, Count));
        }
Example #7
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = new CommonDataProvider(this);

            cdp.SetStringData("Code", Code);
            DataTable dt = DB.GetDataTable("SELECT * FROM EndOfDay where Symbol='" + Code + "' ORDER BY Date");

            double[] OPEN   = new double[dt.Rows.Count];
            double[] HIGH   = new double[dt.Rows.Count];
            double[] LOW    = new double[dt.Rows.Count];
            double[] CLOSE  = new double[dt.Rows.Count];
            double[] VOLUME = new double[dt.Rows.Count];
            double[] AMOUNT = new double[dt.Rows.Count];
            double[] DATE   = new double[dt.Rows.Count];

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                OPEN[i]   = ToDouble(dt.Rows[i]["Open"]);
                HIGH[i]   = ToDouble(dt.Rows[i]["High"]);
                LOW[i]    = ToDouble(dt.Rows[i]["Low"]);
                CLOSE[i]  = ToDouble(dt.Rows[i]["Close"]);
                VOLUME[i] = ToInt(dt.Rows[i]["Volume"]);
                DATE[i]   = ((DateTime)dt.Rows[i]["Date"]).ToOADate();
            }
            cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
            return(cdp);
        }
        public static void MergeOneDay(string[] ss)
        {
            DbParam[] dps = new DbParam[] {
                new DbParam("@QuoteCode", DbType.String, null),
            };

            for (int i = 0; i < ss.Length; i++)
            {
                if (ss[i] != "")
                {
                    try
                    {
                        DataPacket dp = DataPacket.ParseEODData(ss[i]);
                        dps[0].Value = dp.Symbol;
                        DataRow dr = DB.GetFirstRow("select * from StockData where QuoteCode=?", dps);
                        if (dr != null)
                        {
                            string QuoteCode = dr["QuoteCode"].ToString();
                            byte[] bs        = DBDataManager.LoadHisDataFromFile(QuoteCode);
                            bs = CommonDataProvider.MergeOneQuote(bs, dp);
                            CommonDataProvider cdp = new CommonDataProvider(null);
                            cdp.LoadBinary(bs);
                            Utils.UpdateRealtime(QuoteCode, cdp);
                            DBDataManager.SaveBinary(QuoteCode, bs);
                        }
                    }
                    catch (Exception e)
                    {
                        Tools.Log("Merge Data:" + e.Message);
                    }
                }
            }
        }
Example #9
0
        public override IDataProvider GetData(string Code, int Count)
        {
            string FileName = Config.CSVDataPath + Code + Config.CSVExt;

            if (File.Exists(FileName))
            {
                FileStream   fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                StreamReader sr = new StreamReader(fs);
                try
                {
                    string    s  = sr.ReadToEnd().Trim();
                    string[]  ss = s.Split('\n');
                    ArrayList al = new ArrayList();
                    for (int i = 0; i < ss.Length; i++)
                    {
                        ss[i] = ss[i].Trim();
                        if (!ss[i].StartsWith("<!--"))
                        {
                            al.Add(ss[i]);
                        }
                    }

                    int      N      = al.Count;
                    double[] CLOSE  = new double[N];
                    double[] OPEN   = new double[N];
                    double[] HIGH   = new double[N];
                    double[] LOW    = new double[N];
                    double[] VOLUME = new double[N];
                    double[] DATE   = new double[N];

                    DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
                    NumberFormatInfo   nfi  = NumberFormatInfo.InvariantInfo;
                    for (int i = 0; i < N; i++)
                    {
                        string[] sss = ((string)al[i]).Split(',');
                        int      j   = i;                 //N-i-1;
                        DATE[j]   = DateTime.ParseExact(sss[1], "yyyyMMdd", dtfi).ToOADate();
                        OPEN[j]   = double.Parse(sss[2], nfi);
                        HIGH[j]   = double.Parse(sss[3], nfi);
                        LOW[j]    = double.Parse(sss[4], nfi);
                        CLOSE[j]  = double.Parse(sss[5], nfi);
                        VOLUME[j] = double.Parse(sss[6], nfi);
                    }

                    CommonDataProvider cdp = new CommonDataProvider(this);
                    cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                    return(cdp);
                }
                finally
                {
                    sr.Close();
                    fs.Close();
                }
            }
            return(base.GetData(Code, Count));
        }
Example #10
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp      = new CommonDataProvider(this);
            string             FileName = FormulaHelper.Root + "Data\\" + Code + ".txt";

            if (File.Exists(FileName))
            {
                try
                {
                    string s = "";
                    using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        using (StreamReader sr = new StreamReader(fs))
                            s = sr.ReadToEnd();
                    }

                    string[]  ss = s.Trim().Split('\n');
                    ArrayList al = new ArrayList();
                    for (int i = 0; i < ss.Length; i++)
                    {
                        al.Add(ss[i].Trim());
                    }

                    int      N      = al.Count;
                    double[] CLOSE  = new double[N];
                    double[] OPEN   = new double[N];
                    double[] HIGH   = new double[N];
                    double[] LOW    = new double[N];
                    double[] VOLUME = new double[N];
                    double[] DATE   = new double[N];

                    DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
                    NumberFormatInfo   nfi  = NumberFormatInfo.InvariantInfo;
                    for (int i = 0; i < N; i++)
                    {
                        string[] sss = ((string)al[i]).Split(',');
                        int      j   = i;
                        DATE[j]   = DateTime.ParseExact(sss[1] + " " + sss[2], "MM\\/dd\\/yy HH:mm", dtfi).ToOADate();
                        OPEN[j]   = double.Parse(sss[3]);
                        HIGH[j]   = double.Parse(sss[4]);
                        LOW[j]    = double.Parse(sss[5]);
                        CLOSE[j]  = double.Parse(sss[6]);
                        VOLUME[j] = 0;
                    }

                    cdp.SetStringData("Code", Code);
                    cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                    return(cdp);
                }
                catch
                {
                }
            }
            return(CommonDataProvider.Empty);
        }
Example #11
0
        public override IDataProvider GetData(string Code, int Count)
        {
            string FileName = HttpRuntime.AppDomainAppPath + "data\\" + Code + ".csv";

            if (File.Exists(FileName))
            {
                using (StreamReader sr = File.OpenText(FileName))
                {
                    string    s  = sr.ReadToEnd().Trim();
                    string[]  ss = s.Split('\n');
                    ArrayList al = new ArrayList();
                    for (int i = 0; i < ss.Length; i++)
                    {
                        ss[i] = ss[i].Trim();
                        al.Add(ss[i]);
                    }
                    int      N      = al.Count;
                    double[] CLOSE  = new double[N];
                    double[] OPEN   = new double[N];
                    double[] HIGH   = new double[N];
                    double[] LOW    = new double[N];
                    double[] VOLUME = new double[N];
                    double[] DATE   = new double[N];

                    DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
                    NumberFormatInfo   nfi  = NumberFormatInfo.InvariantInfo;
                    for (int i = 0; i < N; i++)
                    {
                        string[] sss = ((string)al[i]).Split(',');
                        VOLUME[i] = double.Parse(sss[3], nfi);
                        HIGH[i]   = double.Parse(sss[4], nfi);
                        LOW[i]    = double.Parse(sss[5], nfi);
                        OPEN[i]   = double.Parse(sss[6], nfi);
                        CLOSE[i]  = double.Parse(sss[7], nfi);
                        string r = sss[8];
                        int    j = r.IndexOf('T');
                        if (j > 0)
                        {
                            r = r.Substring(1, j - 1);
                        }

                        DATE[i] = DateTime.ParseExact(r, "yyyy-MM-dd", dtfi).ToOADate();
                    }

                    CommonDataProvider cdp = new CommonDataProvider(this);
                    cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                    return(cdp);
                }
            }
            return(base.GetData(Code, Count));
        }
Example #12
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = (CommonDataProvider)ddm[Code, Count];

            if (!cdp.HasData)
            {
                EasyStockChartDataFeed df = new EasyStockChartDataFeed();
                try
                {
                    byte[] bs = df.BinaryHistory(Code, true);
                    if (bs != null)
                    {
                        cdp.LoadBinary(bs);
                        DBDataManager.UpdateForNewSymbol(Code, cdp, Config.SaveInServerDataManager);
                    }
                }
                catch
                {
                }
            }
            return(cdp);
        }
Example #13
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = new CommonDataProvider(this);
            DataRow            dr  = DB.GetFirstRow("select * from CompanyInfo where TickerSymbolID='" + Code + "'");

            if (dr != null)
            {
                cdp.SetStringData("Code", dr["Symbol"].ToString());
                cdp.SetStringData("Name", dr["CompanyName"].ToString());
                cdp.SetStringData("Exchange", dr["Exchange"].ToString());

                DataTable dt = DB.GetDataTable(
                    "SELECT S.SessionNUM, S.SessionDate, Q.StockOpen, Q.StockHigh, Q.StockLow, Q.StockClose, Q.StockVolume" +
                    "	FROM StockQuotes Q "+
                    "			INNER JOIN Sessions S ON Q.SessionNUM = S.SessionNUM "+
                    "	WHERE Q.TickerSymbolId='"+ Code + "' ORDER BY Q.SessionNUM");
                double[] OPEN   = new double[dt.Rows.Count];
                double[] HIGH   = new double[dt.Rows.Count];
                double[] LOW    = new double[dt.Rows.Count];
                double[] CLOSE  = new double[dt.Rows.Count];
                double[] VOLUME = new double[dt.Rows.Count];
                double[] AMOUNT = new double[dt.Rows.Count];
                double[] DATE   = new double[dt.Rows.Count];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    OPEN[i]   = (double)dt.Rows[i]["StockClose"];
                    HIGH[i]   = (double)dt.Rows[i]["StockHigh"];
                    LOW[i]    = (double)dt.Rows[i]["StockLow"];
                    CLOSE[i]  = (double)dt.Rows[i]["StockClose"];
                    VOLUME[i] = (double)(int)dt.Rows[i]["StockVolume"];
                    DATE[i]   = ((DateTime)dt.Rows[i]["SessionDate"]).ToOADate();
                }
                cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                return(cdp);
            }
            return(base.GetData(Code, Count));
        }
Example #14
0
        public override IDataProvider GetData(string Code, int Count)
        {
            CommonDataProvider cdp = new CommonDataProvider(this);

            cdp.SetStringData("Code", Code);
            string s = FormulaHelper.Root + "Data\\" + Code + ".xml";

            if (File.Exists(s))
            {
                DataSet ds = new DataSet();
                ds.ReadXml(s);
                if (ds.Tables.Count > 0)
                {
                    DataTable dt     = ds.Tables[0];
                    int       N      = dt.Rows.Count;
                    double[]  OPEN   = new double[N];
                    double[]  HIGH   = new double[N];
                    double[]  LOW    = new double[N];
                    double[]  CLOSE  = new double[N];
                    double[]  VOLUME = new double[N];
                    double[]  AMOUNT = new double[N];
                    double[]  DATE   = new double[N];

                    for (int i = 0; i < N; i++)
                    {
                        OPEN[i]   = double.Parse(dt.Rows[i]["Open"].ToString());
                        HIGH[i]   = double.Parse(dt.Rows[i]["High"].ToString());
                        LOW[i]    = double.Parse(dt.Rows[i]["Low"].ToString());
                        CLOSE[i]  = double.Parse(dt.Rows[i]["Close"].ToString());
                        VOLUME[i] = double.Parse(dt.Rows[i]["Volume"].ToString());
                        DATE[i]   = DateTime.Parse(dt.Rows[i]["Date"].ToString(), DateTimeFormatInfo.InvariantInfo).ToOADate();
                    }
                    cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                    return(cdp);
                }
            }
            return(base.GetData(Code, Count));
        }
Example #15
0
        public override IDataProvider GetData(string Code, int Count)
        {
            try
            {
                CommonDataProvider cdp = new CommonDataProvider(this);
                cdp.SetStringData("Code", Code);
                //	cdp.SetStringData("Name",dr["CompanyName"].ToString());
                //	cdp.SetStringData("Exchange",dr["Exchange"].ToString());

                DataTable dt        = DB.GetDataTable("SELECT top " + Count + " * from " + Code + "_1da order by tstamp desc");
                double[]  OPEN      = new double[dt.Rows.Count];
                double[]  HIGH      = new double[dt.Rows.Count];
                double[]  LOW       = new double[dt.Rows.Count];
                double[]  CLOSE     = new double[dt.Rows.Count];
                double[]  VOLUME    = new double[dt.Rows.Count];
                double[]  AMOUNT    = new double[dt.Rows.Count];
                double[]  DATE      = new double[dt.Rows.Count];
                double    LastClose = 0;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[dt.Rows.Count - 1 - i];
                    HIGH[i]   = ToSingle(dr["priceh"]);
                    LOW[i]    = ToSingle(dr["pricel"]);
                    CLOSE[i]  = ToSingle(dr["pricec"]);
                    OPEN[i]   = Math.Min(Math.Max(LOW[i], LastClose), HIGH[i]);
                    VOLUME[i] = 0;
                    DATE[i]   = ((DateTime)dr["tstamp"]).ToOADate();
                    LastClose = CLOSE[i];
                }
                cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
                return(cdp);
            }
            catch
            {
            }
            return(base.GetData(Code, Count));
        }
Example #16
0
 private CommonDataProvider GetData(string symbol)
 {
     CommonDataProvider result;
     try
     {
         int num = 0;
         string b = "NAV";
         if (symbol == b || symbol == "SET")
         {
             DataTable dataTable = this.tds.Tables["TABLE"];
             num = dataTable.Rows.Count;
             double[] array = new double[num];
             double[] array2 = new double[num];
             double[] array3 = new double[num];
             double[] array4 = new double[num];
             double[] array5 = new double[num];
             double[] array6 = new double[num];
             double[] array7 = new double[num];
             DateTimeFormatInfo invariantInfo = DateTimeFormatInfo.InvariantInfo;
             NumberFormatInfo invariantInfo2 = NumberFormatInfo.InvariantInfo;
             double num2 = 0.0;
             for (int i = 0; i < num; i++)
             {
                 DataRow dataRow = dataTable.Rows[i];
                 string text = dataRow["sDate"].ToString();
                 DateTime dateTime;
                 DateTime.TryParse(string.Concat(new string[]
                 {
                     text.Substring(0, 4),
                     "/",
                     text.Substring(4, 2),
                     "/",
                     text.Substring(6, 2)
                 }), out dateTime);
                 if (symbol == b)
                 {
                     double.TryParse(dataRow["nmrNav"].ToString(), out num2);
                 }
                 else
                 {
                     double.TryParse(dataRow["nmrIndexVal"].ToString(), out num2);
                 }
                 array6[i] = dateTime.ToOADate();
                 array2[i] = double.Parse(num2.ToString(), invariantInfo2);
                 array3[i] = double.Parse(num2.ToString(), invariantInfo2);
                 array4[i] = double.Parse(num2.ToString(), invariantInfo2);
                 array[i] = double.Parse(num2.ToString(), invariantInfo2);
                 array5[i] = 0.0;
                 array7[i] = double.Parse(num2.ToString(), invariantInfo2);
             }
             CommonDataProvider commonDataProvider = new CommonDataProvider(this);
             commonDataProvider.DataCycle.CycleBase = DataCycleBase.TICK;
             commonDataProvider.LoadBinary(new double[][]
             {
                 array2,
                 array3,
                 array4,
                 array,
                 array5,
                 array6
             });
             StockList.StockInformation stockInformation = ApplicationInfo.StockInfo[symbol];
             if (array2.Length > 0)
             {
                 commonDataProvider.Prior = array2[0];
             }
             commonDataProvider.Ceiling = (double)stockInformation.Ceiling;
             commonDataProvider.Floor = (double)stockInformation.Floor;
             result = commonDataProvider;
             return result;
         }
         if (this.tds.Tables.Contains("TABLE"))
         {
             if (this.tds.Tables["TABLE"].Rows.Count > 0)
             {
                 num = this.tds.Tables["TABLE"].Rows.Count;
             }
             string text2 = string.Empty;
             decimal num3 = 0m;
             decimal num4 = 0m;
             decimal num5 = 0m;
             decimal num6 = 0m;
             decimal num7 = 0m;
             int num8 = 0;
             bool flag = false;
             if (num > 0 && this.tds.Tables.Contains("INFO") && this.tds.Tables["INFO"].Rows.Count > 0)
             {
                 text2 = this.tds.Tables["INFO"].Rows[0]["dtLastUpd"].ToString();
                 if (this.tds.Tables["TABLE"].Rows[0]["sDate"].ToString() != text2)
                 {
                     num++;
                     flag = true;
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["open_price1"].ToString(), out num3);
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["last_sale_price"].ToString(), out num4);
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["high_price"].ToString(), out num5);
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["low_price"].ToString(), out num6);
                     decimal.TryParse(this.tds.Tables["INFO"].Rows[0]["accvolume"].ToString(), out num7);
                 }
             }
             double[] array = new double[num];
             double[] array2 = new double[num];
             double[] array3 = new double[num];
             double[] array4 = new double[num];
             double[] array5 = new double[num];
             double[] array6 = new double[num];
             double[] array7 = new double[num];
             DateTimeFormatInfo invariantInfo = DateTimeFormatInfo.InvariantInfo;
             NumberFormatInfo invariantInfo2 = NumberFormatInfo.InvariantInfo;
             if (flag)
             {
                 DateTime dateTime;
                 DateTime.TryParse(string.Concat(new string[]
                 {
                     text2.Substring(0, 4),
                     "/",
                     text2.Substring(4, 2),
                     "/",
                     text2.Substring(6, 2)
                 }), out dateTime);
                 double num9 = double.Parse(num4.ToString(), invariantInfo2);
                 array6[num - 1] = dateTime.ToOADate();
                 array2[num - 1] = double.Parse(num3.ToString(), invariantInfo2);
                 array3[num - 1] = double.Parse(num5.ToString(), invariantInfo2);
                 array4[num - 1] = double.Parse(num6.ToString(), invariantInfo2);
                 array[num - 1] = num9;
                 array5[num - 1] = double.Parse(num7.ToString(), invariantInfo2);
                 array7[num - 1] = num9;
             }
             int count = this.tds.Tables["TABLE"].Rows.Count;
             for (int i = count - 1; i > -1; i--)
             {
                 DataRow dataRow = this.tds.Tables["TABLE"].Rows[i];
                 string text = dataRow["sDate"].ToString();
                 DateTime dateTime;
                 DateTime.TryParse(string.Concat(new string[]
                 {
                     text.Substring(0, 4),
                     "/",
                     text.Substring(4, 2),
                     "/",
                     text.Substring(6, 2)
                 }), out dateTime);
                 double num9 = double.Parse(dataRow["nmrClosingPrice"].ToString(), invariantInfo2);
                 array6[num8] = dateTime.ToOADate();
                 array2[num8] = double.Parse(dataRow["nmrOpenPrice1"].ToString(), invariantInfo2);
                 array3[num8] = double.Parse(dataRow["nmrHighPrice"].ToString(), invariantInfo2);
                 array4[num8] = double.Parse(dataRow["nmrLowPrice"].ToString(), invariantInfo2);
                 array[num8] = num9;
                 array5[num8] = double.Parse(dataRow["nmrDlVol"].ToString(), invariantInfo2);
                 array7[num8] = num9;
                 num8++;
             }
             CommonDataProvider commonDataProvider = new CommonDataProvider(this);
             commonDataProvider.DataCycle.CycleBase = DataCycleBase.TICK;
             commonDataProvider.LoadBinary(new double[][]
             {
                 array2,
                 array3,
                 array4,
                 array,
                 array5,
                 array6
             });
             StockList.StockInformation stockInformation = ApplicationInfo.StockInfo[symbol];
             commonDataProvider.Prior = 0.0;
             commonDataProvider.Ceiling = (double)stockInformation.Ceiling;
             commonDataProvider.Floor = (double)stockInformation.Floor;
             result = commonDataProvider;
             return result;
         }
     }
     catch
     {
     }
     result = CommonDataProvider.Empty;
     return result;
 }
Example #17
0
        public override IDataProvider GetData(string Code, int Count)
        {
            try
            {
                CommonDataProvider cdp = new CommonDataProvider(this);
                DbParam[]          dps = new DbParam[] {
                    new DbParam("@Symbol", DbType.String, Code),
                    new DbParam("@Q1", DbType.DateTime, StartTime),
                    new DbParam("@Q2", DbType.DateTime, EndTime),
                };
                BaseDb bd = DB.Open(false);
                try
                {
                    DataTable dt    = bd.GetDataTable("select Price,Volume,QuoteTime from Intraday where Symbol=? and QuoteTime>=? and QuoteTime<=? order by QuoteTime", dps);
                    double    LastV = -1;
                    foreach (DataRow dr in dt.Rows)
                    {
                        double NowV = (double)dr["Volume"];
                        if (LastV >= 0)
                        {
                            if (NowV > LastV)
                            {
                                dr["Volume"] = NowV - LastV;
                            }
                            else
                            {
                                dr["Volume"] = (double)0;
                            }
                        }
                        LastV = NowV;
                    }

                    dps[2].Value = ((DateTime)dps[1].Value).AddSeconds(-1);
                    dps[1].Value = ((DateTime)dps[1].Value).AddDays(-30);
                    DataRow drr = bd.GetFirstRow("select Price from Intraday where Symbol=? and QuoteTime>=? and QuoteTime<=? order by QuoteTime desc", dps);

                    if (dt.Rows.Count > 0)
                    {
                        cdp.SetStringData("LastTradeTime", ((DateTime)dt.Rows[dt.Rows.Count - 1]["QuoteTime"]).ToString());
                    }
                    if (drr != null)
                    {
                        cdp.SetStringData("LastPrice", drr[0].ToString());
                    }
                    SetStrings(cdp, Code);

                    if (dt.Rows.Count == 0)
                    {
                        dt.Rows.Add(new object[] { double.NaN, 0, StartTime });
                    }
                    double[] CLOSE  = new double[dt.Rows.Count];
                    double[] VOLUME = new double[dt.Rows.Count];
                    double[] DATE   = new double[dt.Rows.Count];

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        CLOSE[i]  = ToDouble(dt.Rows[i]["Price"]);
                        VOLUME[i] = ToDouble(dt.Rows[i]["Volume"]);
                        DATE[i]   = ((DateTime)dt.Rows[i]["QuoteTime"]).ToOADate();
                    }
                    cdp.LoadBinary("CLOSE", CLOSE);
                    cdp.LoadBinary("DATE", DATE);
                    cdp.LoadBinary("VOLUME", VOLUME);
                }
                finally
                {
                    bd.Close();
                }
                return(cdp);
            }
            catch
            {
            }
            return(base.GetData(Code, Count));
        }
Example #18
0
        static public string MergeData(string Symbol, string TextData, string DataFormat, string DateFormat, char Separator, bool HasHeader)
        {
            string[] Keys = { "OPEN", "HIGH", "LOW", "CLOSE", "VOLUME", "DATE", "ADJCLOSE" };
            string[] ss   = TextData.Trim().Split('\n');

            int DateIndex   = 0;
            int TickerIndex = -1;

            string[] ssHeader;
            //string DateFormat;
            GetFormatInfo(DataFormat, ref DateIndex, ref TickerIndex, out ssHeader, ref DateFormat);

            SortedList slAllSymbol = new SortedList(Comparer.Default);
            SortedList slOneSymbol;

            //char r = GetSeperator();

            for (int i = HasHeader?1:0; i < ss.Length; i++)
            {
                string[] sss = ss[i].Trim().Split(Separator);
                try
                {
                    string Ticker = Symbol;                    //tbSymbol.Text;
                    if (TickerIndex >= 0)
                    {
                        Ticker = sss[TickerIndex];
                    }
                    slOneSymbol = (SortedList)slAllSymbol[Ticker];
                    if (Ticker == "")
                    {
                        throw new Exception("Symbol can't be empty!");
                    }
                    if (slOneSymbol == null)
                    {
                        slOneSymbol         = new SortedList(Comparer.Default);
                        slAllSymbol[Ticker] = slOneSymbol;
                    }

                    slOneSymbol[DateTime.ParseExact(sss[DateIndex].Trim(),
                                                    DateFormat,
                                                    DateTimeFormatInfo.InvariantInfo)
                    ] = sss;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message + ";" + sss[DateIndex] + ";" + DateFormat);
                }
            }

            string          Msg = "";
            DataManagerBase dmb = Utils.GetDefaultDataManager();

            try
            {
                foreach (string s in slAllSymbol.Keys)
                {
                    slOneSymbol = (SortedList)slAllSymbol[s];
                    double[][] ds = new double[7][];
                    for (int i = 0; i < ds.Length; i++)
                    {
                        ds[i] = new double[slOneSymbol.Count];
                        for (int j = 0; j < ds[i].Length; j++)
                        {
                            ds[i][j] = double.NaN;
                        }
                    }

                    for (int i = 0; i < slOneSymbol.Count; i++)
                    {
                        ds[5][i] = ((DateTime)slOneSymbol.GetKey(i)).ToOADate();
                        for (int j = 0; j < ssHeader.Length; j++)
                        {
                            if (j != DateIndex && j != TickerIndex)
                            {
                                int k = Array.IndexOf(Keys, ssHeader[j].ToUpper());
                                if (k >= 0)
                                {
                                    string[] sss = (string[])slOneSymbol.GetByIndex(i);
                                    ds[k][i] = double.Parse(sss[j]);
                                }
                            }
                        }
                        for (int j = 0; j < ds.Length; j++)
                        {
                            if (double.IsNaN(ds[j][i]))
                            {
                                ds[j][i] = ds[3][i];
                            }
                        }
                    }

                    CommonDataProvider cdp      = (CommonDataProvider)dmb[s];
                    CommonDataProvider cdpDelta = new CommonDataProvider(null);
                    cdpDelta.LoadBinary(ds);

                    Msg += "Symbol:" + s + "; Original data count :" + cdp.Count + "; Merge data count : " + cdpDelta.Count + "; ";
                    cdp.Merge(cdpDelta);
                    Msg += "New data count : " + cdp.Count + "<br>";
                    Impersonate.ChangeToAdmin();
                    dmb.SaveData(s, cdp, false);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return(Msg);
        }
Example #19
0
        public override IDataProvider GetData(string Code, int Count)
        {
            Hashtable          htList = GetSymbolList();
            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(',');
                    }
                }
                // 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.LoadBinary(bs);
                // Update data from yahoo
                if (AutoYahooToDB)
                {
                    string   FileName = GetHisDataFile(Code);
                    DateTime d        = new DateTime(1900, 1, 1);
                    try
                    {
                        d = File.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 + 2];
                        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.LoadBinary(bs);
                    }
                }
                catch
                {
                    cdpn.LoadBinary(bs);
                }
            }
            //cdpn = TrimToEndTime(cdpn);
            if (ss != null && ss.Length > 2)
            {
                cdpn.SetStringData("Code", ss[0]);
                cdpn.SetStringData("Name", ss[1]);
                cdpn.SetStringData("Exchange", ss[2]);
            }
            return(cdpn);
        }
        private void btnMerge_Click(object sender, System.EventArgs e)
        {
            string[] Keys = { "OPEN", "HIGH", "LOW", "CLOSE", "VOLUME", "DATE", "ADJCLOSE" };
            string[] ss   = tbCSVData.Text.Trim().Split('\n');

            int DateIndex   = 0;
            int TickerIndex = -1;

            string[] ssHeader;
            string   DateFormat;

            GetFormatInfo(ref DateIndex, ref TickerIndex, out ssHeader, out DateFormat);

            SortedList slAllSymbol = new SortedList(Comparer.Default);
            SortedList slOneSymbol;

            char r = GetSeperator();

            for (int i = cbHasHeader.Checked?1:0; i < ss.Length; i++)
            {
                string[] sss = ss[i].Trim().Split(r);
                try
                {
                    string Ticker = tbSymbol.Text;
                    if (TickerIndex >= 0)
                    {
                        Ticker = sss[TickerIndex];
                    }
                    slOneSymbol = (SortedList)slAllSymbol[Ticker];
                    if (Ticker == "")
                    {
                        throw new Exception("Symbol can't be empty!");
                    }
                    if (slOneSymbol == null)
                    {
                        slOneSymbol         = new SortedList(Comparer.Default);
                        slAllSymbol[Ticker] = slOneSymbol;
                    }

                    slOneSymbol[DateTime.ParseExact(sss[DateIndex].Trim(),
                                                    DateFormat,
                                                    DateTimeFormatInfo.InvariantInfo)
                    ] = sss;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message + ";" + sss[DateIndex] + ";" + DateFormat);
                }
            }

            lMsg.Text = "";
            DBDataManager ddm = new DBDataManager();

            try
            {
                foreach (string s in slAllSymbol.Keys)
                {
                    slOneSymbol = (SortedList)slAllSymbol[s];
                    double[][] ds = new double[7][];
                    for (int i = 0; i < ds.Length; i++)
                    {
                        ds[i] = new double[slOneSymbol.Count];
                        for (int j = 0; j < ds[i].Length; j++)
                        {
                            ds[i][j] = double.NaN;
                        }
                    }

                    for (int i = 0; i < slOneSymbol.Count; i++)
                    {
                        ds[5][i] = ((DateTime)slOneSymbol.GetKey(i)).ToOADate();
                        for (int j = 0; j < ssHeader.Length; j++)
                        {
                            if (j != DateIndex && j != TickerIndex)
                            {
                                int k = Array.IndexOf(Keys, ssHeader[j].ToUpper());
                                if (k >= 0)
                                {
                                    string[] sss = (string[])slOneSymbol.GetByIndex(i);
                                    ds[k][i] = double.Parse(sss[j]);
                                }
                            }
                        }
                        for (int j = 0; j < ds.Length; j++)
                        {
                            if (double.IsNaN(ds[j][i]))
                            {
                                ds[j][i] = ds[3][i];
                            }
                        }
                    }

                    CommonDataProvider cdp      = (CommonDataProvider)ddm[s];
                    CommonDataProvider cdpDelta = new CommonDataProvider(null);
                    cdpDelta.LoadBinary(ds);

                    lMsg.Text += "Symbol:" + s + "; Original data count :" + cdp.Count + "; Merge data count : " + cdpDelta.Count + "; ";
                    cdp.Merge(cdpDelta);
                    lMsg.Text += "New data count : " + cdp.Count + "<br>";
                    Impersonate.ChangeToAdmin();
                    Utils.UpdateRealtime(s, cdp);
                    cdp.SaveBinary(DBDataManager.GetHisDataFile(s));
                }
            }
            catch (Exception ex)
            {
                lMsg.Text = ex.Message;
            }
        }
Example #21
0
        public CommonDataProvider GetDataFromString(string s)
        {
            string[]  ss = s.Trim().Split('\n');
            ArrayList al = new ArrayList();

            for (int i = 0; i < ss.Length; i++)
            {
                ss[i] = ss[i].Trim();
                if (!ss[i].StartsWith("<!--") && ss[i] != "")
                {
                    al.Add(ss[i]);
                }
            }

            int N = al.Count;

            double[] CLOSE  = new double[N];
            double[] OPEN   = new double[N];
            double[] HIGH   = new double[N];
            double[] LOW    = new double[N];
            double[] VOLUME = new double[N];
            double[] DATE   = new double[N];

            string Code     = null;
            string Name     = null;
            string Exchange = null;

            DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
            NumberFormatInfo   nfi  = NumberFormatInfo.InvariantInfo;

            for (int i = 0; i < N; i++)
            {
                string[] sss = ((string)al[i]).Split(',');
                int      j   = i;         //N-i-1;
                DATE[j]   = DateTime.ParseExact(sss[1], "yyyyMMdd", dtfi).ToOADate();
                OPEN[j]   = ToDoubleDef(sss[2], 0, nfi);
                HIGH[j]   = ToDoubleDef(sss[3], 0, nfi);
                LOW[j]    = ToDoubleDef(sss[4], 0, nfi);
                CLOSE[j]  = ToDoubleDef(sss[5], 0, nfi);
                VOLUME[j] = ToDoubleDef(sss[6], 0, nfi);
                Code      = sss[0];
                if (string.Compare(Code, "PRN", true) == 0)
                {
                    Code = "PRNN";
                }
                if (sss.Length > 7)
                {
                    Name = sss[7];
                }
                if (sss.Length > 8)
                {
                    Exchange = sss[8];
                }
            }

            CommonDataProvider cdp = new CommonDataProvider(this);

            if (Code != null)
            {
                cdp.SetStringData("Code", Code);
            }
            if (Name != null)
            {
                cdp.SetStringData("Name", Name);
            }
            if (Exchange != null)
            {
                cdp.SetStringData("Exchange", Exchange);
            }
            cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE });
            return(cdp);
        }