Skip to content
essegisolutions edited this page Jan 13, 2018 · 8 revisions

What ADOSC does?

This API returns the Chaikin A/D oscillator (ADOSC) values. The related REST API documentation is here


Including the ADOSC namespace

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


using Avapi.AvapiADOSC

How to get a ADOSC object?

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


...
Int_ADOSC adosc = 
	connection.GetQueryObject_ADOSC();

Perform a ADOSC Synchronous Request

To perform a ADOSC request you have 2 options:

  1. The request with constants:

IAvapiResponse_ADOSC Query(string symbol,
		ADOSC_interval interval,
		int fastperiod [OPTIONAL],
		int slowperiod [OPTIONAL]);

  1. The request without constants:

IAvapiResponse_ADOSC QueryPrimitive(string symbol,
		string interval,
		string fastperiod [OPTIONAL],
		string slowperiod [OPTIONAL]);

Perform an ADOSC Asynchronous Request

To perform an ADOSC asynchronous request you have 2 options:

  1. The request with constants:

async Task<IAvapiResponse_ADOSC> QueryAsync(string symbol,
		ADOSC_interval interval,
		int fastperiod [OPTIONAL],
		int slowperiod [OPTIONAL]);

  1. The request without constants:

async Task<IAvapiResponse_ADOSC> QueryAsync(string symbol,
		string interval,
		string fastperiod [OPTIONAL],
		string slowperiod [OPTIONAL]);

Parameters

The parameters below are needed to perform the ADOSC request.

  • symbol: The name of the equity
  • interval: The time interval between two consecutive data points in the time series.
  • fastperiod [OPTIONAL]: It is a optional value; positive integers are accepted. By default, fastperiod=3
  • slowperiod [OPTIONAL]: It is a optional value; positive integers are accepted. By default, slowperiod=10

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:

  • ADOSC_interval

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


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


ADOSC Response

The response of a ADOSC request is an object that implements the IAvapiResponse_ADOSC interface.


public interface IAvapiResponse_ADOSC
{
    string RawData
    {
        get;
    }
    IAvapiResponse_ADOSC_Content Data
    {
        get;
    }
}

The IAvapiResponse_ADOSC 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_ADOSC_Content.

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


using System;
using System.IO;
using Avapi.AvapiADOSC;

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 ADOSC query object
            Int_ADOSC adosc =
                connection.GetQueryObject_ADOSC();

            // Perform the ADOSC request and get the result
            IAvapiResponse_ADOSC adoscResponse = 
            adosc.Query(
                 "MSFT",
                 Const_ADOSC.ADOSC_interval.n_1min,
                 10,
                 10);

            // Printout the results
            Console.WriteLine("******** RAW DATA ADOSC ********");
            Console.WriteLine(adoscResponse.RawData);

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

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


using Avapi;
using Avapi.AvapiADOSC
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private IAvapiConnection m_connection = AvapiConnection.Instance;
        private Int_ADOSC m_adosc;
        private IAvapiResponse_ADOSC m_adoscResponse;

        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 ADOSC query object
            m_adosc = m_connection.GetQueryObject_ADOSC();

            base.OnLoad(e);
        }

        private async void ADOSCAsyncButton_Click(object sender, EventArgs e)
        {
            // Perform the ADOSC request and get the result
            m_adoscResponse = 
                await m_adosc.QueryAsync(
                     "MSFT",
                     Const_ADOSC.ADOSC_interval.n_1min,
                     10,
                     10);

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

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

Clone this wiki locally