Exemple #1
0
        public static async Task <UICompanyRowDetail> GetUICompanyRowDetailTask(string symbol, List <UIComapnyRow> companyList)
        {
            try
            {
                FmgSingleQuote singleQuote = await RetrieveJsonDataHelper.RetrieveFmgSingleQuote(symbol);

                UIComapnyRow       companyRow = companyList.Find(c => c.Symbol == symbol);
                Company            company    = DatabaseHelper.GetCompanyFromDb(symbol);
                UICompanyRowDetail result     = new UICompanyRowDetail
                {
                    Symbol           = symbol,
                    Name             = company.CompanyName,
                    Price            = companyRow.Price,
                    Open             = companyRow.Open,
                    High             = singleQuote.dayHigh,
                    Low              = singleQuote.dayLow,
                    Volume           = companyRow.Volume,
                    Change           = companyRow.PriceChange,
                    ChangePercentage = companyRow.ChangePercentage,
                    Description      = company.Description,
                    Ceo              = company.CEO,
                    Industry         = company.Industry,
                    Sector           = company.Sector
                };
                return(result);
            }
            catch (SystemException ex)
            {
                throw new SystemException(ex.Message);
            }
        }
 public static FmgSingleQuote ParseStringToSingleQuote(string response)
 {
     try
     {
         List <FmgSingleQuote> list = JsonConvert.DeserializeObject <List <FmgSingleQuote> >(response);
         if (list.Count != 0)
         {
             FmgSingleQuote quote = list[0];
             return(quote);
         }
         else
         {
             throw new SystemException($"Parse single quote null {response}");
         }
     }
     catch (Newtonsoft.Json.JsonSerializationException ex)
     {
         throw new SystemException($"Parse Single Quote exception. {response}" + ex.Message);
     }
 }
        public static async Task <FmgSingleQuote> RetrieveFmgSingleQuote(string symbol)
        {
            try
            {
                string url          = FmgBaseUrl + FmgSingleQuoteUrl + symbol;
                var    responseTask = RetrieveFromUrl(url);
                string response     = await responseTask;
                if (response == "{ }" || string.IsNullOrEmpty(response))
                {
                    throw new ArgumentException("FmgMajorIndexes null. " + url);
                }

                FmgSingleQuote quote = ParseStringToSingleQuote(response);
                return(quote);
            }
            catch (SystemException ex)
            {
                throw new SystemException(ex.Message);
            }
        }
Exemple #4
0
        public static async Task <UIComapnyRow> GetUICompanyRowTaskBySymbol(string symbol) //ex FormatException
        {                                                                                  //ex: ArgumentException, SystemException, FormatException
            try
            {
                DateTime start = DateTime.Now;

                FmgQuoteOnlyPrice fmgQuoteOnlyPrice = await RetrieveJsonDataHelper.RetrieveFmgQuoteOnlyPrice(symbol); //ex: ArgumentException

                FmgSingleQuote singleQuote = await RetrieveJsonDataHelper.RetrieveFmgSingleQuote(symbol);             //ex: ArgumentException

                DateTime end      = DateTime.Now;
                TimeSpan timeSpan = new TimeSpan();
                timeSpan = end - start;
                Console.Out.WriteLine($"Time: {timeSpan.TotalMilliseconds} mills for {symbol}");

                Company company = DatabaseHelper.GetCompanyFromDb(symbol);         //ex: SystemException

                return(new UIComapnyRow(company, fmgQuoteOnlyPrice, singleQuote)); //ex: FormatException
            }
            catch (SystemException ex)
            {
                throw new SystemException(ex.Message);
            }
        }
Exemple #5
0
        private static async Task <UIComapnyRow> GetWatchUIComanyRowTask(int userId, Company company)
        {
            try
            {
                Stopwatch sw = Stopwatch.StartNew();

                FmgQuoteOnlyPrice fmgQuoteOnlyPrice =
                    await RetrieveJsonDataHelper.RetrieveFmgQuoteOnlyPrice(company.Symbol);

                FmgSingleQuote singleQuote = await RetrieveJsonDataHelper.RetrieveFmgSingleQuote(company.Symbol);

                UIComapnyRow
                    companyRow = new UIComapnyRow(company, fmgQuoteOnlyPrice, singleQuote); //ex: FormatException

                sw.Stop();
                Console.Out.WriteLine(
                    $"\n---- Add one companyRow to result in GetWatchUICompanyRowList: {company.Symbol}, time: {sw.Elapsed.TotalMilliseconds} mills");
                return(companyRow);
            }
            catch (SystemException ex)
            {
                throw new SystemException(ex.Message);
            }
        }