示例#1
0
        public ObservableCollection <CurrencyClass> parse(string path)
        {
            ObservableCollection <CurrencyClass> currencyList = new ObservableCollection <CurrencyClass>();

            path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\files\\" + path;
            using (TextFieldParser parser = new TextFieldParser(path))
            {
                parser.TextFieldType = FieldType.Delimited;
                parser.SetDelimiters(",");
                string link             = string.Empty;
                string keyForTimeseries = string.Empty;
                while (!parser.EndOfData)
                {
                    //Processing row

                    string[] fields = parser.ReadFields();

                    keyForTimeseries = "Time Series (Digital Currency Monthly)";
                    link             = "https://www.alphavantage.co/query?function=DIGITAL_CURRENCY_WEEKLY&symbol=" + fields[0] + "&market=CNY&apikey=9P2LP0T1YR34LBSK";
                    try
                    {
                        LoadJSON client = new LoadJSON();
                        client.endPoint = link;

                        string response = string.Empty;
                        //response = client.makeRequest();
                        currencyList.Add(new CurrencyClass {
                            Symbol = fields[0], Name = fields[1]
                        });
                    }
                    catch (Exception e) { }
                }
            }

            return(currencyList);
        }
        //npr DIGITAL_CURRENCY_MONTHLY, BTC -> za mesecni bitcoin
        private void loadJSON(CurrencyIntervalType interval, string symbol)
        {
            LoadJSON client           = new LoadJSON();
            string   link             = string.Empty;
            string   keyForTimeseries = string.Empty;

            switch (interval)
            {
            case CurrencyIntervalType.DIGITAL_CURRENCY_INTRADAY:
                link             = "https://www.alphavantage.co/query?function=DIGITAL_CURRENCY_INTRADAY&symbol=" + symbol + "&market=" + referentCurrency.Symbol + "&apikey=9P2LP0T1YR34LBSK";
                keyForTimeseries = "Time Series (Digital Currency Intraday)";
                break;

            case CurrencyIntervalType.DIGITAL_CURRENCY_DAILY:
                link             = "https://www.alphavantage.co/query?function=DIGITAL_CURRENCY_DAILY&symbol=" + symbol + "&market=" + referentCurrency.Symbol + "&apikey=9P2LP0T1YR34LBSK";
                keyForTimeseries = "Time Series (Digital Currency Daily)";
                break;

            case CurrencyIntervalType.DIGITAL_CURRENCY_WEEKLY:
                link             = "https://www.alphavantage.co/query?function=DIGITAL_CURRENCY_WEEKLY&symbol=" + symbol + "&market=" + referentCurrency.Symbol + "&apikey=9P2LP0T1YR34LBSK";
                keyForTimeseries = "Time Series (Digital Currency Weekly)";
                break;

            case CurrencyIntervalType.DIGITAL_CURRENCY_MONTHLY:
                link             = "https://www.alphavantage.co/query?function=DIGITAL_CURRENCY_MONTHLY&symbol=" + symbol + "&market=" + referentCurrency.Symbol + "&apikey=9P2LP0T1YR34LBSK";
                keyForTimeseries = "Time Series (Digital Currency Monthly)";
                break;

            case CurrencyIntervalType.TIME_SERIES_INTRADAY:
                link             = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=" + symbol + "&interval=15min&outputsize=full&apikey=9P2LP0T1YR34LBSK";
                keyForTimeseries = "Time Series (15min)";
                break;

            case CurrencyIntervalType.TIME_SERIES_DAILY:
                link             = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + symbol + "&outputsize=full&apikey=9P2LP0T1YR34LBSK";
                keyForTimeseries = "Time Series (Daily)";
                break;

            case CurrencyIntervalType.TIME_SERIES_WEEKLY:
                link             = "https://www.alphavantage.co/query?function=TIME_SERIES_WEEKLY&symbol=" + symbol + "&apikey=9P2LP0T1YR34LBSK";
                keyForTimeseries = "Weekly Time Series";
                break;

            default:
                link             = "https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=" + symbol + "&apikey=9P2LP0T1YR34LBSK";
                keyForTimeseries = "Monthly Time Series";
                break;
            }

            client.endPoint = link;

            string response = string.Empty;

            response = client.makeRequest();

            if (!response.Contains("Error") && !response.Contains("kindly contact support") && !string.IsNullOrEmpty(response))
            {
                var jObj = JsonConvert.DeserializeObject <dynamic>(response);
                ShowingCurrencyClass showingCurrency = new ShowingCurrencyClass();

                showingCurrency.Metadata = jObj["Meta Data"].ToObject <Dictionary <string, string> >();
                showingCurrency.Type     = interval;

                //u zavisnosti od intervala se prosledjuje kljuc za timeseries
                showingCurrency.Timeseries = jObj[keyForTimeseries].ToObject <Dictionary <string, Dictionary <string, double> > >();

                shownCurrenciesList.Add(showingCurrency);

                addNewTab(showingCurrency);
            }
            else
            {
                MessageBox.Show("unable to collect data");
            }
        }