diff --git a/alpaca_trade_api/rest.py b/alpaca_trade_api/rest.py index 64f20c63..2255e198 100644 --- a/alpaca_trade_api/rest.py +++ b/alpaca_trade_api/rest.py @@ -269,10 +269,10 @@ def list_orders(self, def submit_order(self, symbol: str, - qty: int, - side: str, - type: str, - time_in_force: str, + qty: float = None, + side: str = "buy", + type: str = "market", + time_in_force: str = "day", limit_price: str = None, stop_price: str = None, client_order_id: str = None, @@ -281,10 +281,11 @@ def submit_order(self, take_profit: dict = None, stop_loss: dict = None, trail_price: str = None, - trail_percent: str = None): + trail_percent: str = None, + notional: float = None): """ :param symbol: symbol or asset ID - :param qty: int + :param qty: float. Mutually exclusive with "notional". :param side: buy or sell :param type: market, limit, stop, stop_limit or trailing_stop :param time_in_force: day, gtc, opg, cls, ioc, fok @@ -300,15 +301,19 @@ def submit_order(self, {"stop_price": "297.95", "limit_price": "298.95"} :param trail_price: str of float :param trail_percent: str of float + :param notional: float. Mutually exclusive with "qty". """ """Request a new order""" params = { 'symbol': symbol, - 'qty': qty, 'side': side, 'type': type, 'time_in_force': time_in_force } + if qty is not None: + params['qty'] = qty + if notional is not None: + params['notional'] = notional if limit_price is not None: params['limit_price'] = FLOAT(limit_price) if stop_price is not None: @@ -335,7 +340,7 @@ def submit_order(self, params['trail_percent'] = trail_percent resp = self.post('/orders', params) return self.response_wrapper(resp, Order) - + def get_order_by_client_order_id(self, client_order_id: str) -> Order: """Get an order by client order id""" params = { diff --git a/alpaca_trade_api/stream2.py b/alpaca_trade_api/stream2.py index d56c6cb1..c3c26e06 100644 --- a/alpaca_trade_api/stream2.py +++ b/alpaca_trade_api/stream2.py @@ -123,6 +123,8 @@ async def _ensure_ws(self): async def subscribe(self, channels): if isinstance(channels, str): channels = [channels] + elif isinstance(channels, set): + channels = list(channels) if len(channels) > 0: await self._ensure_ws() self._streams |= set(channels) @@ -136,6 +138,8 @@ async def subscribe(self, channels): async def unsubscribe(self, channels): if isinstance(channels, str): channels = [channels] + elif isinstance(channels, set): + channels = list(channels) if len(channels) > 0: await self._ws.send(json.dumps({ 'action': 'unlisten',