Configuration

There are four core components of iexfinance’s configuration:

  • Authentication - setting your IEX Cloud Authentication Token

  • Output Formatting - configuring desired output format (mirror IEX output or Pandas DataFrame)

  • API Version - specifying version of IEX Cloud to use

  • Debugging - cached sessions, request retries, and more

Authentication

An IEX Cloud account and authentication token are required to acecss the IEX Cloud API. The IEX Cloud token is accessible via the IEX Cloud Console.

See also

For more information about signing up for an IEX Cloud account, see the pricing section of the IEX Cloud website.

Your IEX Cloud (secret) authentication token can be be stored in the IEX_TOKEN environment variable. It can also be passed to any function or at the instantiation of a Stock object.

Instructions for both authentication methods are below.

Passing as an Argument

The authentication token can also be passed to any function call:

from iexfinance.refdata import get_symbols

get_symbols(output_format='pandas', token="<YOUR-TOKEN>")

or at the instantiation of a Stock object:

from iexfinance.stocks import Stock

a = Stock("AAPL", token="<YOUR-TOKEN>")
a.get_quote()

Where <YOUR-TOKEN> is your IEX Cloud authentication token.

Output Formatting

By default, iexfinance returns data for most endpoints in a pandas DataFrame.

Selecting json as the output format returns data formatted exactly as received from the IEX Endpoint. Configuring iexfinance’s output format can be done in two ways:

Environment Variable (Recommended)

For persistent configuration of a specified output format, use the environment variable IEX_OUTPUT_FORMAT. This value will be overridden by the output_format argument if it is passed.

macOS/Linux

Type the following command into your terminal:

$ export IEX_OUTPUT_FORMAT=pandas

Windows

See here for instructions on setting environment variables in Windows operating systems.

output_format Argument

Pass output_format as an argument to any function call:

In [1]: from iexfinance.refdata import get_symbols

In [2]: get_symbols(output_format='pandas').head()
Out[2]: 
  symbol exchange exchangeSuffix  ...          figi      cik                   lei
0      A      SNY             NU  ...  03D060BCBVG2  1091817  2MAWQ2YIXX7R0GUP78W9
1     AA      SNY             NU  ...  3BTBB00DH3G3  1683493  3WFUZ294EPT615291W00
2    AAA    UPASC             UP  ...  8SX0PFG50BB4  1746829                  None
3   AAAU    PACUS             UP  ...  X080LPX7B2BG  1747873                  None
4   AACG      NSA              0  ...  6SG3B2VP00B0  1486223                  None

[5 rows x 14 columns]

or at the instantiation of a Stock object:

In [3]: from iexfinance.stocks import Stock

In [4]: aapl = Stock("AAPL", output_format='pandas')

In [5]: aapl.get_quote().head()
Out[5]: 
     avgTotalVolume calculationPrice change  ... week52High week52Low ytdChange
AAPL       94398164            close  -0.86  ...      134.5     57.42  0.693918

[1 rows x 55 columns]

API Version

The desired IEX API version can be specified using the IEX_API_VERSION environment variable. The following versions are currently supported:

  • stable - default

  • beta

  • v1

  • latest

  • sandbox for testing purposes

See also

For more information on API versioning, see the IEX Cloud documentation.

Debugging

_IEXBase Class

All iexfinance requests are made using the base class _IEXBase.

class iexfinance.base._IEXBase(**kwargs)

Base class for retrieving equities information from IEX Cloud. Conducts query operations including preparing and executing queries from the API.

retry_count

Desired number of retries if a request fails

Type

int, default 3, optional

pause

Pause time between retry attempts

Type

float default 0.5, optional

session

A cached requests-cache session

Type

requests_cache.session, default None, optional

json_parse_int

Desired integer parsing datatype

Type

datatype, default int, optional

json_parse_float

Desired floating point parsing datatype

Type

datatype, default float, optional

output_format

Desired output format (json or pandas DataFrame). This can also be set using the environment variable IEX_OUTPUT_FORMAT.

Type

str, default “pandas”, optional

token

Authentication token (required for use with IEX Cloud)

Type

str, optional

Cached Sessions

iexfinance import requests-cache cached sessions. To pass a cached session to your request, pass the session keyword argument to any function call, or at instantiation of a Stock object.

Request Parameters

  • Use retry_count to specify the number of times to retry a failed request. The default value is 3.

  • Use pause to specify the time between retry attempts. The default value is 0.5.