Update sql cheatsheet iwth current table structure

This commit is contained in:
Matthias 2020-05-13 06:50:52 +02:00
parent 0bd2fca40b
commit 0c3bdd66ac
1 changed files with 51 additions and 28 deletions

View File

@ -1,13 +1,20 @@
# SQL Helper # SQL Helper
This page contains some help if you want to edit your sqlite db. This page contains some help if you want to edit your sqlite db.
## Install sqlite3 ## Install sqlite3
**Ubuntu/Debian installation**
Sqlite3 is a terminal based sqlite application.
Feel free to use a visual Database editor like SqliteBrowser if you feel more comfortable with that.
### Ubuntu/Debian installation
```bash ```bash
sudo apt-get install sqlite3 sudo apt-get install sqlite3
``` ```
## Open the DB ## Open the DB
```bash ```bash
sqlite3 sqlite3
.open <filepath> .open <filepath>
@ -16,45 +23,61 @@ sqlite3
## Table structure ## Table structure
### List tables ### List tables
```bash ```bash
.tables .tables
``` ```
### Display table structure ### Display table structure
```bash ```bash
.schema <table_name> .schema <table_name>
``` ```
### Trade table structure ### Trade table structure
```sql ```sql
CREATE TABLE trades ( CREATE TABLE trades
id INTEGER NOT NULL, id INTEGER NOT NULL,
exchange VARCHAR NOT NULL, exchange VARCHAR NOT NULL,
pair VARCHAR NOT NULL, pair VARCHAR NOT NULL,
is_open BOOLEAN NOT NULL, is_open BOOLEAN NOT NULL,
fee_open FLOAT NOT NULL, fee_open FLOAT NOT NULL,
fee_close FLOAT NOT NULL, fee_open_cost FLOAT,
open_rate FLOAT, fee_open_currency VARCHAR,
open_rate_requested FLOAT, fee_close FLOAT NOT NULL,
close_rate FLOAT, fee_close_cost FLOAT,
close_rate_requested FLOAT, fee_close_currency VARCHAR,
close_profit FLOAT, open_rate FLOAT,
stake_amount FLOAT NOT NULL, open_rate_requested FLOAT,
amount FLOAT, open_trade_price FLOAT,
open_date DATETIME NOT NULL, close_rate FLOAT,
close_date DATETIME, close_rate_requested FLOAT,
open_order_id VARCHAR, close_profit FLOAT,
stop_loss FLOAT, close_profit_abs FLOAT,
initial_stop_loss FLOAT, stake_amount FLOAT NOT NULL,
stoploss_order_id VARCHAR, amount FLOAT,
stoploss_last_update DATETIME, open_date DATETIME NOT NULL,
max_rate FLOAT, close_date DATETIME,
sell_reason VARCHAR, open_order_id VARCHAR,
strategy VARCHAR, stop_loss FLOAT,
ticker_interval INTEGER, stop_loss_pct FLOAT,
PRIMARY KEY (id), initial_stop_loss FLOAT,
CHECK (is_open IN (0, 1)) initial_stop_loss_pct FLOAT,
stoploss_order_id VARCHAR,
stoploss_last_update DATETIME,
max_rate FLOAT,
min_rate FLOAT,
sell_reason VARCHAR,
strategy VARCHAR,
ticker_interval INTEGER,
PRIMARY KEY (id),
CHECK (is_open IN (0, 1))
); );
CREATE INDEX ix_trades_stoploss_order_id ON trades (stoploss_order_id);
CREATE INDEX ix_trades_pair ON trades (pair);
CREATE INDEX ix_trades_is_open ON trades (is_open);
``` ```
## Get all trades in the table ## Get all trades in the table