Skip to content

Commit 888eff0

Browse files
authored
Merge pull request #50 from alpacahq/fixPep8Stream2
Fix flake8 errors
2 parents 722443d + c27d8d3 commit 888eff0

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

alpaca_trade_api/stream2.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ async def _connect(self):
3131
r = r.decode('utf-8')
3232
msg = json.loads(r)
3333

34-
if not 'data' in msg or msg['data']['status'] != 'authorized':
35-
raise ValueError("Invalid Alpaca API credentials, Failed to authenticate: {}".format(msg))
34+
if 'data' not in msg or msg['data']['status'] != 'authorized':
35+
raise ValueError(
36+
("Invalid Alpaca API credentials, Failed to authenticate: {}"
37+
.format(msg))
38+
)
3639

3740
self._ws = ws
38-
await self._dispatch('authenticated', msg)
41+
await self._dispatch('authorized', msg)
3942

4043
asyncio.ensure_future(self._consume_msg())
4144
return ws

tests/test_stream2.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ def test_stream(websockets):
3838
ws.recv = AsyncMock(return_value=json.dumps({
3939
'stream': 'authentication',
4040
'data': {
41-
'status': 'authenticated',
41+
'status': 'authorized',
4242
}
4343
}).encode())
4444

4545
conn = StreamConn('key-id', 'secret-key')
4646
conn._consume_msg = AsyncMock()
4747

48-
@conn.on('authenticated')
48+
@conn.on('authorized')
4949
async def on_auth(conn, stream, msg):
5050
on_auth.msg = msg
5151
_run(conn._connect())
52-
assert on_auth.msg.status == 'authenticated'
52+
assert on_auth.msg.status == 'authorized'
5353
assert conn._consume_msg.mock.called
5454

55-
conn.deregister('authenticated')
55+
conn.deregister('authorized')
5656
assert len(conn._handlers) == 0
5757

5858
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)