-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,77 +16,55 @@ | |
- [x] [RSI](packages/bot-templates/src/templates/rsi.ts): A Relative Strength Index (RSI) strategy that buys and sells based on the RSI indicator. | ||
- [ ] `DCA`: Dollar-Cost Averaging (DCA) strategy that buys an asset at regular intervals. | ||
|
||
**Supported exchanges:** `OKX`, `BYBIT`, `BINANCE`, `KRAKEN`, `COINBASE`, `GATEIO` | ||
|
||
# Quick start | ||
|
||
## Requirements | ||
|
||
```bash | ||
# NodeJS v20 or higher | ||
$ node -v | ||
Get started with OpenTrader in just a few steps. Follow this quick guide to install, configure, and run your crypto trading bot. | ||
|
||
# `pnpm` must be installed | ||
$ pnpm -v | ||
## Installation | ||
|
||
# Install Turborepo globally | ||
$ pnpm install turbo --global | ||
Install OpenTrader globally using npm: | ||
|
||
# Docker (optional) | ||
$ docker -v | ||
```bash | ||
npm install -g opentrader | ||
``` | ||
|
||
## Environment variables | ||
## Configuration | ||
|
||
The project uses a single `.env` file in the root directory. | ||
Frameworks such as Next.js require the `.env` file to be located directly in the project directory. | ||
To address this, some `apps/packages` might include a symlink pointing to the root `.env` file. | ||
|
||
1. Create environment file `.env` in the root directory | ||
Set an admin password for later accessing the OpenTrader UI: | ||
|
||
```bash | ||
$ cp .env.example .env | ||
opentrader set-password <password> | ||
``` | ||
|
||
2. Replace the `DATABASE_URL` if your URL is different from the actual one. | ||
|
||
## Installation | ||
## Running the app | ||
|
||
1. Install dependencies | ||
Start the OpenTrader: | ||
|
||
```bash | ||
$ pnpm install | ||
opentrader up | ||
``` | ||
|
||
2. Build packages | ||
|
||
```bash | ||
$ turbo run build | ||
``` | ||
The app will start the RPC server and listen on port 8000. | ||
|
||
3. Run db migrations | ||
> **Tip**: Use `opentrader up -d` to start the app as a daemon. To stop it, run `opentrader down`. | ||
```bash | ||
$ turbo run prisma:migrate | ||
``` | ||
# Usage | ||
|
||
4. Seed the database | ||
## UI | ||
|
||
```bash | ||
$ turbo run prisma:seed | ||
``` | ||
The user interface allows managing multiple bots and strategies, viewing backtest results, and monitoring live trading. | ||
|
||
> ⚠️ **Note**: Since the packages do not have a dev server, running the `build` command is mandatory on the first run. | ||
You can access the OpenTrader UI on: http://localhost:8000 | ||
|
||
# Basic usage | ||
## CLI | ||
|
||
## Connect an exchange | ||
### Connect an exchange | ||
|
||
Copy the `exchanges.sample.json5` file to `exchanges.json5` and add your API keys. | ||
|
||
> Supported exchanges: OKX, BYBIT, BINANCE, KRAKEN, COINBASE, GATEIO | ||
> Available exchanges: OKX, BYBIT, BINANCE, KRAKEN, COINBASE, GATEIO | ||
## Choose a strategy | ||
### Choose a strategy | ||
|
||
Create the strategy configuration file `config.json5`. We will use the `grid` strategy as an example. | ||
|
||
|
@@ -106,76 +84,31 @@ Create the strategy configuration file `config.json5`. We will use the `grid` st | |
|
||
> Currently supported strategies: `grid`, `rsi` | ||
## Run a backtest | ||
### Run a backtest | ||
|
||
Command: `./bin/cli.sh backtest <strategy> --from <date> --to <date> -t <timeframe>` | ||
Command: `opentrader backtest <strategy> --from <date> --to <date> -t <timeframe>` | ||
|
||
Example running a `grid` strategy on `1h` timeframe. | ||
|
||
```bash | ||
$ bin/cli.sh backtest grid --from 2024-03-01 --to 2024-06-01 -t 1h | ||
opentrader backtest grid --from 2024-03-01 --to 2024-06-01 -t 1h | ||
``` | ||
|
||
> To get more accurate results, use a smaller timeframe, e.g. 1m, however, it will take more time to download OHLC data from the exchange. | ||
## Live trading | ||
|
||
## Starting the daemon | ||
|
||
Before running live trading, you need to start the daemon: | ||
|
||
```bash | ||
$ bin/cli.sh up | ||
``` | ||
|
||
Now the daemon is ready to listen for incoming commands. | ||
|
||
> Tip: To run the daemon in the background, use: `bin/cli.sh up -d` | ||
### Live trading | ||
|
||
## Running a Live Trading | ||
|
||
Command: `bin/cli.sh trade <strategy>` | ||
Command: `opentrader trade <strategy>` | ||
|
||
Example running a live trading with `grid` strategy. | ||
|
||
```bash | ||
$ bin/cli.sh trade grid | ||
``` | ||
|
||
> To stop the live trading, run `bin/cli.sh stop` | ||
## Stop the daemon | ||
|
||
To stop the daemon, run the following command: | ||
|
||
```bash | ||
$ bin/cli.sh down | ||
``` | ||
|
||
# UI | ||
|
||
The user interface allows managing multiple bots and strategies, viewing backtest results, and monitoring live trading. | ||
|
||
![UI Preview](.github/images/ui.png) | ||
|
||
Currently, the UI is under development. For early access, please email me at [email protected] | ||
|
||
After getting the access, run the following command to pull the UI into monorepo: | ||
|
||
```shell | ||
$ git submodule update --init | ||
``` | ||
|
||
Run frontend app: | ||
|
||
```shell | ||
$ pnpm i | ||
$ turbo run build | ||
$ turbo run dev | ||
$ opentrader trade grid | ||
``` | ||
|
||
- Frontend: http://localhost:3000 | ||
- API: http://localhost:4000 | ||
> To stop the live trading, run `opentrader stop` | ||
# Project structure | ||
|
||
|