From 5fb50fa2cb9e4054d65b914355907926d5180223 Mon Sep 17 00:00:00 2001 From: TonyQ Date: Sat, 11 Dec 2021 02:11:01 +0800 Subject: [PATCH 1/2] exchange: backtest: add ftx kline table --- .gitignore | 2 ++ .../mysql/20211211020303_add_ftx_kline.sql | 33 +++++++++++++++++++ .../sqlite3/20211211020303_add_ftx_kline.sql | 30 +++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 migrations/mysql/20211211020303_add_ftx_kline.sql create mode 100644 migrations/sqlite3/20211211020303_add_ftx_kline.sql diff --git a/.gitignore b/.gitignore index d36fd8d9c..c0c1ccacf 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ /config/bbgo.yaml /pkg/server/assets.go + +bbgo.sqlite3 diff --git a/migrations/mysql/20211211020303_add_ftx_kline.sql b/migrations/mysql/20211211020303_add_ftx_kline.sql new file mode 100644 index 000000000..21827730e --- /dev/null +++ b/migrations/mysql/20211211020303_add_ftx_kline.sql @@ -0,0 +1,33 @@ +-- +up +-- +begin +create table if not exists ftx_klines +( + gid bigint unsigned auto_increment + primary key, + exchange varchar(10) not null, + start_time datetime(3) not null, + end_time datetime(3) not null, + `interval` varchar(3) not null, + symbol varchar(12) not null, + open decimal(16,8) unsigned not null, + high decimal(16,8) unsigned not null, + low decimal(16,8) unsigned not null, + close decimal(16,8) unsigned default 0.00000000 not null, + volume decimal(20,8) unsigned default 0.00000000 not null, + closed tinyint(1) default 1 not null, + last_trade_id int unsigned default '0' not null, + num_trades int unsigned default '0' not null, + quote_volume decimal(32,4) default 0.0000 not null, + taker_buy_base_volume decimal(32,8) not null, + taker_buy_quote_volume decimal(32,4) default 0.0000 not null + ); +-- +end +-- +begin +create index klines_end_time_symbol_interval + on ftx_klines (end_time, symbol, `interval`); +-- +end +-- +down + +-- +begin +drop table ftx_klines; +-- +end diff --git a/migrations/sqlite3/20211211020303_add_ftx_kline.sql b/migrations/sqlite3/20211211020303_add_ftx_kline.sql new file mode 100644 index 000000000..83da4ff73 --- /dev/null +++ b/migrations/sqlite3/20211211020303_add_ftx_kline.sql @@ -0,0 +1,30 @@ +-- +up +-- +begin + +CREATE TABLE `ftx_klines` +( + `gid` INTEGER PRIMARY KEY AUTOINCREMENT, + `exchange` VARCHAR(10) NOT NULL, + `start_time` DATETIME(3) NOT NULL, + `end_time` DATETIME(3) NOT NULL, + `interval` VARCHAR(3) NOT NULL, + `symbol` VARCHAR(7) NOT NULL, + `open` DECIMAL(16, 8) NOT NULL, + `high` DECIMAL(16, 8) NOT NULL, + `low` DECIMAL(16, 8) NOT NULL, + `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0, + `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0, + `closed` BOOLEAN NOT NULL DEFAULT TRUE, + `last_trade_id` INT NOT NULL DEFAULT 0, + `num_trades` INT NOT NULL DEFAULT 0, + `quote_volume` DECIMAL NOT NULL DEFAULT 0.0, + `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0, + `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0 +); +-- +end + +-- +down + +-- +begin +drop table ftx_klines; +-- +end From 0fcc5e5edc0594fbb8e093c175df6b8668449e5f Mon Sep 17 00:00:00 2001 From: TonyQ Date: Sat, 11 Dec 2021 02:19:53 +0800 Subject: [PATCH 2/2] compile and update migration package --- .../mysql/20211211020303_add_ftx_kline.go | 39 +++++++++++++++++++ .../sqlite3/20211211020303_add_ftx_kline.go | 34 ++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 pkg/migrations/mysql/20211211020303_add_ftx_kline.go create mode 100644 pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go diff --git a/pkg/migrations/mysql/20211211020303_add_ftx_kline.go b/pkg/migrations/mysql/20211211020303_add_ftx_kline.go new file mode 100644 index 000000000..cbe487afc --- /dev/null +++ b/pkg/migrations/mysql/20211211020303_add_ftx_kline.go @@ -0,0 +1,39 @@ +package mysql + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddFtxKline, downAddFtxKline) + +} + +func upAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // 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 );") + if err != nil { + return err + } + + _, err = tx.ExecContext(ctx, "create index klines_end_time_symbol_interval\n on ftx_klines (end_time, symbol, `interval`);") + if err != nil { + return err + } + + return err +} + +func downAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is rolled back. + + _, err = tx.ExecContext(ctx, "drop table ftx_klines;") + if err != nil { + return err + } + + return err +} diff --git a/pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go b/pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go new file mode 100644 index 000000000..7775e052f --- /dev/null +++ b/pkg/migrations/sqlite3/20211211020303_add_ftx_kline.go @@ -0,0 +1,34 @@ +package sqlite3 + +import ( + "context" + + "github.com/c9s/rockhopper" +) + +func init() { + AddMigration(upAddFtxKline, downAddFtxKline) + +} + +func upAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is applied. + + _, err = tx.ExecContext(ctx, "CREATE TABLE `ftx_klines`\n(\n `gid` INTEGER PRIMARY KEY AUTOINCREMENT,\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(7) NOT NULL,\n `open` DECIMAL(16, 8) NOT NULL,\n `high` DECIMAL(16, 8) NOT NULL,\n `low` DECIMAL(16, 8) NOT NULL,\n `close` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n `closed` BOOLEAN NOT NULL DEFAULT TRUE,\n `last_trade_id` INT NOT NULL DEFAULT 0,\n `num_trades` INT NOT NULL DEFAULT 0,\n `quote_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0,\n `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0\n);") + if err != nil { + return err + } + + return err +} + +func downAddFtxKline(ctx context.Context, tx rockhopper.SQLExecutor) (err error) { + // This code is executed when the migration is rolled back. + + _, err = tx.ExecContext(ctx, "drop table ftx_klines;") + if err != nil { + return err + } + + return err +}