Skip to content

Python : Research and Implementation of Alternatives to asyncio #51

Description

@kimpro82

Context

Developing a personal trading bot using the LS Securities (formerly eBest) Open API requires handling both RESTful API calls and real-time WebSocket data. While asyncio is a standard approach for asynchronous I/O, its complexity can be overkill for a personal-scale trading application that does not require managing thousands of concurrent client connections.

Objective

The goal is to implement and test lightweight, readable, and maintainable alternatives to asyncio that can still effectively manage network latency and real-time data streaming without the overhead of async/await syntax.

Proposed Alternatives to Test

I plan to create short proof-of-concept (PoC) scripts for the following three approaches:

  1. concurrent.futures.ThreadPoolExecutor:

    • Evaluate performance for parallel REST API requests (e.g., fetching quotes for multiple tickers).
    • Check code readability compared to native asyncio.
  2. Multithreading with Queue (Producer-Consumer Pattern):

    • Isolate the WebSocket feed into a background thread.
    • Use a thread-safe queue.Queue to pass real-time price updates to the main strategy logic.
  3. websocket-client (Synchronous/Threaded):

    • Test the stability of the run_forever() method in a dedicated thread to avoid blocking the main execution loop.

Success Criteria

  • Latency: The implementation must handle real-time quote updates without lagging the main execution loop.
  • Simplicity: The code should be intuitive for a single-developer environment, avoiding deep nested event loops.
  • Stability: Ensure no thread-safety issues when accessing shared data (e.g., current account balance or ticker prices).

Additional Resources

  • LS Securities OpenAPI Documentation
  • Python threading and concurrent.futures modules

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions