예제 #1
0
            //public static StockSymbol_DynamicData GetSymbolsByTradeCenter(TradeCenter tradeCenter, params string[] fields)
            //{
            //    StockSymbol_DynamicData currentData = new StockSymbol_DynamicData();

            //    using (DataTable dtStockList = GetStockSymbolData(tradeCenter))
            //    {
            //        List<SymbolItem> items = new List<SymbolItem>();

            //        for (int i = 0; i < dtStockList.Rows.Count; i++)
            //        {
            //            object[] datas = new object[fields.Length];

            //            for (int j = 0; j < fields.Length; j++)
            //            {
            //                if (fields[j].ToLower() == "currentprice")
            //                {
            //                    if (Lib.Object2Double(dtStockList.Rows[i][fields[j]]) > 0)
            //                    {
            //                        datas[j] = dtStockList.Rows[i][fields[j]];
            //                    }
            //                    else
            //                    {
            //                        try
            //                        {
            //                            datas[j] = dtStockList.Rows[i]["basicPrice"];
            //                        }
            //                        catch
            //                        {
            //                            datas[j] = 0;
            //                        }
            //                    }
            //                }
            //                else
            //                {
            //                    datas[j] = dtStockList.Rows[i][fields[j]];
            //                }
            //            }

            //            items.Add(new SymbolItem(dtStockList.Rows[i]["code"].ToString(), datas));
            //        }

            //        currentData.Symbols = items.ToArray();
            //    }
            //    return currentData;
            //}

            public static StockSymbol_DynamicData GetSymbolsBySymbolArray(string symbolArray, params string[] fields)
            {
                StockSymbol_DynamicData currentData = new StockSymbol_DynamicData();

                List<string> symbols = new List<string>();
                try
                {
                    //string filterString = "";
                    if (!string.IsNullOrEmpty(symbolArray))
                    {
                        //if (symbolArray.StartsWith(";")) symbolArray = symbolArray.Substring(1);
                        //if (symbolArray.EndsWith(";")) symbolArray = symbolArray.Substring(0, symbolArray.Length - 1);

                        //string[] symbolList = symbolArray.Split(';');

                        ////filterString = "";
                        //string stock_Inorge = ConfigurationManager.AppSettings["SymbolInorge"];
                        //string[] tem = stock_Inorge.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        //List<string> codeStack = new List<string>();
                        //for (int i = 0, length = tem.Length; i < length; i++)
                        //    codeStack.Add(tem[i].Trim());

                        //foreach (string symbol in symbolList)
                        //{
                        //    //filterString += " OR code='" + symbol + "'";
                        //    if (!codeStack.Contains(symbol))
                        //        symbols.Add(symbol);
                        //}

                        ////if (filterString != "") filterString = filterString.Substring(4);
                        if (symbolArray.StartsWith(";")) symbolArray = symbolArray.Substring(1);
                        if (symbolArray.EndsWith(";")) symbolArray = symbolArray.Substring(0, symbolArray.Length - 1);

                        string[] symbolList = symbolArray.Split(';');

                        foreach (string symbol in symbolList)
                        {
                            if (!symbols.Contains(symbol.ToUpper())) symbols.Add(symbol.ToUpper());
                        }
                    }

                    List<SymbolItem> items = new List<SymbolItem>();

                    //if (filterString != "")
                    //if (symbols.Count > 0)
                    //{
                    //    DataTable dtHAPriceData = GetStockSymbolData(TradeCenter.HaSTC);
                    //    //DataRow[] arrHAPriceData = dtHAPriceData.Select(filterString);
                    //    //for (int i = 0; i < arrHAPriceData.Length; i++)
                    //    for (int i = 0; i < dtHAPriceData.Rows.Count; i++)
                    //    {
                    //        if (IsSymbolSelected(dtHAPriceData.Rows[i]["code"].ToString(), ref symbols))
                    //        {
                    //            object[] datas = new object[fields.Length];

                    //            for (int j = 0; j < fields.Length; j++)
                    //            {
                    //                if (fields[j].ToLower() == "currentprice")
                    //                {
                    //                    if (Lib.Object2Double(dtHAPriceData.Rows[i][fields[j]]) > 0)
                    //                    {
                    //                        datas[j] = dtHAPriceData.Rows[i][fields[j]];
                    //                    }
                    //                    else
                    //                    {
                    //                        try
                    //                        {
                    //                            datas[j] = dtHAPriceData.Rows[i]["basicPrice"];
                    //                        }
                    //                        catch
                    //                        {
                    //                            datas[j] = 0;
                    //                        }
                    //                    }
                    //                }
                    //                else
                    //                {
                    //                    datas[j] = dtHAPriceData.Rows[i][fields[j]];
                    //                }
                    //                //hungnd
                    //                try
                    //                {
                    //                    if (fields[j].ToLower() == "ceiling")
                    //                    {
                    //                        datas[j] = dtHAPriceData.Rows[i]["Ceiling"];
                    //                    }
                    //                    if (fields[j].ToLower() == "floor")
                    //                    {
                    //                        datas[j] = dtHAPriceData.Rows[i]["Floor"];
                    //                    }
                    //                }
                    //                catch { }
                    //                //
                    //            }

                    //            items.Add(new SymbolItem(dtHAPriceData.Rows[i]["code"].ToString(), datas));
                    //        }
                    //    }
                    //    dtHAPriceData.Dispose();

                    //    DataTable dtHOPriceData = GetStockSymbolData(TradeCenter.HoSE);
                    //    //DataRow[] arrHOPriceData = dtHOPriceData.Select(filterString);
                    //    //for (int i = 0; i < arrHOPriceData.Length; i++)
                    //    for (int i = 0; i < dtHOPriceData.Rows.Count; i++)
                    //    {
                    //        if (IsSymbolSelected(dtHOPriceData.Rows[i]["code"].ToString(), ref symbols))
                    //        {
                    //            object[] datas = new object[fields.Length];

                    //            for (int j = 0; j < fields.Length; j++)
                    //            {
                    //                if (fields[j].ToLower() == "currentprice")
                    //                {
                    //                    if (Lib.Object2Double(dtHOPriceData.Rows[i][fields[j]]) > 0)
                    //                    {
                    //                        datas[j] = dtHOPriceData.Rows[i][fields[j]];
                    //                    }
                    //                    else
                    //                    {
                    //                        try
                    //                        {
                    //                            datas[j] = dtHOPriceData.Rows[i]["basicPrice"];
                    //                        }
                    //                        catch
                    //                        {
                    //                            datas[j] = 0;
                    //                        }
                    //                    }
                    //                }
                    //                else
                    //                {
                    //                    datas[j] = dtHOPriceData.Rows[i][fields[j]];
                    //                }
                    //                //hungnd
                    //                try
                    //                {
                    //                    if (fields[j].ToLower() == "ceiling")
                    //                    {
                    //                        datas[j] = dtHOPriceData.Rows[i]["Ceiling"];
                    //                    }
                    //                    if (fields[j].ToLower() == "floor")
                    //                    {
                    //                        datas[j] = dtHOPriceData.Rows[i]["Floor"];
                    //                    }
                    //                }
                    //                catch { }
                    //                //
                    //            }

                    //            items.Add(new SymbolItem(dtHOPriceData.Rows[i]["code"].ToString(), datas));
                    //        }
                    //    }
                    //    dtHOPriceData.Dispose();
                    //}
                    var ss = new List<string>();
                    foreach (string code in symbols)
                    {
                        if (!ss.Contains(code.ToUpper())) ss.Add(code.ToUpper());
                    }
                    var ts = StockBL.GetStockPriceMultiple(ss);
                    object[] datas;
                    foreach (string code in symbols)
                    {
                        datas = new object[fields.Length];

                        StockPrice price = null;
                        bool updated = false;
                        try
                        {
                            price = ts[code];
                            datas[0] = price.Price;
                            datas[1] = price.Price - price.RefPrice;
                            datas[2] = price.RefPrice <= 0 ? 0 : (price.Price - price.RefPrice) / price.RefPrice * 100;
                            datas[3] = price.CeilingPrice;
                            datas[4] = price.FloorPrice;
                            updated = true;
                        }
                        catch (Exception)
                        {
                            updated = false;
                        }
                        if (!updated)
                        {
                            datas[0] = "0";
                            datas[1] = "0";
                            datas[2] = "0";
                            datas[3] = "0";
                            datas[4] = "0";
                        }
                        items.Add(new SymbolItem(code, datas));
                    }
                    currentData.Symbols = items.ToArray();
                }
                catch (Exception ex)
                {
                    //Lib.WriteError(ex.Message);
                }
                return currentData;
            }
