Avg Entry and Cost Basis not calculated on a particular crypto position [PAPER]

I am coming back to Alpaca to test the crypto API. Specifically, I am building an automation that places buy and sell orders to my paper account.

However, I have just noticed in the web UI that my positions do not have Avg Entry or Cost Basis, and the Total P/L ($) value is just the market value. The below BTC position was bought via API:

Now, if I place an order via the web UI (for ETH), the values are all displayed and calculated properly:

I just used the API buy some XRP, which works as expected. I also used the API to purchase more BTC. The Avg Entry and Cost Basis values are now displayed for my BTC position, but it has clearly been calculated on the assumption that the first purchase didn’t have any cost.

What causes this? Is it a known bug? The only thing I can think of is that I previously had a BTC position which I sold before using the API to purchase a new position. Could the previous position be affecting the cost basis calculation?

@maxks90 You mentioned “I previously had a BTC position which I sold before using the API to purchase a new position”. Yes, that will impact the cost basis. Cost basis calculations use two forms of FIFO depending upon intra-day or overnight cost basis. Take a look here in the docs for an explanation.

Could that be the issue?

Thanks Dan. This could the the reason, but it still doesn’t make much sense to me. I cannot figure out why a long position would have no Cost Basis or Avg Entry, regardless of what happened before it.

@Dan_Whitnable_Alpaca I’m still having this problem, but now also with another position. I have never had a DOT position with Alpaca. This is my first ever DOT order:

However, the position appears to have been created with no Avg Entry or Cost Basis, so the Total P/L value is completely wrong.

image

Am I doing something wrong here? Can it be fixed?

@maxks90 Hmm. That is odd. The Avg Entry and Cost Basis should have non-zero values. I’ve sent a request to the Engineering Team to look into it.

1 Like

Thanks Dan. Much appreciated :slight_smile:

@maxks90 Should be fixed now. The issue was somehow there were two CUSIPS for the same asset (BTC/USD). You bought one CUSIP but that wasn’t the ‘current’ one. When the system tried to look up the price it couldn’t find it. This was definitely a ‘one-off’. Engineering is looking into the root cause.

Apologies for the inconvenience.

1 Like

Thanks Dan. Did this apply to DOT/USD too? If so, did the double CUSIPs problem apply to all crypto assets?

@maxks90 The asset_id issue only impacted several crypto pairs for a short window of trading. It only happened in paper and not live (they don’t share the same asset table).

1 Like

Understood. Thanks for sorting this out so quickly :slight_smile: