Merge pull request #340 from tony1223/feature/336-kline-table

backtest: add ftx kline table
This commit is contained in:
Yo-An Lin 2021-12-11 02:30:06 +08:00 committed by GitHub
commit 9f14d00f3c
5 changed files with 138 additions and 0 deletions

2
.gitignore vendored
View File

@ -33,4 +33,6 @@
/pkg/server/assets.go
bbgo.sqlite3
node_modules

View File

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

View File

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

View File

@ -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
}

View File

@ -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
}