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

Negative quantity #86

Closed lvca closed 4 years ago

lvca commented 4 years ago

I've noticed sometimes the quantity of a position is negative. I've found this on paper account only (so far). Look at this:

{
    "symbol": "SLM",
    "side": "short",
    "market_value": "-22078.98",
    "unrealized_intraday_pl": "-99.12",
    "unrealized_pl": "-1362.9",
    "lastday_price": "8.87",
    "asset_class": "us_equity",
    "change_today": "0.0045095828635851",
    "asset_id": "062b2922-9e0b-4f99-bd72-57ab93d251dc",
    "avg_entry_price": "8.36",
    "cost_basis": "-20716.08",
    "unrealized_intraday_plpc": "-0.0045095828635851",
    "qty": "-2478",
    "unrealized_plpc": "-0.0657894736842105",
    "exchange": "NASDAQ",
    "current_price": "8.91"
}
bdowling commented 4 years ago

Please note that @ivca the negative quantity and "side": "short" go hand in hand. We support short selling of securities as well as long, currently easy to borrow tickers are shortable. This is a case where you sold a position that was at qty=0, which results in a short position. You can short assets that are listed as shortable in our assets api.

We understand there are cases where "over selling" can inadvertently result in this and we are considering options to prevent this in the API. The request #85 actually just came in right before yours that addresses this exact issue.

codebeaulieu commented 4 years ago

This is exactly why I opened up this issue : https://github.com/alpacahq/Alpaca-API/issues/85

These kinda of "happy accidents" could be easily avoided if Alpaca changed from simple Buy Sell to BTO, STC, STO, BTC.

lvca commented 4 years ago

I agree with @codebeaulieu, that this is confusing. By the way, I've spent 10 mins finding how to short a stock on Alpaca docs, and I can't find anything. @bdowling could you please point me to the docs that explain the negative quantity? Thanks.