Esempio n. 1
0
        private async void History3m(object sender, RoutedEventArgs e)
        {
            var values = new ChartValues <DateTimePoint>();
            Int_TIME_SERIES_DAILY_ADJUSTED time_series_daily_adjusted = _connection.GetQueryObject_TIME_SERIES_DAILY_ADJUSTED();

            try
            {
                IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED time_series_daily_adjustedResponse =
                    await time_series_daily_adjusted.QueryPrimitiveAsync(_args.Symbol);

                var data = time_series_daily_adjustedResponse.Data;
                if (data.Error)
                {
                    MessageBox.Show("Failed to fetch data", "Error");
                    SeriesCollection[0].Values = Read("\\3m.csv");
                    ResetZoomOnClick(sender, e);
                    return;
                }
                else
                {
                    DateTime offset = new DateTime(DateTime.Today.Year, DateTime.Today.Month - 3, DateTime.Today.Day);
                    DateTime temp;
                    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.adjustedclose) * _exchangeRate));
                        }
                    }
                    Write("\\3m.csv", values);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Previse zahteva poslato u kratkom vremene server misli da si spamer! Oladi malo sa kliktanjem.");
                SeriesCollection[0].Values = Read("\\3m.csv");
                ResetZoomOnClick(sender, e);
                return;
            }
            SeriesCollection[0].Values = Read("\\3m.csv");
            //SeriesCollection[0].Values = values;
            ResetZoomOnClick(sender, e);
        }
Esempio n. 2
0
        static async Task <int> FetchandUpdateCurrentPriceDataforCompany(string ticker)
        {
            IAvapiConnection connection  = AvapiConnection.Instance;
            float            recentprice = 0;
            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED m_time_series_daily_adjustedResponse;

            // Set up the connection and pass the API_KEY provided by alphavantage.co
            connection.Connect("7NIMRBR8G8UB7P8C");

            // Get the TIME_SERIES_MONTHLY_ADJUSTED query object
            Int_TIME_SERIES_DAILY_ADJUSTED time_series_daily_adjusted =
                connection.GetQueryObject_TIME_SERIES_DAILY_ADJUSTED();

            // Perform the TIME_SERIES_MONTHLY_ADJUSTED request and get the result
            m_time_series_daily_adjustedResponse = await time_series_daily_adjusted.QueryAsync(
                ticker);

            var data = m_time_series_daily_adjustedResponse.Data;

            WebClient client = new WebClient();
            Uri       uri    = new Uri("http://web.engr.oregonstate.edu/~jonesty/UpdateCompanyInfo.php");

            NameValueCollection parameters = new NameValueCollection();

            if (data.Error)
            {
                Console.WriteLine(data.ErrorMessage);
                return(0);
            }
            else
            {
                int counter = 0;
                foreach (var timeseries in data.TimeSeries)
                {
                    if (counter < 1)
                    {
                        recentprice = float.Parse(timeseries.adjustedclose, CultureInfo.InvariantCulture.NumberFormat);
                    }
                    counter = counter + 1;
                }
            }
            Console.WriteLine(recentprice);
            Console.WriteLine(ticker);
            parameters.Add("tickersymbol", ticker);
            parameters.Add("currentprice", recentprice.ToString());

            client.UploadValuesAsync(uri, parameters);
            return(1);
        }
        public void AlphaVantageDownloader(ProgramContext programContext, string symbol)
        {
            // Creating the connection object
            IAvapiConnection connection = AvapiConnection.Instance;

            // Set up the connection and pass the API_KEY provided by alphavantage.co
            connection.Connect(programContext.AlphaVantageKey);

            // Get the TIME_SERIES_DAILY query object
            Int_TIME_SERIES_DAILY_ADJUSTED time_series_daily_adjusted =
                connection.GetQueryObject_TIME_SERIES_DAILY_ADJUSTED();

            // Perform the TIME_SERIES_DAILY request and get the result
            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED time_series_dailyResponse =
                time_series_daily_adjusted.Query(
                    symbol,
                    Const_TIME_SERIES_DAILY_ADJUSTED.TIME_SERIES_DAILY_ADJUSTED_outputsize.full);

            // Printout the results
            Console.WriteLine("******** RAW DATA TIME_SERIES_DAILY ********");
            Console.WriteLine(time_series_dailyResponse.RawData);

            Console.WriteLine("******** STRUCTURED DATA TIME_SERIES_DAILY ********");
            var data = time_series_dailyResponse.Data;

            if (data.Error)
            {
                Console.WriteLine(data.ErrorMessage);
            }
            else
            {
                Console.WriteLine("Information: " + data.MetaData.Information);
                Console.WriteLine("Symbol: " + data.MetaData.Symbol);
                Console.WriteLine("LastRefreshed: " + data.MetaData.LastRefreshed);
                Console.WriteLine("OutputSize: " + data.MetaData.OutputSize);
                Console.WriteLine("TimeZone: " + data.MetaData.TimeZone);
                Console.WriteLine("========================");
                Console.WriteLine("========================");

                //data.TimeSeries.OrderBy(x => x.DateTime);   //testing this out
                foreach (var timeseries in data.TimeSeries)
                {
                    DailyStockRecord tempDailyStockRecord = new DailyStockRecord();

                    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("Dividend: " + timeseries.dividendamount);
                    Console.WriteLine("========================");



                    tempDailyStockRecord.Symbol        = data.MetaData.Symbol;
                    tempDailyStockRecord.Open          = Convert.ToDecimal(timeseries.open);
                    tempDailyStockRecord.High          = Convert.ToDecimal(timeseries.high);
                    tempDailyStockRecord.Low           = Convert.ToDecimal(timeseries.low);
                    tempDailyStockRecord.Close         = Convert.ToDecimal(timeseries.close);
                    tempDailyStockRecord.Volume        = Convert.ToDecimal(timeseries.volume);
                    tempDailyStockRecord.Date          = Convert.ToDateTime(timeseries.DateTime);
                    tempDailyStockRecord.Dividend      = Convert.ToDecimal(timeseries.dividendamount);
                    tempDailyStockRecord.AdjustedClose = Convert.ToDecimal(timeseries.adjustedclose);


                    programContext.DailyRecordList.Add(tempDailyStockRecord);


                    //tempDailyStockRecord.VolitilityRating = calculations.CalcVolitilityRating(dailyRecordList);
                }
            }
        }
