-
Notifications
You must be signed in to change notification settings - Fork 2
This API returns the triple exponential moving average (T3) values. The related REST API documentation is here
The very first thing to do before diving into T3 calls is to include the right namespace.
using Avapi.AvapiT3
The T3 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 T3 from it.
...
Int_T3 t3 =
connection.GetQueryObject_T3();
To perform a T3 request you have 2 options:
- The request with constants:
IAvapiResponse_T3 Query(string symbol,
T3_interval interval,
int time_period,
T3_series_type series_type);
- The request without constants:
IAvapiResponse_T3 QueryPrimitive(string symbol,
string interval,
string time_period,
string series_type);
To perform an T3 asynchronous request you have 2 options:
- The request with constants:
async Task<IAvapiResponse_T3> QueryAsync(string symbol,
T3_interval interval,
int time_period,
T3_series_type series_type);
- The request without constants:
async Task<IAvapiResponse_T3> QueryAsync(string symbol,
string interval,
string time_period,
string series_type);
The parameters below are needed to perform the T3 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 moving average 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 implies the use of different enums:
- T3_interval
- T3_series_type
T3_interval: The time interval between two consecutive data points in the time series.
public enum T3_interval
{
none,
n_1min,
n_5min,
n_15min,
n_30min,
n_60min,
daily,
weekly,
monthly
}
T3_series_type: The price type in the time series. The types supported are: close, open, high, low
public enum T3_series_type
{
none,
close,
open,
high,
low
}
The response of a T3 request is an object that implements the IAvapiResponse_T3 interface.
public interface IAvapiResponse_T3
{
string RawData
{
get;
}
IAvapiResponse_T3_Content Data
{
get;
}
}
The IAvapiResponse_T3 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_T3_Content.
Complete Example of a Console App: Display the result of a T3 request by using the method Query (synchronous request)
using System;
using System.IO;
using Avapi.AvapiT3;
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 T3 query object
Int_T3 t3 =
connection.GetQueryObject_T3();
// Perform the T3 request and get the result
IAvapiResponse_T3 t3Response =
t3.Query(
"MSFT",
Const_T3.T3_interval.n_1min,
10,
Const_T3.T3_series_type.close);
// Printout the results
Console.WriteLine("******** RAW DATA T3 ********");
Console.WriteLine(t3Response.RawData);
Console.WriteLine("******** STRUCTURED DATA T3 ********");
var data = t3Response.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("VolumeFactor: " + data.MetaData.VolumeFactor);
Console.WriteLine("SeriesType: " + data.MetaData.SeriesType);
Console.WriteLine("TimeZone: " + data.MetaData.TimeZone);
Console.WriteLine("========================");
Console.WriteLine("========================");
foreach (var technical in data.TechnicalIndicator)
{
Console.WriteLine("T3: " + technical.T3);
Console.WriteLine("DateTime: " + technical.DateTime);
Console.WriteLine("========================");
}
}
}
}
}
Complete Example of a Windows Form App: Display the result of a T3 request by using the method QueryAsync (asynchronous request)
using Avapi;
using Avapi.AvapiT3
using System;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private IAvapiConnection m_connection = AvapiConnection.Instance;
private Int_T3 m_t3;
private IAvapiResponse_T3 m_t3Response;
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 T3 query object
m_t3 = m_connection.GetQueryObject_T3();
base.OnLoad(e);
}
private async void T3AsyncButton_Click(object sender, EventArgs e)
{
// Perform the T3 request and get the result
m_t3Response =
await m_t3.QueryAsync(
"MSFT",
Const_T3.T3_interval.n_1min,
10,
Const_T3.T3_series_type.close);
// Show the results
resultTextBox.AppendText("******** RAW DATA T3 ********" + "\n");
resultTextBox.AppendText(m_t3Response.RawData + "\n");
resultTextBox.AppendText("******** STRUCTURED DATA T3 ********" + "\n");
var data = m_t3Response.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("VolumeFactor: " + data.MetaData.VolumeFactor + "\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("T3: " + technical.T3 + "\n");
resultTextBox.AppendText("DateTime: " + technical.DateTime + "\n");
resultTextBox.AppendText("========================" + "\n");
}
}
}
}
}