From bb52fcb48f68b127704b8ed427fa170f86eeec3b Mon Sep 17 00:00:00 2001 From: c9s Date: Fri, 4 Mar 2022 16:40:01 +0800 Subject: [PATCH] update profit table columns --- .../mysql/20220304153317_add_profit_table.sql | 60 +++++++++++++------ .../20220304153309_add_profit_table.sql | 59 +++++++++++++----- 2 files changed, 86 insertions(+), 33 deletions(-) diff --git a/migrations/mysql/20220304153317_add_profit_table.sql b/migrations/mysql/20220304153317_add_profit_table.sql index cdb60edb4..5db882b66 100644 --- a/migrations/mysql/20220304153317_add_profit_table.sql +++ b/migrations/mysql/20220304153317_add_profit_table.sql @@ -1,36 +1,62 @@ -- +up CREATE TABLE `profits` ( - `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, - `exchange` VARCHAR(24) NOT NULL DEFAULT '', - - `symbol` VARCHAR(8) NOT NULL, - - `trade_id` BIGINT UNSIGNED NOT NULL, + `symbol` VARCHAR(8) NOT NULL, -- average_cost is the position average cost - `average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL, + `average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL, -- profit is the pnl (profit and loss) - `profit` DECIMAL(16, 8) NOT NULL, + `profit` DECIMAL(16, 8) NOT NULL, - -- price is the price of the trade that makes profit - `price` DECIMAL(16, 8) UNSIGNED NOT NULL, + -- net_profit is the pnl (profit and loss) + `net_profit` DECIMAL(16, 8) NOT NULL, - -- quantity is the quantity of the trade that makes profit - `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, + -- profit_margin is the pnl (profit and loss) + `profit_margin` DECIMAL(16, 8) NOT NULL, - -- quote_quantity is the quote quantity of the trade that makes profit - `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, + -- net_profit_margin is the pnl (profit and loss) + `net_profit_margin` DECIMAL(16, 8) NOT NULL, + + `quote_currency` VARCHAR(10) NOT NULL, + + `base_currency` VARCHAR(10) NOT NULL, + + -- ------------------------------------------------------- + -- embedded trade data -- + -- ------------------------------------------------------- + `exchange` VARCHAR(24) NOT NULL DEFAULT '', + + `is_futures` BOOLEAN NOT NULL DEFAULT FALSE, + + `is_margin` BOOLEAN NOT NULL DEFAULT FALSE, + + `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE, + + `trade_id` BIGINT UNSIGNED NOT NULL, -- side is the side of the trade that makes profit - `side` VARCHAR(4) NOT NULL DEFAULT '', + `side` VARCHAR(4) NOT NULL DEFAULT '', - `traded_at` DATETIME(3) 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, + + -- trade_amount is the quote quantity of the trade that makes profit + `trade_amount` DECIMAL(16, 8) UNSIGNED NOT NULL, + + `traded_at` DATETIME(3) NOT NULL, + + -- fee + `fee_in_usd` DECIMAL(16, 8) UNSIGNED NOT NULL, + `fee` DECIMAL(16, 8) UNSIGNED NOT NULL, + `fee_currency` VARCHAR(10) NOT NULL, PRIMARY KEY (`gid`), - UNIQUE KEY `trade_id` (`trade_id`) ); diff --git a/migrations/sqlite3/20220304153309_add_profit_table.sql b/migrations/sqlite3/20220304153309_add_profit_table.sql index 73eab6853..8c2d99456 100644 --- a/migrations/sqlite3/20220304153309_add_profit_table.sql +++ b/migrations/sqlite3/20220304153309_add_profit_table.sql @@ -1,33 +1,60 @@ -- +up CREATE TABLE `profits` ( - `gid` INTEGER PRIMARY KEY AUTOINCREMENT, + `gid` INTEGER PRIMARY KEY AUTOINCREMENT, - `exchange` VARCHAR(24) NOT NULL DEFAULT '', - - `symbol` VARCHAR(8) NOT NULL, - - `trade_id` INTEGER NOT NULL, + `symbol` VARCHAR(8) NOT NULL, -- average_cost is the position average cost - `average_cost` DECIMAL(16, 8) NOT NULL, + `average_cost` DECIMAL(16, 8) NOT NULL, -- profit is the pnl (profit and loss) - `profit` DECIMAL(16, 8) NOT NULL, + `profit` DECIMAL(16, 8) NOT NULL, - -- price is the price of the trade that makes profit - `price` DECIMAL(16, 8) NOT NULL, + -- net_profit is the pnl (profit and loss) + `net_profit` DECIMAL(16, 8) NOT NULL, - -- quantity is the quantity of the trade that makes profit - `quantity` DECIMAL(16, 8) NOT NULL, + -- profit_margin is the pnl (profit and loss) + `profit_margin` DECIMAL(16, 8) NOT NULL, - -- quote_quantity is the quote quantity of the trade that makes profit - `quote_quantity` DECIMAL(16, 8) NOT NULL, + -- net_profit_margin is the pnl (profit and loss) + `net_profit_margin` DECIMAL(16, 8) NOT NULL, + + `quote_currency` VARCHAR(10) NOT NULL, + + `base_currency` VARCHAR(10) NOT NULL, + + -- ------------------------------------------------------- + -- embedded trade data -- + -- ------------------------------------------------------- + `exchange` VARCHAR(24) NOT NULL DEFAULT '', + + `is_futures` BOOLEAN NOT NULL DEFAULT FALSE, + + `is_margin` BOOLEAN NOT NULL DEFAULT FALSE, + + `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE, + + `trade_id` BIGINT NOT NULL, -- side is the side of the trade that makes profit - `side` VARCHAR(4) NOT NULL DEFAULT '', + `side` VARCHAR(4) NOT NULL DEFAULT '', - `traded_at` DATETIME(3) 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, + + -- trade_amount is the quote quantity of the trade that makes profit + `trade_amount` DECIMAL(16, 8) NOT NULL, + + `traded_at` DATETIME(3) NOT NULL, + + -- fee + `fee_in_usd` DECIMAL(16, 8) NOT NULL, + `fee` DECIMAL(16, 8) NOT NULL, + `fee_currency` VARCHAR(10) NOT NULL ); -- +down