Skip to content

Commit

Permalink
Comply PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
umitanuki committed Apr 22, 2020
1 parent a5076d8 commit f8d5d14
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion alpaca_trade_api/polygon/rest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dateutil
import requests
from .entity import (
Aggs, Aggsv2, Aggsv2Set,
Aggsv2, Aggsv2Set,
Trade, Trades, TradesV2,
Quote, Quotes, QuotesV2,
Exchange, SymbolTypeMap, ConditionMap,
Expand Down
13 changes: 8 additions & 5 deletions alpaca_trade_api/polygon/streamconn.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ async def _consume_msg(self):
data['ev'] = 'status'
await self._dispatch(data)
raise ConnectionResetError(
'Polygon terminated connection: '
f'({data.get("message")})')
'Polygon terminated connection: '
f'({data.get("message")})')

async def _ensure_ws(self):
if self._ws is not None:
Expand Down Expand Up @@ -189,11 +189,14 @@ async def close(self):

def _cast(self, subject, data):
if subject == 'T':
return Trade({trade_mapping[k]: v for k, v in data.items() if k in trade_mapping})
return Trade({trade_mapping[k]: v for k,
v in data.items() if k in trade_mapping})
if subject == 'Q':
return Quote({quote_mapping[k]: v for k, v in data.items() if k in quote_mapping})
return Quote({quote_mapping[k]: v for k,
v in data.items() if k in quote_mapping})
if subject == 'AM' or subject == 'A':
return Agg({agg_mapping[k]: v for k, v in data.items() if k in agg_mapping})
return Agg({agg_mapping[k]: v for k,
v in data.items() if k in agg_mapping})
return Entity(data)

async def _dispatch(self, msg):
Expand Down
24 changes: 17 additions & 7 deletions alpaca_trade_api/stream2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from .common import get_base_url, get_data_url, get_credentials
from .entity import Account, Entity
from . import polygon
from .polygon.entity import Trade, Quote, Agg, trade_mapping, agg_mapping, quote_mapping
from .polygon.entity import (
Trade, Quote, Agg, trade_mapping, agg_mapping, quote_mapping
)
import logging


Expand Down Expand Up @@ -113,11 +115,14 @@ def _cast(self, channel, msg):
if channel == 'account_updates':
return Account(msg)
if channel.startswith('T.'):
return Trade({trade_mapping[k]: v for k, v in msg.items() if k in trade_mapping})
return Trade({trade_mapping[k]: v for k,
v in msg.items() if k in trade_mapping})
if channel.startswith('Q.'):
return Quote({quote_mapping[k]: v for k, v in msg.items() if k in quote_mapping})
return Quote({quote_mapping[k]: v for k,
v in msg.items() if k in quote_mapping})
if channel.startswith('A.') or channel.startswith('AM.'):
return Agg({agg_mapping[k]: v for k, v in msg.items() if k in agg_mapping})
return Agg({agg_mapping[k]: v for k,
v in msg.items() if k in agg_mapping})
return Entity(msg)

async def _dispatch(self, channel, msg):
Expand Down Expand Up @@ -150,15 +155,20 @@ def deregister(self, channel_pat):

class StreamConn(object):

def __init__(self, key_id=None, secret_key=None, base_url=None, data_url=None):
def __init__(
self,
key_id=None,
secret_key=None,
base_url=None,
data_url=None):
_key_id, _secret_key, _ = get_credentials(key_id, secret_key)
_base_url = base_url or get_base_url()
_data_url = data_url or get_data_url()

self.trading_ws = _StreamConn(_key_id, _secret_key, _base_url)
self.data_ws = _StreamConn(_key_id, _secret_key, _data_url)
self.polygon = polygon.StreamConn(_key_id +
'-staging' if 'staging' in _base_url else '')
self.polygon = polygon.StreamConn(
_key_id + '-staging' if 'staging' in _base_url else '')

self._handlers = {}
self._handler_symbols = {}
Expand Down

0 comments on commit f8d5d14

Please sign in to comment.