(live trading) my equity went WAY UP in error

I’m doing live algo trading using Python SDK. My new buy order total amounts (dollar amounts to invest into a single asset) are calculated as a fraction of my equity considering the remaining margin. The more free funds I have and the farther from hitting the margin I am, the more I invest. I get my current equity by pulling my account data every time before buying:

import alpaca_trade_api as tradeapi
api = tradeapi.REST(...)
account = api.get_account()
equity = float(account.equity)
maintenance_margin = float(account.maintenance_margin)

My point is that equity is obtained directly from Alpaca. I also pull my maintenance margin and do calculations to make sure than a new buy order would never lead to going over it. This worked flawlessly for months.

This morning my equity value went haywire for a few minutes and then went back:

2021-05-05 10:28:37 EST   Equity:                  $  28864.32
2021-05-05 10:32:54 EST   Equity:                  $  51374.48
2021-05-05 10:37:50 EST   Equity:                  $ 109092.32
2021-05-05 10:43:14 EST   Equity:                  $  29347.46

Over the course of these 10 or so minutes, I was allowed to buy stocks for about $150k (real money). The maintenance margin increased to about $90k but this was still below my (incorrect) equity, which was shown as about $110k. Then my equity dropped back to what is was originally, give or take a few bucks. Therefore my maintenance margin suddenly turned to be way higher than my equity. As a result I was some $60k OVER the maintenance margin. Let me stress again that this wasn’t the result of an error in my algo or codes, but a direct consequence of Alpaca reporting wrong equity value over those 10-15 minutes. Could you guys tell me what happened?

Alpaca experienced an error in how account equity and associated buying_power and margin calculations were calculated. This resulted in anomalies as posted above for some accounts. The error was immediately detected and then fixed over the course of an hour or so. Everything is back to normal now.

If there are specific trades or situations you would like Alpaca to review, please send an email to support@alpaca.markets. Include the email address associated with the account and a brief description of the request. The broker team will work with you to resolve.

1 Like