Exemplo n.º 1
0
 // Returns all objects specified by <key> in the respective <region>.
 public IEnumerable <KeyValuePair <string, object> > BulkGet(IEnumerable <string> key, string region)
 {
     //var cache = GetCache();
     GetCache();
     if (Cache.RegionExists(Convert.ToString(ConfigurationManager.AppSettings[region]).Split('_')[1], Convert.ToString(ConfigurationManager.AppSettings[region]).Split('_')[0]))
     {
         return(_cache.BulkGet(key, region));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Get Equity,Balance and Pnl from Cache
        /// </summary>
        /// <param name="lstLogin"></param>
        /// <returns></returns>
        public JsonResult GetEquityList(string strLogin)
        {
            var lstMarginDetails = new List <MarginDetails>();
            var lstLogin         = new List <int>();

            try
            {
                //Convert platform login to List<int>
                string[] lstStrLogins = strLogin.Split(new[] { ',' });
                foreach (var pl in lstStrLogins)
                {
                    lstLogin.Add(pl.Int32TryParse());
                }

                //Get Data from cache
                var           marginCache = new DataCache("MarginCache");
                List <string> lstStrLogin = lstLogin.Select(s => s.StringTryParse()).ToList();
                IEnumerable <KeyValuePair <string, object> > lstMarginsObj = marginCache.BulkGet(lstStrLogin);

                //Create a Json Data
                var lstMargins = lstMarginsObj.Select(s => (Margin)s.Value).ToList();
                foreach (var margin in lstMargins)
                {
                    var ed = new MarginDetails();
                    if (margin != null)
                    {
                        ed.Pl  = margin.Login ?? 0;
                        ed.Equ = margin.Equity.CurrencyFormat();
                        ed.Bal = margin.Balance.CurrencyFormat();

                        var equity = margin.Equity ?? 0;
                        var bal    = margin.Balance ?? 0;

                        var pnl = equity - bal;
                        ed.Pnl = pnl.CurrencyFormat();
                        lstMarginDetails.Add(ed);
                    }
                }

                return(Json(lstMarginDetails, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                CurrentDeskLog.Error(ex.Message, ex);
            }

            return(Json(string.Empty, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get Equity,Balance and Pnl from Cache
        /// </summary>
        /// <param name="lstLogin"></param>
        /// <returns></returns>
        public JsonResult GetEquityListwww(List <int> lstLogin)
        {
            decimal marginVal = 0;

            try
            {
                var marginCache = new DataCache("MarginCache");

                var lstStrLogin = lstLogin.Select(s => s.StringTryParse()).ToList();

                IEnumerable <KeyValuePair <string, object> > lstMarginsObj = marginCache.BulkGet(lstStrLogin);
                var lstMargins = lstMarginsObj.Select(s => (Margin)s.Value).ToList();


                var tradesCache = new DataCache("TradesCache");
                IEnumerable <KeyValuePair <string, object> > lstTrades = tradesCache.BulkGet(lstStrLogin);
                var lstTradesInfo = lstTrades.Select(s => (TradesInfo)s.Value).ToList();
                var lstPnl        = (from lt in lstTradesInfo
                                     group lt by lt.Login into g
                                     select new
                {
                    Login = g.Key,
                    Profit = g.Sum(k => k.Profit)
                }).ToList();


                var lstData = (from lm in lstMargins
                               join lp in lstPnl on lm.Login equals lp.Login
                               select new
                {
                    Login = lm.Login,
                    Balance = lm.Balance,
                    Pnl = lp.Profit
                }).ToList();

                return(Json(lstData, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                CurrentDeskLog.Error(ex.Message, ex);
            }


            return(Json(string.Empty, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get AllTrades from TradesCache and cacculate profit
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        public double GetPnl(int loginid)
        {
            double profits = 0;

            try
            {
                var tradesCache = new DataCache("TradesCache");

                var lstLogin = new List <string>();
                lstLogin.Add(loginid.StringTryParse());
                IEnumerable <KeyValuePair <string, object> > lstTrades = tradesCache.BulkGet(lstLogin);
                profits = lstTrades.Select(s => (TradesInfo)s.Value).ToList().Sum(s => s.Profit);
            }
            catch (Exception ex)
            {
                CurrentDeskLog.Error(ex.Message, ex);
            }

            return(profits);
        }