Skip to content

MINUS_DM

essegisolutions edited this page Jan 13, 2018 · 8 revisions

What MINUS_DM does?

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


Including the MINUS_DM namespace

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


using Avapi.AvapiMINUS_DM

How to get a MINUS_DM object?

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


...
Int_MINUS_DM minusdm = 
	connection.GetQueryObject_MINUS_DM();

Perform a MINUS_DM Synchronous Request

To perform a MINUS_DM request you have 2 options:

  1. The request with constants:

IAvapiResponse_MINUS_DM Query(string symbol,
		MINUS_DM_interval interval,
		int time_period);

  1. The request without constants:

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

Perform an MINUS_DM Asynchronous Request

To perform an MINUS_DM asynchronous request you have 2 options:

  1. The request with constants:

async Task<IAvapiResponse_MINUS_DM> QueryAsync(string symbol,
		MINUS_DM_interval interval,
		int time_period);

  1. The request without constants:

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

Parameters

The parameters below are needed to perform the MINUS_DM 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_DM 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_DM_interval

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


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


MINUS_DM Response

The response of a MINUS_DM request is an object that implements the IAvapiResponse_MINUS_DM interface.


public interface IAvapiResponse_MINUS_DM
{
    string RawData
    {
        get;
    }
    IAvapiResponse_MINUS_DM_Content Data
    {
        get;
    }
}

The IAvapiResponse_MINUS_DM 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_DM_Content.

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


using System;
using System.IO;
using Avapi.AvapiMINUS_DM;

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_DM query object
            Int_MINUS_DM minus_dm =
                connection.GetQueryObject_MINUS_DM();

            // Perform the MINUS_DM request and get the result
            IAvapiResponse_MINUS_DM minus_dmResponse = 
            minus_dm.Query(
                 "MSFT",
                 Const_MINUS_DM.MINUS_DM_interval.n_1min,
                 10);

            // Printout the results
            Console.WriteLine("******** RAW DATA MINUS_DM ********");
            Console.WriteLine(minus_dmResponse.RawData);

            Console.WriteLine("******** STRUCTURED DATA MINUS_DM ********");
            var data = minus_dmResponse.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_DM: " + technical.MINUS_DM);
                    Console.WriteLine("DateTime: " + technical.DateTime);
                    Console.WriteLine("========================");
                }
            }
        }
    }
}

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


using Avapi;
using Avapi.AvapiMINUS_DM
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private IAvapiConnection m_connection = AvapiConnection.Instance;
        private Int_MINUS_DM m_minus_dm;
        private IAvapiResponse_MINUS_DM m_minus_dmResponse;

        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_DM query object
            m_minus_dm = m_connection.GetQueryObject_MINUS_DM();

            base.OnLoad(e);
        }

        private async void MINUS_DMAsyncButton_Click(object sender, EventArgs e)
        {
            // Perform the MINUS_DM request and get the result
            m_minus_dmResponse = 
                await m_minus_dm.QueryAsync(
                     "MSFT",
                     Const_MINUS_DM.MINUS_DM_interval.n_1min,
                     10);

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

            resultTextBox.AppendText("******** STRUCTURED DATA MINUS_DM ********" + "\n");
            var data = m_minus_dmResponse.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_DM: " + technical.MINUS_DM + "\n");
                    resultTextBox.AppendText("DateTime: " + technical.DateTime + "\n");
                    resultTextBox.AppendText("========================" + "\n");
                }
            }
        }
    }
}

Clone this wiki locally