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

Add a faster formatter import sorter, linter #295

Merged
merged 6 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
Expand All @@ -31,9 +31,9 @@ jobs:
python setup.py install
python -m pip install .[Dev]

- name: Run linter
run: python setup.py lint -c True
- name: Trunk Check # runs linters under trunk check
uses: trunk-io/trunk-action@v1

- name: Run test
run: python setup.py test

Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# ignore ide files
.vscode

# ignore compiled python files
**/__pycache__/
*.py[cod]
Expand All @@ -22,6 +19,7 @@ data/

# misc.
*.yaml
!trunk.yaml
!dummy_account.yaml
!dummy_account_copy.yaml
package-lock.json
Expand All @@ -30,4 +28,4 @@ package-lock.json

*.log
env
save
save
159 changes: 159 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Enable pylint error, pylint warning, flake8-copyright, Isort
# For full list of pylint rules implemented in ruff, see https://github.com/astral-sh/ruff/issues/970
lint.select = [
"B", # flake8-Bugbear
"I", # isort
"PLE", # pylint errors
"PLW", # pylint warnings
# pydocstyle (flake8-docstring) select docstring
"D207",
"D208",
"D300",
"D419",
# pylint warnings equivalent in ruff (not marked as PLW)
"A001",
"ARG001",
"B033",
"B904",
"E703",
"E722",
"F401",
"F403",
"F404",
"F504",
"F507",
"F524",
"F525",
"F541",
"F541",
"F601",
"F631",
"F811",
"F841",
"N999",
"PIE790",
"Q000",
"S102",
"S307",
"TRY302",
"UP025",
"W605",
# pylint errors equivalent in ruff (not marked as PLE)
"E999",
"F501",
"F502",
"F506",
"F522",
"F524",
"F524",
"F622",
"F701",
"F702",
"F704",
"F706",
"F811",
"F821",
"F822",
"F901",
"N805",
"TID252",
# pylint refactor errors equivalent in ruff
"C416",
"PLR0133",
"PLR1711",
"PLR1722",
"SIM115",
"UP008",
]
lint.ignore = [
"B008", # function-call-in-default-argument
"B017", # assert-raises-exception
"B027", # empty-method-without-abstract-decorator
"B028", # explicit-stacklevel
"B905", # zip-without-explicit-strict
"E701", # multiple-statements part 1
"E702", # multiple-statements part 2
"E741", # ambiguous-name
"PIE790", # uncecessary ... literal
"PLR", # refactor
"PLW0406", # import-self
"PLW0603", # global-statement
"PLW0133", # useless-exception-statement
"PLW1514", # unexpected-encoding
"PLW1641", # eq-without-hash
"PLW2901", # redefined-loop-name
"PLW3201", # bad-dunder-method-name
"RET501", # inconsistent-return-statements
"RET502", # inconsistent-return-statements
"RET505", # no-else-return
"RET506", # no-else-raise
"RET507", # no-else-continue
"RET508", # no-else-break
]
# Full list of error codes https://beta.ruff.rs/docs/rules/
# Pylint warning of global
# Overwritten variables

# Allow autofix for all enabled rules (when `--fix`) is provided.
lint.fixable = [
"A",
"ANN",
"ARG",
"B",
"BLE",
"C",
"COM",
"D",
"DJ",
"DTZ",
"E",
"EM",
"ERA",
"EXE",
"F",
"FBT",
"G",
"I",
"I",
"ICN",
"INP",
"N",
"NPY",
"PD",
"PIE",
"PL",
"PT",
"PTH",
"PYI",
"Q",
"RET",
"RSE",
"RUF",
"S",
"S307",
"SIM",
"SLF",
"T",
"TCH",
"TID",
"TRY",
"UP",
"W",
"YTT",
]
lint.unfixable = [
"F401", # unused-imports this may lead to imports removed when not intended in init.py
]

# Exclude a variety of commonly ignored directories.
exclude = [
".cache",
".git",
".ruff_cache",
".trunk",
".vscode",
]

line-length = 120

