Submit multiple orders in parallel

I’m trying to submit multiple orders in parallel. I’ve tried couple of methods and doesn’t seem that orders can be submitted simultaneously.

I tried to test with submitting 2 orders, with:

  1. submit first order, then the next. This is just for comparison, to see the latency for submitting an order. There is a ~0.1s delay between the two orders submission, which means the first order takes 0.1s to be submitted before the second one start to submit.
  2. using asyncio to submit 2 orders. It’s still the second order was submitted ~0.1s after the first one submitted.
  3. created 2 threads with threading module to submit 2 orders. The behavior is the same as above, still 0.1s different between the two order submission.
  4. using multiprocessing. This returns an SSL error from multiprocessing, as the two processes are using the same Alpaca api connection.

I understand that Python async and threading are not truely parallelism, so it might be one of the reasons that two orders not being submitted simultaneously. But I wonder if there is any kind of limit from Alpaca API that prevent this? Say, if hypothetically there is a way that 2 orders come in exactly at the same time, will the REST API take the 2 orders simultaneously? Will it solve the problem if I switch to Golang which handles parallelism better?


Somewhere in the api you will find the ability to submit multiple orders with one request.

Would you please point me to the code pointer that does the multiple orders? I can’t seem to find it. Thanks.

nm looks like you can send bracket orders for one position. Understand Orders - Documentation | Alpaca