alpacahq / alpaca-trade-api-python

Python client for Alpaca's trade API
https://pypi.org/project/alpaca-trade-api/
Apache License 2.0
1.73k stars 538 forks source link

the method BarSet.df have performance issues #291

Closed weiguang-zz closed 2 years ago

weiguang-zz commented 4 years ago

https://github.com/alpacahq/alpaca-trade-api-python/blob/261cd55461f4793a44bd6ec9225f3d16dcae9bc2/alpaca_trade_api/entity.py#L111

Steps to reproduce:

import profile
import alpaca_trade_api as tradeapi
import pandas as pd
symbols = ['A', 'AA', 'AAL', 'AAN', 'AAP', 'AAPL', 'AAXJ', 'AAXN', 'ABB', 'ABBV', 'ABC', 'ABEV', 'ABMD', 'ABT', 'ACAD', 'ACB', 'ACC', 'ACGL', 'ACIA', 'ACM', 'ACMR', 'ACN', 'ACWI', 'ACWV', 'ACWX', 'ADBE', 'ADC', 'ADI', 'ADM', 'ADP', 'ADPT', 'ADS', 'ADSK', 'ADSW', 'AEE', 'AEM', 'AEO', 'AEP', 'AER', 'AES', 'AFG', 'AFL', 'AG', 'AGCO', 'AGG', 'AGIO', 'AGNC', 'AGR', 'AIG', 'AIMT', 'AIV', 'AIZ', 'AJG', 'AKAM', 'AL', 'ALB', 'ALC', 'ALGN', 'ALGT', 'ALK', 'ALKS', 'ALL', 'ALLE', 'ALLK', 'ALLO', 'ALLY', 'ALNY', 'ALRM', 'ALSN', 'ALT', 'ALV', 'ALXN', 'AM', 'AMAT', 'AMBA', 'AMC', 'AMCR', 'AMCX', 'AMD', 'AME', 'AMED', 'AMG', 'AMGN', 'AMH', 'AMJ', 'AMLP', 'AMN', 'AMP', 'AMRN', 'AMT', 'AMTD', 'AMX', 'AMZN', 'AN', 'ANET', 'ANF', 'ANGI', 'ANGL', 'ANSS', 'ANTM', 'AON', 'AOS', 'APA', 'APD', 'APH', 'APHA', 'APLE', 'APLS', 'APO', 'APPN', 'APT', 'APTV', 'ARCC', 'ARE', 'ARGX', 'ARKK', 'ARKW', 'ARMK', 'ARNA', 'ARNC', 'ARW', 'ARWR', 'ASH', 'ASHR', 'ASML', 'ASND', 'ATH', 'ATHM', 'ATI', 'ATO', 'ATR', 'ATUS', 'ATVI', 'AU', 'AUPH', 'AUY', 'AVB', 'AVGO', 'AVLR', 'AVT', 'AVTR', 'AVY', 'AVYA', 'AWI', 'AWK', 'AXP', 'AXS', 'AXSM', 'AXTA', 'AYI', 'AYX', 'AZN', 'AZO', 'AZPN', 'AZUL', 'BA', 'BABA', 'BAC', 'BAH', 'BAM', 'BAND', 'BAP', 'BAX', 'BB', 'BBBY', 'BBD', 'BBEU', 'BBJP', 'BBL', 'BBY', 'BC', 'BCE', 'BCO', 'BCRX', 'BCS', 'BDX', 'BE', 'BEN', 'BERY', 'BF.B', 'BFAM', 'BG', 'BGNE', 'BHC', 'BHF', 'BHP', 'BHVN', 'BIDU', 'BIG', 'BIIB', 'BIL', 'BILI', 'BILL', 'BIO', 'BIV', 'BJ', 'BK', 'BKI', 'BKLN']
size = 'minute'
_from = pd.Timestamp('2020-07-30T09:30:00-04:00')
to = pd.Timestamp('2020-07-31T16:00:00-04:00')
api = tradeapi.REST(key_id, secret, base_url, api_version=api_version)
profile.run('api.get_barset(symbols, size, start=_from.isoformat(), end=to.isoformat()).df[symbols]')

the results: image

however, the Network cost is small: image

drew887 commented 2 years ago

Hey closing this one out due to inactivity. Also it looks like maybe your issue was actually solved in the chain of linked issues to other repos here.