Skip to content

MINUS_DI

essegisolutions edited this page Jan 13, 2018 · 8 revisions

What MINUS_DI does?

This API returns the minus directional indicator (MINUS_DI) values. The related REST API documentation is here


Including the MINUS_DI namespace

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


using Avapi.AvapiMINUS_DI

How to get a MINUS_DI object?

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


...
Int_MINUS_DI minusdi = 
	connection.GetQueryObject_MINUS_DI();

Perform a MINUS_DI Synchronous Request

To perform a MINUS_DI request you have 2 options:

  1. The request with constants:

IAvapiResponse_MINUS_DI Query(string symbol,
		MINUS_DI_interval interval,
		int time_period);

  1. The request without constants:

IAvapiResponse_MINUS_DI QueryPrimitive(string symbol,
		string interval,
		string time_period);

Perform an MINUS_DI Asynchronous Request

To perform an MINUS_DI asynchronous request you have 2 options:

  1. The request with constants:

async Task<IAvapiResponse_MINUS_DI> QueryAsync(string symbol,
		MINUS_DI_interval interval,
		int time_period);

  1. The request without constants:

async Task<IAvapiResponse_MINUS_DI> QueryAsync(string symbol,
		string interval,
		string time_period);

Parameters

The parameters below are needed to perform the MINUS_DI request.

  • symbol: The name of the equity
  • interval: The time interval between two consecutive data points in the time series.
  • time_period: Number of data points used to calculate each MINUS_DI value.

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:

  • MINUS_DI_interval

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


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


MINUS_DI Response

The response of a MINUS_DI request is an object that implements the IAvapiResponse_MINUS_DI interface.


public interface IAvapiResponse_MINUS_DI
{
    string RawData
    {
        get;
    }
    IAvapiResponse_MINUS_DI_Content Data
    {
        get;
    }
}

The IAvapiResponse_MINUS_DI 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_MINUS_DI_Content.

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


using System;
using System.IO;
using Avapi.AvapiMINUS_DI;

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 MINUS_DI query object
            Int_MINUS_DI minus_di =
                connection.GetQueryObject_MINUS_DI();

            // Perform the MINUS_DI request and get the result
            IAvapiResponse_MINUS_DI minus_diResponse = 
            minus_di.Query(
                 "MSFT",
                 Const_MINUS_DI.MINUS_DI_interval.n_1min,
                 10);

            // Printout the results
            Console.WriteLine("******** RAW DATA MINUS_DI ********");
            Console.WriteLine(minus_diResponse.RawData);

            Console.WriteLine("******** STRUCTURED DATA MINUS_DI ********");
            var data = minus_diResponse.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("TimePeriod: " + data.MetaData.TimePeriod);
                Console.WriteLine("TimeZone: " + data.MetaData.TimeZone);
                Console.WriteLine("========================");
                Console.WriteLine("========================");
                foreach (var technical in data.TechnicalIndicator)
                {
                    Console.WriteLine("MINUS_DI: " + technical.MINUS_DI);
                    Console.WriteLine("DateTime: " + technical.DateTime);
                    Console.WriteLine("========================");
                }
            }
        }
    }
}

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


using Avapi;
using Avapi.AvapiMINUS_DI
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private IAvapiConnection m_connection = AvapiConnection.Instance;
        private Int_MINUS_DI m_minus_di;
        private IAvapiResponse_MINUS_DI m_minus_diResponse;

        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 MINUS_DI query object
            m_minus_di = m_connection.GetQueryObject_MINUS_DI();

            base.OnLoad(e);
        }

        private async void MINUS_DIAsyncButton_Click(object sender, EventArgs e)
        {
            // Perform the MINUS_DI request and get the result
            m_minus_diResponse = 
                await m_minus_di.QueryAsync(
                     "MSFT",
                     Const_MINUS_DI.MINUS_DI_interval.n_1min,
                     10);

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

            resultTextBox.AppendText("******** STRUCTURED DATA MINUS_DI ********" + "\n");
            var data = m_minus_diResponse.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("TimePeriod: " + data.MetaData.TimePeriod + "\n");
                resultTextBox.AppendText("TimeZone: " + data.MetaData.TimeZone + "\n");
                resultTextBox.AppendText("========================" + "\n");
                resultTextBox.AppendText("========================" + "\n");
                foreach (var technical in data.TechnicalIndicator)
                {
                    resultTextBox.AppendText("MINUS_DI: " + technical.MINUS_DI + "\n");
                    resultTextBox.AppendText("DateTime: " + technical.DateTime + "\n");
                    resultTextBox.AppendText("========================" + "\n");
                }
            }
        }
    }
}

Clone this wiki locally