alpacahq / alpaca-py

The Official Python SDK for Alpaca API
https://alpaca.markets/sdks/python/getting_started.html
Apache License 2.0
605 stars 150 forks source link

[Feature Request] Merge similar orders #189

Open sshcli opened 2 years ago

sshcli commented 2 years ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe.

About the problem:

Describe the solution you'd like.

For example: We have 3 separated orders to sell AAPL at $170.02

Sell Order1: Symbol: APPL Qty: 1 Limit Price: 172.02

Sell Order2: Symbol: APPL Qty: 5 Limit Price: 172.02

Sell Order3: Symbol: APPL Qty: 3 Limit Price: 172.02

We need a feature to be able to convert those 3 orders in just 1 order. The results will be something like this:

Unique Sell Order: Symbol: APPL Qty: 9 Limit Price: 172.02

This new feature will help us to:

Describe an alternate solution.

Occam's razor | keep it simple

Anything else? (Additional Context)

Occam's razor | keep it simple

impredicative commented 2 years ago

More simply, I think it would be nice to have a backend feature to merge an unsubmitted new order into an accepted order. This is assuming the direction of long or short is the same across the two orders. Currently this doesn't seem possible. I assume the combined limit price can then be its weighted average. If the merge fails, then just the new order can be submitted.

In any case, I don't think this package is the best place for backend requests. This package is just the SDK over the backend interfaces.

sshcli commented 2 years ago

The feature could be also available in the web version. See image below:

merge-similar-orders
impredicative commented 2 years ago

I am not convinced that this should be a global setting for the account. I currently take the more conservative opinion that it should be API driven.

sshcli commented 2 years ago

Someone from Alpaca team has suggested a method in the py package.

impredicative commented 2 years ago

Someone from Alpaca team has suggested a method in the py package.

I have looked and there is no applicable method that replaces an accepted order. The only way I know to do it is to cancel the existing order(s) and submit a new order.

sshcli commented 2 years ago

The suggestion was for implement it, is not available yet.