Skip to content

Commit b929515

Browse files
authored
fix!: Support the recent ibapi changes (#132)
This pull request updates the documentation and example scripts to improve virtual environment handling and contract definitions, refines tick type usage, and makes API and error handling more precise. The changes also clarify the order placement process and update various contract parameters for accuracy. **Virtual Environment and Documentation Improvements** * Updated the `README.md` to recommend creating a temporary local virtual environment for running the `dhib_env.py` installer script, preventing system-wide package installations. Instructions for activating, using, and cleaning up the environment are now included. **Contract and Example Script Updates** * Changed contract definitions in `examples/example_all_functionality.py` and `examples/example_read_only_functionality.py` to use updated symbols and parameters (e.g., `ESM6`, new expiry dates, and strikes for options). [[1]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eL107-R107) [[2]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eL173-R174) [[3]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7L103-R103) [[4]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7L169-R170) * Added `tif = "DAY"` to all sample orders for clarity and consistency in both example scripts. [[1]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eR493) [[2]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eR505) [[3]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eR517) [[4]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7R489) [[5]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7R507-R523) **API and Error Handling Refinements** * Modified the `request_account_pnl` method to require an explicit account argument, removing the default "All" value, and updated example scripts to pass the account parameter. [[1]](diffhunk://#diff-2908a81036e0aa30f05a7491e9ba007a7be2622e6393c2fa22b67ad3fe49954dL737-R741) [[2]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eL250-R250) [[3]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7L246-R246) * Added new error codes to `src/deephaven_ib/_internal/error_codes.py` for improved feedback, including codes for indicative product valuation and order TIF preset. [[1]](diffhunk://#diff-3eec66c3648fafd75936057e023fccd38778770da1e6f9399d538383c6976c6fR36) [[2]](diffhunk://#diff-3eec66c3648fafd75936057e023fccd38778770da1e6f9399d538383c6976c6fR46) **Tick Type and Market Data Adjustments** * Removed unsupported or deprecated tick types (`NEWS`, `OPTION_VOLATILITY_HISTORICAL`) from the codebase and updated tick type definitions to include delayed yield bid/ask. [[1]](diffhunk://#diff-2908a81036e0aa30f05a7491e9ba007a7be2622e6393c2fa22b67ad3fe49954dL56-L58) [[2]](diffhunk://#diff-2908a81036e0aa30f05a7491e9ba007a7be2622e6393c2fa22b67ad3fe49954dL98-R99) [[3]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eL418) [[4]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eL440) [[5]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7L414) [[6]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7L436) * Updated example scripts to default to delayed market data type and commented out real-time market data and news article requests for clarity. [[1]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eL275-R282) [[2]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7L271-R278) **Output and Logging Improvements** * Improved output formatting in example scripts for readability by adding newlines to contract print statements and clarifying order placement logs. [[1]](diffhunk://#diff-f4fb9199c484cedf1eda84e6adfe319200009a55ad49b25ab64b9bf2a79a709eL240-R240) [[2]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7L236-R236) [[3]](diffhunk://#diff-4ea80aca49ce3a9308c5f29615ec342c39a735c698576b90e9b849d03e6588c7R507-R523) These changes enhance usability, maintainability, and clarity for users and developers working with the deephaven-ib integration.
1 parent 7840aaf commit b929515

File tree

7 files changed

+72
-50
lines changed

7 files changed

+72
-50
lines changed

.github/workflows/build-and-publish.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
python3 dhib_env.py ib-wheel --ib_version ${{ env.IB_VERSION }}
3131
find . -name \*.whl
3232
- name: Archive build artifacts
33-
uses: actions/upload-artifact@v2
33+
uses: actions/upload-artifact@v5
3434
with:
3535
name: ib-wheels
3636
path: |
@@ -45,7 +45,7 @@ jobs:
4545
- name: Setup Python
4646
uses: actions/setup-python@v1
4747
with:
48-
python-version: 3.7
48+
python-version: 3.9
4949
- name: Install dependencies
5050
run: |
5151
python -m pip install --upgrade pip
@@ -74,7 +74,7 @@ jobs:
7474
run: |
7575
python -m build
7676
- name: Archive build artifacts
77-
uses: actions/upload-artifact@v2
77+
uses: actions/upload-artifact@v5
7878
with:
7979
name: wheels
8080
path: |
@@ -87,7 +87,7 @@ jobs:
8787
if: ${{ github.event_name == 'release' && github.event.action == 'released' }}
8888
steps:
8989
- name: Download Build Artifacts
90-
uses: actions/download-artifact@v3
90+
uses: actions/download-artifact@v5
9191
with:
9292
name: wheels
9393
path: wheel/
@@ -112,13 +112,13 @@ jobs:
112112
- name: Pip installs
113113
run: pip3 install --upgrade sphinx~=7.3.0 sphinx-autodoc-typehints furo==2024.5.6
114114
- name: Download IB wheels
115-
uses: actions/download-artifact@v3
115+
uses: actions/download-artifact@v5
116116
with:
117117
name: ib-wheels
118118
- name: Install IB Whl
119119
run: pip3 install *.whl
120120
- name: Download wheels
121-
uses: actions/download-artifact@v3
121+
uses: actions/download-artifact@v5
122122
with:
123123
name: wheels
124124
- name: Install Whl
@@ -131,12 +131,12 @@ jobs:
131131
make html
132132
touch build/html/.nojekyll
133133
- name: Archive Sphinx artifacts
134-
uses: actions/upload-artifact@v1
134+
uses: actions/upload-artifact@v5
135135
with:
136136
name: documentation-html
137137
path: sphinx/build/html/
138138
- name: Upload JVM Error Logs
139-
uses: actions/upload-artifact@v3
139+
uses: actions/upload-artifact@v5
140140
if: failure()
141141
with:
142142
name: check-ci-jvm-err
@@ -152,7 +152,7 @@ jobs:
152152
steps:
153153
- uses: actions/checkout@v1
154154
- name: Download Sphinx Artifacts
155-
uses: actions/download-artifact@v3
155+
uses: actions/download-artifact@v5
156156
with:
157157
name: documentation-html
158158
path: html/
@@ -162,7 +162,7 @@ jobs:
162162
branch: gh-pages
163163
folder: html/
164164
- name: Upload JVM Error Logs
165-
uses: actions/upload-artifact@v3
165+
uses: actions/upload-artifact@v5
166166
if: failure()
167167
with:
168168
name: sphinx-jvm-err
@@ -184,12 +184,12 @@ jobs:
184184
id: branch-name
185185
uses: tj-actions/[email protected]
186186
- name: Download IB wheels
187-
uses: actions/download-artifact@v3
187+
uses: actions/download-artifact@v5
188188
with:
189189
name: ib-wheels
190190
path: ib-wheels/
191191
- name: Download wheels
192-
uses: actions/download-artifact@v3
192+
uses: actions/download-artifact@v5
193193
with:
194194
name: wheels
195195
path: wheels/
@@ -242,12 +242,12 @@ jobs:
242242
id: branch-name
243243
uses: tj-actions/[email protected]
244244
- name: Download IB wheels
245-
uses: actions/download-artifact@v3
245+
uses: actions/download-artifact@v5
246246
with:
247247
name: ib-wheels
248248
path: ib-wheels/
249249
- name: Download wheels
250-
uses: actions/download-artifact@v3
250+
uses: actions/download-artifact@v5
251251
with:
252252
name: wheels
253253
path: wheels/

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.idea
2+
.venv
3+
.venv-*
24
venv
35
venv-*
46
build
@@ -7,4 +9,5 @@ src/deephaven_ib.egg-info
79
docker/data
810
docker/*/data
911
docker/*/build
12+
*.pyc
1013

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,43 @@ you can use the `--use_venv false` option to [./dhib_env.py](./dhib_env.py).
193193
```
194194
4) Build a [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) virtual environment:
195195

196-
First, install the dependencies needed to run the script:
196+
First, create a small, local virtual environment that will be used only to run the `dhib_env.py` script (this avoids installing packages system-wide):
197197
```bash
198-
python3 -m pip install -r requirements_dhib_env.txt
198+
python3 -m venv .venv-installer
199+
source .venv-installer/bin/activate
199200
```
200201

202+
Install the dependencies needed to run the script into this installer virtual environment:
203+
```bash
204+
pip install -r requirements_dhib_env.txt
205+
```
206+
207+
With the installer virtual environment still activated, use its `python` to run the script.
208+
201209
To see all options:
202210
```bash
203-
python3 ./dhib_env.py --help
211+
python ./dhib_env.py --help
204212
```
205213

206214
To install the latest production release version of [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) from PyPi plus the release-specified `ibapi` and `deephaven` versions:
207215
```bash
208-
python3 ./dhib_env.py release
216+
python ./dhib_env.py release
209217
```
210218

211219
To install the latest development version of [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) from source plus the default `ibapi` and `deephaven` versions:
212220
```bash
213-
python3 ./dhib_env.py dev
221+
python ./dhib_env.py dev
214222
```
215223

216224
To create a venv for developing [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) in PyCharm: (This will not install `deephaven-ib`, but it will install the default `ibapi` and `deephaven` versions.)
217225
```bash
218-
python3 ./dhib_env.py dev --install_dhib false
226+
python ./dhib_env.py dev --install_dhib false
227+
```
228+
229+
After the main `venv-<versiondetails>` has been created and noted from the logs, you can deactivate and optionally remove the temporary installer virtual environment:
230+
```bash
231+
deactivate
232+
rm -rf .venv-installer
219233
```
220234

221235
5) In the logs, take note of where the virtual environment is located. It will be in a directory like `./venv-<versiondetails>`.

examples/example_all_functionality.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_contracts() -> Dict[str, Contract]:
104104
contract.secType = "FUT"
105105
contract.exchange = "CME"
106106
contract.currency = "USD"
107-
contract.localSymbol = "ESM4"
107+
contract.localSymbol = "ESM6"
108108
rst["future_2"] = contract
109109

110110
contract = Contract()
@@ -170,8 +170,8 @@ def get_contracts() -> Dict[str, Contract]:
170170
contract.secType = "FOP"
171171
contract.exchange = "CME"
172172
contract.currency = "USD"
173-
contract.lastTradeDateOrContractMonth = "202409"
174-
contract.strike = 5000
173+
contract.lastTradeDateOrContractMonth = "202601"
174+
contract.strike = 7000
175175
contract.right = "C"
176176
contract.multiplier = "50"
177177
rst["futureoption_1"] = contract
@@ -237,7 +237,7 @@ def get_contracts() -> Dict[str, Contract]:
237237
contracts = get_contracts()
238238

239239
for name, contract in contracts.items():
240-
print(f"{name} {contract}")
240+
print(f"\n{name} {contract}")
241241
rc = client.get_registered_contract(contract)
242242
print(rc)
243243

@@ -247,7 +247,7 @@ def get_contracts() -> Dict[str, Contract]:
247247
print("==== Request account pnl.")
248248
print("==============================================================================================================")
249249

250-
client.request_account_pnl()
250+
client.request_account_pnl(account=account)
251251

252252
print("==============================================================================================================")
253253
print("==== Request contracts matching.")
@@ -272,14 +272,14 @@ def get_contracts() -> Dict[str, Contract]:
272272
end = "2021-01-10T00:00:00 ET"
273273
client.request_news_historical(rc, start=start, end=end)
274274

275-
client.request_news_article(provider_code="BRFUPDN", article_id="BRFUPDN$107d53ea")
275+
#client.request_news_article(provider_code="BRFUPDN", article_id="BRFUPDN$107d53ea")
276276

277277
print("==============================================================================================================")
278278
print("==== Set market data type.")
279279
print("==============================================================================================================")
280280

281-
# client.set_market_data_type(dhib.MarketDataType.DELAYED)
282-
client.set_market_data_type(dhib.MarketDataType.REAL_TIME)
281+
client.set_market_data_type(dhib.MarketDataType.DELAYED)
282+
# client.set_market_data_type(dhib.MarketDataType.REAL_TIME)
283283

284284
print("==============================================================================================================")
285285
print("==== Request bars.")
@@ -415,7 +415,6 @@ def get_contracts() -> Dict[str, Contract]:
415415
print(contract)
416416

417417
generic_tick_types = [
418-
dhib.GenericTickType.NEWS,
419418
dhib.GenericTickType.DIVIDENDS,
420419
dhib.GenericTickType.AUCTION,
421420
dhib.GenericTickType.MARK_PRICE,
@@ -437,7 +436,6 @@ def get_contracts() -> Dict[str, Contract]:
437436
# dhib.GenericTickType.FUTURE_OPEN_INTEREST,
438437
# dhib.GenericTickType.FUTURE_INDEX_PREMIUM,
439438

440-
dhib.GenericTickType.OPTION_VOLATILITY_HISTORICAL,
441439
dhib.GenericTickType.OPTION_VOLATILITY_HISTORICAL_REAL_TIME,
442440
dhib.GenericTickType.OPTION_VOLATILITY_IMPLIED,
443441
dhib.GenericTickType.OPTION_VOLUME,
@@ -492,6 +490,7 @@ def get_contracts() -> Dict[str, Contract]:
492490
order.orderType = "LIMIT"
493491
order.totalQuantity = 1
494492
order.lmtPrice = 100
493+
order.tif = "DAY"
495494

496495
print("Placing order: START")
497496
client.order_place(rc, order)
@@ -503,17 +502,19 @@ def get_contracts() -> Dict[str, Contract]:
503502
order.orderType = "LIMIT"
504503
order.totalQuantity = 1
505504
order.lmtPrice = 90
505+
order.tif = "DAY"
506506

507507
print("Placing order: START")
508508
client.order_place(rc, order)
509-
print("Placing order: START")
509+
print("Placing order: END")
510510

511511
order = Order()
512512
order.account = account
513513
order.action = "BUY"
514514
order.orderType = "LIMIT"
515515
order.totalQuantity = 1
516516
order.lmtPrice = 91
517+
order.tif = "DAY"
517518

518519
print("Placing order: START")
519520
req = client.order_place(rc, order)

examples/example_read_only_functionality.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def get_contracts() -> Dict[str, Contract]:
100100
contract.secType = "FUT"
101101
contract.exchange = "CME"
102102
contract.currency = "USD"
103-
contract.localSymbol = "ESM4"
103+
contract.localSymbol = "ESM6"
104104
rst["future_2"] = contract
105105

106106
contract = Contract()
@@ -166,8 +166,8 @@ def get_contracts() -> Dict[str, Contract]:
166166
contract.secType = "FOP"
167167
contract.exchange = "CME"
168168
contract.currency = "USD"
169-
contract.lastTradeDateOrContractMonth = "202409"
170-
contract.strike = 5000
169+
contract.lastTradeDateOrContractMonth = "202601"
170+
contract.strike = 7000
171171
contract.right = "C"
172172
contract.multiplier = "50"
173173
rst["futureoption_1"] = contract
@@ -233,7 +233,7 @@ def get_contracts() -> Dict[str, Contract]:
233233
contracts = get_contracts()
234234

235235
for name, contract in contracts.items():
236-
print(f"{name} {contract}")
236+
print(f"\n{name} {contract}")
237237
rc = client.get_registered_contract(contract)
238238
print(rc)
239239

@@ -243,7 +243,7 @@ def get_contracts() -> Dict[str, Contract]:
243243
print("==== Request account pnl.")
244244
print("==============================================================================================================")
245245

246-
client.request_account_pnl()
246+
client.request_account_pnl(account=account)
247247

248248
print("==============================================================================================================")
249249
print("==== Request contracts matching.")
@@ -268,14 +268,14 @@ def get_contracts() -> Dict[str, Contract]:
268268
end = "2021-01-10T00:00:00 ET"
269269
client.request_news_historical(rc, start=start, end=end)
270270

271-
client.request_news_article(provider_code="BRFUPDN", article_id="BRFUPDN$107d53ea")
271+
#client.request_news_article(provider_code="BRFUPDN", article_id="BRFUPDN$107d53ea")
272272

273273
print("==============================================================================================================")
274274
print("==== Set market data type.")
275275
print("==============================================================================================================")
276276

277-
# client.set_market_data_type(dhib.MarketDataType.DELAYED)
278-
client.set_market_data_type(dhib.MarketDataType.REAL_TIME)
277+
client.set_market_data_type(dhib.MarketDataType.DELAYED)
278+
# client.set_market_data_type(dhib.MarketDataType.REAL_TIME)
279279

280280
print("==============================================================================================================")
281281
print("==== Request bars.")
@@ -411,7 +411,6 @@ def get_contracts() -> Dict[str, Contract]:
411411
print(contract)
412412

413413
generic_tick_types = [
414-
dhib.GenericTickType.NEWS,
415414
dhib.GenericTickType.DIVIDENDS,
416415
dhib.GenericTickType.AUCTION,
417416
dhib.GenericTickType.MARK_PRICE,
@@ -433,7 +432,6 @@ def get_contracts() -> Dict[str, Contract]:
433432
# dhib.GenericTickType.FUTURE_OPEN_INTEREST,
434433
# dhib.GenericTickType.FUTURE_INDEX_PREMIUM,
435434

436-
dhib.GenericTickType.OPTION_VOLATILITY_HISTORICAL,
437435
dhib.GenericTickType.OPTION_VOLATILITY_HISTORICAL_REAL_TIME,
438436
dhib.GenericTickType.OPTION_VOLATILITY_IMPLIED,
439437
dhib.GenericTickType.OPTION_VOLUME,
@@ -488,6 +486,7 @@ def get_contracts() -> Dict[str, Contract]:
488486
order.orderType = "LIMIT"
489487
order.totalQuantity = 1
490488
order.lmtPrice = 100
489+
order.tif = "DAY"
491490

492491
print("Placing order -- confirm fail: START")
493492
try:
@@ -505,6 +504,7 @@ def get_contracts() -> Dict[str, Contract]:
505504
order.orderType = "LIMIT"
506505
order.totalQuantity = 1
507506
order.lmtPrice = 90
507+
order.tif = "DAY"
508508

509509
print("Placing order -- confirm fail: START")
510510
try:
@@ -514,24 +514,26 @@ def get_contracts() -> Dict[str, Contract]:
514514
raise e
515515
except Exception:
516516
pass
517-
print("Placing order -- confirm fail: START")
517+
print("Placing order -- confirm fail: END")
518518

519519
order = Order()
520520
order.account = account
521521
order.action = "BUY"
522522
order.orderType = "LIMIT"
523523
order.totalQuantity = 1
524524
order.lmtPrice = 91
525+
order.tif = "DAY"
525526

526527
print("Placing order -- confirm fail: START")
527528
try:
528-
req = client.order_place(rc, order)
529+
client.order_place(rc, order)
529530
raise AssertionError("Operation should not be possible")
530531
except AssertionError as e:
531532
raise e
532533
except Exception:
533534
pass
534535
print("Placing order -- confirm fail: END")
536+
535537
# req.cancel()
536538

537539
# client.order_cancel_all()

0 commit comments

Comments
 (0)