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.
Environment Variable (Recommended)¶
The easiest (and recommended) way to authenticate your IEX Cloud account is by
storing your authentication token (secret key beginning with sk_
) 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-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.
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 NYS UN ... B0D0G62BC0V3 1107025 IY2X87GQPMA9XWW0R7U2
1 AA NYS UN ... B03HT33D0BGB 1686945 Z91362T920U4W1P0EWF5
2 AAA USPAC PU ... 8GBB4FS0P50X 1707109 None
3 AAAU USPAC UP ... 2P0GL0XBB87X 1756702 None
4 AAC NYS UN ... GZY0B20BZC19 1852201 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 86958507 close 0.79 ... 150.36 80.12 -0.055532
[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
- defaultbeta
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: 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 “pandas”, 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 is3
.Use
pause
to specify the time between retry attempts. The default value is0.5
.