From 79fbad1266453290643ab8bd0e34d462433738b6 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 31 May 2022 02:01:54 +0800 Subject: [PATCH] migrations: add margin_liquidations table --- .../mysql/20220531013542_margin_interests.sql | 3 +- .../20220531015005_margin_liquidations.sql | 33 +++++++++++++++++++ .../20220531015005_margin_liquidations.sql | 30 +++++++++++++++++ pkg/types/margin.go | 4 +++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 migrations/mysql/20220531015005_margin_liquidations.sql create mode 100644 migrations/sqlite3/20220531015005_margin_liquidations.sql diff --git a/migrations/mysql/20220531013542_margin_interests.sql b/migrations/mysql/20220531013542_margin_interests.sql index 2a7c9772c..30e898769 100644 --- a/migrations/mysql/20220531013542_margin_interests.sql +++ b/migrations/mysql/20220531013542_margin_interests.sql @@ -19,8 +19,7 @@ CREATE TABLE `margin_interests` `time` DATETIME(3) NOT NULL, - PRIMARY KEY (`gid`), - UNIQUE KEY (`transaction_id`) + PRIMARY KEY (`gid`) ); -- +down diff --git a/migrations/mysql/20220531015005_margin_liquidations.sql b/migrations/mysql/20220531015005_margin_liquidations.sql new file mode 100644 index 000000000..86f0675b7 --- /dev/null +++ b/migrations/mysql/20220531015005_margin_liquidations.sql @@ -0,0 +1,33 @@ +-- +up +CREATE TABLE `margin_liquidations` +( + `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + + `exchange` VARCHAR(24) NOT NULL DEFAULT '', + + `symbol` VARCHAR(24) NOT NULL DEFAULT '', + + `order_id` BIGINT UNSIGNED NOT NULL, + + `is_isolated` BOOL NOT NULL DEFAULT false, + + `average_price` DECIMAL(16, 8) UNSIGNED NOT NULL, + + `price` DECIMAL(16, 8) UNSIGNED NOT NULL, + + `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, + + `executed_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, + + `side` VARCHAR(5) NOT NULL DEFAULT '', + + `time_in_force` VARCHAR(5) NOT NULL DEFAULT '', + + `updated_time` DATETIME(3) NOT NULL, + + PRIMARY KEY (`gid`), + UNIQUE KEY (`order_id`, `exchange`) +); + +-- +down +DROP TABLE IF EXISTS `margin_liquidations`; diff --git a/migrations/sqlite3/20220531015005_margin_liquidations.sql b/migrations/sqlite3/20220531015005_margin_liquidations.sql new file mode 100644 index 000000000..9cd4cc116 --- /dev/null +++ b/migrations/sqlite3/20220531015005_margin_liquidations.sql @@ -0,0 +1,30 @@ +-- +up +CREATE TABLE `margin_liquidations` +( + `gid` INTEGER PRIMARY KEY AUTOINCREMENT, + + `exchange` VARCHAR(24) NOT NULL DEFAULT '', + + `symbol` VARCHAR(24) NOT NULL DEFAULT '', + + `order_id` INTEGER NOT NULL, + + `is_isolated` BOOL NOT NULL DEFAULT false, + + `average_price` DECIMAL(16, 8) NOT NULL, + + `price` DECIMAL(16, 8) NOT NULL, + + `quantity` DECIMAL(16, 8) NOT NULL, + + `executed_quantity` DECIMAL(16, 8) NOT NULL, + + `side` VARCHAR(5) NOT NULL DEFAULT '', + + `time_in_force` VARCHAR(5) NOT NULL DEFAULT '', + + `updated_time` DATETIME(3) NOT NULL +); + +-- +down +DROP TABLE IF EXISTS `margin_liquidations`; diff --git a/pkg/types/margin.go b/pkg/types/margin.go index a907eb1de..5aa569c3f 100644 --- a/pkg/types/margin.go +++ b/pkg/types/margin.go @@ -60,6 +60,7 @@ type MarginBorrowRepayService interface { } type MarginInterest struct { + Exchange ExchangeName `json:"exchange" db:"exchange"` Asset string `json:"asset" db:"asset"` Principle fixedpoint.Value `json:"principle" db:"principle"` Interest fixedpoint.Value `json:"interest" db:"interest"` @@ -69,6 +70,7 @@ type MarginInterest struct { } type MarginLoan struct { + Exchange ExchangeName `json:"exchange" db:"exchange"` TransactionID uint64 `json:"transactionID" db:"transaction_id"` Asset string `json:"asset" db:"asset"` Principle fixedpoint.Value `json:"principle" db:"principle"` @@ -77,6 +79,7 @@ type MarginLoan struct { } type MarginRepay struct { + Exchange ExchangeName `json:"exchange" db:"exchange"` TransactionID uint64 `json:"transactionID" db:"transaction_id"` Asset string `json:"asset" db:"asset"` Principle fixedpoint.Value `json:"principle" db:"principle"` @@ -85,6 +88,7 @@ type MarginRepay struct { } type MarginLiquidation struct { + Exchange ExchangeName `json:"exchange" db:"exchange"` AveragePrice fixedpoint.Value `json:"averagePrice" db:"average_price"` ExecutedQuantity fixedpoint.Value `json:"executedQuantity" db:"executed_quantity"` OrderID uint64 `json:"orderID" db:"order_id"`