-
Notifications
You must be signed in to change notification settings - Fork 2
ULTOSC
This API returns the ultimate oscillator (ULTOSC) values. The related REST API documentation is here
The very first thing to do before diving into ULTOSC calls is to include the right namespace.
using Avapi.AvapiULTOSC
The ULTOSC 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 ULTOSC from it.
...
Int_ULTOSC ultosc =
connection.GetQueryObject_ULTOSC();
To perform a ULTOSC request you have 2 options:
- The request with constants:
IAvapiResponse_ULTOSC Query(string symbol,
ULTOSC_interval interval,
int timeperiod1 [OPTIONAL],
int timeperiod2 [OPTIONAL],
int timeperiod3 [OPTIONAL]);
- The request without constants:
IAvapiResponse_ULTOSC QueryPrimitive(string symbol,
string interval,
string timeperiod1 [OPTIONAL],
string timeperiod2 [OPTIONAL],
string timeperiod3 [OPTIONAL]);
To perform an ULTOSC asynchronous request you have 2 options:
- The request with constants:
async Task<IAvapiResponse_ULTOSC> QueryAsync(string symbol,
ULTOSC_interval interval,
int timeperiod1 [OPTIONAL],
int timeperiod2 [OPTIONAL],
int timeperiod3 [OPTIONAL]);
- The request without constants:
async Task<IAvapiResponse_ULTOSC> QueryAsync(string symbol,
string interval,
string timeperiod1 [OPTIONAL],
string timeperiod2 [OPTIONAL],
string timeperiod3 [OPTIONAL]);
The parameters below are needed to perform the ULTOSC request.
- symbol: The name of the equity
- interval: The time interval between two consecutive data points in the time series.
- timeperiod1 [OPTIONAL]: The first time period for the indicator. It is a optional value; positive integers are accepted. By default, timeperiod1=7
- timeperiod2 [OPTIONAL]: The second time period for the indicator. It is a optional value; positive integers are accepted. By default, timeperiod2=14
- timeperiod3 [OPTIONAL]: The third time period for the indicator. It is a optional value; positive integers are accepted. By default, timeperiod3=28
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:
- ULTOSC_interval
ULTOSC_interval: The time interval between two consecutive data points in the time series.
public enum ULTOSC_interval
{
none,
n_1min,
n_5min,
n_15min,
n_30min,
n_60min,
daily,
weekly,
monthly
}
The response of a ULTOSC request is an object that implements the IAvapiResponse_ULTOSC interface.
public interface IAvapiResponse_ULTOSC
{
string RawData
{
get;
}
IAvapiResponse_ULTOSC_Content Data
{
get;
}
}
The IAvapiResponse_ULTOSC 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_ULTOSC_Content.
Complete Example of a Console App: Display the result of a ULTOSC request by using the method Query (synchronous request)
using System;
using System.IO;
using Avapi.AvapiULTOSC;
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 ULTOSC query object
Int_ULTOSC ultosc =
connection.GetQueryObject_ULTOSC();
// Perform the ULTOSC request and get the result
IAvapiResponse_ULTOSC ultoscResponse =
ultosc.Query(
"MSFT",
Const_ULTOSC.ULTOSC_interval.n_1min,
10,
10,
10);
// Printout the results
Console.WriteLine("******** RAW DATA ULTOSC ********");
Console.WriteLine(ultoscResponse.RawData);
Console.WriteLine("******** STRUCTURED DATA ULTOSC ********");
var data = ultoscResponse.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("TimePeriod1: " + data.MetaData.TimePeriod1);
Console.WriteLine("TimePeriod2: " + data.MetaData.TimePeriod2);
Console.WriteLine("TimePeriod3: " + data.MetaData.TimePeriod3);
Console.WriteLine("TimeZone: " + data.MetaData.TimeZone);
Console.WriteLine("========================");
Console.WriteLine("========================");
foreach (var technical in data.TechnicalIndicator)
{
Console.WriteLine("ULTOSC: " + technical.ULTOSC);
Console.WriteLine("DateTime: " + technical.DateTime);
Console.WriteLine("========================");
}
}
}
}
}
Complete Example of a Windows Form App: Display the result of a ULTOSC request by using the method QueryAsync (asynchronous request)
using Avapi;
using Avapi.AvapiULTOSC
using System;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private IAvapiConnection m_connection = AvapiConnection.Instance;
private Int_ULTOSC m_ultosc;
private IAvapiResponse_ULTOSC m_ultoscResponse;
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 ULTOSC query object
m_ultosc = m_connection.GetQueryObject_ULTOSC();
base.OnLoad(e);
}
private async void ULTOSCAsyncButton_Click(object sender, EventArgs e)
{
// Perform the ULTOSC request and get the result
m_ultoscResponse =
await m_ultosc.QueryAsync(
"MSFT",
Const_ULTOSC.ULTOSC_interval.n_1min,
10,
10,
10);
// Show the results
resultTextBox.AppendText("******** RAW DATA ULTOSC ********" + "\n");
resultTextBox.AppendText(m_ultoscResponse.RawData + "\n");
resultTextBox.AppendText("******** STRUCTURED DATA ULTOSC ********" + "\n");
var data = m_ultoscResponse.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("TimePeriod1: " + data.MetaData.TimePeriod1 + "\n");
resultTextBox.AppendText("TimePeriod2: " + data.MetaData.TimePeriod2 + "\n");
resultTextBox.AppendText("TimePeriod3: " + data.MetaData.TimePeriod3 + "\n");
resultTextBox.AppendText("TimeZone: " + data.MetaData.TimeZone + "\n");
resultTextBox.AppendText("========================" + "\n");
resultTextBox.AppendText("========================" + "\n");
foreach (var technical in data.TechnicalIndicator)
{
resultTextBox.AppendText("ULTOSC: " + technical.ULTOSC + "\n");
resultTextBox.AppendText("DateTime: " + technical.DateTime + "\n");
resultTextBox.AppendText("========================" + "\n");
}
}
}
}
}