target-version = "py310"
9 changes: 9 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
50 changes: 50 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.1
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.5.0
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- [email protected]
- [email protected]
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
lint:
enabled:
- [email protected]:
commands: [lint, format]
definitions:
- name: ruff
commands:
- name: lint
output: rewrite
run: ruff check --fix --preview ${target}
success_codes: [0]
batch: true
in_place: true
allow_empty_files: false
cache_results: false # there are issues when ruff.toml is modified and checks are not rerun
formatter: true
- name: format
output: rewrite
run: ruff format --line-length=120 ${target}
success_codes: [0]
batch: true
in_place: true
allow_empty_files: false
cache_results: true
formatter: true
enabled: false
actions:
disabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
enabled:
- trunk-upgrade-available
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"trunk.io",
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "trunk.io",
}
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![Header](docs/banner.png)<br />
Harvest is a simple yet flexible Python framework for algorithmic trading. Paper trade and live trade stocks, cryptos, and options![^1][^2] Visit [**here**](https://tfukaza.github.io/harvest-website) for tutorials and documentation.
Harvest is a simple yet flexible Python framework for algorithmic trading. Paper trade and live trade stocks, cryptos, and options![^1][^2] Visit [**here**](https://tfukaza.github.io/harvest-website) for tutorials and documentation.

<br />

Expand All @@ -10,7 +10,7 @@ Harvest is a simple yet flexible Python framework for algorithmic trading. Paper
---

**⚠️WARNING⚠️**
Harvest is currently at **v0.3**. The program is unstable and contains many bugs. Use with caution, and contributions are greatly appreciated.
Harvest is currently at **v0.3**. The program is unstable and contains many bugs. Use with caution, and contributions are greatly appreciated.
- 🪲 [File a bug report](https://github.com/tfukaza/harvest/issues/new?assignees=&labels=bug&template=bug_report.md&title=%5B%F0%9F%AA%B0BUG%5D)
- 💡 [Submit a feature suggestion](https://github.com/tfukaza/harvest/issues/new?assignees=&labels=enhancement%2C+question&template=feature-request.md&title=%5B%F0%9F%92%A1Feature+Request%5D)
- 📝 [Request documentation](https://github.com/tfukaza/harvest/issues/new?assignees=&labels=documentation&template=documentation.md&title=%5B%F0%9F%93%9DDocumentation%5D)
Expand All @@ -36,7 +36,7 @@ class Watch(BaseAlgo):
```
To paper trade using this algorithm, run the following command:
```bash
harvest start -s yahoo -b paper
harvest start -s yahoo -b paper
```
To live trade using Robinhood, run:
```bash
Expand All @@ -58,21 +58,28 @@ pip install harvest-python[BROKER]
```
Replace `BROKER` with a brokerage/data source of your choice:
- Robinhood
- Alpaca
- Alpaca
- Webull
- Kraken
- Polygon
- Polygon

Now you're all set!

# Contributing
Contributions are greatly appreciated. Check out the [CONTRIBUTING](CONTRIBUTING.md) document for details, and [ABOUT](ABOUT.md) for the long-term goals of this project.
Contributions are greatly appreciated. Check out the [CONTRIBUTING](CONTRIBUTING.md) document for details, and [ABOUT](ABOUT.md) for the long-term goals of this project.

# Disclaimer
- Harvest is not officially associated with Robinhood, Alpaca, Webull, Kraken, Polygon, or Yahoo.
- Many of the brokers were also not designed to be used for algo-trading. Excessive access to their API can result in your account getting locked.
- Tutorials and documentation solely exist to provide technical references of the code. They are not recommendations of any specific securities or strategies.
- Harvest is not officially associated with Robinhood, Alpaca, Webull, Kraken, Polygon, or Yahoo.
- Many of the brokers were also not designed to be used for algo-trading. Excessive access to their API can result in your account getting locked.
- Tutorials and documentation solely exist to provide technical references of the code. They are not recommendations of any specific securities or strategies.
- Use Harvest at your own responsibility. Developers of Harvest take no responsibility for any financial losses you incur by using Harvest. By using Harvest, you certify you understand that Harvest is a software in early development and may contain bugs and unexpected behaviors.

[^1]: What assets you can trade depends on the broker you are using.
[^2]: Backtesting is also available, but it is not supported for options.
# Linter
- Trunk is a wrapper around linters. see `trunk.yaml` for details on which linters are enabled
- Currently we run `ruff` which supports isort, pylint, black
- For the best experience, please install the proper extensions under vscode "recommended extensions"
- To run lint checks manually, use `trunk check`, to run formatters, use `trunk fmt`
- To run lint & format checks automatically, install the extensions recommended and save

[^1]: What assets you can trade depends on the broker you are using.
[^2]: Backtesting is also available, but it is not supported for options.
13 changes: 6 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = Simple and intuitive python framework for algorithmic trading.
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/tfukaza/harvest/

classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
Expand All @@ -30,21 +30,20 @@ install_requires =
rich

[options.extras_require]
Alpaca =
Alpaca =
alpaca-trade-api
Robinhood =
Robinhood =
pyotp
robin_stocks
robin_stocks
Webull =
webull
Kraken =
Kraken =
krakenex
Dev =
coverage
black

[options.entry_points]
console_scripts =
console_scripts =
harvest = harvest.cli:main

[coverage:run]
Expand Down
Loading
Loading