Esempio n. 4
0
        // dataSize must be "full" or "compact"
        public void RetrieveData(String dataSize)
        {
            /*
             *   *******Init Objects for StockExchange ********
             *
             */


            IAvapiConnection connection = AvapiConnection.Instance;

            connection.Connect("CJ7QO45PVDJ8371Q");
            Int_TIME_SERIES_DAILY_ADJUSTED TSD = connection.GetQueryObject_TIME_SERIES_DAILY_ADJUSTED();

            //ASX
            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED ASXResponse =
                TSD.QueryPrimitive(
                    "^AXJO",
                    dataSize
                    );

            this.ASX = ASXResponse.Data;
            //ESTOX
            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED ESTOXResponse =
                TSD.QueryPrimitive(
                    "^STOXX50E",
                    dataSize
                    );

            this.ESTOX = ESTOXResponse.Data;

            //FTSE
            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED FTSEResponse =
                TSD.QueryPrimitive(
                    "^FTSE",
                    dataSize
                    );

            this.FTSE = FTSEResponse.Data;

            //SP500
            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED SP500Response =
                TSD.QueryPrimitive(
                    "^GSPC",
                    dataSize
                    );

            this.SP500 = SP500Response.Data;

            //N225
            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED N225Response =
                TSD.QueryPrimitive(
                    "^N225",
                    dataSize
                    );

            this.N225 = N225Response.Data;

            //HANG
            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED HangResponse =
                TSD.QueryPrimitive(
                    "^HSI",
                    dataSize
                    );

            this.HANG = HangResponse.Data;



            /*
             *   ******* CurrencyExchange ********
             *
             *   Possible to request only 1 value, see currency_exchange_rate
             */

            //EURUSD
            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED EURUSDResponse =
                TSD.QueryPrimitive(
                    "EURUSD=X",
                    dataSize
                    );

            this.EURUSD = EURUSDResponse.Data;

            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED EURGBPResponse =
                TSD.QueryPrimitive(
                    "EURGBP=X",
                    dataSize
                    );

            this.EURGBP = EURGBPResponse.Data;

            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED EURJPYResponse =
                TSD.QueryPrimitive(
                    "EURJPY=X",
                    dataSize
                    );

            this.EURJPY = EURJPYResponse.Data;

            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED AUDUSDResponse =
                TSD.QueryPrimitive(
                    "AUDUSD=X",
                    dataSize
                    );

            this.AUDUSD = AUDUSDResponse.Data;

            IAvapiResponse_TIME_SERIES_DAILY_ADJUSTED USDHKDResponse =
                TSD.QueryPrimitive(
                    "USDHKD=X",
                    dataSize
                    );

            this.USDHKD = USDHKDResponse.Data;
        }