Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Deephaven as a Python Library #63

Merged
merged 56 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
16b8977
Progress towards using DHaaL
chipkent Jul 13, 2022
5e83e18
Trying to build whl files
chipkent Jul 13, 2022
cf0ee99
Trying to build whl files
chipkent Jul 13, 2022
264570f
Working to fix sphinx
chipkent Jul 13, 2022
9432887
Working to fix sphinx and build
chipkent Jul 13, 2022
0a9d6ff
Working to fix sphinx and build
chipkent Jul 13, 2022
f6f01c4
Working to fix sphinx and build
chipkent Jul 13, 2022
6b5b375
Working to fix sphinx and build
chipkent Jul 13, 2022
219d505
Working to fix sphinx and build
chipkent Jul 13, 2022
3e1c0e3
Working to fix sphinx and build
chipkent Jul 13, 2022
e70ca66
Working to fix sphinx and build
chipkent Jul 13, 2022
31b1716
Working to fix sphinx and build
chipkent Jul 13, 2022
194264f
Working to fix sphinx and build
chipkent Jul 13, 2022
753d77b
Working to fix sphinx and build
chipkent Jul 13, 2022
c69f541
Working to fix sphinx and build
chipkent Jul 13, 2022
7901ba0
Working to fix sphinx and build
chipkent Jul 13, 2022
09a22b1
Working to fix sphinx and build
chipkent Jul 13, 2022
000f8b8
Working to fix sphinx and build
chipkent Jul 13, 2022
43f08e8
Working to fix sphinx and build
chipkent Jul 15, 2022
41e6817
Working to fix sphinx and build
chipkent Jul 15, 2022
5fac08c
Working to fix sphinx and build
chipkent Jul 15, 2022
8bb554c
Working to fix sphinx and build
chipkent Jul 15, 2022
48a4b9b
Working to fix sphinx and build
chipkent Jul 15, 2022
aee4e59
Working to fix sphinx and build
chipkent Jul 15, 2022
f78d923
Working to fix sphinx and build
chipkent Jul 15, 2022
756c4d5
Working to fix sphinx and build
chipkent Jul 15, 2022
4d2ce30
Working to fix sphinx and build
chipkent Jul 15, 2022
481d830
Added docker builds
chipkent Jul 15, 2022
8a56c50
Added docker builds
chipkent Jul 15, 2022
115b912
Added docker builds
chipkent Jul 15, 2022
ac2101b
Added docker builds
chipkent Jul 15, 2022
6235be5
Added docker builds
chipkent Jul 15, 2022
1ca7125
Added docker builds
chipkent Jul 15, 2022
ba4fd4c
Added docker builds
chipkent Jul 15, 2022
9d2faeb
Added docker builds
chipkent Jul 15, 2022
dd8197e
Added docker builds
chipkent Jul 15, 2022
d42d06b
Added docker builds
chipkent Jul 15, 2022
5adb2e2
Added docker builds
chipkent Jul 15, 2022
fab36b5
Added docker builds
chipkent Jul 15, 2022
7d3f890
Added docker builds
chipkent Jul 15, 2022
2ddd9ae
Added docker builds
chipkent Jul 15, 2022
d0f0a4d
added deephaven_server to docs.
chipkent Jul 20, 2022
9fd349b
Refactored local docker.
chipkent Jul 20, 2022
2ed1871
Updated documentation.
chipkent Jul 20, 2022
50479f4
Updated documentation.
chipkent Jul 20, 2022
40b8cbb
Updated documentation.
chipkent Jul 20, 2022
d236467
Renamed the wheel version number for dev branches to make twine happy.
chipkent Jul 22, 2022
07f1e1b
Set pypi publishing credential.
chipkent Jul 22, 2022
3878a93
Updated readme with run instructions
chipkent Jul 22, 2022
60c2d97
Updated readme with better run instructions
chipkent Jul 22, 2022
a65ea23
Updated readme
chipkent Jul 22, 2022
0610abf
Fixed readme bugs
chipkent Jul 22, 2022
bb1a1ea
Fixed docs on port exposure
chipkent Jul 22, 2022
2e2222d
Handle blocking contract error conditions properly.
chipkent Jul 24, 2022
6936701
Better error reporting on contract details problems.
chipkent Jul 24, 2022
7b19802
Fixed example code.
chipkent Jul 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

FROM ubuntu:22.04

RUN apt update && \
apt install -y openjdk-11-jdk python3-pip

ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/

COPY ./wheels /wheels

