Skip to content

HT_DCPHASE

essegisolutions edited this page Jan 13, 2018 · 8 revisions

What HT_DCPHASE does?

This API returns the Hilbert transform, dominant cycle phase (HT_DCPHASE) values. The related REST API documentation is here


Including the HT_DCPHASE namespace

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


using Avapi.AvapiHT_DCPHASE

How to get a HT_DCPHASE object?

The HT_DCPHASE 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 HT_DCPHASE from it.


...
Int_HT_DCPHASE htdcphase = 
	connection.GetQueryObject_HT_DCPHASE();

Perform a HT_DCPHASE Synchronous Request

To perform a HT_DCPHASE request you have 2 options:

  1. The request with constants:

IAvapiResponse_HT_DCPHASE Query(string symbol,
		HT_DCPHASE_interval interval,
		HT_DCPHASE_series_type series_type);

  1. The request without constants:

IAvapiResponse_HT_DCPHASE QueryPrimitive(string symbol,
		string interval,
		string series_type);

Perform an HT_DCPHASE Asynchronous Request

To perform an HT_DCPHASE asynchronous request you have 2 options:

  1. The request with constants:

async Task<IAvapiResponse_HT_DCPHASE> QueryAsync(string symbol,
		HT_DCPHASE_interval interval,
		HT_DCPHASE_series_type series_type);

  1. The request without constants:

async Task<IAvapiResponse_HT_DCPHASE> QueryAsync(string symbol,
		string interval,
		string series_type);

Parameters

The parameters below are needed to perform the HT_DCPHASE request.

  • symbol: The name of the equity
  • interval: The time interval between two consecutive data points in the time series.
  • series_type: The price type in the time series. The types supported are: close, open, high, low

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:

  • HT_DCPHASE_interval
  • HT_DCPHASE_series_type

HT_DCPHASE_interval: The time interval between two consecutive data points in the time series.


public enum HT_DCPHASE_interval
{
	none,
	n_1min,
	n_5min,
	n_15min,
	n_30min,
	n_60min,
	daily,
	weekly,
	monthly
}

HT_DCPHASE_series_type: The price type in the time series. The types supported are: close, open, high, low


public enum HT_DCPHASE_series_type
{
	none,
	close,
	open,
	high,
	low
}


HT_DCPHASE Response

The response of a HT_DCPHASE request is an object that implements the IAvapiResponse_HT_DCPHASE interface.


public interface IAvapiResponse_HT_DCPHASE
{
    string RawData
    {
        get;
    }
    IAvapiResponse_HT_DCPHASE_Content Data
    {
        get;
    }
}

The IAvapiResponse_HT_DCPHASE 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_HT_DCPHASE_Content.

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


using System;
using System.IO;
using Avapi.AvapiHT_DCPHASE;

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 HT_DCPHASE query object
            Int_HT_DCPHASE ht_dcphase =
                connection.GetQueryObject_HT_DCPHASE();

            // Perform the HT_DCPHASE request and get the result
            IAvapiResponse_HT_DCPHASE ht_dcphaseResponse = 
            ht_dcphase.Query(
                 "MSFT",
                 Const_HT_DCPHASE.HT_DCPHASE_interval.n_1min,
                 Const_HT_DCPHASE.HT_DCPHASE_series_type.close);

            // Printout the results
            Console.WriteLine("******** RAW DATA HT_DCPHASE ********");
            Console.WriteLine(ht_dcphaseResponse.RawData);

            Console.WriteLine("******** STRUCTURED DATA HT_DCPHASE ********");
            var data = ht_dcphaseResponse.Data;
            if (data.Error)
            {
                Console.WriteLine(data.ErrorMessage);
            }
            else
            {
                Console.WriteLine("Symbol: " + data.MetaData.Symbol);
                Console.WriteLine("Indicator: " + data.MetaData.Indicator);
                Console.WriteLine("LastRefreshed: " + data.MetaData.LastRefreshed);
                Console.WriteLine("Interval: " + data.MetaData.Interval);
                Console.WriteLine("SeriesType: " + data.MetaData.SeriesType);
                Console.WriteLine("TimeZone: " + data.MetaData.TimeZone);
                Console.WriteLine("========================");
                Console.WriteLine("========================");
                foreach (var technical in data.TechnicalIndicator)
                {
                    Console.WriteLine("HT_DCPHASE: " + technical.HT_DCPHASE);
                    Console.WriteLine("DateTime: " + technical.DateTime);
                    Console.WriteLine("========================");
                }
            }
        }
    }
}

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


using Avapi;
using Avapi.AvapiHT_DCPHASE
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private IAvapiConnection m_connection = AvapiConnection.Instance;
        private Int_HT_DCPHASE m_ht_dcphase;
        private IAvapiResponse_HT_DCPHASE m_ht_dcphaseResponse;

        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 HT_DCPHASE query object
            m_ht_dcphase = m_connection.GetQueryObject_HT_DCPHASE();

            base.OnLoad(e);
        }

        private async void HT_DCPHASEAsyncButton_Click(object sender, EventArgs e)
        {
            // Perform the HT_DCPHASE request and get the result
            m_ht_dcphaseResponse = 
                await m_ht_dcphase.QueryAsync(
                     "MSFT",
                     Const_HT_DCPHASE.HT_DCPHASE_interval.n_1min,
                     Const_HT_DCPHASE.HT_DCPHASE_series_type.close);

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

            resultTextBox.AppendText("******** STRUCTURED DATA HT_DCPHASE ********" + "\n");
            var data = m_ht_dcphaseResponse.Data;
            if (data.Error)
            {
                resultTextBox.AppendText(data.ErrorMessage + "\n");
            }
            else
            {
                resultTextBox.AppendText("Symbol: " + data.MetaData.Symbol + "\n");
                resultTextBox.AppendText("Indicator: " + data.MetaData.Indicator + "\n");
                resultTextBox.AppendText("LastRefreshed: " + data.MetaData.LastRefreshed + "\n");
                resultTextBox.AppendText("Interval: " + data.MetaData.Interval + "\n");
                resultTextBox.AppendText("SeriesType: " + data.MetaData.SeriesType + "\n");
                resultTextBox.AppendText("TimeZone: " + data.MetaData.TimeZone + "\n");
                resultTextBox.AppendText("========================" + "\n");
                resultTextBox.AppendText("========================" + "\n");
                foreach (var technical in data.TechnicalIndicator)
                {
                    resultTextBox.AppendText("HT_DCPHASE: " + technical.HT_DCPHASE + "\n");
                    resultTextBox.AppendText("DateTime: " + technical.DateTime + "\n");
                    resultTextBox.AppendText("========================" + "\n");
                }
            }
        }
    }
}

Clone this wiki locally