Skip to content

Commit

Permalink
Improved messages on missing key to mention env
Browse files Browse the repository at this point in the history
  • Loading branch information
bdowling committed Jul 15, 2019
1 parent 53b6e3f commit a20bb80
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions alpaca_trade_api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@ def get_data_url():
def get_credentials(key_id=None, secret_key=None):
key_id = key_id or os.environ.get('APCA_API_KEY_ID')
if key_id is None:
raise ValueError('Key ID must be given to access Alpaca trade API')
raise ValueError('Key ID must be given to access Alpaca trade API',
'(env: APCA_API_KEY_ID)')

secret_key = secret_key or os.environ.get('APCA_API_SECRET_KEY')
if secret_key is None:
raise ValueError('Secret key must be given to access Alpaca trade API')
raise ValueError('Secret key must be given to access Alpaca trade API'
' (env: APCA_API_SECRET_KEY')

return key_id, secret_key


def get_polygon_credentials(alpaca_key=None):
try:
alpaca_key, _ = get_credentials(alpaca_key)
alpaca_key, _ = get_credentials(alpaca_key, 'ignored')
except ValueError:
pass
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')
raise ValueError('Key ID must be given to access Polygon API'
'(env: APCA_API_KEY_ID or POLYGON_KEY_ID)')
return key_id


Expand Down

0 comments on commit a20bb80

Please sign in to comment.