diff --git a/doc/development/migration.md b/doc/development/migration.md index 77cf0c11a..47dc911b6 100644 --- a/doc/development/migration.md +++ b/doc/development/migration.md @@ -8,19 +8,22 @@ 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 ``` -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, then do: diff --git a/migrations/mysql/20220304153317_add_profit_table.sql b/migrations/mysql/20220304153317_add_profit_table.sql new file mode 100644 index 000000000..cdb60edb4 --- /dev/null +++ b/migrations/mysql/20220304153317_add_profit_table.sql @@ -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`; diff --git a/migrations/sqlite3/20220304153309_add_profit_table.sql b/migrations/sqlite3/20220304153309_add_profit_table.sql new file mode 100644 index 000000000..73eab6853 --- /dev/null +++ b/migrations/sqlite3/20220304153309_add_profit_table.sql @@ -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`; diff --git a/rockhopper_mysql.yaml b/rockhopper_mysql.yaml index a0b6e7864..d8b459dbb 100644 --- a/rockhopper_mysql.yaml +++ b/rockhopper_mysql.yaml @@ -1,6 +1,15 @@ +# vim:filetype=yaml: +# you can copy this file to rockhopper_mysql_local.yaml to have your modification --- driver: 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