Skip to content

Commit 024f188

Browse files
committed
Add ability to override key used to authenticate with Polygon
1 parent 63addf7 commit 024f188

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

alpaca_trade_api/common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def get_credentials(key_id=None, secret_key=None):
2323
return key_id, secret_key
2424

2525

26+
def get_polygon_credentials(alpaca_key=None):
27+
key_id = os.environ.get('POLYGON_KEY_ID') or alpaca_key
28+
if key_id is None:
29+
raise ValueError('Key ID must be given to access Polygon API')
30+
return key_id
31+
32+
2633
def get_api_version(api_version):
2734
api_version = api_version or os.environ.get('APCA_API_VERSION')
2835
if api_version is None:

alpaca_trade_api/polygon/rest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Exchange, SymbolTypeMap, ConditionMap,
77
Company, Dividends, Splits, Earnings, Financials, NewsList, Ticker
88
)
9+
from alpaca_trade_api.common import get_polygon_credentials
910

1011

1112
def _is_list_like(o):
@@ -15,6 +16,7 @@ def _is_list_like(o):
1516
class REST(object):
1617

1718
def __init__(self, api_key, staging=False):
19+
self._api_key = get_polygon_credentials(api_key)
1820
self._api_key = api_key
1921
self._staging = staging
2022
self._session = requests.Session()

alpaca_trade_api/polygon/stream2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from .entity import (
88
Quote, Trade, Agg, Entity,
99
)
10+
from alpaca_trade_api.common import get_polygon_credentials
1011
import logging
1112

1213

1314
class StreamConn(object):
1415
def __init__(self, key_id=None):
15-
self._key_id = key_id or os.environ.get('APCA_API_KEY_ID')
16+
self._key_id = get_polygon_credentials(key_id)
1617
self._endpoint = os.environ.get(
1718
'POLYGON_WS_URL',
1819
'wss://alpaca.socket.polygon.io/stocks'

0 commit comments

Comments
 (0)