add profits table migration

This commit is contained in:
c9s 2022-03-04 15:58:59 +08:00
parent d01fcb304d
commit 51e97284cf
4 changed files with 92 additions and 8 deletions

View File

@ -8,19 +8,22 @@
2. Create migration files 2. Create migration files
```sh
rockhopper --config rockhopper_sqlite.yaml create --type sql add_pnl_column
rockhopper --config rockhopper_mysql.yaml create --type sql add_pnl_column
```
or you can use the util script: You can use the util script to generate the migration files:
``` ```
bash utils/generate-new-migration.sh add_pnl_column bash utils/generate-new-migration.sh add_pnl_column
``` ```
Be sure to edit both sqlite3 and mysql migration files. ( [Sample](migrations/mysql/20210531234123_add_kline_taker_buy_columns.sql) ) Or, you can generate the migration files separately:
```sh
rockhopper --config rockhopper_sqlite.yaml create --type sql add_pnl_column
rockhopper --config rockhopper_mysql.yaml create --type sql add_pnl_column
```
Be sure to edit both sqlite3 and mysql migration files. ( [Sample](migrations/mysql/20210531234123_add_kline_taker_buy_columns.sql) )
To test the drivers, you have to update the rockhopper_mysql.yaml file to connect your database, To test the drivers, you have to update the rockhopper_mysql.yaml file to connect your database,
then do: then do:

View File

@ -0,0 +1,38 @@
-- +up
CREATE TABLE `profits`
(
`gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`exchange` VARCHAR(24) NOT NULL DEFAULT '',
`symbol` VARCHAR(8) NOT NULL,
`trade_id` BIGINT UNSIGNED NOT NULL,
-- average_cost is the position average cost
`average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL,
-- profit is the pnl (profit and loss)
`profit` DECIMAL(16, 8) NOT NULL,
-- price is the price of the trade that makes profit
`price` DECIMAL(16, 8) UNSIGNED NOT NULL,
-- quantity is the quantity of the trade that makes profit
`quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,
-- quote_quantity is the quote quantity of the trade that makes profit
`quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,
-- side is the side of the trade that makes profit
`side` VARCHAR(4) NOT NULL DEFAULT '',
`traded_at` DATETIME(3) NOT NULL,
PRIMARY KEY (`gid`),
UNIQUE KEY `trade_id` (`trade_id`)
);
-- +down
DROP TABLE IF EXISTS `profits`;

View File

@ -0,0 +1,34 @@
-- +up
CREATE TABLE `profits`
(
`gid` INTEGER PRIMARY KEY AUTOINCREMENT,
`exchange` VARCHAR(24) NOT NULL DEFAULT '',
`symbol` VARCHAR(8) NOT NULL,
`trade_id` INTEGER NOT NULL,
-- average_cost is the position average cost
`average_cost` DECIMAL(16, 8) NOT NULL,
-- profit is the pnl (profit and loss)
`profit` DECIMAL(16, 8) NOT NULL,
-- price is the price of the trade that makes profit
`price` DECIMAL(16, 8) NOT NULL,
-- quantity is the quantity of the trade that makes profit
`quantity` DECIMAL(16, 8) NOT NULL,
-- quote_quantity is the quote quantity of the trade that makes profit
`quote_quantity` DECIMAL(16, 8) NOT NULL,
-- side is the side of the trade that makes profit
`side` VARCHAR(4) NOT NULL DEFAULT '',
`traded_at` DATETIME(3) NOT NULL
);
-- +down
DROP TABLE IF EXISTS `profits`;

View File

@ -1,6 +1,15 @@
# vim:filetype=yaml:
# you can copy this file to rockhopper_mysql_local.yaml to have your modification
--- ---
driver: mysql driver: mysql
dialect: mysql dialect: mysql
dsn: "root@tcp(localhost:3306)/bbgo_dev?parseTime=true"
# dsn: "root@tcp(localhost:3306)/bbgo_backtest?parseTime=true" # unix socket connection to mysql with password
# dsn: "root:123123@unix(/opt/local/var/run/mysql57/mysqld.sock)/bbgo_dev?parseTime=true"
# tcp connection to mysql with password
# dsn: "root:123123@tcp(localhost:3306)/bbgo_dev?parseTime=true"
# tcp connection to mysql without password
# dsn: "root@tcp(localhost:3306)/bbgo_dev?parseTime=true"
migrationsDir: migrations/mysql migrationsDir: migrations/mysql