prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  API Server under 2021.8
  <!-- 
  Have you searched for similar issues before posting it?
  Did you have a VERY good look at the [documentation](https://www.freqtrade.io/en/latest/) and are sure that the question is not explained there
  
  Please do not use the question template to report bugs or to request new features.
  -->
  
  ## Describe your environment
  
    * Operating system: Windows Server 2019
    * Python Version: Miniconda 3
    * CCXT version: 1.55.56_____ (`pip freeze | grep ccxt`)
    * Freqtrade Version: 2021.8 (`freqtrade -V` or `docker-compose run --rm freqtrade -V` for Freqtrade running in docker)
    
  ## Your question
  This might be a bug, I post it as question, since I am nor sure for 100%.
  
  (OS and Miniconda configuration works fine for Freqtrade since 2020.12)
  Trading works fine under Telegram with current version.
  With current version and activated API Server, the system remains idle and does not begin to trade. Play button in GUI is pushed.  Even no trades visible in DB, opened in a SQlite explorer.
  API Server web GUI works excellent.
  (Trading with API Server works fine under 2021.7)
  
  *Ask the question you have not been able to find an answer in our [Documentation](https://www.freqtrade.io/en/latest/)*
  
  
  </issue>
  <code>
  [start of freqtrade/rpc/api_server/uvicorn_threaded.py]
  1 import contextlib
  2 import threading
  3 import time
  4 
  5 import uvicorn
  6 
  7 
  8 class UvicornServer(uvicorn.Server):
  9     """
  10     Multithreaded server - as found in https://github.com/encode/uvicorn/issues/742
  11 
  12     Removed install_signal_handlers() override based on changes from this commit:
  13         https://github.com/encode/uvicorn/commit/ce2ef45a9109df8eae038c0ec323eb63d644cbc6
  14 
  15     Cannot rely on asyncio.get_event_loop() to create new event loop because of this check:
  16         https://github.com/python/cpython/blob/4d7f11e05731f67fd2c07ec2972c6cb9861d52be/Lib/asyncio/events.py#L638
  17 
  18     Fix by overriding run() and forcing creation of new event loop if uvloop is available
  19     """
  20 
  21     def run(self, sockets=None):
  22         import asyncio
  23 
  24         """
  25         Parent implementation calls self.config.setup_event_loop(),
  26             but we need to create uvloop event loop manually
  27         """
  28         try:
  29             import uvloop  # noqa
  30         except ImportError:  # pragma: no cover
  31             from uvicorn.loops.asyncio import asyncio_setup
  32             asyncio_setup()
  33         else:
  34             asyncio.set_event_loop(uvloop.new_event_loop())
  35         try:
  36             loop = asyncio.get_event_loop()
  37         except RuntimeError:
  38             # When running in a thread, we'll not have an eventloop yet.
  39             loop = asyncio.new_event_loop()
  40         loop.run_until_complete(self.serve(sockets=sockets))
  41 
  42     @contextlib.contextmanager
  43     def run_in_thread(self):
  44         self.thread = threading.Thread(target=self.run)
  45         self.thread.start()
  46         while not self.started:
  47             time.sleep(1e-3)
  48 
  49     def cleanup(self):
  50         self.should_exit = True
  51         self.thread.join()
  52
  [end of freqtrade/rpc/api_server/uvicorn_threaded.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/freqtrade/rpc/api_server/uvicorn_threaded.py b/freqtrade/rpc/api_server/uvicorn_threaded.py
  --- a/freqtrade/rpc/api_server/uvicorn_threaded.py
  +++ b/freqtrade/rpc/api_server/uvicorn_threaded.py
  @@ -5,6 +5,20 @@
   import uvicorn
   
   
  +def asyncio_setup() -> None:  # pragma: no cover
  +    # Set eventloop for win32 setups
  +    # Reverts a change done in uvicorn 0.15.0 - which now sets the eventloop
  +    # via policy.
  +    import sys
  +
  +    if sys.version_info >= (3, 8) and sys.platform == "win32":
  +        import asyncio
  +        import selectors
  +        selector = selectors.SelectSelector()
  +        loop = asyncio.SelectorEventLoop(selector)
  +        asyncio.set_event_loop(loop)
  +
  +
   class UvicornServer(uvicorn.Server):
       """
       Multithreaded server - as found in https://github.com/encode/uvicorn/issues/742
  @@ -28,7 +42,7 @@
           try:
               import uvloop  # noqa
           except ImportError:  # pragma: no cover
  -            from uvicorn.loops.asyncio import asyncio_setup
  +
               asyncio_setup()
           else:
               asyncio.set_event_loop(uvloop.new_event_loop())
  
verification_info: {"golden_diff": "diff --git a/freqtrade/rpc/api_server/uvicorn_threaded.py b/freqtrade/rpc/api_server/uvicorn_threaded.py\n--- a/freqtrade/rpc/api_server/uvicorn_threaded.py\n+++ b/freqtrade/rpc/api_server/uvicorn_threaded.py\n@@ -5,6 +5,20 @@\n import uvicorn\n \n \n+def asyncio_setup() -> None:  # pragma: no cover\n+    # Set eventloop for win32 setups\n+    # Reverts a change done in uvicorn 0.15.0 - which now sets the eventloop\n+    # via policy.\n+    import sys\n+\n+    if sys.version_info >= (3, 8) and sys.platform == \"win32\":\n+        import asyncio\n+        import selectors\n+        selector = selectors.SelectSelector()\n+        loop = asyncio.SelectorEventLoop(selector)\n+        asyncio.set_event_loop(loop)\n+\n+\n class UvicornServer(uvicorn.Server):\n     \"\"\"\n     Multithreaded server - as found in https://github.com/encode/uvicorn/issues/742\n@@ -28,7 +42,7 @@\n         try:\n             import uvloop  # noqa\n         except ImportError:  # pragma: no cover\n-            from uvicorn.loops.asyncio import asyncio_setup\n+\n             asyncio_setup()\n         else:\n             asyncio.set_event_loop(uvloop.new_event_loop())\n", "issue": "API Server under 2021.8\n<!-- \r\nHave you searched for similar issues before posting it?\r\nDid you have a VERY good look at the [documentation](https://www.freqtrade.io/en/latest/) and are sure that the question is not explained there\r\n\r\nPlease do not use the question template to report bugs or to request new features.\r\n-->\r\n\r\n## Describe your environment\r\n\r\n  * Operating system: Windows Server 2019\r\n  * Python Version: Miniconda 3\r\n  * CCXT version: 1.55.56_____ (`pip freeze | grep ccxt`)\r\n  * Freqtrade Version: 2021.8 (`freqtrade -V` or `docker-compose run --rm freqtrade -V` for Freqtrade running in docker)\r\n  \r\n## Your question\r\nThis might be a bug, I post it as question, since I am nor sure for 100%.\r\n\r\n(OS and Miniconda configuration works fine for Freqtrade since 2020.12)\r\nTrading works fine under Telegram with current version.\r\nWith current version and activated API Server, the system remains idle and does not begin to trade. Play button in GUI is pushed.  Even no trades visible in DB, opened in a SQlite explorer.\r\nAPI Server web GUI works excellent.\r\n(Trading with API Server works fine under 2021.7)\r\n\r\n*Ask the question you have not been able to find an answer in our [Documentation](https://www.freqtrade.io/en/latest/)*\r\n\n", "before_files": [{"content": "import contextlib\nimport threading\nimport time\n\nimport uvicorn\n\n\nclass UvicornServer(uvicorn.Server):\n    \"\"\"\n    Multithreaded server - as found in https://github.com/encode/uvicorn/issues/742\n\n    Removed install_signal_handlers() override based on changes from this commit:\n        https://github.com/encode/uvicorn/commit/ce2ef45a9109df8eae038c0ec323eb63d644cbc6\n\n    Cannot rely on asyncio.get_event_loop() to create new event loop because of this check:\n        https://github.com/python/cpython/blob/4d7f11e05731f67fd2c07ec2972c6cb9861d52be/Lib/asyncio/events.py#L638\n\n    Fix by overriding run() and forcing creation of new event loop if uvloop is available\n    \"\"\"\n\n    def run(self, sockets=None):\n        import asyncio\n\n        \"\"\"\n        Parent implementation calls self.config.setup_event_loop(),\n            but we need to create uvloop event loop manually\n        \"\"\"\n        try:\n            import uvloop  # noqa\n        except ImportError:  # pragma: no cover\n            from uvicorn.loops.asyncio import asyncio_setup\n            asyncio_setup()\n        else:\n            asyncio.set_event_loop(uvloop.new_event_loop())\n        try:\n            loop = asyncio.get_event_loop()\n        except RuntimeError:\n            # When running in a thread, we'll not have an eventloop yet.\n            loop = asyncio.new_event_loop()\n        loop.run_until_complete(self.serve(sockets=sockets))\n\n    @contextlib.contextmanager\n    def run_in_thread(self):\n        self.thread = threading.Thread(target=self.run)\n        self.thread.start()\n        while not self.started:\n            time.sleep(1e-3)\n\n    def cleanup(self):\n        self.should_exit = True\n        self.thread.join()\n", "path": "freqtrade/rpc/api_server/uvicorn_threaded.py"}]}