예제 #2
0
            public static StockSymbol_DynamicData GetSymbolsBySymbolArray(string symbolArray, params string[] fields)
            {
                StockSymbol_DynamicData currentData = new StockSymbol_DynamicData();
                try
                {
                    List<string> symbols = new List<string>();

                    if (!string.IsNullOrEmpty(symbolArray))
                    {
                        if (symbolArray.StartsWith(";")) symbolArray = symbolArray.Substring(1);
                        if (symbolArray.EndsWith(";")) symbolArray = symbolArray.Substring(0, symbolArray.Length - 1);

                        string[] symbolList = symbolArray.Split(';');

                        foreach (string symbol in symbolList)
                        {
                            if (!symbols.Contains(symbol.ToUpper())) symbols.Add(symbol.ToUpper());
                        }

                    }
                    var hsx = TradeCenterBL.getByTradeCenter((int)TradeCenter.HoSE);
                    var hnx = TradeCenterBL.getByTradeCenter((int)TradeCenter.HaSTC);
                    List<SymbolItem> items = new List<SymbolItem>();
                    DataTable tblSymbol;
                    if (symbols.Count > 0)
                    {
                        var ss = new List<string>();
                        foreach (string code in symbols)
                        {
                            if (!ss.Contains(code.ToUpper())) ss.Add(code.ToUpper());
                        }
                        var ts = PriceRedisBL.GetStockPriceMultiple(ss);
                        object[] datas;
                        foreach (string code in symbols)
                        {
                            //tblSymbol = GetSymbolDataByCache(code, TradeCenter.HaSTC);
                            //if (tblSymbol == null || tblSymbol.Rows.Count < 1)
                            //    tblSymbol = GetSymbolDataByCache(code, TradeCenter.HoSE);
                            //if (tblSymbol == null || tblSymbol.Rows.Count < 1)
                            //    tblSymbol = GetSymbolDataByCache(code, TradeCenter.UpCom);


                            //datas = new object[fields.Length];
                            ////currentPrice','chgIndex','pctIndex
                            ////this.Fields = {'Price':0,'Change':1,'ChangePercent':2,'ceiling':3,'floor':4};
                            //if (tblSymbol != null && tblSymbol.Rows.Count > 0)
                            //{
                            //    if (Lib.Object2Double(tblSymbol.Rows[0][1]) > 0)
                            //        datas[0] = tblSymbol.Rows[0][1];//currentprice
                            //    else
                            //        datas[0] = tblSymbol.Rows[0][10];//currentprice
                            //    datas[1] = tblSymbol.Rows[0][2];//chgIndex
                            //    datas[2] = tblSymbol.Rows[0][6];//pctIndex
                            //    try
                            //    {
                            //        datas[3] = tblSymbol.Rows[0][17];//ceiling
                            //        datas[4] = tblSymbol.Rows[0][18];//Floor
                            //    }
                            //    catch { }
                            //    items.Add(new SymbolItem(code, datas));
                            //}
                            //else
                            //{
                            //    datas[0] = "0";
                            //    datas[1] = "0";
                            //    datas[2] = "0";
                            //    datas[3] = "0";
                            //    datas[4] = "0";
                            //    items.Add(new SymbolItem(code, datas));
                            //}
                            datas = new object[5];
                            if (code.ToUpper() == "HSXD")
                            {
                                datas[0] = hsx.CurrentVolume.ToString("#,##0");
                                datas[1] = hsx.ForeignNetVolume.ToString("#,##0");
                                datas[2] = hsx.Ceiling + "|" + hsx.Up + "|" + hsx.Normal + "|" + hsx.Down + "|" + hsx.Floor;
                                datas[3] = 0;
                                datas[4] = 0;
                                items.Add(new SymbolItem(code, datas));
                                continue;
                            }
                            if (code.ToUpper() == "HNXD")
                            {
                                datas[0] = hnx.CurrentVolume.ToString("#,##0");
                                datas[1] = hnx.ForeignNetVolume.ToString("#,##0");
                                datas[2] = hnx.Ceiling + "|" + hnx.Up + "|" + hnx.Normal + "|" + hnx.Down + "|" + hnx.Floor;
                                datas[3] = 0;
                                datas[4] = 0;
                                items.Add(new SymbolItem(code, datas));
                                continue;
                            }

                            StockPrice price = null;
                            bool updated = false;
                            try
                            {
                                price = ts[code];
                                datas[0] = price.Price;
                                datas[1] = price.Price - price.RefPrice;
                                datas[2] = price.RefPrice <= 0 ? 0 : (price.Price - price.RefPrice) / price.RefPrice * 100;
                                datas[3] = price.CeilingPrice;
                                datas[4] = price.FloorPrice;
                                updated = true;
                            }
                            catch (Exception)
                            {
                                updated = false;
                            }
                            if (!updated)
                            {
                                datas[0] = "0";
                                datas[1] = "0";
                                datas[2] = "0";
                                datas[3] = "0";
                                datas[4] = "0";
                            }
                            items.Add(new SymbolItem(code, datas));
                        }
                    }
                    #region Header index

                    var san = new object[5];
                    san[0] = hsx.CurrentIndex.ToString("#,##0.00");
                    san[1] = (hsx.CurrentIndex > hsx.PrevIndex ? "+" : "") + (hsx.CurrentIndex - hsx.PrevIndex).ToString("#,##0.00");
                    san[2] = (hsx.CurrentIndex > hsx.PrevIndex ? "+" : "") + (hsx.PrevIndex <= 0 ? 0 : (hsx.CurrentIndex - hsx.PrevIndex) / hsx.PrevIndex * 100).ToString("#,##0.00");
                    san[3] = hsx.CurrentValue.ToString("#,##0.0");
                    san[4] = (Utils.InTradingTime(1) ? hsx.CurrentDate : Utils.GetCloseTime(1)).ToString("HH:mm");
                    items.Add(new SymbolItem("HSX", san));

                    san = new object[5];
                    san[0] = hnx.CurrentIndex.ToString("#,##0.00");
                    san[1] = (hnx.CurrentIndex > hnx.PrevIndex ? "+" : "") + (hnx.CurrentIndex - hnx.PrevIndex).ToString("#,##0.00");
                    san[2] = (hnx.CurrentIndex > hnx.PrevIndex ? "+" : "") + (hnx.PrevIndex <= 0 ? 0 : (hnx.CurrentIndex - hnx.PrevIndex) / hnx.PrevIndex * 100).ToString("#,##0.00");
                    san[3] = hnx.CurrentValue.ToString("#,##0.0");
                    san[4] = (Utils.InTradingTime(2) ? hnx.CurrentDate : Utils.GetCloseTime(2)).ToString("HH:mm");
                    items.Add(new SymbolItem("HNX", san));
                    #endregion
                    currentData.Symbols = items.ToArray();
                }
                catch (Exception ex) { Lib.WriteError(fields.Length + ":GetSymbolsBySymbolArray: " + symbolArray + " : " + ex.Message); }
                return currentData;
            }
