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

What CMO does?

This API returns the Chande momentum oscillator (CMO) values. The related REST API documentation is here


Including the CMO namespace

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


using Avapi.AvapiCMO

How to get a CMO object?

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


...
Int_CMO cmo = 
	connection.GetQueryObject_CMO();

Perform a CMO Synchronous Request

To perform a CMO request you have 2 options:

  1. The request with constants:

IAvapiResponse_CMO Query(string symbol,
		CMO_interval interval,
		int time_period,
		CMO_series_type series_type);

  1. The request without constants:

IAvapiResponse_CMO QueryPrimitive(string symbol,
		string interval,
		string time_period,
		string series_type);

Perform an CMO Asynchronous Request

To perform an CMO asynchronous request you have 2 options:

  1. The request with constants:

async Task<IAvapiResponse_CMO> QueryAsync(string symbol,
		CMO_interval interval,
		int time_period,
		CMO_series_type series_type);

  1. The request without constants:

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

Parameters

The parameters below are needed to perform the CMO 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 CMO value.
  • 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:

  • CMO_interval
  • CMO_series_type

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


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

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


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


CMO Response

The response of a CMO request is an object that implements the IAvapiResponse_CMO interface.


public interface IAvapiResponse_CMO
{
    string RawData
    {
        get;
    }
    IAvapiResponse_CMO_Content Data
    {
        get;
    }
}

The IAvapiResponse_CMO 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_CMO_Content.

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


using System;
using System.IO;
using Avapi.AvapiCMO;

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 CMO query object
            Int_CMO cmo =
                connection.GetQueryObject_CMO();

            // Perform the CMO request and get the result
            IAvapiResponse_CMO cmoResponse = 
            cmo.Query(
                 "MSFT",
                 Const_CMO.CMO_interval.n_1min,
                 10,
                 Const_CMO.CMO_series_type.close);

            // Printout the results
            Console.WriteLine("******** RAW DATA CMO ********");
            Console.WriteLine(cmoResponse.RawData);

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

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


using Avapi;
using Avapi.AvapiCMO
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private IAvapiConnection m_connection = AvapiConnection.Instance;
        private Int_CMO m_cmo;
        private IAvapiResponse_CMO m_cmoResponse;

        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 CMO query object
            m_cmo = m_connection.GetQueryObject_CMO();

            base.OnLoad(e);
        }

        private async void CMOAsyncButton_Click(object sender, EventArgs e)
        {
            // Perform the CMO request and get the result
            m_cmoResponse = 
                await m_cmo.QueryAsync(
                     "MSFT",
                     Const_CMO.CMO_interval.n_1min,
                     10,
                     Const_CMO.CMO_series_type.close);

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

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

Clone this wiki locally