Configuration

There are four core components of iexfinance’s configuration:

  • API Version - specifying version of IEX Cloud to use

  • Authentication - setting your IEX Cloud Authentication Token

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

  • Debugging - cached sessions, request retries, and more

API Version

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

  • v1 - note: this will be deprecated in iexfinance version 0.4.2

  • iexcloud-beta

  • iexcloud-v1 - default

Warning

iexfinance now defaults to IEX Cloud for all calls. The use of v1 as IEX_API_VERSION will be warned in iexfinance 0.4.1 and deprecated in 0.4.2.

Note

The beta period for IEX Cloud ends on June 1st, 2019. At this time, all calls using iexcloud-beta will mirror those of iexcloud-v1.

See also

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

Authentication

An IEX Cloud account is required to acecss the IEX Cloud API.

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

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 AUTH TOKEN>")

or at the instantiation of a Stock object:

from iexfinance.stocks import Stock

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

Output Formatting

By default, iexfinance returns data formatted exactly as received from the IEX Endpoint. pandas DataFrame output formatting is available for most endpoints. Configuring iexfinance’s output format can be done in two ways:

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]: 
  currency        date exchange  ... region  symbol type
0      UDS  2019-05-14      NSY  ...     SU       A   cs
1      UDS  2019-05-14      SNY  ...     SU      AA   cs
2      SUD  2019-05-14      SEP  ...     US    AAAU   te
3      UDS  2019-05-14      ANS  ...     US    AABA  fec
4      DSU  2019-05-14      NYS  ...     SU     AAC   cs

[5 rows x 9 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]: 
                      AAPL
avgTotalVolume    29464923
calculationPrice     close
change                2.97
changePercent      0.01606
close               190.62

Environment Variable

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

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 “json”, optional

token

Authentication token (reuqired 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.