A flexible event-driven daemon for Interactive Brokers TWS/Gateway that handles real-time market data and trading events.
- Event-driven architecture for handling IBKR market data and trading events
- Simple handler pattern for implementing custom event processors
- Built-in support for real-time bar data
- Configurable via environment variables or command-line options
- Comprehensive logging with rotation and retention policies
- Supervisor integration for process management
pip install ibkr-event-daemon- Configure your environment variables in
.env:
IB_EVENT_DAEMON_HOST=127.0.0.1
IB_EVENT_DAEMON_PORT=7497
IB_EVENT_DAEMON_CLIENTID=1
IB_EVENT_DAEMON_TIMEOUT=4
IB_EVENT_DAEMON_READONLY=False
IB_EVENT_DAEMON_ACCOUNT=
IB_EVENT_DAEMON_RAISESYNCERRORS=False
IB_EVENT_DAEMON_SETUP_PATHS="./example"
- Start the daemon:
ibkr-daemon startOr with custom logging:
ibkr-daemon start --log-level DEBUG --log-file logs/daemon.logHandlers are Python modules that process IBKR events. Place your handlers in the directory specified by IB_EVENT_DAEMON_SETUP_PATHS.
Example handler for real-time bar data (example/realtimebar_example.py):
from ib_async import IB, Forex
from ibkr_event_daemon.core import LoggerType
def setup(ib: IB, logger: LoggerType) -> None:
usd_jpy = Forex('USDJPY')
bars = ib.reqRealTimeBars(
usd_jpy,
barSize=5,
whatToShow="MIDPOINT",
useRTH=True
)
bars.updateEvent += onBarUpdate
def onBarUpdate(bars, hasNewBar):
if hasNewBar:
print(bars[-1])Configuration can be managed through:
- Environment variables (
.envfile) - Command-line options
- Configuration commands
Show current configuration:
ibkr-daemon config showInitialize default configuration:
ibkr-daemon config initThe project includes a supervisord.conf for process management. This allows for:
- Automatic restart on failure
- Process monitoring
- Log management
To run in development mode:
- Clone the repository
- Install dependencies:
pip install -e .- Create and configure
.envfile:
ibkr-daemon config init- Start the daemon:
python -m ibkr_event_daemon start