Skip to content

Commit

Permalink
Merge 3af655e into 980f766
Browse files Browse the repository at this point in the history
  • Loading branch information
danielecook committed Jul 22, 2018
2 parents 980f766 + 3af655e commit 9be0844
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 156 deletions.
6 changes: 3 additions & 3 deletions docs/batch.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# batch
# Batch

!!! note "The batch class"
The batch object is used to request data on multiple stocks. It is designed to operate very similar to the [`stock`](stock) object with nearly identical methods. The key difference is that the `batch` object will return data as a Pandas Dataframe so that it is more convenient to work with.
!!! note "The Batch class"
The batch object is used to request data on multiple stocks. It is designed to operate very similar to the [`stock`](stock) object with nearly identical methods. The key difference is that the `Batch` object will return data as a Pandas Dataframe so that it is more convenient to work with.

7 changes: 7 additions & 0 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Getting Started

## Installation

``` shell
pip install iex-api-python
```
18 changes: 11 additions & 7 deletions docs/iex_stats.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ __Parameters__
- __`dataframe` (default)__ - Return result as a pandas dataframe.
- __`json`__ - Return raw result converted from JSON to a python data structure.

!!! note "The iex_stats class"
!!! note "The `iex_stats` instance and class"

The `iex_stats` class creates an object that can be used to fetch IEX aggregate data.
`IexStats` is the class used to instantiate the `iex_stats` object. Both can be imported from the `iex` module. The `iex_stats` object can be used to fetch IEX aggregate data.

## Creating a new `iex_stats` object

Provide a stock symbol to create a stock object. Stock symbols are case-insensitive.
```python
from iex import IexStats
iex_stats = IexStats()
```

``` python
__or__

```
from iex import iex_stats
stats = iex_stats()
```

----
Expand All @@ -36,8 +40,8 @@ open_in_new
</i>](https://iextrading.com/developer/docs/#intraday)

``` python
from iex import iex_stats
iex_stats(date_format='datetime').intraday()
from iex import IexStats
IexStats(date_format='datetime').intraday()
```
```
lastUpdated value
Expand Down
7 changes: 3 additions & 4 deletions docs/market.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ open_in_new
__Example__

``` python
market_list = market()
market_list.mostactive()
from iex import market
market.mostactive()
```

avgTotalVolume calculationPrice change changePercent close \
Expand Down Expand Up @@ -83,8 +83,7 @@ __Example__

``` python
from iex import market
m = market()
m.previous()
market.previous()
```
```
symbol change changePercent close date high low \
Expand Down
42 changes: 19 additions & 23 deletions docs/reference_data.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
# Reference

<div class='code-def'>reference(output_format)</div>
<div class='code-def'>ReferenceData(output_format)</div>

__Parameters__

* __`output_format`__ - The format to output. Options:
- __`dataframe` (default)__ - Return result as a pandas dataframe.
- __`json`__ - Return raw result converted from JSON to a python data structure.

!!! note "The `reference` instance"

!!! note "The reference class"
The `reference` object is designed to map closely to the [`Reference Data`](https://iextrading.com/developer/docs/#reference-data) section of the IEX API.

The `reference` class is designed to map closely to the [`Reference Data`](https://iextrading.com/developer/docs/#reference-data) section of the IEX API.
You can import either `ReferenceData` (the class) or `reference` from iex. The `reference` import is an instance of `ReferenceData` that can be used without having to instantiate a new object.

## Creating a new `reference` object
## Importing the `reference` object

``` python
from iex import reference
ref = reference()
```

----
#### Setting the output format using the instance

To update the output format, set the `output_format` attribute:

```python
reference.output_format = 'json'
```

----

## Reference Methods

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

### `symbols()`

[IEX API - symbols <i class="material-icons md-16">
open_in_new
</i>](https://iextrading.com/developer/docs/#symbols)
[IEX API - symbols](https://iextrading.com/developer/docs/#symbols)

``` python
from iex import reference
ref = reference()
ref.symbols()
reference.symbols()
```

# Output
Expand All @@ -49,39 +53,31 @@ ref.symbols()

### `iex_corporate_actions()`

[IEX API - IEX Corporate Actions <i class="material-icons md-16">
open_in_new
</i>](https://iextrading.com/developer/docs/#iex-corporate-actions)
[IEX API - IEX Corporate Actions](https://iextrading.com/developer/docs/#iex-corporate-actions)

__Parameters__

* __`date`__ - Date specified as `YYYYMMDD` or a datetime object.

### `iex_dividends()`

[IEX API - IEX Dividends <i class="material-icons md-16">
open_in_new
</i>](https://iextrading.com/developer/docs/#iex-dividends)
[IEX API - IEX Dividends](https://iextrading.com/developer/docs/#iex-dividends)

__Parameters__

* __`date`__ - Date specified as `YYYYMMDD` or a datetime object.

### `iex_next_day_ex_date()`

[IEX API - IEX Next Day Ex Date <i class="material-icons md-16">
open_in_new
</i>](https://iextrading.com/developer/docs/#iex-next-day-ex-date)
[IEX API - IEX Next Day Ex Date](https://iextrading.com/developer/docs/#iex-next-day-ex-date)

__Parameters__

* __`date`__ - Date specified as `YYYYMMDD` or a datetime object.

### `iex_listed_symbol_directory()`

[IEX API - IEX Listed Symbol Directory <i class="material-icons md-16">
open_in_new
</i>](https://iextrading.com/developer/docs/#iex-listed-symbol-directory)
[IEX API - IEX Listed Symbol Directory](https://iextrading.com/developer/docs/#iex-listed-symbol-directory)

__Parameters__

Expand Down
11 changes: 10 additions & 1 deletion docs/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ h3 code {
h3 code:before {
content: ".";
color: #7f7f7f;
}
}

pre {
padding: 15px;
background-color: #dcdcdc;
}

code {
color: #3a7cff;
}
56 changes: 27 additions & 29 deletions docs/stocks.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
# Stock

<div class='code-def'>stock(symbol, date_format)</div>
<div class='code-def'>Stock(symbol, date_format)</div>

__Parameters__

* __`symbol`__ - A stock symbol
* __`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.

