Skip to content

Commit

Permalink
Read only client (#35)
Browse files Browse the repository at this point in the history
* Make the client read only
* Change the default to be read-only.
* Remove subscriptions that cause errors.
  • Loading branch information
chipkent authored Mar 2, 2022
1 parent 2dc26ac commit 483bdbc
Show file tree
Hide file tree
Showing 5 changed files with 536 additions and 13 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,26 @@ of Docker, `host` should be set to `host.docker.internal`.
communicates on. This value can be found in the [IB Trader Workstation (TWS)](https://www.interactivebrokers.com/en/trading/tws.php)
settings. By default, production trading uses port 7496, and paper trading uses port 7497. See [Setup](#setup) and [TWS Initial Setup](https://interactivebrokers.github.io/tws-api/initial_setup.html) for more details.

`order_id_strategy` is the strategy used for obtaining new order ids.
`read_only` is a boolean value that is used to enable trading. By default `read_only=True`, preventing trading. Use `read_only=False` to enable trading.

`order_id_strategy` is the strategy used for obtaining new order ids. Order id algorithms have tradeoffs in execution time, support for multiple, concurrent sessions, and avoidance of TWS bugs.
* `OrderIdStrategy.RETRY` (default) - Request a new order ID from TWS every time one is needed. Retry if TWS does not respond quickly. This usually avoids a TWS bug where it does not always respond.
* `OrderIdStrategy.BASIC` - Request a new order ID from TWS every time one is needed. Does not retry, so it may deadlock if TWS does not respond.
* `OrderIdStrategy.INCREMENT` - Use the initial order ID sent by TWS and increment the value upon every request. This is fast, but it may fail for multiple, concurrent sessions connected to TWS.

For a read-write session that allows trading:
```python
import deephaven_ib as dhib
client = dhib.IbSessionTws(host="host.docker.internal", port=7497, read_only=False)
client.connect()
```

For a read-only session that does not allow trading:
```python
import deephaven_ib as dhib
client = dhib.IbSessionTws(host="host.docker.internal", port=7497)
client = dhib.IbSessionTws(host="host.docker.internal", port=7497, read_only=True)
client.connect()
```

Expand Down
2 changes: 1 addition & 1 deletion examples/example_all_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
print("==== Create a client and connect.")
print("==============================================================================================================")

client = dhib.IbSessionTws(host="host.docker.internal", port=7497, client_id=0, download_short_rates=False)
client = dhib.IbSessionTws(host="host.docker.internal", port=7497, client_id=0, download_short_rates=False, read_only=False)
print(f"IsConnected: {client.is_connected()}")

client.connect()
Expand Down
Loading

0 comments on commit 483bdbc

Please sign in to comment.