Hi,
Does anyone know the limit on how often clock function can be called using the trading client in alpaca-py? I am getting this error when calling it
clock = trade_client.get_clock()
alpaca.common.exceptions.APIError: {"message": "too many requests."}
Maybe I need to work on my architecture but here is what I have: 35 scripts trading 35 single names. Each has a sleep of 5 seconds at different interval and trade_client_.get_clock() gets called at different intervals. It is still giving me an issue.
However, when I get errored out randomly I am left with 19 traders/scripts running at 5 seconds interval and that seems to work.
Within 1 minute:
(60/5) x 19 = 228 calls per minute is fine
(60/5) x 35 = 420 call per minute is NOT fine
my version of alpaca-py: 0.43.4
Can anyone share how they have implemented market open/close logic for their intraday implementation?
@lracerk Each account is limited to 200 Trading API calls/min. If all of your calls are being made to the same account, that is why you are seeing this error when running in 19 scripts/algos.
If all you were trying to do is check when markets are open, there are some very good packages for this such as pandas_market_calendars. Just ensure your local machine clock is synchronized to NIST time. No need to call the Alpaca clock method.
Something like this
# import required packages
!pip install -q pandas_market_calendars
import pandas_market_calendars as mcal
import pandas as pd
# instantiate a calendar object
US_EQUITY_MARKET = mcal.get_calendar("XNYS")
# get the current market time
current_market_time = pd.Timestamp.now(US_EQUITY_MARKET.tz)
# get a schedule of open and close times within a week from the current time
current_schedule = US_EQUITY_MARKET.schedule(start_date=current_market_time-pd.Timedelta('1W'), end_date=current_market_time+pd.Timedelta('1W'), tz=US_EQUITY_MARKET.tz
)
# check if the markets are open now
is_open = US_EQUITY_MARKET.is_open_now(schedule=current_schedule)