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:
-
concurrent.futures.ThreadPoolExecutor:
- Evaluate performance for parallel REST API requests (e.g., fetching quotes for multiple tickers).
- Check code readability compared to native
asyncio.
-
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.
-
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
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
asynciois 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
asynciothat can still effectively manage network latency and real-time data streaming without the overhead ofasync/awaitsyntax.Proposed Alternatives to Test
I plan to create short proof-of-concept (PoC) scripts for the following three approaches:
concurrent.futures.ThreadPoolExecutor:asyncio.Multithreading with
Queue(Producer-Consumer Pattern):queue.Queueto pass real-time price updates to the main strategy logic.websocket-client(Synchronous/Threaded):run_forever()method in a dedicated thread to avoid blocking the main execution loop.Success Criteria
Additional Resources
threadingandconcurrent.futuresmodules