Skip to content

Commit

Permalink
add buy/sell stock
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme22 committed Dec 3, 2024
1 parent 5b5913a commit 9211685
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 145 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

install:
uv sync
uv pip install .
uv pip install -e .

lint:
uv run ruff format ttcli/
uv run ruff check ttcli/
uv run pyright ttcli/
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ Available commands:
```
tt option view chains, buy/sell equities and futures options
tt pf (portfolio) view & close positions, check margin and analyze BP usage
tt stock buy, sell, and analyze stock
```
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 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
Many aspects of the CLI's behavior can be customized using the `ttcli.cfg` file generated upon the first usage of the CLI. The file is located in your OS's home directory followed by the path `.config/ttcli/ttcli.cfg`. If you don't know where that is, you can just run `python -c "from ttcli.utils import config_path; print(config_path)"`.

The default configuration file contains lots of options along with explanations of what they do.

## Shell completion
<details>
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "tastytrade-cli"
version = "0.2"
version = "0.3"
description = "An easy-to-use command line interface for Tastytrade!"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
16 changes: 15 additions & 1 deletion ttcli/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os
import shutil
from importlib.resources import as_file, files

import asyncclick as click

from ttcli.option import option
from ttcli.portfolio import portfolio
from ttcli.utils import CONTEXT_SETTINGS, VERSION
from ttcli.stock import stock
from ttcli.utils import CONTEXT_SETTINGS, VERSION, config_path


@click.group(context_settings=CONTEXT_SETTINGS)
Expand All @@ -14,5 +19,14 @@ async def app():
def main():
app.add_command(option)
app.add_command(portfolio, name="pf")
app.add_command(stock)

# create ttcli.cfg if it doesn't exist
if not os.path.exists(config_path):
data_file = files("ttcli.data").joinpath("ttcli.cfg")
with as_file(data_file) as path:
# copy default config to user home dir
os.makedirs(os.path.dirname(config_path), exist_ok=True)
shutil.copyfile(path, config_path)

app(_anyio_backend="asyncio")
28 changes: 22 additions & 6 deletions ttcli/data/ttcli.cfg
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
[general]
# the username & password can be passed to the CLI in 3 ways: here,
# through the $TT_USERNAME/$TT_PASSWORD environment variables, or,
# if neither is present, entered manually.
# username = foo
# password = bar
# default-account = example

# the account number to use by default for trades/portfolio commands.
# this bypasses the account choice menu.
# default-account = 5WX01234

[portfolio]
# this number controls how much BP can be used in total, relative to
# the current $VIX level, before the CLI will warn you.
# for example, with a VIX of 25, BP usage of 40%, and variation of 10,
# you'd be warned for high BP usage since the acceptable range would be
# VIX - variation < BP% < VIX + variation. you may also be warned for
# low usage if you're perceived to be using your capital inefficiently;
# e.g. with a VIX of 25, BP usage of 10%, and variation of 10.
bp-target-percent-variation = 10
# this sets an upper bound for the amount of BP that can be allocated
# to a single positions before the CLI will warn you.
bp-max-percent-per-position = 5.0
# this allows you to set a target beta-weighted delta for your portfolio;
# the CLI will warn you unless target - variation < BWD < target + variation.
delta-target = 0
delta-variation = 5
[portfolio.positions]
# these control whether the columns show up when running `tt pf positions`
show-mark-price = false
show-trade-price = false
show-delta = false
show-theta = false
show-gamma = false

[order]
bp-warn-above-percent = 5 # TODO: make this a float

[option.chain]
# these control whether the columns show up when running `tt option chain`
show-delta = true
show-volume = true
show-volume = false
show-open-interest = true
show-theta = true
show-theta = false
Loading

0 comments on commit 9211685

Please sign in to comment.