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()); }