Skip to content

Commit

Permalink
Adds a 'side' param to Rest::list_orders (alpacahq#610)
Browse files Browse the repository at this point in the history
* Adds a 'side' param to Rest::list_orders

* Update README as well
  • Loading branch information
drew887 authored Apr 26, 2022
1 parent d512c40 commit a9055b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,22 +338,22 @@ You can access the following information through this object.

#### API REST Methods

| Rest Method | End Point | Result |
| -------------------------------- | -------------------| ------------------------------------------------------------------ |
| get_account() | `GET /account` and | `Account` entity.|
| get_order_by_client_order_id(client_order_id) | `GET /orders` with client_order_id | `Order` entity.|
| list_orders(status=None, limit=None, after=None, until=None, direction=None, nested=None) | `GET /orders` | list of `Order` entities. `after` and `until` need to be string format, which you can obtain by `pd.Timestamp().isoformat()` |
| submit_order(symbol, qty=None, side="buy", type="market", time_in_force="day", limit_price=None, stop_price=None, client_order_id=None, order_class=None, take_profit=None, stop_loss=None, trail_price=None, trail_percent=None, notional=None)| `POST /orders` | `Order` entity. |
| get_order(order_id) | `GET /orders/{order_id}` | `Order` entity.|
| cancel_order(order_id) | `DELETE /orders/{order_id}` | |
| cancel_all_orders() | `DELETE /orders`| |
| list_positions() | `GET /positions` | list of `Position` entities|
| get_position(symbol) | `GET /positions/{symbol}` | `Position` entity.|
| list_assets(status=None, asset_class=None) | `GET /assets` | list of `Asset` entities|
| get_asset(symbol) | `GET /assets/{symbol}` | `Asset` entity|
| get_clock() | `GET /clock` | `Clock` entity|
| get_calendar(start=None, end=None) | `GET /calendar` | `Calendar` entity|
| get_portfolio_history(date_start=None, date_end=None, period=None, timeframe=None, extended_hours=None) | `GET /account/portfolio/history` | PortfolioHistory entity. PortfolioHistory.df can be used to get the results as a dataframe|
| Rest Method | End Point | Result |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| get_account() | `GET /account` and | `Account` entity. |
| get_order_by_client_order_id(client_order_id) | `GET /orders` with client_order_id | `Order` entity. |
| list_orders(status=None, limit=None, after=None, until=None, direction=None, params=None,nested=None, symbols=None, side=None) | `GET /orders` | list of `Order` entities. `after` and `until` need to be string format, which you can obtain by `pd.Timestamp().isoformat()` |
| submit_order(symbol, qty=None, side="buy", type="market", time_in_force="day", limit_price=None, stop_price=None, client_order_id=None, order_class=None, take_profit=None, stop_loss=None, trail_price=None, trail_percent=None, notional=None) | `POST /orders` | `Order` entity. |
| get_order(order_id) | `GET /orders/{order_id}` | `Order` entity. |
| cancel_order(order_id) | `DELETE /orders/{order_id}` | |
| cancel_all_orders() | `DELETE /orders` | |
| list_positions() | `GET /positions` | list of `Position` entities |
| get_position(symbol) | `GET /positions/{symbol}` | `Position` entity. |
| list_assets(status=None, asset_class=None) | `GET /assets` | list of `Asset` entities |
| get_asset(symbol) | `GET /assets/{symbol}` | `Asset` entity |
| get_clock() | `GET /clock` | `Clock` entity |
| get_calendar(start=None, end=None) | `GET /calendar` | `Calendar` entity |
| get_portfolio_history(date_start=None, date_end=None, period=None, timeframe=None, extended_hours=None) | `GET /account/portfolio/history` | PortfolioHistory entity. PortfolioHistory.df can be used to get the results as a dataframe |

#### Rest Examples

Expand Down
6 changes: 5 additions & 1 deletion alpaca_trade_api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ def list_orders(self,
direction: str = None,
params=None,
nested: bool = None,
symbols: List[str] = None
symbols: List[str] = None,
side: str = None
) -> Orders:
"""
Get a list of orders
Expand All @@ -323,6 +324,7 @@ def list_orders(self,
:param params: refer to documentation
:param nested: should the data be nested like json
:param symbols: list of str (symbols)
:param side: Lets you filter to only 'buy' or 'sell' orders
"""
if params is None:
params = dict()
Expand All @@ -338,6 +340,8 @@ def list_orders(self,
params['status'] = status
if nested is not None:
params['nested'] = nested
if side is not None:
params['side'] = side
if symbols is not None:
params['symbols'] = ",".join(symbols)
url = '/orders'
Expand Down

0 comments on commit a9055b9

Please sign in to comment.