!!! note "The stock class"
!!! note "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](https://iextrading.com/developer/docs/#stocks)__ section of the IEX API.
The `Stock` class is useful for returning information for a specific Stock, and is designed to map closely to the organization of the __[Stocks](https://iextrading.com/developer/docs/#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 (multiple stocks) or market data. 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`](batch), and market requests should use the [`market`](market) object.
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`](batch), and market requests should use the [`market`](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.
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
## Creating a new `Stock` object

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

``` python
from iex import stock
tsla = stock("tsla")
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.
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()`

[IEX API - Book <i class="material-icons md-16">
open_in_new
</i>](https://iextrading.com/developer/docs/#book)
[`/Stock/<symbol>/book`](https://iextrading.com/developer/docs/#book) <i class='fa fa-external-link'></i>

``` python
from iex import stock
goog = stock("goog")
from iex import Stock
goog = Stock("goog")
goog.book()
```

Expand Down Expand Up @@ -78,8 +76,8 @@ The same parameters are available as with [`chart()`](#chart).
__Example__

``` python
from iex import stock
goog = stock("goog")
from iex import Stock
goog = Stock("goog")
goog.chart_table(range='1d')
```

Expand Down Expand Up @@ -118,8 +116,8 @@ __parameters__
__Example__

``` python
from iex import stock
F = stock("F")
from iex import Stock
F = Stock("F")
f.dividends_table()
```

Expand Down Expand Up @@ -156,35 +154,35 @@ Returns a dataframe of [`effective_spread()`](#effective_spread)
[IEX API - OHLC <i class="material-icons md-16">open_in_new</i>](https://iextrading.com/developer/docs/#ohlc)

!!! info
If you are trying to return the official open/close for all stocks use [`market.ohlc()`](market#ohlc()).
If you are trying to return the official open/close for all Stocks use [`market.ohlc()`](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`.
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.
* __`as_string` (Default: `False`)__ - If set to `True`, return the list of peers as strings rather than `Stock` objects.

__Example__

``` python
from iex import stock
tsla = stock("tsla")
from iex import Stock
tsla = Stock("tsla")
tsla.peers()
```

# Output
[<stock:HMC>, <stock:TM>, <stock:F>, <stock:GM>]
[<Stock:HMC>, <Stock:TM>, <Stock:F>, <Stock:GM>]

### `previous()`

[IEX API - Previous <i class="material-icons md-16">open_in_new</i>](https://iextrading.com/developer/docs/#previous)

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()`](market#previous()).
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()`](market#previous()).

!!! info
If you are trying to return the previous days market data, use [`market.previous()`](market#previous()).
Expand All @@ -194,12 +192,12 @@ Returns the previous day adjusted stock price. The IEX API can also return the p

[IEX API - Price <i class="material-icons md-16">open_in_new</i>](https://iextrading.com/developer/docs/#price)

Returns the stock price.
Returns the Stock price.

__Example__

``` python
tsla = stock("TSLA")
tsla = Stock("TSLA")
tsla.price()
```

Expand Down
12 changes: 6 additions & 6 deletions iex/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from iex.reference_data import reference
from iex.stocks import stock
from iex.batch import batch
from iex.market import market
from iex.iex_stats import iex_stats
from iex.iex_market import iex_market
from iex.reference_data import reference, ReferenceData
from iex.stocks import Stock
from iex.batch import Batch
from iex.market import market, Market
from iex.iex_stats import iex_stats, IexStats
from iex.iex_market import IexMarket
8 changes: 4 additions & 4 deletions iex/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
DATE_FIELDS)


class batch:
class Batch:
"""
The batch object is designed to fetch data
The Batch object is designed to fetch data
from multiple stocks.
"""

Expand All @@ -43,7 +43,7 @@ def __init__(self, symbols, date_format='timestamp', output_format='dataframe'):
self.output_format = validate_output_format(output_format)

def _get(self, _type, params={}):
request_url = BASE_URL + '/stock/market/batch'
request_url = BASE_URL + '/stock/market/Batch'
params.update({'symbols': self.symbols_list,
'types': _type})
response = requests.get(request_url, params=params)
Expand Down Expand Up @@ -155,4 +155,4 @@ def quote(self, displayPercent=False):
return self._get("quote", params={"displayPercent": displayPercent})

def __repr__(self):
return f"<batch: {len(self.symbols)} symbols>"
return f"<Batch: {len(self.symbols)} symbols>"

0 comments on commit 9be0844

Please sign in to comment.