Exemplo n.º 1
0
        private ChartValues <DateTimePoint> GetData()
        {
            var values = new ChartValues <DateTimePoint>();
            Int_TIME_SERIES_DAILY time_series_daily =
                _connection.GetQueryObject_TIME_SERIES_DAILY();

            try
            {
                IAvapiResponse_TIME_SERIES_DAILY time_series_dailyResponse =
                    time_series_daily.Query(
                        _args.Symbol,
                        Const_TIME_SERIES_DAILY.TIME_SERIES_DAILY_outputsize.compact);


                var data = time_series_dailyResponse.Data;
                if (data.Error)
                {
                    MessageBox.Show("Failed to fetch data", "Error");
                    SeriesCollection[0].Values = Read("\\init.csv");
                    return((ChartValues <DateTimePoint>)SeriesCollection[0].Values);
                }
                else
                {
                    if (_args.DefaultCurrency != "USD")
                    {
                        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", "Error");
                            }
                            else
                            {
                                _exchangeRate = double.Parse(data2.ExchangeRate);

                                foreach (var timeseries in data.TimeSeries)
                                {
                                    values.Add(new DateTimePoint(DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                                                                 double.Parse(timeseries.close) * _exchangeRate));
                                }
                                Write("\\init.csv", values);
                            }
                        }
                        catch (NullReferenceException)
                        {
                            MessageBox.Show("Failed to fetch currency exchange rate for chosen currency. Values will be show in USD", "Error");
                            _exchangeRate = 1;
                            foreach (var timeseries in data.TimeSeries)
                            {
                                values.Add(new DateTimePoint(DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                                                             double.Parse(timeseries.close) * _exchangeRate));
                            }
                            YFormatter = val => "$" + val.ToString("0.##");
                            Write("\\init.csv", values);
                        }
                    }
                    else
                    {
                        _exchangeRate = 1;
                        foreach (var timeseries in data.TimeSeries)
                        {
                            values.Add(new DateTimePoint(DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                                                         double.Parse(timeseries.close) * _exchangeRate));
                        }
                        Write("\\init.csv", values);
                    }
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Suvise se upita salje serveru za krato vreme, misli da smo spameri. Oladi malo! Prikazuju se podaci koji su dostupni u skladstu podataka.", "Error");
                SeriesCollection[0].Values = Read("\\init.csv");
                return((ChartValues <DateTimePoint>)SeriesCollection[0].Values);
            }

            return(values);
        }
Exemplo n.º 2
0
        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());
        }
        private ChartValues <DateTimePoint> GetData()
        {
            var values = new ChartValues <DateTimePoint>();


            Int_DIGITAL_CURRENCY_DAILY digital_currency_daily =
                _connection.GetQueryObject_DIGITAL_CURRENCY_DAILY();

            try
            {
                IAvapiResponse_DIGITAL_CURRENCY_DAILY digital_currency_dailyResponse =
                    digital_currency_daily.QueryPrimitive(_args.Symbol, _args.DefaultCurrency);

                var data = digital_currency_dailyResponse.Data;
                if (data.Error && _args.DefaultCurrency == "USD")
                {
                    MessageBox.Show("Failed to fetch data", "Error");
                    Read("\\" + _args.Symbol + ".csv");
                    try
                    {
                        return((ChartValues <DateTimePoint>)SeriesCollection[0].Values);
                    }
                    catch
                    {
                    }
                }
                else if (data.Error)
                {
                    digital_currency_dailyResponse = digital_currency_daily.QueryPrimitive(_args.Symbol, "USD");
                    var data1 = digital_currency_dailyResponse.Data;
                    if (data1.Error)
                    {
                        MessageBox.Show("Failed to fetch data", "Error");
                        values = Read("\\" + _args.Symbol + ".csv");
                        try
                        {
                            return((ChartValues <DateTimePoint>)SeriesCollection[0].Values);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else
                    {
                        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 exchange rate data for " + _args, "Error");
                            }

                            else
                            {
                                _exchangeRate = double.Parse(data2.ExchangeRate);
                                DateTime offset = DateTime.Now.AddYears(-1);
                                DateTime temp;
                                foreach (var timeseries in data1.TimeSeries)
                                {
                                    temp = DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                                    if (temp > offset)
                                    {
                                        values.Add(new DateTimePoint(temp, double.Parse(timeseries.Close) * _exchangeRate));
                                    }
                                }
                                Write("\\" + _args.Symbol + ".csv", values);
                            }
                        }
                        catch (NullReferenceException)
                        {
                            MessageBox.Show("Failed to fetch currency exchange rate for " + _args.DefaultCurrency + " currency. Values will be show in USD", "Error");
                            DateTime offset = DateTime.Now.AddYears(-1);
                            DateTime temp;
                            _exchangeRate = 1;
                            foreach (var timeseries in data1.TimeSeries)
                            {
                                temp = DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                                if (temp > offset)
                                {
                                    values.Add(new DateTimePoint(temp, double.Parse(timeseries.Close)));
                                }
                            }
                            YFormatter = val => "$" + val.ToString("0.##");
                            Write("\\" + _args.Symbol + ".csv", values);
                        }
                    }
                }
                else
                {
                    DateTime offset = DateTime.Now.AddYears(-1);
                    DateTime temp;
                    _exchangeRate = 1;
                    foreach (var timeseries in data.TimeSeries)
                    {
                        temp = DateTime.ParseExact(timeseries.DateTime, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                        if (temp > offset)
                        {
                            values.Add(new DateTimePoint(temp, double.Parse(timeseries.Close)));
                        }
                    }
                    Write("\\" + _args.Symbol + ".csv", values);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                values = Read("\\" + _args.Symbol + ".csv");
            }

            //SeriesCollection[0].Title = data.MetaData.DigitalCurrencyName;
            return(values);
        }