private void SetValues(object sender, EventArgs e)
        {
            var values = new ChartValues <DateTimePoint>();

            Int_TIME_SERIES_INTRADAY time_series_intraday =
                _connection.GetQueryObject_TIME_SERIES_INTRADAY();

            try
            {
                IAvapiResponse_TIME_SERIES_INTRADAY time_series_intradayResponse =
                    time_series_intraday.Query(
                        _args.Symbol,
                        Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_1min,
                        Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_outputsize.compact);

                var data = time_series_intradayResponse.Data;
                if (data.Error)
                {
                    //MessageBox.Show("Failed to fetch data", "Error");
                }
                else
                {
                    Console.WriteLine("Information: " + data.MetaData.Information);
                    Console.WriteLine("Symbol: " + data.MetaData.Symbol);
                    Console.WriteLine("LastRefreshed: " + data.MetaData.LastRefreshed);
                    Console.WriteLine("Interval: " + data.MetaData.Interval);
                    Console.WriteLine("OutputSize: " + data.MetaData.OutputSize);
                    Console.WriteLine("TimeZone: " + data.MetaData.TimeZone);
                    Console.WriteLine("========================");
                    Console.WriteLine("========================");
                    int count = 12;
                    foreach (var timeseries in data.TimeSeries)
                    {
                        if (count <= 0)
                        {
                            break;
                        }
                        Console.WriteLine("open: " + timeseries.open);
                        Console.WriteLine("high: " + timeseries.high);
                        Console.WriteLine("low: " + timeseries.low);
                        Console.WriteLine("close: " + timeseries.close);
                        Console.WriteLine("volume: " + timeseries.volume);
                        Console.WriteLine("DateTime: " + timeseries.DateTime);
                        Console.WriteLine("========================");

                        values.Insert(0, new DateTimePoint
                        {
                            Value    = double.Parse(timeseries.close),
                            DateTime = DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)
                        });
                    }
                    LastHourSeries[0].Values = values;
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Failed to send request", "Error");
            }
        }
        private async Task <Finance[]> parseFinance()
        {
            IAvapiConnection connection = AvapiConnection.Instance;

            connection.Connect($"{BadAPI.Startup.Configuration["APIKeys:AlphaVantage"]}");

            // Get the Int_TIME_SERIES_INTRADAY query object
            Int_TIME_SERIES_INTRADAY time_intraday =
                connection.GetQueryObject_TIME_SERIES_INTRADAY();

            // Perform the Int_TIME_SERIES_INTRADAY request and get the result
            IAvapiResponse_TIME_SERIES_INTRADAY time_series_intradayResponse =
                time_intraday.Query(
                    "MS",
                    Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_1min,
                    Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_outputsize.compact);



            List <Finance[]> financeResults = new List <Finance[]>();
            var data = time_series_intradayResponse.Data;

            foreach (var timeseries in data.TimeSeries)
            {
                Finance[] finance = new Finance[1];
                finance[0] = new Finance();
                if (finance[0] != null)
                {
                    finance[0].symbol = data.MetaData.Symbol;
                    finance[0].date   = timeseries.DateTime.ToString();
                    finance[0].open   = timeseries.open;
                    finance[0].close  = timeseries.close;
                    finance[0].high   = timeseries.high;
                    finance[0].low    = timeseries.low;
                    finance[0].volume = timeseries.volume;
                    financeResults.Add(finance);
                }
            }

            return(CombineResponses(financeResults));
        }
        private RealTimeData GetData()
        {
            if (_args.DefaultCurrency != "USD" && _exchangeRate == 1 && _args.Type != TypeSeries.CURRENCY)
            {
                try
                {
                    Int_CURRENCY_EXCHANGE_RATE            currency_exchange_rate         = _connection.GetQueryObject_CURRENCY_EXCHANGE_RATE();
                    IAvapiResponse_CURRENCY_EXCHANGE_RATE currency_exchange_rateResponse =
                        currency_exchange_rate.QueryPrimitive("USD", _args.DefaultCurrency);
                    var data2 = currency_exchange_rateResponse.Data;
                    if (data2.Error)
                    {
                        MessageBox.Show("Failed to fetch data for exchage rate", "Error");
                    }
                    else
                    {
                        _exchangeRate = double.Parse(data2.ExchangeRate);
                    }
                }
                catch (NullReferenceException)
                {
                    MessageBox.Show("Failed to fetch currency exchange rate for chosen currency. Values will be show in USD", "Error");
                }
            }

            if (_args.Type == TypeSeries.STOCK)
            {
                Int_TIME_SERIES_INTRADAY time_series_intraday =
                    _connection.GetQueryObject_TIME_SERIES_INTRADAY();

                try
                {
                    //Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval cst = Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_1min;
                    //if (Refreshrate == "1 minute(s)")
                    //{
                    //    cst = Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_1min;
                    //}
                    //else if (Refreshrate == "5 minutes(s)")
                    //{
                    //    cst = Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_5min;
                    //}
                    //else if (Refreshrate == "15 minute(s)")
                    //{
                    //    cst = Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_15min;
                    //}
                    //else if (Refreshrate == "30 minute(s)")
                    //{
                    //    cst = Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_30min;
                    //}
                    //else if (Refreshrate == "60 minute(s)")
                    //{
                    //    cst = Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_60min;
                    //}
                    //else
                    //{
                    //    cst = Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.none;
                    //}
                    IAvapiResponse_TIME_SERIES_INTRADAY time_series_intradayResponse =
                        time_series_intraday.Query(
                            _args.Symbol,
                            Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_interval.n_1min,
                            Const_TIME_SERIES_INTRADAY.TIME_SERIES_INTRADAY_outputsize.compact);

                    var data = time_series_intradayResponse.Data;
                    if (data.Error)
                    {
                        MessageBox.Show("Failed to fetch data for " + _args.Symbol, "Error");
                    }
                    else
                    {
                        return(new RealTimeData
                        {
                            Value = double.Parse(data.TimeSeries.First().close) * _exchangeRate,
                            Date = DateTime.ParseExact(data.TimeSeries.First().DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                            Trend = 0
                        });
                    }
                }
                catch (Exception)
                {
                    //MessageBox.Show("Failed to send request", "Error");
                    Console.WriteLine("Desila je greska za deonice!");
                }
            }
            else if (_args.Type == TypeSeries.DIGITAL_CURRENCY)
            {
                Int_DIGITAL_CURRENCY_INTRADAY digital_currency_intraday =
                    _connection.GetQueryObject_DIGITAL_CURRENCY_INTRADAY();
                try
                {
                    IAvapiResponse_DIGITAL_CURRENCY_INTRADAY digital_currency_intradayResponse =
                        digital_currency_intraday.QueryPrimitive(_args.Symbol, "USD");

                    var data = digital_currency_intradayResponse.Data;
                    if (data.Error)
                    {
                        MessageBox.Show("Failed to fetch data for " + _args.FullName);
                    }
                    else
                    {
                        return(new RealTimeData
                        {
                            Value = double.Parse(data.TimeSeries.First().Price) * _exchangeRate,
                            Date = DateTime.ParseExact(data.TimeSeries.First().DateTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                            Trend = 0
                        });
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Desila je greska za kripto valute!");
                }
            }
            else if (_args.Type == TypeSeries.CURRENCY)
            {
                try
                {
                    Int_CURRENCY_EXCHANGE_RATE            currency_exchange_rate         = _connection.GetQueryObject_CURRENCY_EXCHANGE_RATE();
                    IAvapiResponse_CURRENCY_EXCHANGE_RATE currency_exchange_rateResponse =
                        currency_exchange_rate.QueryPrimitive(_args.Symbol, _args.DefaultCurrency);
                    var data2 = currency_exchange_rateResponse.Data;
                    if (data2.Error)
                    {
                        MessageBox.Show("Failed to fetch data for exchage rate for " + _args.Symbol, "Error");
                    }
                    else
                    {
                        var temp = new RealTimeData
                        {
                            Value = double.Parse(data2.ExchangeRate),
                            Date  = DateTime.Now,
                            Trend = 0
                        };
                        Write(temp);
                        return(temp);
                    }
                }
                catch (NullReferenceException)
                {
                    MessageBox.Show("Failed to fetch data for exchage rate for " + _args.Symbol, "Error");
                }
            }

            return(new RealTimeData());
        }