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

What MAMA does?

This API returns the MESA adaptive moving average (MAMA) values. The related REST API documentation is here


Including the MAMA namespace

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


using Avapi.AvapiMAMA

How to get a MAMA object?

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


...
Int_MAMA mama = 
	connection.GetQueryObject_MAMA();

Perform a MAMA Synchronous Request

To perform a MAMA request you have 2 options:

  1. The request with constants:

IAvapiResponse_MAMA Query(string symbol,
		MAMA_interval interval,
		MAMA_series_type series_type,
		float fastlimit [OPTIONAL],
		float slowlimit [OPTIONAL]);

  1. The request without constants:

IAvapiResponse_MAMA QueryPrimitive(string symbol,
		string interval,
		string series_type,
		string fastlimit [OPTIONAL],
		string slowlimit [OPTIONAL]);

Perform an MAMA Asynchronous Request

To perform an MAMA asynchronous request you have 2 options:

  1. The request with constants:

async Task<IAvapiResponse_MAMA> QueryAsync(string symbol,
		MAMA_interval interval,
		MAMA_series_type series_type,
		float fastlimit [OPTIONAL],
		float slowlimit [OPTIONAL]);

  1. The request without constants:

async Task<IAvapiResponse_MAMA> QueryAsync(string symbol,
		string interval,
		string series_type,
		string fastlimit [OPTIONAL],
		string slowlimit [OPTIONAL]);

Parameters

The parameters below are needed to perform the MAMA request.

  • symbol: The name of the equity
  • interval: The time interval between two consecutive data points in the time series.
  • series_type: The price type in the time series. The types supported are: close, open, high, low
  • fastlimit [OPTIONAL]: It is a optional value; positive floats are accepted. By default, fastlimit=0.01
  • slowlimit [OPTIONAL]: It is a optional value; positive floats are accepted. By default, slowlimit=0.01

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:

  • MAMA_interval
  • MAMA_series_type

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


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

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


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


MAMA Response

The response of a MAMA request is an object that implements the IAvapiResponse_MAMA interface.


public interface IAvapiResponse_MAMA
{
    string RawData
    {
        get;
    }
    IAvapiResponse_MAMA_Content Data
    {
        get;
    }
}

The IAvapiResponse_MAMA 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_MAMA_Content.

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


using System;
using System.IO;
using Avapi.AvapiMAMA;

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 MAMA query object
            Int_MAMA mama =
                connection.GetQueryObject_MAMA();

            // Perform the MAMA request and get the result
            IAvapiResponse_MAMA mamaResponse = 
            mama.Query(
                 "MSFT",
                 Const_MAMA.MAMA_interval.n_1min,
                 Const_MAMA.MAMA_series_type.close,
                 0.2f,
                 0.2f);

            // Printout the results
            Console.WriteLine("******** RAW DATA MAMA ********");
            Console.WriteLine(mamaResponse.RawData);

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

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


using Avapi;
using Avapi.AvapiMAMA
using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private IAvapiConnection m_connection = AvapiConnection.Instance;
        private Int_MAMA m_mama;
        private IAvapiResponse_MAMA m_mamaResponse;

        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 MAMA query object
            m_mama = m_connection.GetQueryObject_MAMA();

            base.OnLoad(e);
        }

        private async void MAMAAsyncButton_Click(object sender, EventArgs e)
        {
            // Perform the MAMA request and get the result
            m_mamaResponse = 
                await m_mama.QueryAsync(
                     "MSFT",
                     Const_MAMA.MAMA_interval.n_1min,
                     Const_MAMA.MAMA_series_type.close,
                     0.2f,
                     0.2f);

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

            resultTextBox.AppendText("******** STRUCTURED DATA MAMA ********" + "\n");
            var data = m_mamaResponse.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("FastLimit: " + data.MetaData.FastLimit + "\n");
                resultTextBox.AppendText("SlowLimit: " + data.MetaData.SlowLimit + "\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("MAMA: " + technical.MAMA + "\n");
                    resultTextBox.AppendText("FAMA: " + technical.FAMA + "\n");
                    resultTextBox.AppendText("DateTime: " + technical.DateTime + "\n");
                    resultTextBox.AppendText("========================" + "\n");
                }
            }
        }
    }
}

Clone this wiki locally