Skip to content

Commit

Permalink
DataConstants restructuring to store API keys (#28)
Browse files Browse the repository at this point in the history
* fixed yahoo datareader bug + added BoE vendor

* fixed yahoo datareader bug + added BoE vendor

* restructured api key storage in DataConstants
  • Loading branch information
dkn22 authored and saeedamen committed Nov 2, 2019
1 parent 3a068fe commit 6110e68
Show file tree
Hide file tree
Showing 3 changed files with 842 additions and 9 deletions.
3 changes: 2 additions & 1 deletion findatapy/market/datavendorweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def download_daily(self, market_data_request):

while(trials < 5):
try:
data_frame = Quandl.get(market_data_request.tickers, authtoken=market_data_request.quandl_api_key, trim_start=market_data_request.start_date,
data_frame = Quandl.get(market_data_request.tickers,
authtoken=market_data_request.quandl_api_key, trim_start=market_data_request.start_date,
trim_end=market_data_request.finish_date)

break
Expand Down
30 changes: 22 additions & 8 deletions findatapy/util/dataconstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
"""

import os
import keyring

def key_store(service_name):
key = keyring.get_password(service_name, os.getlogin())

if key is None:
key = input("Please enter the %s API key: " % service_name)

return key


class DataConstants(object):

Expand Down Expand Up @@ -114,22 +124,22 @@ class DataConstants(object):
fxcm_write_temp_tick_disk = False

# Quandl settings
quandl_api_key = "x"
quandl_api_key = key_store("Quandl")

# Alpha Vantage settings
alpha_vantage_api_key = "x"
alpha_vantage_api_key = key_store("AlphaVantage")

# FXCM API (contact FXCM to get this)
fxcm_api_key = "x"

# Twitter settings (you need to set these up on Twitter)
TWITTER_APP_KEY = "x"
TWITTER_APP_SECRET = "x"
TWITTER_OAUTH_TOKEN = "x"
TWITTER_OAUTH_TOKEN_SECRET = "x"
TWITTER_APP_KEY = key_store("Twitter App Key")
TWITTER_APP_SECRET = key_store("Twitter App Secret")
TWITTER_OAUTH_TOKEN = key_store("Twitter OAUTH token")
TWITTER_OAUTH_TOKEN_SECRET = key_store("Twitter OAUTH token Secret")

# FRED (Federal Reserve of St Louis data) settings
fred_api_key = "x"
fred_api_key = key_store("FRED")

# overwrite field variables with those listed in DataCred
def __init__(self):
Expand All @@ -141,4 +151,8 @@ def __init__(self):
if k in cred_keys and '__' not in k:
setattr(DataConstants, k, getattr(DataCred, k))
except:
pass
pass

@staticmethod
def reset_api_key(service_name, api_key):
keyring.set_password(service_name, os.getlogin(), api_key)
818 changes: 818 additions & 0 deletions findatapy_examples/notebooks/equitiesdata_example.ipynb

Large diffs are not rendered by default.

0 comments on commit 6110e68

Please sign in to comment.