Skip to content

Commit cfe03b6

Browse files
committed
bi-insync implementation complete (for starters)
1 parent b6dbef7 commit cfe03b6

20 files changed

+2336
-39
lines changed

config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ MAX_DAILY_TRADES: 3
2222
STOP_LOSS_ATR_MULT: 2.0
2323
MAX_HOLDING_PERIOD: 10
2424

25+
# IBKR API Connection
26+
ibkr:
27+
host: "127.0.0.1"
28+
port: 7497 # TWS: 7497, IB Gateway: 4001
29+
client_id: 1
30+
read_only: false
31+
account: "" # Set your account ID or leave blank to use active account
32+
use_ib_insync: true # Use new implementation instead of placeholder
33+
timeout: 20 # Connection timeout in seconds
34+
auto_reconnect: true # Automatically try to reconnect on disconnection
35+
max_rate: 45 # Maximum API requests per second (IB's limit is 50)
36+
2537
# Backtest Parameters
2638
INITIAL_EQUITY: 100000
2739
BACKTEST_SYMBOLS:

documentation/ib-insync-overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This step implements:
5050

5151
These functions allow the application to get current market prices and available options.
5252

53-
## Step 4: Order Management
53+
## Step 4: Order Management [COMPLETED]
5454

5555
[View full documentation](ib-insync-step4-order-management.md)
5656

@@ -62,7 +62,7 @@ This step implements:
6262

6363
These components enable the application to execute trading strategies.
6464

65-
## Step 5: Account and Position Management
65+
## Step 5: Account and Position Management [COMPLETED]
6666

6767
[View full documentation](ib-insync-step5-account-management.md)
6868

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# IB Insync Implementation: Step 1 - Setup and Initial Structure Completed
2+
3+
## Work Completed
4+
5+
1. **Updated Dependencies**
6+
- Verified that `ib_insync` and `pytz` packages were already installed in the project
7+
- Updated requirements.txt to specify newer versions
8+
9+
2. **Created Class Structure**
10+
- Created the `IBKRIBInsyncApi` class in `python/src/brokers/ibkr_ib_insync.py`
11+
- Implemented initialization with proper configuration parameters
12+
- Set up instance variables for tracking connection state, orders, and positions
13+
14+
3. **Updated Factory Method**
15+
- Updated `python/src/brokers/__init__.py` to include the new implementation
16+
- Added factory method `get_broker_api()` that can switch between implementations
17+
18+
4. **Updated Configuration**
19+
- Added IBKR API settings to `config.yaml`
20+
- Configured connection parameters, timeouts, and other settings
21+
22+
5. **Added Tests**
23+
- Created unit tests for the setup in `python/tests/unit/test_ibkr_ib_insync_setup.py`
24+
- Created BDD tests with Gherkin scenarios in `python/tests/features/setup.feature`
25+
- Implemented the test steps using pytest-bdd
26+
27+
## Next Steps
28+
29+
After completing this setup, you're now ready to move on to [Step 2 - Connection Management](ib-insync-step2-connection.md), which will implement:
30+
31+
1. Event handlers for connection events
32+
2. Connection and disconnection methods
33+
3. Error handling
34+
4. Callback processing
35+
36+
## Notes for Testing
37+
38+
To run the tests, you'll need a properly configured Python environment with:
39+
- pytest
40+
- pytest-bdd
41+
- pytest-mock
42+
- ib_insync
43+
- pytz
44+
45+
Use the following command to run the tests:
46+
```bash
47+
python -m pytest python/tests/test_ibkr_ib_insync_setup.py -v
48+
```
49+
50+
## Configuration Settings
51+
52+
The following settings are now available in `config.yaml`:
53+
```yaml
54+
# IBKR API Connection
55+
ibkr:
56+
host: "127.0.0.1"
57+
port: 7497 # TWS: 7497, IB Gateway: 4001
58+
client_id: 1
59+
read_only: false
60+
account: "" # Set your account ID or leave blank to use active account
61+
use_ib_insync: true # Use new implementation instead of placeholder
62+
timeout: 20 # Connection timeout in seconds
63+
auto_reconnect: true # Automatically try to reconnect on disconnection
64+
max_rate: 45 # Maximum API requests per second (IB's limit is 50)
65+
```

python/src/brokers/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
Brokers module for interacting with various trading platforms.
33
"""
44

5-
__all__ = ["IBKRApi"]
6-
75
from src.brokers.ibkr_api import IBKRApi
6+
from src.brokers.ibkr_ib_insync import IBKRIBInsyncApi
7+
8+
def get_broker_api(config, use_ib_insync=True):
9+
"""Factory method to get the appropriate broker API implementation.
10+
11+
Args:
12+
config: Application configuration
13+
use_ib_insync: Whether to use the ib_insync implementation
14+
15+
Returns:
16+
An instance of the appropriate broker API
17+
"""
18+
if use_ib_insync:
19+
return IBKRIBInsyncApi(config)
20+
else:
21+
return IBKRApi(config)
22+
23+
__all__ = ["IBKRApi", "IBKRIBInsyncApi", "get_broker_api"]

0 commit comments

Comments
 (0)