-
Notifications
You must be signed in to change notification settings - Fork 61
Closed
Description
Problem
Trading systems using this library need to minimize latency on order submissions. Currently, the TcpStream connections use Nagle's algorithm (the default), which can buffer small writes (order messages ~100-200 bytes) for up to 40ms before sending them.
For algorithmic trading, this adds unnecessary latency to order routing — a critical path where milliseconds matter.
Proposed Solution
Add opt-in TCP_NODELAY support via:
- Environment variable
IBAPI_TCP_NODELAY=1to disable Nagle's algorithm - Apply to all 4 connection paths:
TcpSocket::new()(sync initial connection) —transport/sync.rs:704TcpSocket::reconnect()(sync reconnect) —transport/sync.rs:719AsyncConnection::connect_with_callback()(async initial connection) —connection/async.rs:42AsyncConnection::reconnect()(async reconnect) —connection/async.rs:91
Backward Compatibility
- Default behavior: unchanged (Nagle enabled)
- Opt-in: Set
IBAPI_TCP_NODELAY=1before callingClient::connect() - No API changes required
- Zero breaking changes
Performance Impact
When enabled:
- Eliminates up to 40ms delay on small writes (order submissions, market data requests)
- For trading systems with low message rates (~1-10/sec), bandwidth overhead is negligible
- Significantly reduces order routing latency
Implementation
I have a fork with this change ready to submit as a PR. The implementation:
- Adds 4
socket.set_nodelay(true)?calls, one per connection path - All 100 existing unit tests pass
- Environment variable is checked at connection time only
- ~18 lines of code total
Would you be open to this feature? I can open a PR if this aligns with the project's goals.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels