Calculate profit/loss for correlated buy/sell orders

Is there a way to easily calculate profit/loss for individual trades?

I know there are two endpoints to grab historical activity/order data

  1. REST.list_orders(status=‘filled’)
  2. REST.get_activities(activity_types=[‘FILL’])

I am wondering how to correlate a buy/sell together. For instance, if I buy 2 shares of Delta stock (DAL) on 12/1, and sell 1 share on 2/3, I would like to know the buy date, buy price, sell date, and sell price for that trade of 1 share of Delta stock.

From what I have seen, there are individual Orders for buy and sell, but no way to correlate the pair together?

There is no obvious way to do this since it’s not clear what transactions belong together. In you example, had you bought DAL in two different occasions, it’s not clear which one was sold. There has been a helpful piece of code posted recently that determines the profit when you sold the last stock: Easy way to calculate Profit per trade in python

My understanding:
Alpaca does note track or expose lot information, which is what would be needed to associate individual sells with corresponding buys. Consequently, when a sell occurs the average buy price of all accumulated holdings of the given asset is used.

I have no idea how this works w/r/t tax reporting for long for short term capital gains. Is the assumption by Alpaca that no shares will be held long enough to qualify as long?

Assuming my understanding of the above is correct, I consider it unfortunate. Hopefully they will address this in the future.

For algorithm purposes, you can track historical buys / sells via the Activities API and do your own book-keeping if you want to match buy-sell pairs for the purposes of trading choices. I don’t know of a better way to do it given Alpaca’s current behavior and API.

Hope this helps.