Merge pull request #544 from c9s/fix/fee-unsigned

fix: fee unsigned for ftx
This commit is contained in:
Yo-An Lin 2022-04-19 19:43:54 +08:00 committed by GitHub
commit 11a215f4ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 103 additions and 23 deletions

View File

@ -11,7 +11,7 @@ CREATE TABLE `trades`
`quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,
`quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL, `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,
`fee` DECIMAL(16, 8) UNSIGNED NOT NULL, `fee` DECIMAL(16, 8) UNSIGNED NOT NULL,
`fee_currency` VARCHAR(6) NOT NULL, `fee_currency` VARCHAR(10) NOT NULL,
`is_buyer` BOOLEAN NOT NULL DEFAULT FALSE, `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,
`is_maker` BOOLEAN NOT NULL DEFAULT FALSE, `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,
`side` VARCHAR(4) NOT NULL DEFAULT '', `side` VARCHAR(4) NOT NULL DEFAULT '',

View File

@ -7,11 +7,11 @@ CREATE TABLE `klines`
`end_time` DATETIME(3) NOT NULL, `end_time` DATETIME(3) NOT NULL,
`interval` VARCHAR(3) NOT NULL, `interval` VARCHAR(3) NOT NULL,
`symbol` VARCHAR(20) NOT NULL, `symbol` VARCHAR(20) NOT NULL,
`open` DECIMAL(16, 8) UNSIGNED NOT NULL, `open` DECIMAL(20, 8) UNSIGNED NOT NULL,
`high` DECIMAL(16, 8) UNSIGNED NOT NULL, `high` DECIMAL(20, 8) UNSIGNED NOT NULL,
`low` DECIMAL(16, 8) UNSIGNED NOT NULL, `low` DECIMAL(20, 8) UNSIGNED NOT NULL,
`close` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0, `close` DECIMAL(20, 8) UNSIGNED NOT NULL DEFAULT 0.0,
`volume` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0, `volume` DECIMAL(20, 8) UNSIGNED NOT NULL DEFAULT 0.0,
`closed` BOOL NOT NULL DEFAULT TRUE, `closed` BOOL NOT NULL DEFAULT TRUE,
`last_trade_id` INT UNSIGNED NOT NULL DEFAULT 0, `last_trade_id` INT UNSIGNED NOT NULL DEFAULT 0,
`num_trades` INT UNSIGNED NOT NULL DEFAULT 0, `num_trades` INT UNSIGNED NOT NULL DEFAULT 0,

View File

@ -8,11 +8,11 @@ create table if not exists ftx_klines
start_time datetime(3) not null, start_time datetime(3) not null,
end_time datetime(3) not null, end_time datetime(3) not null,
`interval` varchar(3) not null, `interval` varchar(3) not null,
symbol varchar(12) not null, symbol varchar(20) not null,
open decimal(16,8) unsigned not null, open decimal(20,8) unsigned not null,
high decimal(16,8) unsigned not null, high decimal(20,8) unsigned not null,
low decimal(16,8) unsigned not null, low decimal(20,8) unsigned not null,
close decimal(16,8) unsigned default 0.00000000 not null, close decimal(20,8) unsigned default 0.00000000 not null,
volume decimal(20,8) unsigned default 0.00000000 not null, volume decimal(20,8) unsigned default 0.00000000 not null,
closed tinyint(1) default 1 not null, closed tinyint(1) default 1 not null,
last_trade_id int unsigned default '0' not null, last_trade_id int unsigned default '0' not null,

View File

@ -1,9 +1,9 @@
-- +up -- +up
-- +begin -- +begin
ALTER TABLE trades CHANGE fee_currency fee_currency varchar(10) NOT NULL; SELECT 1;
-- +end -- +end
-- +down -- +down
-- +begin -- +begin
ALTER TABLE trades CHANGE fee_currency fee_currency varchar(4) NOT NULL; SELECT 1;
-- +end -- +end

View File

@ -59,8 +59,8 @@ CREATE TABLE `profits`
`traded_at` DATETIME(3) NOT NULL, `traded_at` DATETIME(3) NOT NULL,
-- fee -- fee
`fee_in_usd` DECIMAL(16, 8) UNSIGNED, `fee_in_usd` DECIMAL(16, 8),
`fee` DECIMAL(16, 8) UNSIGNED NOT NULL, `fee` DECIMAL(16, 8) NOT NULL,
`fee_currency` VARCHAR(10) NOT NULL, `fee_currency` VARCHAR(10) NOT NULL,
PRIMARY KEY (`gid`), PRIMARY KEY (`gid`),

View File

@ -1,8 +1,10 @@
-- +up -- +up
-- +begin -- +begin
SELECT 1;
-- +end -- +end
-- +down -- +down
-- +begin -- +begin
SELECT 1;
-- +end -- +end

View File

@ -14,7 +14,7 @@ func init() {
func upTrades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func upTrades(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `trades`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `id` BIGINT UNSIGNED,\n `order_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(20) NOT NULL,\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `fee` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `fee_currency` VARCHAR(6) NOT NULL,\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `traded_at` DATETIME(3) NOT NULL,\n `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `strategy` VARCHAR(32) NULL,\n `pnl` DECIMAL NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `id` (`exchange`, `symbol`, `side`, `id`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `trades`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `id` BIGINT UNSIGNED,\n `order_id` BIGINT UNSIGNED NOT NULL,\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `symbol` VARCHAR(20) NOT NULL,\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `fee` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `fee_currency` VARCHAR(10) NOT NULL,\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `traded_at` DATETIME(3) NOT NULL,\n `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `strategy` VARCHAR(32) NULL,\n `pnl` DECIMAL NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `id` (`exchange`, `symbol`, `side`, `id`)\n);")
if err != nil { if err != nil {
return err return err
} }

