alpacahq / Alpaca-API

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

Replace side "Buy, Sell" with "BTO, STC, STO, BTC" #85

Open codebeaulieu opened 4 years ago

codebeaulieu commented 4 years ago

My algorithm sometimes tries to sell a position twice, which results in in liquidation of my current position and then the filling of a short order. In a perfect world, our code is so tried and tested that this could never happen by mistake. But, as we know, we do not live in a perfect world and bugs occur, regressions occur, hiccups occur.

The accidental shorting of an equity due to two sell orders clearing is dangerous, unacceptable and yet, completely avoidable by a responsible API.

Recommendation:

Please replace current "Buy, Sell" options with the following:

BTO = Buy To Open STC = Sell To Close STO = Sell To Open BTC = Buy To Close

This will ensure orders accepted by the API are accepted as intended by the developer and it will help protect your clients equity.

bdowling commented 4 years ago

@codebeaulieu we agree there needs to be some added protection here, we had discussed this early on in the design of adding shorts, but initially went for a simpler implementation.

One other option we had considered was an added field which defines your position intent rather than changing the buy/sell which is already ubiquitous across our API and user's usage. For example:

position_intent='long'
position_intent='short'
position_intent='flat'

One thing using a flag such as this could enable is immediately flipping your position from long to short for example. e.g. If you had qty=100 You could sell qty=200, position_intent='short'

Let us know your thoughts, but either way thanks for raising the issue, we will find a way to make this safer.

codebeaulieu commented 4 years ago

@bdowling I think as long as we can clearly specify "this order is a long" or "this order is a short" the implementation isn't super important. Whatever is the easiest to implement on your end.

I just want the server to kick back an error if I try to exit and already liquidated position rather than flipping me short.

Thanks for responding quickly @bdowling I know it takes a while to get this stuff implemented of course. But this is a scary one for me.

nahomtefera commented 3 years ago

did you find a way to fix this nuisance?