This repository was archived by the owner on Jun 17, 2026. It is now read-only.
Commit 19eb538
committed
Close the WebSocket connection immediately when the stream is stopped.
Currently, when the stream is stopped, we set the stream status accordingly and then wait for the `_consume` loop to check the stream status and close the WebSocket connection. The `_consume` loop calls `self._ws.recv()` with a timeout of 5 seconds, so it can take up to 5 seconds for the WebSocket connection to be closed after the stream is stopped. This is unnecessarily inefficient and complicated.
Instead, we could close the WebSocket connection immediately when the stream is stopped. The `_consume` loop would still be broken out of properly because `self._ws.recv()` would raise a `ConnectionClosed` error.
# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date: Fri Feb 24 00:02:18 2023 -0800
#
# On branch stop_faster
# Your branch and 'fork/stop_faster' have diverged,
# and have 7 and 1 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
#
# Changes to be committed:
# modified: alpaca_trade_api/stream.py
#1 parent a7e23c6 commit 19eb538
1 file changed
Lines changed: 19 additions & 52 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
62 | | - | |
63 | 61 | | |
64 | 62 | | |
65 | 63 | | |
| |||
113 | 111 | | |
114 | 112 | | |
115 | 113 | | |
116 | | - | |
117 | | - | |
| 114 | + | |
118 | 115 | | |
119 | 116 | | |
120 | 117 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
136 | 122 | | |
137 | 123 | | |
138 | 124 | | |
| |||
230 | 216 | | |
231 | 217 | | |
232 | 218 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
| 219 | + | |
237 | 220 | | |
238 | 221 | | |
239 | 222 | | |
240 | | - | |
241 | 223 | | |
242 | 224 | | |
243 | 225 | | |
| |||
253 | 235 | | |
254 | 236 | | |
255 | 237 | | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
260 | 242 | | |
261 | 243 | | |
262 | 244 | | |
| |||
621 | 603 | | |
622 | 604 | | |
623 | 605 | | |
624 | | - | |
625 | 606 | | |
626 | 607 | | |
627 | 608 | | |
| |||
686 | 667 | | |
687 | 668 | | |
688 | 669 | | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
703 | 673 | | |
704 | 674 | | |
705 | 675 | | |
706 | 676 | | |
707 | 677 | | |
708 | | - | |
709 | | - | |
| 678 | + | |
710 | 679 | | |
711 | 680 | | |
712 | 681 | | |
713 | | - | |
714 | 682 | | |
715 | 683 | | |
716 | 684 | | |
| |||
723 | 691 | | |
724 | 692 | | |
725 | 693 | | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
730 | 698 | | |
731 | 699 | | |
732 | 700 | | |
| |||
741 | 709 | | |
742 | 710 | | |
743 | 711 | | |
744 | | - | |
745 | | - | |
| 712 | + | |
746 | 713 | | |
747 | 714 | | |
748 | 715 | | |
| |||
0 commit comments