Skip to content

TIME_SERIES_DAILY

essegisolutions edited this page Feb 24, 2018 · 8 revisions

What TIME_SERIES_DAILY does?

This API returns daily time series (date, daily open, daily high, daily low, daily close, daily volume) of the equity specified, covering up to 20 years of historical data. The most recent data point is the current trading day. The related REST API documentation is here


Including the TIME_SERIES_DAILY namespace

The very first thing to do before diving into TIME_SERIES_DAILY calls is to include the right namespace.


using Avapi.AvapiTIME_SERIES_DAILY

How to get a TIME_SERIES_DAILY object?

The TIME_SERIES_DAILY object is retrieved from the Connection object.

The snippet below shows how to get the Connection object:


...
IAvapiConnection connection = AvapiConnection.Instance
connection.Connect("Your Alpha Vantage API Key !!!!");
...

Once you got the Connection object you can extract the TIME_SERIES_DAILY from it.


...
Int_TIME_SERIES_DAILY timeseriesdaily = 
	connection.GetQueryObject_TIME_SERIES_DAILY();

Perform a TIME_SERIES_DAILY Synchronous Request

To perform a TIME_SERIES_DAILY request you have 2 options:

  1. The request with constants:

IAvapiResponse_TIME_SERIES_DAILY Query(string symbol,
		TIME_SERIES_DAILY_outputsize outputsize [OPTIONAL]);

  1. The request without constants:

IAvapiResponse_TIME_SERIES_DAILY QueryPrimitive(string symbol,
		string outputsize [OPTIONAL]);

Perform an TIME_SERIES_DAILY Asynchronous Request

To perform an TIME_SERIES_DAILY asynchronous request you have 2 options:

  1. The request with constants:

async Task<IAvapiResponse_TIME_SERIES_DAILY> QueryAsync(string symbol,
		TIME_SERIES_DAILY_outputsize outputsize [OPTIONAL]);

  1. The request without constants:

async Task<IAvapiResponse_TIME_SERIES_DAILY> QueryAsync(string symbol,
		string outputsize [OPTIONAL]);

Parameters

The parameters below are needed to perform the TIME_SERIES_DAILY request.

  • symbol: The name of the equity
  • outputsize [OPTIONAL]: It is a optional value; compact and full are accepted with the following specifications: compact returns only the latest data points; full returns the full-length time series of up to 20 years of historical data. The "compact" option is recommended if you would like to reduce the data size of each API call.

Please notice that the info above are copied from the official alphavantage documentation, that you can find here.


The request with constants

The request with constants implies the use of different enums:

  • TIME_SERIES_DAILY_outputsize

TIME_SERIES_DAILY_outputsize: It is a optional value; compact and full are accepted with the following specifications: compact returns only the latest data points; full returns the full-length time series of up to 20 years of historical data. The "compact" option is recommended if you would like to reduce the data size of each API call.


public enum TIME_SERIES_DAILY_outputsize
{
	none,
	compact,
	full
}


TIME_SERIES_DAILY Response

The response of a TIME_SERIES_DAILY request is an object that implements the IAvapiResponse_TIME_SERIES_DAILY interface.


public interface IAvapiResponse_TIME_SERIES_DAILY
{
    string RawData
    {
        get;
    }
    IAvapiResponse_TIME_SERIES_DAILY_Content Data
    {
        get;
    }
}

The IAvapiResponse_TIME_SERIES_DAILY interface has two members: RawData and Data.

  • RawData: represents the json response in string format.
  • Data: It represents the parsed response in an object implementing the interface IAvapiResponse_TIME_SERIES_DAILY_Content.

Complete Example of a Console App: Display the result of a TIME_SERIES_DAILY request by using the method Query (synchronous request)


using System;
using System.IO;
using Avapi.AvapiTIME_SERIES_DAILY;

namespace Avapi
{
    public class Example
    {
        static void Main()
        {
            // Creating the connection object
            IAvapiConnection connection = AvapiConnection.Instance;

            // Set up the connection and pass the API_KEY provided by alphavantage.co
            connection.Connect("Your Alpha Vantage API Key !!!!");

            // Get the TIME_SERIES_DAILY query object
            Int_TIME_SERIES_DAILY time_series_daily =
                connection.GetQueryObject_TIME_SERIES_DAILY();

            // Perform the TIME_SERIES_DAILY request and get the result
            IAvapiResponse_TIME_SERIES_DAILY time_series_dailyResponse = 
            time_series_daily.Query(
                 "MSFT",
                 Const_TIME_SERIES_DAILY.TIME_SERIES_DAILY_outputsize.compact);

            // 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("========================");
                foreach (var timeseries in data.TimeSeries)
                {
                    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("========================");
                }
            }
        }
    }
}

Complete Example of a Windows Form App: Display the result of a TIME_SERIES_DAILY request by using the method QueryAsync (asynchronous request)


using Avapi;
using Avapi.AvapiTIME_SERIES_DAILY
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private IAvapiConnection m_connection = AvapiConnection.Instance;
        private Int_TIME_SERIES_DAILY m_time_series_daily;
        private IAvapiResponse_TIME_SERIES_DAILY m_time_series_dailyResponse;

        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            // Set up the connection and pass the API_KEY provided by alphavantage.co
            m_connection.Connect("Your Alpha Vantage Key");

            // Get the TIME_SERIES_DAILY query object
            m_time_series_daily = m_connection.GetQueryObject_TIME_SERIES_DAILY();

            base.OnLoad(e);
        }

        private async void TIME_SERIES_DAILYAsyncButton_Click(object sender, EventArgs e)
        {
            // Perform the TIME_SERIES_DAILY request and get the result
            m_time_series_dailyResponse = 
                await m_time_series_daily.QueryAsync(
                     "MSFT",
                     Const_TIME_SERIES_DAILY.TIME_SERIES_DAILY_outputsize.compact);

             // Show the results
            resultTextBox.AppendText("******** RAW DATA TIME_SERIES_DAILY ********" + "\n");
            resultTextBox.AppendText(m_time_series_dailyResponse.RawData + "\n");

            resultTextBox.AppendText("******** STRUCTURED DATA TIME_SERIES_DAILY ********" + "\n");
            var data = m_time_series_dailyResponse.Data;
            if (data.Error)
            {
                resultTextBox.AppendText(data.ErrorMessage + "\n");
            }
            else
            {
                resultTextBox.AppendText("Information: " + data.MetaData.Information + "\n");
                resultTextBox.AppendText("Symbol: " + data.MetaData.Symbol + "\n");
                resultTextBox.AppendText("LastRefreshed: " + data.MetaData.LastRefreshed + "\n");
                resultTextBox.AppendText("OutputSize: " + data.MetaData.OutputSize + "\n");
                resultTextBox.AppendText("TimeZone: " + data.MetaData.TimeZone + "\n");
                resultTextBox.AppendText("========================" + "\n");
                resultTextBox.AppendText("========================" + "\n");
                foreach (var timeseries in data.TimeSeries)
                {
                    resultTextBox.AppendText("open: " + timeseries.open + "\n");
                    resultTextBox.AppendText("high: " + timeseries.high + "\n");
                    resultTextBox.AppendText("low: " + timeseries.low + "\n");
                    resultTextBox.AppendText("close: " + timeseries.close + "\n");
                    resultTextBox.AppendText("volume: " + timeseries.volume + "\n");
                    resultTextBox.AppendText("DateTime: " + timeseries.DateTime + "\n");
                    resultTextBox.AppendText("========================" + "\n");
                }
            }
        }
    }
}

Clone this wiki locally