Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where self._streams set is used as channels but cannot be s… #398

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions alpaca_trade_api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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 = {
Expand Down
4 changes: 4 additions & 0 deletions alpaca_trade_api/stream2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand Down