How tapanhaz/kite-ticker works
Main Components
• Client Application: This is the user’s code which imports and instantiates the KiteTicker class, provides callback functions (e.g., on_tick, on_message) and manages the event loop.
• KiteTicker Core Module: The heart of the library, implemented in Cython (see kite_ticker.pyx), which manages the websocket connection, partial Cython optimizations, and callback dispatching.
• External Dependencies:
– Asynchronous Event Loop: Depending on the OS, either uvloop (for Linux) or winloop (for Windows) is set as the event loop policy.
– Zerodha Websocket Server: The external service that the KiteTicker connects to (wss://ws.kite.trade).
• Build/Extension Infrastructure: The setup.py and requirements files indicate that the project uses a build process to compile the Cython module. Prebuilt extensions provided in the prebuilt-extensions folder constitute part of this aspect.
Relationships and Interactions
• The Client Application calls into the KiteTicker instance, and registers various asynchronous callbacks.
• KiteTicker uses the asynchronous event loop (configured by uvloop or winloop) to drive operations.
• Upon startup, KiteTicker establishes a websocket connection to the Zerodha endpoint and maintains communication. Data flows from the websocket back to KiteTicker, which then dispatches messages to the appropriate callback functions in the client.
• The build process compiles the Cython module via setup.py using requirements-build.txt – ensuring that the KiteTicker component is optimized.
Architectural Patterns & Design Principles
• Asynchronous Event-driven Design: Reflects the use of async callbacks and non-blocking I/O.
• Modular Separation: Keeping the KiteTicker module separate from client code, and isolating the build/extension compilation process.
• Callback-based Notification: External events are handled and forwarded via well-defined callback channels (on_tick, on_order_update, etc.).
• Cross-platform Considerations: The design distinguishes between Windows and Linux based on event loop choices.