Skip to content

PLUS_DM

essegisolutions edited this page Jan 13, 2018 · 8 revisions

What PLUS_DM does?

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


Including the PLUS_DM namespace

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


using Avapi.AvapiPLUS_DM

How to get a PLUS_DM object?

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


...
Int_PLUS_DM plusdm = 
	connection.GetQueryObject_PLUS_DM();

Perform a PLUS_DM Synchronous Request

To perform a PLUS_DM request you have 2 options:

  1. The request with constants:

IAvapiResponse_PLUS_DM Query(string symbol,
		PLUS_DM_interval interval,
		int time_period);

  1. The request without constants:

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

Perform an PLUS_DM Asynchronous Request

To perform an PLUS_DM asynchronous request you have 2 options:

  1. The request with constants:

async Task<IAvapiResponse_PLUS_DM> QueryAsync(string symbol,
		PLUS_DM_interval interval,
		int time_period);

  1. The request without constants:

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

Parameters

The parameters below are needed to perform the PLUS_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 PLUS_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:

  • PLUS_DM_interval

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


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


PLUS_DM Response

The response of a PLUS_DM request is an object that implements the IAvapiResponse_PLUS_DM interface.


public interface IAvapiResponse_PLUS_DM
{
    string RawData
    {
        get;
    }
    IAvapiResponse_PLUS_DM_Content Data
    {
        get;
    }
}

The IAvapiResponse_PLUS_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_PLUS_DM_Content.

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


using System;
using System.IO;
using Avapi.AvapiPLUS_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 PLUS_DM query object
            Int_PLUS_DM plus_dm =
                connection.GetQueryObject_PLUS_DM();

            // Perform the PLUS_DM request and get the result
            IAvapiResponse_PLUS_DM plus_dmResponse = 
            plus_dm.Query(
                 "MSFT",
                 Const_PLUS_DM.PLUS_DM_interval.n_1min,
                 10);

            // Printout the results
            Console.WriteLine("******** RAW DATA PLUS_DM ********");
            Console.WriteLine(plus_dmResponse.RawData);

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

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


using Avapi;
using Avapi.AvapiPLUS_DM
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private IAvapiConnection m_connection = AvapiConnection.Instance;
        private Int_PLUS_DM m_plus_dm;
        private IAvapiResponse_PLUS_DM m_plus_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 PLUS_DM query object
            m_plus_dm = m_connection.GetQueryObject_PLUS_DM();

            base.OnLoad(e);
        }

        private async void PLUS_DMAsyncButton_Click(object sender, EventArgs e)
        {
            // Perform the PLUS_DM request and get the result
            m_plus_dmResponse = 
                await m_plus_dm.QueryAsync(
                     "MSFT",
                     Const_PLUS_DM.PLUS_DM_interval.n_1min,
                     10);

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

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

Clone this wiki locally