View File

@ -14,7 +14,7 @@ func init() {
func upKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func upKlines(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `klines`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(10) NOT NULL,\n `start_time` DATETIME(3) NOT NULL,\n `end_time` DATETIME(3) NOT NULL,\n `interval` VARCHAR(3) NOT NULL,\n `symbol` VARCHAR(20) NOT NULL,\n `open` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `high` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `low` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `close` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `closed` BOOL NOT NULL DEFAULT TRUE,\n `last_trade_id` INT UNSIGNED NOT NULL DEFAULT 0,\n `num_trades` INT UNSIGNED NOT NULL DEFAULT 0,\n PRIMARY KEY (`gid`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `klines`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `exchange` VARCHAR(10) NOT NULL,\n `start_time` DATETIME(3) NOT NULL,\n `end_time` DATETIME(3) NOT NULL,\n `interval` VARCHAR(3) NOT NULL,\n `symbol` VARCHAR(20) NOT NULL,\n `open` DECIMAL(20, 8) UNSIGNED NOT NULL,\n `high` DECIMAL(20, 8) UNSIGNED NOT NULL,\n `low` DECIMAL(20, 8) UNSIGNED NOT NULL,\n `close` DECIMAL(20, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(20, 8) UNSIGNED NOT NULL DEFAULT 0.0,\n `closed` BOOL NOT NULL DEFAULT TRUE,\n `last_trade_id` INT UNSIGNED NOT NULL DEFAULT 0,\n `num_trades` INT UNSIGNED NOT NULL DEFAULT 0,\n PRIMARY KEY (`gid`)\n);")
if err != nil { if err != nil {
return err return err
} }

View File

@ -14,7 +14,7 @@ func init() {
func upAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func upAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "create table if not exists ftx_klines\n(\n gid bigint unsigned auto_increment\n primary key,\n exchange varchar(10) not null,\n start_time datetime(3) not null,\n end_time datetime(3) not null,\n `interval` varchar(3) not null,\n symbol varchar(12) not null,\n open decimal(16,8) unsigned not null,\n high decimal(16,8) unsigned not null,\n low decimal(16,8) unsigned not null,\n close decimal(16,8) unsigned default 0.00000000 not null,\n volume decimal(20,8) unsigned default 0.00000000 not null,\n closed tinyint(1) default 1 not null,\n last_trade_id int unsigned default '0' not null,\n num_trades int unsigned default '0' not null,\n quote_volume decimal(32,4) default 0.0000 not null,\n taker_buy_base_volume decimal(32,8) not null,\n taker_buy_quote_volume decimal(32,4) default 0.0000 not null\n );") _, err = tx.ExecContext(ctx, "create table if not exists ftx_klines\n(\n gid bigint unsigned auto_increment\n primary key,\n exchange varchar(10) not null,\n start_time datetime(3) not null,\n end_time datetime(3) not null,\n `interval` varchar(3) not null,\n symbol varchar(20) not null,\n open decimal(20,8) unsigned not null,\n high decimal(20,8) unsigned not null,\n low decimal(20,8) unsigned not null,\n close decimal(20,8) unsigned default 0.00000000 not null,\n volume decimal(20,8) unsigned default 0.00000000 not null,\n closed tinyint(1) default 1 not null,\n last_trade_id int unsigned default '0' not null,\n num_trades int unsigned default '0' not null,\n quote_volume decimal(32,4) default 0.0000 not null,\n taker_buy_base_volume decimal(32,8) not null,\n taker_buy_quote_volume decimal(32,4) default 0.0000 not null\n );")
if err != nil { if err != nil {
return err return err
} }

View File

@ -14,7 +14,7 @@ func init() {
func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE trades CHANGE fee_currency fee_currency varchar(10) NOT NULL;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
@ -25,7 +25,7 @@ func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (
func downUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func downUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE trades CHANGE fee_currency fee_currency varchar(4) NOT NULL;") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }

View File

@ -14,7 +14,7 @@ func init() {
func upAddProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func upAddProfitTable(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "CREATE TABLE `profits`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `strategy` VARCHAR(32) NOT NULL,\n `strategy_instance_id` VARCHAR(64) NOT NULL,\n `symbol` VARCHAR(8) NOT NULL,\n -- average_cost is the position average cost\n `average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- profit is the pnl (profit and loss)\n `profit` DECIMAL(16, 8) NOT NULL,\n -- net_profit is the pnl (profit and loss)\n `net_profit` DECIMAL(16, 8) NOT NULL,\n -- profit_margin is the pnl (profit and loss)\n `profit_margin` DECIMAL(16, 8) NOT NULL,\n -- net_profit_margin is the pnl (profit and loss)\n `net_profit_margin` DECIMAL(16, 8) NOT NULL,\n `quote_currency` VARCHAR(10) NOT NULL,\n `base_currency` VARCHAR(10) NOT NULL,\n -- -------------------------------------------------------\n -- embedded trade data --\n -- -------------------------------------------------------\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `is_futures` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `trade_id` BIGINT UNSIGNED NOT NULL,\n -- side is the side of the trade that makes profit\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n -- price is the price of the trade that makes profit\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- quantity is the quantity of the trade that makes profit\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- quote_quantity is the quote quantity of the trade that makes profit\n `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `traded_at` DATETIME(3) NOT NULL,\n -- fee\n `fee_in_usd` DECIMAL(16, 8) UNSIGNED,\n `fee` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `fee_currency` VARCHAR(10) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `trade_id` (`trade_id`)\n);") _, err = tx.ExecContext(ctx, "CREATE TABLE `profits`\n(\n `gid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n `strategy` VARCHAR(32) NOT NULL,\n `strategy_instance_id` VARCHAR(64) NOT NULL,\n `symbol` VARCHAR(8) NOT NULL,\n -- average_cost is the position average cost\n `average_cost` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- profit is the pnl (profit and loss)\n `profit` DECIMAL(16, 8) NOT NULL,\n -- net_profit is the pnl (profit and loss)\n `net_profit` DECIMAL(16, 8) NOT NULL,\n -- profit_margin is the pnl (profit and loss)\n `profit_margin` DECIMAL(16, 8) NOT NULL,\n -- net_profit_margin is the pnl (profit and loss)\n `net_profit_margin` DECIMAL(16, 8) NOT NULL,\n `quote_currency` VARCHAR(10) NOT NULL,\n `base_currency` VARCHAR(10) NOT NULL,\n -- -------------------------------------------------------\n -- embedded trade data --\n -- -------------------------------------------------------\n `exchange` VARCHAR(24) NOT NULL DEFAULT '',\n `is_futures` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_margin` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_isolated` BOOLEAN NOT NULL DEFAULT FALSE,\n `trade_id` BIGINT UNSIGNED NOT NULL,\n -- side is the side of the trade that makes profit\n `side` VARCHAR(4) NOT NULL DEFAULT '',\n `is_buyer` BOOLEAN NOT NULL DEFAULT FALSE,\n `is_maker` BOOLEAN NOT NULL DEFAULT FALSE,\n -- price is the price of the trade that makes profit\n `price` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- quantity is the quantity of the trade that makes profit\n `quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n -- quote_quantity is the quote quantity of the trade that makes profit\n `quote_quantity` DECIMAL(16, 8) UNSIGNED NOT NULL,\n `traded_at` DATETIME(3) NOT NULL,\n -- fee\n `fee_in_usd` DECIMAL(16, 8),\n `fee` DECIMAL(16, 8) NOT NULL,\n `fee_currency` VARCHAR(10) NOT NULL,\n PRIMARY KEY (`gid`),\n UNIQUE KEY `trade_id` (`trade_id`)\n);")
if err != nil { if err != nil {
return err return err
} }

View File

@ -0,0 +1,44 @@
package mysql
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upFixFeeColumn, downFixFeeColumn)
}
func upFixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE trades\n CHANGE fee fee DECIMAL(16, 8) NOT NULL;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE fee fee DECIMAL(16, 8) NOT NULL;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE profits\n CHANGE fee_in_usd fee_in_usd DECIMAL(16, 8);")
if err != nil {
return err
}
return err
}
func downFixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}

View File

@ -14,7 +14,7 @@ func init() {
func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied. // This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }
@ -25,7 +25,7 @@ func upUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (
func downUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { func downUpdateFeeCurrencyLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back. // This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "") _, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil { if err != nil {
return err return err
} }

View File

@ -0,0 +1,34 @@
package sqlite3
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upFixFeeColumn, downFixFeeColumn)
}
func upFixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}
func downFixFeeColumn(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}