Executing Orders

  1. Can we execute multiple orders at once? We are currently trying to send 1000 bracket orders. What is the quickest and most efficient way to execute all the orders.
  2. While executing orders I run into this - ’ [Sleep 3 seconds and retrying https://paper-api.alpaca.markets/v2/orders 3 more time(s)]'. I just upgraded to Alpaca Unlimited Subscription so I am not sure why I am receiving this error if API Calls are unlimited. Please advise.

@suraj Standard accounts are limited to 200 calls/minute. Orders must be placed individually so it would take a minimum of 1000 calls to place 1000 orders.

The simple way to ensure one doesn’t exceed the rate limit is to wait 1/200 minutes (or .3 seconds) between calls. A more sophisticated method to maximize throughput is to look at the header information of the last API call. All Trading API responses include 3 rate related pieces of data in their header

X-Ratelimit-Limit: 200
X-Ratelimit-Remaining: 195
X-Ratelimit-Reset: 1679411617

The X-Ratelimit-Limit is static and simply tells you the account’s rate limit. The X-Ratelimit-Remaining tells you how many calls you can make until the account’s rate counter is reset. The X-Ratelimit-Reset is the next time (in seconds epoch time) when the rate counter will reset. One way to use this information is to send orders as fast as you wish. If one gets a "429 rate limit exceeded" error, simply look at the header X-Ratelimit-Reset time. Pause until that time and then continue.

There is also a new program called Alpaca Plus which, for a fee, one can get increased rates (up to 1000/minute) along with some other perks. You may want to check that out.

How am I to access the header information of the last API call?

I upgraded and have an Unlimited Plan and the pricing options say that there are unlimited API calls with that plan. Why am I being limited to 200/calls?

@suraj The data plans which Alpaca offers (ie the “Unlimited” plan) are completely separate offerings than general account access. The rate limit for the market data APIs (ie https://data.alpaca.markets) is separate than the rate limit to access one’s account via the trading APIs (ie https://api.alpaca.markets and https://paper-api.alpaca.markets). Those trading API rate limits are independant of any data plan you may choose and do not change.

The header responses can be fetched in different ways depending upon the SDK or method you use to make the API calls. For example, using Postman they appear in the ‘headers’ tab

Which language and/or SDK are you using?

We are using Python as the programming language and Python’s SDK provided by alpaca. How can I extract the header responses using Python? Thank you for all the help.

In addition, how much does Alpaca Plus plan cost?

Hi Dan, just want to follow up on the above request.