コード例 #1
0
ファイル: test.aspx.cs プロジェクト: giangcoffee/cafef.redis
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack) return;
     txtSymbol.Text = "SSI";
     var center = TradeCenterBL.getByTradeCenter(1);
     dpkTradeDate1.SelectedDate = center.CurrentDate;
     price = PriceRedisBL.getStockPriceBySymbol(txtSymbol.Text);
     LoadData();
 }
コード例 #2
0
ファイル: test.aspx.cs プロジェクト: giangcoffee/cafef.redis
 private void LoadData()
 {
     if (string.IsNullOrEmpty(txtSymbol.Text)) return;
     int count;
     var prices = dpkTradeDate1.SelectedDate.ToString("yyyyMMdd")==DateTime.Now.ToString("yyyyMMdd") ? null : StockHistoryBL.get_StockHistoryBySymbolAndDate(txtSymbol.Text.Trim().ToUpper(), dpkTradeDate1.SelectedDate, dpkTradeDate1.SelectedDate, 1, 1, out count);
     if (prices != null && prices.Count > 0)
     {
         history = prices[0];
         price = null;
     }
     else
     {
         history = null;
         price = PriceRedisBL.getStockPriceBySymbol(txtSymbol.Text.Trim().ToUpper());
     }
     repResult.DataSource = KhopLenhBL.GetBySymbolDate(txtSymbol.Text.Trim().ToUpper(), dpkTradeDate1.SelectedDate);
     repResult.DataBind();
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: giangcoffee/cafef.redis
        private void button2_Click(object sender, EventArgs e)
        {
            var redis = new RedisClient(ConfigRedis.Host, ConfigRedis.Port);

            //var pdt = bFirst ? sql.GetAllPrice(centerId) : sql.GetChangedPriceSymbols(centerId);

            DateTime start = DateTime.Now;
            var dt = SqlDb.GetAllPrice(1);
            var allkey = string.Format(RedisKey.KeyRealTimePrice, 1);
            if (redis.ContainsKey(allkey))
                redis.Set(allkey, Lib.Serialize(dt));
            else
                redis.Add(allkey, Lib.Serialize(dt));
            var testdt = Lib.Deserialize(redis.Get<string>(allkey));
            dt.Merge(SqlDb.GetAllPrice(2));
            dt.Merge(SqlDb.GetAllPrice(9));
            foreach (DataRow pdr in dt.Rows)
            {
                try
                {

                    //Thread.Sleep(1000);
                    //update stock price 
                    var symbol = pdr["Symbol"].ToString();

                    #region Get Stock Price Data

                    //var cdt = SqlDb.GetCenterId(symbol);
                    //if (cdt.Rows.Count == 0) continue;
                    var centerId = int.Parse(pdr["centerId"].ToString());
                    //var pdt = SqlDb.GetRealtimePriceData(symbol, centerId);
                    //if (pdt.Rows.Count == 0) continue;
                    //var pdr = pdt.Rows[0];
                    var bAvg = centerId != 1 && !Lib.InTradingTime(centerId);
                    var price = new StockPrice() { Symbol = symbol, LastTradeDate = (DateTime)pdr["TradeDate"], Price = double.Parse(pdr[bAvg ? "AveragePrice" : "TradingPrice"].ToString()), RefPrice = double.Parse(pdr["Ref"].ToString()), CeilingPrice = double.Parse(pdr["Ceiling"].ToString()), FloorPrice = double.Parse(pdr["Floor"].ToString()), Volume = double.Parse(pdr["TradingVol"].ToString()), Value = double.Parse(pdr["TotalTradingValue"].ToString()), HighPrice = double.Parse(pdr["TradingPriceMax"].ToString()), LowPrice = double.Parse(pdr["TradingPriceMin"].ToString()), OpenPrice = double.Parse(pdr["OpenPrice"].ToString()), ClosePrice = double.Parse(pdr["TradingPrice"].ToString()), ForeignBuyValue = double.Parse(pdr["BuyFrValue"].ToString()), ForeignBuyVolume = double.Parse(pdr["BuyFrVolume"].ToString()), ForeignSellValue = double.Parse(pdr["SellFrValue"].ToString()), ForeignSellVolume = double.Parse(pdr["SellFrVolume"].ToString()), ForeignCurrentRoom = double.Parse(pdr["RemainFrRoom"].ToString()), AskPrice01 = double.Parse(pdr["SellPrice1"].ToString()), AskPrice02 = double.Parse(pdr["SellPrice2"].ToString()), AskPrice03 = double.Parse(pdr["SellPrice3"].ToString()), AskVolume01 = double.Parse(pdr["SellVol1"].ToString()), AskVolume02 = double.Parse(pdr["SellVol2"].ToString()), AskVolume03 = double.Parse(pdr["SellVol3"].ToString()), BidPrice01 = double.Parse(pdr["BidPrice1"].ToString()), BidPrice02 = double.Parse(pdr["BidPrice2"].ToString()), BidPrice03 = double.Parse(pdr["BidPrice3"].ToString()), BidVolume01 = double.Parse(pdr["BidVol1"].ToString()), BidVolume02 = double.Parse(pdr["BidVol2"].ToString()), BidVolume03 = double.Parse(pdr["BidVol3"].ToString()) };

                    #endregion

                    var key = string.Format(RedisKey.PriceKey, symbol);

                    if (redis.ContainsKey(key))
                        redis.Set<StockPrice>(key, price);
                    else
                        redis.Add<StockPrice>(key, price);
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
            //var set = DateTime.Now;

            //textBox3.Text = set.ToString();

            //var st = redis.Get<StockPrice>(key);
            //var get = DateTime.Now;
            //textBox4.Text = get.ToString();
            DateTime end = DateTime.Now;
            MessageBox.Show("Done");

        }