Skip to content

Commit

Permalink
Add ability to override key used to authenticate with Polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
ttt733 committed Jul 12, 2019
1 parent 63addf7 commit 024f188
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions alpaca_trade_api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def get_credentials(key_id=None, secret_key=None):
return key_id, secret_key


def get_polygon_credentials(alpaca_key=None):
key_id = os.environ.get('POLYGON_KEY_ID') or alpaca_key
if key_id is None:
raise ValueError('Key ID must be given to access Polygon API')
return key_id


def get_api_version(api_version):
api_version = api_version or os.environ.get('APCA_API_VERSION')
if api_version is None:
Expand Down
2 changes: 2 additions & 0 deletions alpaca_trade_api/polygon/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Exchange, SymbolTypeMap, ConditionMap,
Company, Dividends, Splits, Earnings, Financials, NewsList, Ticker
)
from alpaca_trade_api.common import get_polygon_credentials


def _is_list_like(o):
Expand All @@ -15,6 +16,7 @@ def _is_list_like(o):
class REST(object):

def __init__(self, api_key, staging=False):
self._api_key = get_polygon_credentials(api_key)
self._api_key = api_key
self._staging = staging
self._session = requests.Session()
Expand Down
3 changes: 2 additions & 1 deletion alpaca_trade_api/polygon/stream2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from .entity import (
Quote, Trade, Agg, Entity,
)
from alpaca_trade_api.common import get_polygon_credentials
import logging


class StreamConn(object):
def __init__(self, key_id=None):
self._key_id = key_id or os.environ.get('APCA_API_KEY_ID')
self._key_id = get_polygon_credentials(key_id)
self._endpoint = os.environ.get(
'POLYGON_WS_URL',
'wss://alpaca.socket.polygon.io/stocks'
Expand Down

0 comments on commit 024f188

Please sign in to comment.