Tradier API

Tradier - Account Set Up

  1. Sign up for a develop account and get a token.

    https://developer.tradier.com/getting_started

  2. Export Environment Variable

    export TD_TOKEN=<TRADIER_ACCOUNT_TOKEN>
    

Tradier Consts, Environment Variables and Authentication Helper

analysis_engine.td.consts.get_auth_headers(use_token='MISSING_TD_TOKEN', env_token=None)[source]

Get connection and auth headers for Tradier account: https://developer.tradier.com/getting_started

Parameters:
  • use_token – optional - token instead of the default TD_TOKEN
  • env_token – optional - env key to use instead of the default TD_TOKEN

Tradier - Fetch API Reference

Please use the command line tool to store the data in redis correctly for the extraction tools.

fetch -t TICKER -g td
# fetch -t SPY -g td

Here is how to use the fetch api:

import analysis_engine.td.fetch_api as td_fetch

# Please set the TD_TOKEN environment variable to your token
calls_status, calls_df = td_fetch.fetch_calls(
    ticker='SPY')
puts_status, puts_df = td_fetch.fetch_puts(
    ticker='SPY')

print(f'Fetched SPY Option Calls from Tradier status={calls_status}:')
print(calls_df)

print(f'Fetched SPY Option Puts from Tradier status={puts_status}:')
print(puts_df)

Fetch API calls wrapping Tradier

Supported environment variables:

# verbose logging in this module
export DEBUG_FETCH=1
analysis_engine.td.fetch_api.fetch_calls(ticker=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]

Fetch Tradier option calls for a ticker and return a tuple: (status, pandas.DataFrame)

import analysis_engine.td.fetch_api as td_fetch

# Please set the TD_TOKEN environment variable to your token
calls_status, calls_df = td_fetch.fetch_calls(
    ticker='SPY')

print(f'Fetched SPY Option Calls from Tradier status={calls_status}:')
print(calls_df)
Parameters:
  • ticker – string ticker to fetch
  • work_dict – dictionary of args used by the automation
  • scrub_mode – optional - string type of scrubbing handler to run
  • verbose – optional - bool for debugging
analysis_engine.td.fetch_api.fetch_puts(ticker=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]

Fetch Tradier option puts for a ticker and return a tuple: (status, pandas.DataFrame)

import analysis_engine.td.fetch_api as td_fetch

puts_status, puts_df = td_fetch.fetch_puts(
    ticker='SPY')

print(f'Fetched SPY Option Puts from Tradier status={puts_status}:')
print(puts_df)
Parameters:
  • ticker – string ticker to fetch
  • work_dict – dictionary of args used by the automation
  • scrub_mode – optional - string type of scrubbing handler to run
  • verbose – optional - bool for debugging

Tradier - Extraction API Reference

Once fetched you can extract the options data with:

import analysis_engine.td.extract_df_from_redis as td_extract

# extract by historical date is also supported:
# date='2019-02-15'
calls_status, calls_df = td_extract.extract_option_calls_dataset(
    ticker='SPY')
puts_status, puts_df = td_extract.extract_option_puts_dataset(
    ticker='SPY')

print(f'SPY Option Calls from Tradier extract status={calls_status}:')
print(calls_df)

print(f'SPY Option Puts from Tradier extract status={puts_status}:')
print(puts_df)

Extract an TD dataset from Redis (S3 support coming soon) and load it into a pandas.DataFrame

Supported environment variables:

# to show debug, trace logging please export ``SHARED_LOG_CFG``
# to a debug logger json file. To turn on debugging for this
# library, you can export this variable to the repo's
# included file with the command:
export SHARED_LOG_CFG=/opt/sa/analysis_engine/log/debug-logging.json
analysis_engine.td.extract_df_from_redis.extract_option_calls_dataset(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]

Extract the TD options calls for a ticker and return a tuple (status, pandas.Dataframe)

import analysis_engine.td.extract_df_from_redis as td_extract

# extract by historical date is also supported as an arg
# date='2019-02-15'
calls_status, calls_df = td_extract.extract_option_calls_dataset(
    ticker='SPY')
print(calls_df)
Parameters:
  • ticker – string ticker to extract
  • date – optional - string date to extract formatted YYYY-MM-DD
  • work_dict – dictionary of args
  • scrub_mode – optional - string type of scrubbing handler to run
  • verbose – optional - boolean for turning on logging
analysis_engine.td.extract_df_from_redis.extract_option_puts_dataset(ticker=None, date=None, work_dict=None, scrub_mode='sort-by-date', verbose=False)[source]

Extract the TD options puts for a ticker and return a tuple (status, pandas.Dataframe)

import analysis_engine.td.extract_df_from_redis as td_extract

# extract by historical date is also supported as an arg
# date='2019-02-15'
puts_status, puts_df = td_extract.extract_option_puts_dataset(
    ticker='SPY')
print(puts_df)
Parameters:
  • ticker – string ticker to extract
  • date – optional - string date to extract formatted YYYY-MM-DD
  • work_dict – dictionary of args
  • scrub_mode – optional - string type of scrubbing handler to run
  • verbose – optional - boolean for turning on logging

Distributed Automation API

Fetch data from Tradier: https://developer.tradier.com/getting_started

analysis_engine.td.fetch_data.fetch_data(work_dict, fetch_type=None)[source]

Factory method for fetching data from TD using an enum or string alias. Returns a pandas DataFrame and only supports one ticker at a time.

Supported enums from: analysis_engine.td.consts

fetch_type = FETCH_TD_CALLS
fetch_type = FETCH_TD_PUTS

Supported work_dict['ft_type'] string values:

work_dict['ft_type'] = 'tdcalls'
work_dict['ft_type'] = 'tdputs'
Parameters:
  • work_dict – dictionary of args for the Tradier api
  • fetch_type – optional - name or enum of the fetcher to create can also be a lower case string in work_dict[‘ft_type’]

Tradier API - Get Data Helper

Parse data from TD

Supported environment variables:

export DEBUG_TD_DATA=1
analysis_engine.td.get_data.get_data_from_td(work_dict)[source]

Get pricing data from Tradier

Parameters:work_dict – request dictionary