Skip to content

Commit

Permalink
Fix DH examples.
Browse files Browse the repository at this point in the history
Add a script to start and run deephaven.
  • Loading branch information
chipkent committed May 1, 2024
1 parent 2905ca6 commit 26fe2d5
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 60 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,19 @@ python

## Start Deephaven

To start Deephaven, run the following command in the console. This command will start Deephaven with 4GB of memory and
the password `DeephavenRocks!`.
To start Deephaven, run the following python script. It can be found at [./examples/run_deephaven.py](./examples/run_deephaven.py).
This command will start Deephaven with 4GB of memory and the password `DeephavenRocks!`.

```python
import os
from time import sleep
from deephaven_server import Server
_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()
while True:
sleep(1)
```
> :warning: These deephaven server commands **must** be run before importing `deephaven` or `deephaven_ib`.
Expand All @@ -251,6 +256,11 @@ See the [Deephaven Documentation](https://deephaven.io/core/docs/) for details.
## Launch the Deephaven IDE
Once the Deephaven server is started, you can launch the Deephaven IDE.
The Deephaven IDE is a web-based interface for working with Deephaven.
Once in the IDE, you can run queries, create notebooks, and visualize data.
You can also run all of the example code below and the more complex examples in [./examples](./examples).
To launch the Deephaven IDE, navigate to [http://localhost:10000/ide/](http://localhost:10000/ide/) in your web browser.
How you authenticate will depend upon how authentication is configured.
In the examples here, you will use the password `DeephavenRocks!`.
Expand Down
25 changes: 11 additions & 14 deletions examples/example_all_functionality.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

import os
from deephaven_server import Server
_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()
# Run this example in the Deephaven IDE Console

from typing import Dict

Expand All @@ -20,7 +17,7 @@
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")

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

client.connect()
Expand Down Expand Up @@ -135,8 +132,8 @@ def get_contracts() -> Dict[str, Contract]:
contract.secType = "OPT"
contract.exchange = "BOX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "20240119"
contract.strike = 138.5
contract.lastTradeDateOrContractMonth = "20260116"
contract.strike = 170.0
contract.right = "C"
contract.multiplier = "100"
rst["option_1"] = contract
Expand Down Expand Up @@ -169,8 +166,8 @@ def get_contracts() -> Dict[str, Contract]:
contract.secType = "FOP"
contract.exchange = "CME"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "202312"
contract.strike = 4700
contract.lastTradeDateOrContractMonth = "202409"
contract.strike = 5000
contract.right = "C"
contract.multiplier = "50"
rst["futureoption_1"] = contract
Expand All @@ -179,14 +176,14 @@ def get_contracts() -> Dict[str, Contract]:

contract = Contract()
# enter CUSIP as symbol
contract.symbol = "912828C57"
contract.symbol = "084664BL4"
contract.secType = "BOND"
contract.exchange = "SMART"
contract.currency = "USD"
rst["bond_1"] = contract

contract = Contract()
contract.conId = 147554578
contract.conId = 577489715
contract.exchange = "SMART"
rst["bond_2"] = contract

Expand Down Expand Up @@ -322,7 +319,7 @@ def get_contracts() -> Dict[str, Contract]:

# enter CUSIP as symbol
contract = Contract()
contract.symbol = "IBCID411964960"
contract.conId = 505885457
contract.secType = "BOND"
contract.exchange = "SMART"
contract.currency = "USD"
Expand Down Expand Up @@ -462,8 +459,8 @@ def get_contracts() -> Dict[str, Contract]:
contract.secType = "OPT"
contract.exchange = "BOX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "20240119"
contract.strike = 138.5
contract.lastTradeDateOrContractMonth = "20260116"
contract.strike = 170.0
contract.right = "C"
contract.multiplier = "100"

Expand Down
7 changes: 2 additions & 5 deletions examples/example_beta_calc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

import os
from deephaven_server import Server
_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()
# Run this example in the Deephaven IDE Console

## Set the API port. Default port numbers are:
# 7496 - Trader Workstation, real trading
Expand All @@ -19,7 +16,7 @@
else:
read_only_api = True

client = dhib.IbSessionTws(host="host.docker.internal", port=API_PORT, read_only=read_only_api)
client = dhib.IbSessionTws(host="localhost", port=API_PORT, read_only=read_only_api)
client.connect()

if client.is_connected():
Expand Down
7 changes: 2 additions & 5 deletions examples/example_market_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

import os
from deephaven_server import Server
_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()
# Run this example in the Deephaven IDE Console

from ibapi.contract import Contract

Expand All @@ -12,7 +9,7 @@
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")

client = dhib.IbSessionTws(host="host.docker.internal", port=7497, download_short_rates=False)
client = dhib.IbSessionTws(host="localhost", port=7497, download_short_rates=False)
client.connect()

# Makes all tables global variables so that they are displayed in the user interface
Expand Down
7 changes: 2 additions & 5 deletions examples/example_market_maker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

import os
from deephaven_server import Server
_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()
# Run this example in the Deephaven IDE Console

from ibapi.contract import Contract
from ibapi.order import Order
Expand All @@ -24,7 +21,7 @@
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")

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

client.connect()
Expand Down
7 changes: 2 additions & 5 deletions examples/example_option_risk.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Compute real-time risk scenarios for a portfolio of options

import os
from deephaven_server import Server
_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()
# Run this example in the Deephaven IDE Console

import math
from ibapi.contract import Contract
Expand All @@ -16,7 +13,7 @@
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")

client = dhib.IbSessionTws(host="host.docker.internal", port=7497, download_short_rates=False)
client = dhib.IbSessionTws(host="localhost", port=7497, download_short_rates=False)
client.connect()

print("==============================================================================================================")
Expand Down
7 changes: 2 additions & 5 deletions examples/example_overview_image.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@

import os
from deephaven_server import Server
_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()
# Run this example in the Deephaven IDE Console

import deephaven_ib as dhib

print("==============================================================================================================")
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")

client = dhib.IbSessionTws(host="host.docker.internal", port=7497)
client = dhib.IbSessionTws(host="localhost", port=7497)
client.connect()

from ibapi.contract import Contract
Expand Down
8 changes: 3 additions & 5 deletions examples/example_query_and_plot.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import os
from deephaven_server import Server
_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()

# Run this example in the Deephaven IDE Console

import deephaven_ib as dhib

print("==============================================================================================================")
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")

client = dhib.IbSessionTws(host="host.docker.internal", port=7497)
client = dhib.IbSessionTws(host="localhost", port=7497)
client.connect()

from ibapi.contract import Contract
Expand Down
26 changes: 12 additions & 14 deletions examples/example_read_only_functionality.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
from deephaven_server import Server
_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()

# Run this example in the Deephaven IDE Console

from typing import Dict

Expand All @@ -15,7 +13,7 @@
print("==== ** Accept the connection in TWS **")
print("==============================================================================================================")

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

client.connect()
Expand Down Expand Up @@ -130,8 +128,8 @@ def get_contracts() -> Dict[str, Contract]:
contract.secType = "OPT"
contract.exchange = "BOX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "20240119"
contract.strike = 138.5
contract.lastTradeDateOrContractMonth = "20260116"
contract.strike = 170.0
contract.right = "C"
contract.multiplier = "100"
rst["option_1"] = contract
Expand Down Expand Up @@ -164,8 +162,8 @@ def get_contracts() -> Dict[str, Contract]:
contract.secType = "FOP"
contract.exchange = "CME"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "202312"
contract.strike = 4700
contract.lastTradeDateOrContractMonth = "202409"
contract.strike = 5000
contract.right = "C"
contract.multiplier = "50"
rst["futureoption_1"] = contract
Expand All @@ -174,14 +172,14 @@ def get_contracts() -> Dict[str, Contract]:

contract = Contract()
# enter CUSIP as symbol
contract.symbol = "912828C57"
contract.symbol = "084664BL4"
contract.secType = "BOND"
contract.exchange = "SMART"
contract.currency = "USD"
rst["bond_1"] = contract

contract = Contract()
contract.conId = 147554578
contract.conId = 577489715
contract.exchange = "SMART"
rst["bond_2"] = contract

Expand Down Expand Up @@ -317,7 +315,7 @@ def get_contracts() -> Dict[str, Contract]:

# enter CUSIP as symbol
contract = Contract()
contract.symbol = "IBCID411964960"
contract.conId = 505885457
contract.secType = "BOND"
contract.exchange = "SMART"
contract.currency = "USD"
Expand Down Expand Up @@ -457,8 +455,8 @@ def get_contracts() -> Dict[str, Contract]:
contract.secType = "OPT"
contract.exchange = "BOX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "20240119"
contract.strike = 138.5
contract.lastTradeDateOrContractMonth = "20260116"
contract.strike = 170.0
contract.right = "C"
contract.multiplier = "100"

Expand Down
16 changes: 16 additions & 0 deletions examples/run_deephaven.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

# This script runs the Deephaven server with the specified port and JVM arguments.
# The server will run until the script is interrupted.
#
# To connect to the Deephaven IDE, navigate to https://localhost:10000
# The login password is: DeephavenRocks!

import os
from time import sleep
from deephaven_server import Server

_server = Server(port=10000, jvm_args=['-Xmx4g','-Dauthentication.psk=DeephavenRocks!','-Dstorage.path=' + os.path.expanduser('~/.deephaven')])
_server.start()

while True:
sleep(1)

0 comments on commit 26fe2d5

Please sign in to comment.