From 1aa93d7a5c2d0d3d411bdeec545c6fb32500f4f5 Mon Sep 17 00:00:00 2001 From: Brian Guarraci Date: Fri, 12 Mar 2021 06:16:05 -0800 Subject: [PATCH 1/2] Fix issue where self._streams set is used as channels but cannot be serialized --- alpaca_trade_api/stream2.py | 4 ++++ 1 file changed, 4 insertions(+) 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', From 9983dfd7c488a22d7c4544804f93f9debd24072c Mon Sep 17 00:00:00 2001 From: Brian Guarraci Date: Mon, 15 Nov 2021 07:58:38 -0700 Subject: [PATCH 2/2] add notional to submit_order --- alpaca_trade_api/rest.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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 = {