Skip to content

Commit

Permalink
Merge pull request #30 from jbussdieker/jbb-fix-connection-pool
Browse files Browse the repository at this point in the history
Reuse sessions for Alpaca API calls
  • Loading branch information
Shlomi Kushchi authored Jan 11, 2021
2 parents 3b45146 + ad0ad13 commit d288bd7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pipeline_live/data/sources/alpaca.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@


def list_symbols():
api = tradeapi.REST()
return [
a.symbol for a in tradeapi.REST().list_assets()
a.symbol for a in api.list_assets()
if a.tradable and a.status == 'active'
]

Expand All @@ -27,8 +28,10 @@ def _get_stockprices(symbols, limit=365, timespan='day'):
Just deal with Alpaca's 200 stocks per request limit.
'''

api = tradeapi.REST()

def fetch(symbols):
barset = tradeapi.REST().get_barset(symbols, timespan, limit)
barset = api.get_barset(symbols, timespan, limit)
data = {}
for symbol in barset:
df = barset[symbol].df
Expand Down

0 comments on commit d288bd7

Please sign in to comment.