From f8d5d14108af187ab59b00084398d547cd11af48 Mon Sep 17 00:00:00 2001 From: Hitoshi Harada Date: Tue, 21 Apr 2020 18:16:19 -0700 Subject: [PATCH] Comply PEP8 --- alpaca_trade_api/polygon/rest.py | 2 +- alpaca_trade_api/polygon/streamconn.py | 13 ++++++++----- alpaca_trade_api/stream2.py | 24 +++++++++++++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/alpaca_trade_api/polygon/rest.py b/alpaca_trade_api/polygon/rest.py index 07267f83..92b46d90 100644 --- a/alpaca_trade_api/polygon/rest.py +++ b/alpaca_trade_api/polygon/rest.py @@ -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, diff --git a/alpaca_trade_api/polygon/streamconn.py b/alpaca_trade_api/polygon/streamconn.py index eccb6463..110ffdd4 100644 --- a/alpaca_trade_api/polygon/streamconn.py +++ b/alpaca_trade_api/polygon/streamconn.py @@ -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: @@ -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): diff --git a/alpaca_trade_api/stream2.py b/alpaca_trade_api/stream2.py index 543f2f8c..6d8364ea 100644 --- a/alpaca_trade_api/stream2.py +++ b/alpaca_trade_api/stream2.py @@ -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 @@ -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): @@ -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 = {}