Skip to content

Using Market Data methods

Henrique Tedeschi edited this page May 29, 2020 · 4 revisions

Implementation

Fetch quotes, chains, and historical data. For all the market data related usages, make sure you include the MarketData Model namespace:

using Tradier.Client.Models.MarketData;

Get Quotes

Get a list of symbols using a keyword lookup on the symbols description. Results are in descending order by average volume of the security. This can be used for simple search functions.

You can call GetQuotes passing a comma-separated string with the symbols:

Quotes quotes = await client.MarketData.GetQuotes("AAPL, NFLX");

Or you can call GetQuotes passing a List<string> with the symbols:

List<string> symbols = new List<string>();
symbols.Add("AAPL");
symbols.Add("NFLX");

Quotes quotes = await client.MarketData.GetQuotes(symbols);

Get Quotes (POST method)

Get a list of symbols using a keyword lookup on the symbols description. Results are in descending order by average volume of the security. This can be used for simple search functions.

You can call PostGetQuotespassing a comma-separated string with the symbols:

Quotes quotes = await client.MarketData.PostGetQuotes("AAPL, NFLX");

Or you can call PostGetQuotes passing a List<string> with the symbols:

List<string> symbols = new List<string>();
symbols.Add("AAPL");
symbols.Add("NFLX");

Quotes quotes = await client.MarketData.PostGetQuotes(symbols);

Get Option Chains

Get all quotes in an option chain. Greek and IV data is included courtesy of ORATS. Please check out their APIs for more in-depth options data.

Options options = await client.MarketData.GetOptionChain("AAPL", "2020-05-27");

Get Options Expirations

Get expiration dates for a particular underlying.

Note that some underlying securities use a different symbol for their weekly options (RUT/RUTW, SPX/SPXW). To make sure you see all expirations, make sure to send the includeAllRoots parameter. This will also ensure any unique options due to corporate actions (AAPL1) are returned.

Expirations expirations = await client.MarketData.GetOptionExpirations("AAPL");

Get Option Strikes

Get an options strike prices for a specified expiration date.

You can call GetStrikes passing the expiration as a string:

Strikes strikes = await client.MarketData.GetStrikes("UNG", "May 15, 2020");

Or you can call GetStrikes passing the expiration as a DateTime

Strikes strikes = await client.MarketData.GetStrikes("UNG", DateTime.Now);

Get Historical Quotes

Get historical pricing for a security. This data will usually cover the entire lifetime of the company if sending reasonable start/end times. You can fetch historical pricing for options by passing the OCC option symbol (ex. AAPL220617C00270000) as the symbol.

You can call GetStrikes passing the start/end dates as a string:

HistoricalQuotes historicalQuotes = 
	await client.MarketData.GetHistoricalQuotes("AAPL", "daily", "January 1, 2020", "May 15, 2020");

Or you can call GetStrikes passing the start/end dates as a DateTime

HistoricalQuotes historicalQuotes = 
	await client.MarketData.GetHistoricalQuotes("AAPL", "daily", DateTime.Today.AddDays(-1), DateTime.Today);

Get Time and Sales

Time and Sales (timesales) is typically used for charting purposes. It captures pricing across a time slice at predefined intervals.

Tick data is also available through this endpoint. This results in a very large data set for high-volume symbols, so the time slice needs to be much smaller to keep downloads time reasonable.

Interval Data Available (Open) Data Available (All)
tick 5 days N/A
1min 20 days 10 days
5min 40 days 18 days
15min 40 days 18 days

You can call GetStrikes passing the start/end dates as a string:

Series timeSales = 
	await client.MarketData.GetTimeSales("AAPL", "1min", "May 1, 2020", "May 15, 2020");

Or you can call GetStrikes passing the start/end dates as a DateTime

Series timeSales = 
	await client.MarketData.GetTimeSales("AAPL", "1min", DateTime.Today.AddDays(-1), DateTime.Today);

Get ETB Securities

The ETB list contains securities that are able to be sold short with a Tradier Brokerage account. The list is quite comprehensive and can result in a long download response time.

Securities securities = await client.MarketData.GetEtbSecurities();

Get Clock

Get the intraday market status. This call will change and return information pertaining to the current day. If programming logic on whether the market is open/closed – this call should be used to determine the current state.

Clock clock = await client.MarketData.GetClock();

Get Calendar

Get the market calendar for the current or given month. This can be used to plan ahead regarding strategies. However, the Get Intraday Status should be used to determine the current status of the market.

Calendar calendar = await client.MarketData.GetCalendar();

Search Companies

Get a list of symbols using a keyword lookup on the symbols description. Results are in descending order by average volume of the security. This can be used for simple search functions.

Securities securitiesFilter = await client.MarketData.SearchCompanies("NY");

Lookup Symbol

Search for a symbol using the ticker symbol or partial symbol. Results are in descending order by average volume of the security. This can be used for simple search functions.

Securities lookup = await client.MarketData.LookupSymbol("goog");


Example

using System;
using System.Linq;
using System.Threading.Tasks;
using Tradier.Client;
using Tradier.Client.Models.MarketData;

namespace MyConsoleApp
{
    class Program
    {
        static async Task Main(string[] args)
        {
            TradierClient client = new TradierClient("<TOKEN>");

            Quotes quotes = await client.MarketData.PostGetQuotes("AAPL, UNG");
            foreach (var quote in quotes.Quote)
            {
                Console.WriteLine($"{quote.Symbol}: High: ${quote.High}");
            }

            Strikes strikes = await client.MarketData.GetStrikes("UNG", DateTime.Now);
            foreach (var strike in strikes.Strike)
            {
                Console.WriteLine($"Strike: {strike}");
            }


            Expirations expirations = await client.MarketData.GetOptionExpirations("AAPL");
            Console.WriteLine($"Expirations: {String.Join(",", expirations.Date.Select(x => x.ToString("D")))}");

            HistoricalQuotes historicalQuotes =
                await client.MarketData.GetHistoricalQuotes("AAPL", "daily", "January 1, 2020", "May 15, 2020");
            Console.WriteLine($"Highs: {String.Join(",", historicalQuotes.Day.Select(x => x.High))}");

            Series timeSales = await client.MarketData.GetTimeSales("AAPL", "1min", "May 1, 2020", "May 15, 2020");
            Console.WriteLine($"Prices: {String.Join(",", timeSales.Data.Select(x => x.Price))}");

            Securities securities = await client.MarketData.GetEtbSecurities();
            Console.WriteLine($"Symbols: {String.Join(",", securities.Security.Select(x => x.Symbol))}");

            Clock clock = await client.MarketData.GetClock();
            Console.WriteLine($"Next Change: {clock.NextChange}");

            Calendar calendar = await client.MarketData.GetCalendar();
            Console.WriteLine($"Dates: {calendar.Days.Day.Select(x => x.Date)}");

            Securities securitiesFilter = await client.MarketData.SearchCompanies("NY", true);
            Console.WriteLine($"Symbols: {String.Join(",", securitiesFilter.Security.Select(x => x.Symbol))}");
        }
    }
}