예제 #3
0
            public static StockSymbol_DynamicData GetTop10Symbols(TopSymbolBy type, TradeCenter tradeCenter, params string[] fields)
            {
                StockSymbol_DynamicData currentData = new StockSymbol_DynamicData();

                //string cacheName = "";
                //if (type == TopSymbolBy.TopUp)
                //{
                //    cacheName = (tradeCenter == TradeCenter.AllTradeCenter ? "MemCached_Top10_Tang_All" : (tradeCenter == TradeCenter.HaSTC ? "MemCached_Top10_Tang_HaSTC" : "MemCached_Top10_Tang_HoSE"));
                //}
                //else if (type == TopSymbolBy.TopDown)
                //{
                //    cacheName = (tradeCenter == TradeCenter.AllTradeCenter ? "MemCached_Top10_Giam_All" : (tradeCenter == TradeCenter.HaSTC ? "MemCached_Top10_Giam_HaSTC" : "MemCached_Top10_Giam_HoSE"));
                //}
                //else
                //{
                //    cacheName = (tradeCenter == TradeCenter.AllTradeCenter ? "MemCached_Top10_KhoiLuong_All" : (tradeCenter == TradeCenter.HaSTC ? "MemCached_Top10_KhoiLuong_HaSTC" : "MemCached_Top10_KhoiLuong_HoSE"));
                //}

                //DataTable dtStockList = GetDataTable(cacheName);
                //var dtStockList = new DataTable();
                List<SymbolItem> items = new List<SymbolItem>();
                #region Get From WebService
                //if (dtStockList == null || dtStockList.Rows.Count == 0)
                //{
                    //CafeF_DataService.CafeF_DataService dataServices = new CafeF_EmbedData.CafeF_DataService.CafeF_DataService();
                    //WServices.Function dataServices = new WServices.Function();
                    var key = "";
                    switch (type)
                    {
                        case TopSymbolBy.TopUp:
                            switch (tradeCenter)
                            {
                                case TradeCenter.HaSTC:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopUp,
                                    //                                        WServices.Function.TradeCenter.HaSTC).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ha, RedisKey.KeyTopStockType.PriceUp);
                                    break;
                                case TradeCenter.HoSE:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopUp,
                                    //                                        WServices.Function.TradeCenter.HoSE).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ho, RedisKey.KeyTopStockType.PriceUp);
                                    break;
                                default:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopUp,
                                    //                                        WServices.Function.TradeCenter.All).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.All, RedisKey.KeyTopStockType.PriceUp);
                                    break;
                            }
                            break;
                        case TopSymbolBy.TopDown:
                            switch (tradeCenter)
                            {
                                case TradeCenter.HaSTC:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopDown,
                                    //                                        WServices.Function.TradeCenter.HaSTC).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ha, RedisKey.KeyTopStockType.PriceDown);
                                    break;
                                case TradeCenter.HoSE:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopDown,
                                    //                                        WServices.Function.TradeCenter.HoSE).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ho, RedisKey.KeyTopStockType.PriceDown);
                                    break;
                                default:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopDown,
                                    //                                        WServices.Function.TradeCenter.All).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.All, RedisKey.KeyTopStockType.PriceDown);
                                    break;
                            }
                            break;
                        default:
                            switch (tradeCenter)
                            {
                                case TradeCenter.HaSTC:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopTrade,
                                    //                                        WServices.Function.TradeCenter.HaSTC).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ha, RedisKey.KeyTopStockType.VolumeDown);
                                    break;
                                case TradeCenter.HoSE:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopTrade,
                                    //                                        WServices.Function.TradeCenter.HoSE).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.Ho, RedisKey.KeyTopStockType.VolumeDown);
                                    break;
                                default:
                                    //dtStockList = dataServices.GetTopSymbol(10,
                                    //                                        WServices.Function.TopStockSymbol.TopTrade,
                                    //                                        WServices.Function.TradeCenter.All).Tables[0];
                                    key = string.Format(RedisKey.KeyTopStock, RedisKey.KeyTopStockCenter.All, RedisKey.KeyTopStockType.VolumeDown);
                                    break;
                            }
                            break;
                    }
                    var tops = BLFACTORY.RedisClient.Get<List<TopStock>>(key);
                    //'Quantity':0,'Price':1,'Change':2,'ChangePercent':3
                //}
                foreach (var top in tops)
                {
                    object[] datas = new object[fields.Length];
                    datas[0] = top.Volume;
                    datas[1] = top.Price;
                    datas[2] = top.Price - top.BasicPrice;
                    datas[3] = top.BasicPrice <= 0 ? 0 : (top.Price - top.BasicPrice) / top.BasicPrice * 100;
                    items.Add(new SymbolItem(top.Symbol,datas));
                }
                #endregion

                //if (dtStockList == null || dtStockList.Rows.Count == 0)
                //{
                //    DataTable dtTemp;
                //    if (tradeCenter == TradeCenter.AllTradeCenter)
                //    {
                //        dtTemp = GetStockSymbolData(TradeCenter.HoSE);
                //        dtTemp.Merge(GetStockSymbolData(TradeCenter.HaSTC));
                //    }
                //    else
                //    {
                //        dtTemp = GetStockSymbolData(tradeCenter);
                //    }
                //    using (DataView dvTemp = new DataView(dtTemp))
                //    {
                //        dvTemp.RowFilter = (type == TopSymbolBy.TopUp ? "chgIndex > 0" : (type == TopSymbolBy.TopDown ? "chgIndex < 0" : ""));
                //        dvTemp.Sort = (type == TopSymbolBy.TopUp ? "chgIndex DESC" : (type == TopSymbolBy.TopDown ? "chgIndex ASC" : "totalTradingQtty DESC"));
                //        dtStockList = dvTemp.ToTable();
                //    }
                //    dtTemp.Dispose();
                //}

               

                //for (int i = 0; i < dtStockList.Rows.Count && i < 10; i++)
                //{
                //    object[] datas = new object[fields.Length];

                //    for (int j = 0; j < fields.Length; j++)
                //    {
                //        if (fields[j].ToLower() == "currentprice")
                //        {
                //            if (Lib.Object2Double(dtStockList.Rows[i][fields[j]]) > 0)
                //            {
                //                datas[j] = dtStockList.Rows[i][fields[j]];
                //            }
                //            else
                //            {
                //                try
                //                {
                //                    datas[j] = dtStockList.Rows[i]["basicPrice"];
                //                }
                //                catch
                //                {
                //                    datas[j] = 0;
                //                }
                //            }
                //        }
                //        else
                //        {
                //            datas[j] = dtStockList.Rows[i][fields[j]];
                //        }
                //    }

                //    items.Add(new SymbolItem(dtStockList.Rows[i]["code"].ToString(), datas));
                //}

                //dtStockList.Dispose();

                

                currentData.Symbols = items.ToArray();
                //Lib.WriteLog("Top10CP: " + currentData.Symbols.Length.ToString() + " Items");
                return currentData;
            }