migrations: add margin_liquidations table

This commit is contained in:
c9s 2022-05-31 02:01:54 +08:00
parent 17e575df33
commit 79fbad1266
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
4 changed files with 68 additions and 2 deletions

View File

@ -19,8 +19,7 @@ CREATE TABLE `margin_interests`
`time` DATETIME(3) NOT NULL, `time` DATETIME(3) NOT NULL,
PRIMARY KEY (`gid`), PRIMARY KEY (`gid`)
UNIQUE KEY (`transaction_id`)
); );
-- +down -- +down

View File

@ -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`;

View File

@ -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`;

View File

@ -60,6 +60,7 @@ type MarginBorrowRepayService interface {
} }
type MarginInterest struct { type MarginInterest struct {
Exchange ExchangeName `json:"exchange" db:"exchange"`
Asset string `json:"asset" db:"asset"` Asset string `json:"asset" db:"asset"`
Principle fixedpoint.Value `json:"principle" db:"principle"` Principle fixedpoint.Value `json:"principle" db:"principle"`
Interest fixedpoint.Value `json:"interest" db:"interest"` Interest fixedpoint.Value `json:"interest" db:"interest"`
@ -69,6 +70,7 @@ type MarginInterest struct {
} }
type MarginLoan struct { type MarginLoan struct {
Exchange ExchangeName `json:"exchange" db:"exchange"`
TransactionID uint64 `json:"transactionID" db:"transaction_id"` TransactionID uint64 `json:"transactionID" db:"transaction_id"`
Asset string `json:"asset" db:"asset"` Asset string `json:"asset" db:"asset"`
Principle fixedpoint.Value `json:"principle" db:"principle"` Principle fixedpoint.Value `json:"principle" db:"principle"`
@ -77,6 +79,7 @@ type MarginLoan struct {
} }
type MarginRepay struct { type MarginRepay struct {
Exchange ExchangeName `json:"exchange" db:"exchange"`
TransactionID uint64 `json:"transactionID" db:"transaction_id"` TransactionID uint64 `json:"transactionID" db:"transaction_id"`
Asset string `json:"asset" db:"asset"` Asset string `json:"asset" db:"asset"`
Principle fixedpoint.Value `json:"principle" db:"principle"` Principle fixedpoint.Value `json:"principle" db:"principle"`
@ -85,6 +88,7 @@ type MarginRepay struct {
} }
type MarginLiquidation struct { type MarginLiquidation struct {
Exchange ExchangeName `json:"exchange" db:"exchange"`
AveragePrice fixedpoint.Value `json:"averagePrice" db:"average_price"` AveragePrice fixedpoint.Value `json:"averagePrice" db:"average_price"`
ExecutedQuantity fixedpoint.Value `json:"executedQuantity" db:"executed_quantity"` ExecutedQuantity fixedpoint.Value `json:"executedQuantity" db:"executed_quantity"`
OrderID uint64 `json:"orderID" db:"order_id"` OrderID uint64 `json:"orderID" db:"order_id"`