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 is now the same as ``iexcloud-v1``
  • iexcloud-beta
  • iexcloud-v1 - default

Warning

iexfinance now defaults to IEX Cloud for all calls. The use of v1 as IEX_API_VERSION is now the same as iexcloud-v1.

Note

The beta period for IEX Cloud ended on June 1, 2019. All calls using iexcloud-beta now 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                 iexId  isEnabled  \
0      USD  2019-06-19      YNS  IEX_46574843354B2D52       True   
1      USD  2019-06-19      NYS  IEX_4238333734532D52       True   
2      USD  2019-06-19      SPE  IEX_474B433136332D52       True   
3      USD  2019-06-19      SNA  IEX_4E5434354A302D52       True   
4      USD  2019-06-19      NSY  IEX_4843364642592D52       True   

                           name region symbol type  
0     og llhsgn enneoiTIc.ecAit     US      A   cs  
1                   Ao. Cpcralo     US     AA   cs  
2  aoTnhdP yi sMhtEe P ticlGrlF     US   AAAU   et  
3                    bIla.naAct     US   AABA  cef  
4             igo .c nAIdAHlsCn     US    AAC   cs  

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    30578248
calculationPrice     close
change               -0.58
changePercent     -0.00298
close               207.27

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

int, default 3, optional – Desired number of retries if a request fails

pause

float default 0.5, optional – Pause time between retry attempts

session

requests_cache.session, default None, optional – A cached requests-cache session

json_parse_int

datatype, default int, optional – Desired integer parsing datatype

json_parse_float

datatype, default float, optional – Desired floating point parsing datatype

output_format

str, default “json”, optional – Desired output format (json or pandas DataFrame). This can also be set using the environment variable IEX_OUTPUT_FORMAT.

token

str, optional – Authentication token (required for use with IEX Cloud)

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.