Stock

Stock(symbol, date_format)

Parameters

  • symbol - A Stock symbol
  • date_format (default: timestamp) - Specifies how timestamps should be should be returned. Set to one of the following:
    • timestamp - default; Does not alter IEX API output.
    • datetime - Datetime object.
    • isoformat - Converts to isoformat.

The Stock class

The Stock class is useful for returning information for a specific Stock, and is designed to map closely to the organization of the Stocks section of the IEX API.

One major difference between the Stock class and the Stocks section of the IEX API is that the Stock object is not designed to handle batch requests or requests about the market. Batch requests are requests for data on multiple Stocks at the same time. Market requests return data for all Stocks or a set of Stocks based on the request (e.g. gainers and losers). For batch requests, you should use the batch, and market requests should use the market object.

Also note that the Stock object most often returns data as a python dictionary or list - closely mimicking the returned JSON of the IEX API. However, in some cases there are additional methods (suffixed with _table) that will return a Pandas dataframe for convenience.

Creating a new Stock object

Provide a Stock symbol to create a Stock object. Stock symbols are case-insensitive.

from iex import Stock
tsla = Stock("tsla")

Stock Methods

Below are the methods that can be invoked with a Stock object. Beneath the listed method you will find a link that will take you to the corresponding IEX API documentation.

book()

/Stock/<symbol>/book

from iex import Stock
goog = Stock("goog")
goog.book()
# Output
{
 'quote': {...},
 'bids': [...],
 'asks': [...],
 'trades': [...],
 'systemEvent': {...}
}

chart()

IEX API - Chart open_in_new

Parameters

  • range (default: 1m) - Historical adjusted market-wide data or IEX-only data. See the IEX API reference for further details.
    • 5y 2y 1y ytd 6m 3m 1m YYYYMMDD (date) dynamic
  • chartReset (bool; default: None) - 1d chart will reset at midnight instead of the default behavior of 9:30am ET.
  • chartSimplify (bool; default: None) - If True, runs a polyline simplification using the Douglas-Peucker algorithm. This is useful if plotting sparkline charts.
  • chartInterval (bool: default: None) - If passed, chart data will return every Nth element.

chart_table()

Returns a pandas dataframe from chart data. If range=dynamic, a range column is appended to the returned dataframe indicating whether the data is for 1d or 1m. See the See the IEX API documentation for further details.

Parameters

The same parameters are available as with chart().

Example

from iex import Stock
goog = Stock("goog")
goog.chart_table(range='1d')
# Output
      average  changeOverTime     close      date      high  \
0    1094.852        0.000000  1095.535  20180511  1095.535
1      -1.000             NaN       NaN  20180511    -1.000
2      -1.000             NaN       NaN  20180511    -1.000
3    1093.145       -0.001559  1093.420  20180511  1093.630
...

company()

IEX API - Company open_in_new

delayed_quote()

IEX API - Delayed Quote open_in_new

dividends()

IEX API - Dividends open_in_new

parameters

  • range (default: 1m) - Historical market data; range of data on dividends to return.

dividends_table()

Returns a dataframe of dividend()

parameters

  • range (default: 1m) - Historical market data; range of data on dividends to return.

Example

from iex import Stock
F = Stock("F")
f.dividends_table()
    # Output
    change  changeOverTime  changePercent    close        date   \
0   0.098676        0.000000          0.887  11.2293  2018-04-16 
1   0.000000        0.000000          0.000  11.2293  2018-04-17 
2  -0.049338       -0.004390         -0.439  11.1800  2018-04-18 
3  -0.220002       -0.023982         -1.968  10.9600  2018-04-19 
4  -0.140000       -0.036449         -1.277  10.8200  2018-04-20 
...

earnings()

IEX API - Earnings open_in_new

effective_spread()

IEX API - Effective Spread open_in_new

effective_spread_table()

Returns a dataframe of effective_spread()

financials()

financials_table()

ohlc()

IEX API - OHLC open_in_new

Info

If you are trying to return the official open/close for all Stocks use market.ohlc().

price()

peers()

Returns a list of peer (competitor/related) companies. By default, the returned list is a set of Stock objects. You can return a list of companies as strings by setting as_string=True.

Parameters

  • as_string (Default: False) - If set to True, return the list of peers as strings rather than Stock objects.

Example

from iex import Stock
tsla = Stock("tsla")
tsla.peers()
# Output
[&lt;Stock:HMC&gt;, &lt;Stock:TM&gt;, &lt;Stock:F&gt;, &lt;Stock:GM&gt;]

previous()

IEX API - Previous open_in_new

Returns the previous day adjusted Stock price. The IEX API can also return the previous day prices for the entire market. For this query, use market.previous().

Info

If you are trying to return the previous days market data, use market.previous().

price()

IEX API - Price open_in_new

Returns the Stock price.

Example

tsla = Stock("TSLA")
tsla.price()
284.18

quote()

stats()