-
Notifications
You must be signed in to change notification settings - Fork 2
APO
This API returns the absolute price oscillator (APO) values. The related REST API documentation is here
The very first thing to do before diving into APO calls is to include the right namespace.
using Avapi.AvapiAPO
The APO 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 APO from it.
...
Int_APO apo =
connection.GetQueryObject_APO();
To perform a APO request you have 2 options:
- The request with constants:
IAvapiResponse_APO Query(string symbol,
APO_interval interval,
APO_series_type series_type,
int fastperiod [OPTIONAL],
int slowperiod [OPTIONAL],
APO_matype matype [OPTIONAL]);
- The request without constants:
IAvapiResponse_APO QueryPrimitive(string symbol,
string interval,
string series_type,
string fastperiod [OPTIONAL],
string slowperiod [OPTIONAL],
string matype [OPTIONAL]);
To perform an APO asynchronous request you have 2 options:
- The request with constants:
async Task<IAvapiResponse_APO> QueryAsync(string symbol,
APO_interval interval,
APO_series_type series_type,
int fastperiod [OPTIONAL],
int slowperiod [OPTIONAL],
APO_matype matype [OPTIONAL]);
- The request without constants:
async Task<IAvapiResponse_APO> QueryAsync(string symbol,
string interval,
string series_type,
string fastperiod [OPTIONAL],
string slowperiod [OPTIONAL],
string matype [OPTIONAL]);
The parameters below are needed to perform the APO 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
- fastperiod [OPTIONAL]: It is a optional value; positive integers are accepted. By default, fastperiod=12
- slowperiod [OPTIONAL]: It is a optional value; positive integers are accepted. By default, slowperiod=26
- matype [OPTIONAL]: Moving average type, it is a optional value. By default: matype=0, check the Alphavantage documentation for the mapping.
Please notice that the info above are copied from the official alphavantage documentation, that you can find here.
The request with constants implies the use of different enums:
- APO_interval
- APO_series_type
- APO_matype
APO_interval: The time interval between two consecutive data points in the time series.
public enum APO_interval
{
none,
n_1min,
n_5min,
n_15min,
n_30min,
n_60min,
daily,
weekly,
monthly
}
APO_series_type: The price type in the time series. The types supported are: close, open, high, low
public enum APO_series_type
{
none,
close,
open,
high,
low
}
APO_matype: Moving average type, it is a optional value. By default: matype=0, check the Alphavantage documentation for the mapping.
public enum APO_matype
{
none,
n_0,
n_1,
n_2,
n_3,
n_4,
n_5,
n_6,
n_7,
n_8
}
The response of a APO request is an object that implements the IAvapiResponse_APO interface.
public interface IAvapiResponse_APO
{
string RawData
{
get;
}
IAvapiResponse_APO_Content Data
{
get;
}
}
The IAvapiResponse_APO 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_APO_Content.
Complete Example of a Console App: Display the result of a APO request by using the method Query (synchronous request)
using System;
using System.IO;
using Avapi.AvapiAPO;
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 APO query object
Int_APO apo =
connection.GetQueryObject_APO();
// Perform the APO request and get the result
IAvapiResponse_APO apoResponse =
apo.Query(
"MSFT",
Const_APO.APO_interval.n_1min,
Const_APO.APO_series_type.close,
10,
10,
Const_APO.APO_matype.n_0);
// Printout the results
Console.WriteLine("******** RAW DATA APO ********");
Console.WriteLine(apoResponse.RawData);
Console.WriteLine("******** STRUCTURED DATA APO ********");
var data = apoResponse.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("FastPeriod: " + data.MetaData.FastPeriod);
Console.WriteLine("SlowPeriod: " + data.MetaData.SlowPeriod);
Console.WriteLine("MAType: " + data.MetaData.MAType);
Console.WriteLine("SeriesType: " + data.MetaData.SeriesType);
Console.WriteLine("TimeZone: " + data.MetaData.TimeZone);
Console.WriteLine("========================");
Console.WriteLine("========================");
foreach (var technical in data.TechnicalIndicator)
{
Console.WriteLine("APO: " + technical.APO);
Console.WriteLine("DateTime: " + technical.DateTime);
Console.WriteLine("========================");
}
}
}
}
}
Complete Example of a Windows Form App: Display the result of a APO request by using the method QueryAsync (asynchronous request)
using Avapi;
using Avapi.AvapiAPO
using System;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private IAvapiConnection m_connection = AvapiConnection.Instance;
private Int_APO m_apo;
private IAvapiResponse_APO m_apoResponse;
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 APO query object
m_apo = m_connection.GetQueryObject_APO();
base.OnLoad(e);
}
private async void APOAsyncButton_Click(object sender, EventArgs e)
{
// Perform the APO request and get the result
m_apoResponse =
await m_apo.QueryAsync(
"MSFT",
Const_APO.APO_interval.n_1min,
Const_APO.APO_series_type.close,
10,
10,
Const_APO.APO_matype.n_0);
// Show the results
resultTextBox.AppendText("******** RAW DATA APO ********" + "\n");
resultTextBox.AppendText(m_apoResponse.RawData + "\n");
resultTextBox.AppendText("******** STRUCTURED DATA APO ********" + "\n");
var data = m_apoResponse.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("FastPeriod: " + data.MetaData.FastPeriod + "\n");
resultTextBox.AppendText("SlowPeriod: " + data.MetaData.SlowPeriod + "\n");
resultTextBox.AppendText("MAType: " + data.MetaData.MAType + "\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("APO: " + technical.APO + "\n");
resultTextBox.AppendText("DateTime: " + technical.DateTime + "\n");
resultTextBox.AppendText("========================" + "\n");
}
}
}
}
}