# {T: 'error', code: 406, msg: 'connection limit exceeded'}

**URL:** <https://forum.alpaca.markets/t/t-error-code-406-msg-connection-limit-exceeded/10896>\
**Category:** Alpaca Market Data\
**Created:** [October 24, 2022, 4:44am UTC](https://forum.alpaca.markets/t/t-error-code-406-msg-connection-limit-exceeded/10896 "2022-10-24T04:44:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chatofking](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@chatofking](https://forum.alpaca.markets/u/chatofking)\
**Post date:** [October 24, 2022, 4:44am UTC](https://forum.alpaca.markets/t/t-error-code-406-msg-connection-limit-exceeded/10896/1 "2022-10-24T04:44:09Z")

</div>

I get an error when I try to use the market data API  
error 406  
“connection limit exceeded”  
what should i do??

---

<div class="post-metadata">

**Author:** ![oleg.rakhmatulin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/oleg.rakhmatulin/32/559_2.png) [@oleg.rakhmatulin](https://forum.alpaca.markets/u/oleg.rakhmatulin)\
**Post date:** [October 25, 2022, 5:35am UTC](https://forum.alpaca.markets/t/t-error-code-406-msg-connection-limit-exceeded/10896/2 "2022-10-25T05:35:50Z")

</div>

This message is documented [here](https://alpaca.markets/docs/api-references/market-data-api/stock-pricing-data/realtime/#control-messages). Most probably you have another connection with the same API key/secret opened. Only one active real-time connection is allowed now. The server has 90 seconds timeout for ‘partially dead’ connections so if you try to reconnect right after network-related disconnection (without proper web socket shutdown) using another socket you will receive this message too.

---

<div class="post-metadata">

**Author:** ![chatofking](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@chatofking](https://forum.alpaca.markets/u/chatofking)\
**Post date:** [November 4, 2022, 1:16pm UTC](https://forum.alpaca.markets/t/t-error-code-406-msg-connection-limit-exceeded/10896/4 "2022-11-04T13:16:15Z")

</div>

can you give an example of how to close WebSocket in a proper way?

---

<div class="post-metadata">

**Author:** ![oleg.rakhmatulin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/oleg.rakhmatulin/32/559_2.png) [@oleg.rakhmatulin](https://forum.alpaca.markets/u/oleg.rakhmatulin)\
**Post date:** [November 5, 2022, 12:04pm UTC](https://forum.alpaca.markets/t/t-error-code-406-msg-connection-limit-exceeded/10896/5 "2022-11-05T12:04:52Z")

</div>

@chatofking Proper network resource closing depends on your programming language/library. In most cases, socket-related objects provide a method/function for closing the underlying connection. It can have names like `close`, `disconnect`, or something like this. Ideally, it should send a low-level WS protocol message to the server that indicates the end of the communication session and close the network socket after receiving a confirmation response from the server side.