RUN pip3 install /wheels/*.whl && \
rm -rf /wheels/

CMD python3
138 changes: 126 additions & 12 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
name: Build and publish to PyPI
name: Build & Publish

on: push
on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build-and-publish:
name: Build and publish to PyPI
build-whl:
name: Build WHL
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master
Expand All @@ -22,7 +28,8 @@ jobs:
TAG_NAME=${{ github.event.release.tag_name }}
if [ -z "${TAG_NAME}" ]
then
echo "::set-output name=version::development"
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
echo "::set-output name=version::0.0.0.dev${PR_NUMBER}"
else
echo "::set-output name=version::${{ github.event.release.tag_name }}"
fi
Expand All @@ -31,15 +38,122 @@ jobs:
DH_IB_VERSION: ${{ steps.version.outputs.version }}
run: |
python -m build
- name: Archive production artifacts
- name: Archive build artifacts
uses: actions/upload-artifact@v2
with:
name: Artifacts
name: wheels
path: |
dist/*
#TODO: publish
# - name: Publish
# if: xxxx
# python -m twine upload --repository testpypi dist/*


publish-whl:
name: Publish WHL
runs-on: ubuntu-20.04
needs: [build-whl]
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
path: wheel/
- name: Publish WHL to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.DEEPHAVENIB_PYPI_TOKEN }}
packages_dir: wheel/


build-sphinx:
name: Build Sphinx
runs-on: ubuntu-20.04
needs: [build-whl]
steps:
- uses: actions/checkout@v1
- name: Apt installs
run: |
sudo apt update
sudo apt install -y openjdk-11-jdk
- name: Pip installs
run: pip3 install --upgrade sphinx==4.2.0 sphinx-autodoc-typehints furo==2021.10.9
- name: Download wheels
uses: actions/download-artifact@v3
with:
name: wheels
- name: Install Whl
run: pip3 install *.whl
- name: Run Sphinx
working-directory: ./sphinx
env:
JAVA_HOME: /usr/lib/jvm/java-11-openjdk-amd64
run: |
make html
touch build/html/.nojekyll
- name: Archive Sphinx artifacts
uses: actions/upload-artifact@v1
with:
name: documentation-html
path: sphinx/build/html/

publish-sphinx:
name: Publish Sphinx
runs-on: ubuntu-20.04
needs: [build-sphinx]
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- name: Download Sphinx Artifacts
uses: actions/download-artifact@v3
with:
name: documentation-html
path: html/
- name: Deploy Sphinx docs to gh-pages
uses: JamesIves/github-pages-deploy-action@v4.2.3
with:
branch: gh-pages
folder: html/

docker:
name: Build and Publish Docker
runs-on: ubuntu-20.04
needs: [build-whl]
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v5.2
- name: Download wheels
uses: actions/download-artifact@v3
with:
name: wheels
path: wheels/
- name: Log in to the Container registry
uses: docker/login-action@v1.10.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta-base
uses: docker/metadata-action@v4.0.1
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,${{ steps.branch-name.outputs.current_branch }}
- name: Build and push Docker image
uses: docker/build-push-action@v2.7.0
with:
context: .
file: ./.github/workflows/Dockerfile
push: true
tags: ${{ steps.meta-base.outputs.tags }}
labels: ${{ steps.meta-base.outputs.labels }}
env:
IMAGE_NAME: ${{ github.repository }}
26 changes: 26 additions & 0 deletions .github/workflows/docker-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Delete Docker images after PR merge
#

name: 'Clean up Docker images from PR'

on:
pull_request:
types: [closed]

jobs:
purge-image:
name: Delete images from ghcr.io
runs-on: ubuntu-20.04
steps:
- name: Delete image (Base)
uses: chipkent/action-cleanup-package@v1.0.2
with:
package-name: ${{ github.event.repository.name }}-base
tag: pr-${{ github.event.pull_request.number }}
github-token: ${{ secrets.CI_ACTION_TOKEN }}
- name: Delete image (Downloader)
uses: chipkent/action-cleanup-package@v1.0.2
with:
package-name: ${{ github.event.repository.name }}-downloader
tag: pr-${{ github.event.pull_request.number }}
github-token: ${{ secrets.CI_ACTION_TOKEN }}
42 changes: 0 additions & 42 deletions .github/workflows/sphinx.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.idea
venv
dist
src/deephaven_ib.egg-info
src/deephaven_ib.egg-info
docker/data
docker/*/data
docker/*/build
80 changes: 63 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# deephaven-ib

![Deephaven Data Labs Logo](docs/assets/Deephaven-Logo-Wordmark-Community-OnLight.png)
Expand Down Expand Up @@ -174,33 +173,80 @@ upper right corner. ![](docs/assets/config-gear.png)
1) [For Paper Trading] Log into the [Interactive Brokers Web Interface](https://interactivebrokers.com/).
1) [For Paper Trading] In the [Interactive Brokers Web Interface](https://interactivebrokers.com/), navigate to `Account->Settings->Paper Trading Account` and make sure that "Share real-time market data subscriptions with paper trading account?" is set to true.


## Launch
To launch the system:

### Launch with Docker

This is the most tested way to launch.

1) Launch [IB Trader Workstation (TWS)](https://www.interactivebrokers.com/en/trading/tws.php).
1) Accept incoming connections to [IB Trader Workstation (TWS)](https://www.interactivebrokers.com/en/trading/tws.php). (May not be required for all sessions.)
2) Accept incoming connections to [IB Trader Workstation (TWS)](https://www.interactivebrokers.com/en/trading/tws.php). (May not be required for all sessions.)
![](docs/assets/allow-connections.png)
1) Build the Docker images:
3) Create a directory for your data and scripts
```bash
mkdir data
```
4) Launch the system (Option 1):
* On Mac:
```bash
./docker/deephaven_ib_docker.sh build --dh-version <deephaven_version>
git clone git@github.com:deephaven-examples/deephaven-ib.git
cd deephaven-ib/docker/dev/build.sh
# Set jvm_args to the desired JVM memory for Deephaven
docker run -it -v data:/data -p 10000:10000 deephaven-examples/deephaven-ib:dev python3 -i -c "from deephaven_server import Server; _server = Server(port=10000, jvm_args=['-Xmx4g']); _server.start()"
```
1) Launch the system:
* On other platforms:
```bash
./docker/deephaven_ib_docker.sh up --dh-version <deephaven_version>
# Set jvm_args to the desired JVM memory for Deephaven
docker run -it -v data:/data -p 10000:10000 ghcr.io/deephaven-examples/deephaven-ib python3 -i -c "from deephaven_server import Server; _server = Server(port=10000, jvm_args=['-Xmx4g']); _server.start()"
```
1) Launch the [Deephaven IDE](https://github.com/deephaven/deephaven-core/blob/main/README.md#run-deephaven-ide) by navigating to [http://localhost:10000/ide/](http://localhost:10000/ide/) in a browser.
5) Launch the system and execute a custom script (Option 2):
* On Mac:
```bash
git clone git@github.com:deephaven-examples/deephaven-ib.git
cd deephaven-ib/docker/dev/build.sh
# your_script.py must begin with: "from deephaven_server import Server; _server = Server(port=10000, jvm_args=['-Xmx4g']); _server.start()"
# Set jvm_args to the desired JVM memory for Deephaven
cp path/to/your_script.py data/your_script.py
docker run -it -v data:/data -p 10000:10000 deephaven-examples/deephaven-ib:dev python3 -i /data/your_script.py
```
* On other platforms:
```bash
# your_script.py must begin with: "from deephaven_server import Server; _server = Server(port=10000, jvm_args=['-Xmx4g']); _server.start()"
# Set jvm_args to the desired JVM memory for Deephaven
cp path/to/your_script.py data/your_script.py
docker run -it -v data:/data -p 10000:10000 ghcr.io/deephaven-examples/deephaven-ib python3 -i /data/your_script.py
```
7) Launch the [Deephaven IDE](https://github.com/deephaven/deephaven-core/blob/main/README.md#run-deephaven-ide) by navigating to [http://localhost:10000/ide/](http://localhost:10000/ide/) in a browser.

## Shutdown
To shut down the system:
```bash
./docker/deephaven_ib_docker.sh down --dh-version <deephaven_version>
```
### Launch with a local installation (No Docker)

## Help
To get help on running the system:
```bash
./docker/deephaven_ib_docker.sh help
```
> **_NOTE:_** Deephaven pip install does not yet supported on all architectures. This launch should work on Linux (AMD64 and ARM64) and Windows WSL. It is not yet supported on Windows without WSL or Mac. For these architectures, you should use the Docker installation. As soon as Deephaven supports these architectures for pip, [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) will work.

It is possible to use [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib) without docker, but this is a
new feature and has not been well tested. To do this:
1) Launch [IB Trader Workstation (TWS)](https://www.interactivebrokers.com/en/trading/tws.php).
2) Accept incoming connections to [IB Trader Workstation (TWS)](https://www.interactivebrokers.com/en/trading/tws.php). (May not be required for all sessions.)
![](docs/assets/allow-connections.png)
3) Install [deephaven-ib](https://github.com/deephaven-examples/deephaven-ib):
```bash
pip3 install deephaven-ib
```
4) Install Java 11 and set the appropriate `JAVA_HOME` environment variable.
5) Launch the system (Option 1):
```bash
# Set jvm_args to the desired JVM memory for Deephaven
python3 -i -c "from deephaven_server import Server; _server = Server(port=10000, jvm_args=['-Xmx4g']); _server.start()"
```
6) Launch the system and execute a custom script (Option 2):
```bash
# your_script.py must begin with: "from deephaven_server import Server; _server = Server(port=10000, jvm_args=['-Xmx4g']); _server.start()"
# Set jvm_args to the desired JVM memory for Deephaven
python3 -i /data/your_script.py
```
7) Launch the [Deephaven IDE](https://github.com/deephaven/deephaven-core/blob/main/README.md#run-deephaven-ide) by navigating to [http://localhost:10000/ide/](http://localhost:10000/ide/) in a browser.
8) Use `host=localhost` for the hostname in the examples

# Use deephaven-ib

Expand Down
24 changes: 0 additions & 24 deletions docker/Dockerfile

This file was deleted.

Loading