alpacahq / Alpaca-API

The Alpaca API is a developer interface for trading operations and market data reception through the Alpaca platform.
https://alpaca.markets/
141 stars 13 forks source link

New API for submitting multiple orders #155

Open WinJ opened 3 years ago

WinJ commented 3 years ago

Hi,

Currently there is submit_order() API that takes one order. I’m wondering if it is possible to support a new API like submit_orders().

In the current behavior if the client side wants to submit X orders at the same time, it needs to call the REST API X times. Even with async in Python it’s still not fully parallel, which means there are some latency between order submission. If we can submit X orders with one request then it’ll solve the problem. Brokers like IB do support this kind of functionality.

This is also very useful if we want to split a big order to smaller ones.

Thanks!

ghost commented 3 years ago

@WinJ Agree. Also, note that async is not parallel in any way. You are mistaking async with multi-threaded / multi process execution. Async just runs a queue of tasks one after the other one. If you want to send multiple trade requests to Alpaca's API using a request session you should use multiple threads, either programming it yourself or using a library (look at grequests for python for instance). Also be careful if you are managing globals, do everything thread safe. However, I do agree that the optimal way should be being able to submit a basket of orders in a single request, this feature would be amazing.