bbgo_origin/migrations/mysql/20220304153317_add_profit_table.sql

72 lines
2.4 KiB
MySQL
Raw Normal View History

2022-03-04 07:58:59 +00:00
-- +up
CREATE TABLE `profits`
(
2022-03-04 11:24:40 +00:00
`gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
2022-03-04 07:58:59 +00:00
2022-03-04 11:24:40 +00:00
`strategy` VARCHAR(32) NOT NULL,
`strategy_instance_id` VARCHAR(64) NOT NULL,
`symbol` VARCHAR(8) NOT NULL,
2022-03-04 07:58:59 +00:00
-- average_cost is the position average cost
2022-03-04 11:24:40 +00:00
`average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL,
2022-03-04 07:58:59 +00:00
-- profit is the pnl (profit and loss)
2022-03-04 11:24:40 +00:00
`profit` DECIMAL(16, 8) NOT NULL,
2022-03-04 08:40:01 +00:00
-- net_profit is the pnl (profit and loss)
2022-03-04 11:24:40 +00:00
`net_profit` DECIMAL(16, 8) NOT NULL,
2022-03-04 08:40:01 +00:00
-- profit_margin is the pnl (profit and loss)
2022-03-04 11:24:40 +00:00
`profit_margin` DECIMAL(16, 8) NOT NULL,
2022-03-04 08:40:01 +00:00
-- net_profit_margin is the pnl (profit and loss)
2022-03-04 11:24:40 +00:00
`net_profit_margin` DECIMAL(16, 8) NOT NULL,
2022-03-04 08:40:01 +00:00
2022-03-04 11:24:40 +00:00
`quote_currency` VARCHAR(10) NOT NULL,
2022-03-04 08:40:01 +00:00
2022-03-04 11:24:40 +00:00
`base_currency` VARCHAR(10) NOT NULL,
2022-03-04 08:40:01 +00:00
-- -------------------------------------------------------
-- embedded trade data --
-- -------------------------------------------------------
2022-03-04 11:24:40 +00:00
`exchange` VARCHAR(24) NOT NULL DEFAULT '',
2022-03-04 08:40:01 +00:00
2022-03-04 11:24:40 +00:00
`is_futures` BOOLEAN NOT NULL DEFAULT FALSE,
2022-03-04 08:40:01 +00:00
2022-03-04 11:24:40 +00:00
`is_margin` BOOLEAN NOT NULL DEFAULT FALSE,
2022-03-04 08:40:01 +00:00
2022-03-04 11:24:40 +00:00
`is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,
2022-03-04 08:40:01 +00:00
2022-03-04 11:24:40 +00:00
`trade_id` BIGINT UNSIGNED NOT NULL,
2022-03-04 08:40:01 +00:00
-- side is the side of the trade that makes profit
2022-03-04 11:24:40 +00:00
`side` VARCHAR(4) NOT NULL DEFAULT '',
`is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,
`is_maker` BOOLEAN NOT NULL DEFAULT FALSE,
2022-03-04 07:58:59 +00:00
-- price is the price of the trade that makes profit
2022-03-04 11:24:40 +00:00
`price` DECIMAL(16, 8) UNSIGNED NOT NULL,
2022-03-04 07:58:59 +00:00
-- quantity is the quantity of the trade that makes profit
2022-03-04 11:24:40 +00:00
`quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,
2022-03-04 07:58:59 +00:00
2022-03-04 11:24:40 +00:00
-- quote_quantity is the quote quantity of the trade that makes profit
`quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,
2022-03-04 07:58:59 +00:00
2022-03-04 11:24:40 +00:00
`traded_at` DATETIME(3) NOT NULL,
2022-03-04 07:58:59 +00:00
2022-03-04 08:40:01 +00:00
-- fee
`fee_in_usd` DECIMAL(16, 8),
`fee` DECIMAL(16, 8) NOT NULL,
2022-03-04 11:24:40 +00:00
`fee_currency` VARCHAR(10) NOT NULL,
2022-03-04 07:58:59 +00:00
PRIMARY KEY (`gid`),
UNIQUE KEY `trade_id` (`trade_id`)
);
-- +down
DROP TABLE IF EXISTS `profits`;