Skip to content

Commit

Permalink
finish portfolio commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme22 committed Sep 26, 2024
1 parent bd24705 commit 954e0d0
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 89 deletions.
25 changes: 12 additions & 13 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ on:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.12
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install dependencies
python-version: '3.12'
- uses: yezz123/setup-uv@v4
- name: Setup uv venv
run: |
uv sync
uv pip install .
- name: Lint with ruff
run: |
uv run ruff check ttcli/
- name: Type check with mypy
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Sorting...
run: isort --check --diff ttcli/
- name: Linting...
run: flake8 --count --show-source --statistics ttcli/
- name: Type checking...
run: mypy -p ttcli/
uv run mypy -p ttcli
53 changes: 53 additions & 0 deletions .github/workflows/python-publish-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Publish Python distribution to TestPyPI

on:
workflow_dispatch:

jobs:
build:
name: Build distribution
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish Python distribution to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/tastytrade-cli

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
56 changes: 40 additions & 16 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package
name: Publish Python distribution to PyPI

on:
release:
types: [created]

jobs:
deploy:
build:
name: Build distribution
runs-on: ubuntu-latest
permissions:
id-token: write

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python distribution to PyPI
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/tastytrade-cli
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
python-version: '3.x'
- name: Install dependencies and build
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
python setup.py sdist bdist_wheel
- name: Publish to PyPI
name: python-package-distributions
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ $ pip install tastytrade-cli

Available commands:
```
tt option buy, sell, and analyze options
tt option view chains, buy/sell equities and futures options
tt pf (portfolio) view & close positions, check margin and analyze BP usage
```
Unavailable commands pending development:
```
tt crypto buy, sell, and analyze cryptocurrencies
tt future buy, sell, and analyze futures
tt stock buy, sell, and analyze stock
tt order view, replace, and cancel orders
tt pf (portfolio) view statistics and risk metrics for your portfolio
tt wl (watchlist) view current prices and other data for symbols in your watchlists
```
For more options, run `tt --help` or `tt <subcommand> --help`.

## Configuration

TODO

## Shell completion

Place this line in your `.bashrc`:
Expand All @@ -41,11 +45,11 @@ $ eval "$(_TT_COMPLETE=bash_source tt)"
## Development/Contributing

This project includes a number of helpers in the `Makefile` to streamline common development tasks.
Make sure you already have [uv](https://docs.astral.sh/uv/getting-started/installation/) installed!

Creating a virtualenv for development:
```
$ make venv
$ source .venv/bin/activate
$ make install
```

It's usually a good idea to make sure you're passing tests locally before submitting a PR:
Expand Down
15 changes: 7 additions & 8 deletions ttcli/data/ttcli.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
# default-account = example

[portfolio]
bp-target-percent-vix-low = 15
bp-target-percent-vix-high = 55
bp-target-percent-variation = 5
bp-target-percent-variation = 10
bp-max-percent-per-position = 5.0
portfolio-delta-target = 0
portfolio-delta-variation = 5
table-show-mark-price = false
table-show-trade-price = false
table-show-delta = false
table-show-theta = false
table-show-gamma = false
positions-show-mark-price = false
positions-show-trade-price = false
positions-show-delta = false
positions-show-theta = false
positions-show-gamma = false

[order]
bp-warn-above-percent = 5
Expand Down
6 changes: 2 additions & 4 deletions ttcli/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def choose_expiration(
raw = input('Please choose an expiration: ')
choice = int(raw)
except ValueError:
if not raw:
return default_option
return default_option

return exps[choice - 1]

Expand Down Expand Up @@ -74,8 +73,7 @@ def choose_futures_expiration(
raw = input('Please choose an expiration: ')
choice = int(raw)
except ValueError:
if not raw:
return default
return default

return exps[choice - 1]

Expand Down
Loading

0 comments on commit 954e0d0

Please sign in to comment.