public async static Task <Akcii> GetAkcii() { var url = "http://feeds.mse.mk/service/FreeMSEFeeds.svc/ticker/JSON/{token}"; Akcii ak = new Akcii(); using (HttpClient client = new HttpClient()) { var response = await client.GetAsync(url); var json = await response.Content.ReadAsStringAsync(); var st = JsonConvert.DeserializeObject <Akcii>(json); ak = st as Akcii; } return(ak); }
private async void showAkcii() { stek.Children.Clear(); if (k == 0) { Akcii akciiList = null; await Task.Run(async() => { akciiList = await AQIAPI.GetAkcii(); }); await Task.Run(async() => { cryresult = await GetCrypto.GetResult(); }); Label lbb = new Label() { Text = "Сеуште не е отворена берзата\nПробајте повторно подоцна", HorizontalTextAlignment = TextAlignment.Center }; if (akciiList.GetTickerJSONResult.Count == 0) { stek.Children.Add(lbb); Frame frfr1 = new Frame() { CornerRadius = 5, HasShadow = true, Margin = new Thickness(10, 5), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, BackgroundColor = Color.FromHex("#121212") }; Grid grgr1 = new Grid(); Label kripto = new Label() { Text = "Криптовалути:", FontSize = 20, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#6cf58e"), HorizontalTextAlignment = TextAlignment.Start }; grgr1.Children.Add(kripto, 0, 0); Grid.SetColumnSpan(kripto, 2); for (int i = 0; i < cryresult.Count; i++) { Label ime = new Label() { Text = cryresult[i].name, FontSize = 14, FontAttributes = FontAttributes.Bold, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Start }; Label perCh = new Label() { Text = cryresult[i].price_change_percentage_24h.ToString() + "%", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Center }; Label cena = new Label() { Text = cryresult[i].current_price.ToString() + "€", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.End }; if (cryresult[i].price_change_percentage_24h >= 0) { perCh.TextColor = Color.FromHex("#6cf58e"); } else { perCh.TextColor = Color.FromHex("#FF7595"); } grgr1.Children.Add(ime, 0, i + 1); grgr1.Children.Add(perCh, 1, i + 1); grgr1.Children.Add(cena, 2, i + 1); } frfr1.Content = grgr1; stek.Children.Add(frfr1); return; } ordered = akciiList.GetTickerJSONResult.OrderBy(f => f.AvgPerChange).ToList(); all = ordered; } ordered.Reverse(); int forBrojac = 0; foreach (var akcija in ordered) { if (forBrojac == 2) { Frame frfr1 = new Frame() { CornerRadius = 5, HasShadow = true, Margin = new Thickness(10, 5), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, BackgroundColor = Color.FromHex("#121212") }; Grid grgr1 = new Grid(); Label kripto = new Label() { Text = "Криптовалути:", FontSize = 20, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#6cf58e"), HorizontalTextAlignment = TextAlignment.Start }; grgr1.Children.Add(kripto, 0, 0); Grid.SetColumnSpan(kripto, 2); for (int i = 0; i < cryresult.Count; i++) { Label ime = new Label() { Text = cryresult[i].name, FontSize = 14, FontAttributes = FontAttributes.Bold, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Start }; Label perCh = new Label() { Text = cryresult[i].price_change_percentage_24h.ToString() + "%", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Center }; Label cena = new Label() { Text = cryresult[i].current_price.ToString() + "€", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.End }; if (cryresult[i].price_change_percentage_24h >= 0) { perCh.TextColor = Color.FromHex("#6cf58e"); } else { perCh.TextColor = Color.FromHex("#FF7595"); } grgr1.Children.Add(ime, 0, i + 1); grgr1.Children.Add(perCh, 1, i + 1); grgr1.Children.Add(cena, 2, i + 1); } frfr1.Content = grgr1; stek.Children.Add(frfr1); } Frame frfr = new Frame() { CornerRadius = 5, HasShadow = true, Margin = new Thickness(10, 5), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, BackgroundColor = Color.FromHex("#121212") }; Grid grgr = new Grid(); grgr.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2, GridUnitType.Star) }); grgr.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); grgr.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(5, GridUnitType.Star) }); grgr.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(3, GridUnitType.Star) }); string titleText = String.Format("{0} ({1})", akcija.Description, akcija.Symbol); Label title = new Label() { Text = titleText, FontSize = 15, FontAttributes = FontAttributes.Bold, TextColor = Color.White }; Label priceNow = new Label() { Text = akcija.AvgPrice.ToString() + " den.", FontSize = 15, FontAttributes = FontAttributes.Bold, TextColor = Color.White }; string perChange = akcija.AvgPerChange.ToString() + "%"; if (akcija.AvgPerChange > 0) { perChange = "+" + akcija.AvgPerChange.ToString() + "%"; } string absChange = akcija.AvgAbsChange.ToString() + " den."; if (akcija.AvgAbsChange > 0) { absChange = "+" + akcija.AvgAbsChange.ToString() + " den."; } if (akcija.AvgPerChange > 0) { priceNow.TextColor = Color.FromHex("#6cf58e"); } else { priceNow.TextColor = Color.FromHex("#FF7595"); } Label percent = new Label() { Text = perChange, FontSize = 13, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, TextColor = Color.White }; Label abs = new Label() { Text = absChange, FontSize = 13, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, TextColor = Color.White }; grgr.Children.Add(title, 0, 0); grgr.Children.Add(priceNow, 0, 1); grgr.Children.Add(percent, 1, 0); grgr.Children.Add(abs, 1, 1); frfr.Content = grgr; stek.Children.Add(frfr); forBrojac++; } if (ordered.Count < 2) { Frame frfr1 = new Frame() { CornerRadius = 5, HasShadow = true, Margin = new Thickness(10, 5), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Start, BackgroundColor = Color.FromHex("#121212") }; Grid grgr1 = new Grid(); Label kripto = new Label() { Text = "Криптовалути:", FontSize = 20, FontAttributes = FontAttributes.Bold, TextColor = Color.FromHex("#6cf58e"), HorizontalTextAlignment = TextAlignment.Start }; grgr1.Children.Add(kripto, 0, 0); Grid.SetColumnSpan(kripto, 2); for (int i = 0; i < cryresult.Count; i++) { Label ime = new Label() { Text = cryresult[i].name, FontSize = 14, FontAttributes = FontAttributes.Bold, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Start }; Label perCh = new Label() { Text = cryresult[i].price_change_percentage_24h.ToString() + "%", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Center }; Label cena = new Label() { Text = cryresult[i].current_price.ToString() + "€", FontSize = 14, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.End }; if (cryresult[i].price_change_percentage_24h >= 0) { perCh.TextColor = Color.FromHex("#6cf58e"); } else { perCh.TextColor = Color.FromHex("#FF7595"); } grgr1.Children.Add(ime, 0, i + 1); grgr1.Children.Add(perCh, 1, i + 1); grgr1.Children.Add(cena, 2, i + 1); } frfr1.Content = grgr1; stek.Children.Add(frfr1); } }