# Liquidation via API does not work 5 minutes before market close

**URL:** https://forum.alpaca.markets/t/liquidation-via-api-does-not-work-5-minutes-before-market-close/17241
**Category:** Alpaca Trading
**Created:** [July 1, 2025, 8:39pm UTC](https://forum.alpaca.markets/t/liquidation-via-api-does-not-work-5-minutes-before-market-close/17241 "2025-07-01T20:39:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fred\_pickles](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@fred\_pickles](https://forum.alpaca.markets/u/fred_pickles)
#### Post date: [July 1, 2025, 8:39pm UTC](https://forum.alpaca.markets/t/liquidation-via-api-does-not-work-5-minutes-before-market-close/17241/1 "2025-07-01T20:39:31Z")

</div>

I have a project in live deployment with QuantConnect (local LEAN CLI) trading a $30,000 margin paper trading account at Alpaca, which takes positions intra-day only, both long and short. I’m using 1 minute data, but my code only takes action at 5 minute intervals.

I have a scheduled event setup that is supposed to close all open positions exactly 5 minutes before market close every trading day. In backtesting everything works as intended, and open positions are closed exactly 5 minutes before market close. However, during live deployment, the liquidate function does not work at the 5 minutes before market close mark. 20 minutes, 15 minutes, 10 minutes, and 6 minutes before market close all work as intended in live deployment, as do other times throughout the trading day, but 5 minutes before close does not.

The instrument I’m trading is extremely liquid, so there’s no issue there. Additionally, I am able to liquidate my open positions manually via the Alpaca dashboard any time between 5 and 0 minutes prior to market close. Why am I not allowed to liquidate my positions via API at 5 minutes or less before market close?

---

<div class="post-metadata">

### Author: ![fred\_pickles](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@fred\_pickles](https://forum.alpaca.markets/u/fred_pickles)
#### Post date: [April 17, 2026, 6:45pm UTC](https://forum.alpaca.markets/t/liquidation-via-api-does-not-work-5-minutes-before-market-close/17241/2 "2026-04-17T18:45:25Z")

</div>

This turned out to be an error on my part. My code was trying to perform multiple operations at the same time and was tripping over itself.

---

<div class="post-metadata">

### Author: ![Dan\_Whitnable\_Alpaca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/dan_whitnable_alpaca/32/1658_2.png) [@Dan\_Whitnable\_Alpaca](https://forum.alpaca.markets/u/Dan_Whitnable_Alpaca)
#### Post date: [April 19, 2026, 10:41am UTC](https://forum.alpaca.markets/t/liquidation-via-api-does-not-work-5-minutes-before-market-close/17241/3 "2026-04-19T10:41:17Z")

</div>

@fred_pickles Thank you for the update and glad to hear everything’s working for you now. Good luck!
