fix kline record insert fields

This commit is contained in:
c9s 2021-06-01 01:08:02 +08:00
parent 4bec8984c0
commit b5c4fc3e4e
7 changed files with 67 additions and 36 deletions

View File

@ -1,35 +1,41 @@
-- +up
-- +begin
ALTER TABLE `binance_klines`
ADD COLUMN `quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0,
ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,
ADD COLUMN `taker_buy_quote_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0;
ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0;
-- +end
-- +begin
ALTER TABLE `max_klines`
ADD COLUMN `quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0,
ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,
ADD COLUMN `taker_buy_quote_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0;
ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0;
-- +end
-- +begin
ALTER TABLE `okex_klines`
ADD COLUMN `quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0,
ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,
ADD COLUMN `taker_buy_quote_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0;
ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0;
-- +end
-- +down
-- +begin
ALTER TABLE `binance_klines`
DROP COLUMN `quote_volume`,
DROP COLUMN `taker_buy_base_volume`,
DROP COLUMN `taker_buy_quote_volume`;
-- +end
-- +begin
ALTER TABLE `max_klines`
DROP COLUMN `quote_volume`,
DROP COLUMN `taker_buy_base_volume`,
DROP COLUMN `taker_buy_quote_volume`;
-- +end
-- +begin
ALTER TABLE `okex_klines`
DROP COLUMN `quote_volume`,
DROP COLUMN `taker_buy_base_volume`,
DROP COLUMN `taker_buy_quote_volume`;
-- +end

View File

@ -1,10 +1,27 @@
-- +up
-- +begin
SELECT 'up SQL query';
ALTER TABLE `binance_klines`
ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;
ALTER TABLE `binance_klines`
ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;
ALTER TABLE `binance_klines`
ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;
-- +end
-- +begin
ALTER TABLE `max_klines`
ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;
ALTER TABLE `max_klines`
ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;
ALTER TABLE `max_klines`
ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;
-- +end
-- +begin
ALTER TABLE `okex_klines`
ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;
ALTER TABLE `okex_klines`
ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;
ALTER TABLE `okex_klines`
ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;
-- +end
-- +down
-- +begin
SELECT 'down SQL query';
-- +end

View File

@ -793,6 +793,8 @@ func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval type
Low: util.MustParseFloat(k.Low),
Volume: util.MustParseFloat(k.Volume),
QuoteVolume: util.MustParseFloat(k.QuoteAssetVolume),
TakerBuyBaseAssetVolume: util.MustParseFloat(k.TakerBuyBaseAssetVolume),
TakerBuyQuoteAssetVolume: util.MustParseFloat(k.TakerBuyQuoteAssetVolume),
LastTradeID: 0,
NumberOfTrades: uint64(k.TradeNum),
Closed: true,

View File

@ -14,17 +14,17 @@ func init() {
func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0;")
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0;")
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0;")
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_base_volume` DECIMAL(16, 8) NOT NULL DEFAULT 0.0,\n ADD COLUMN `taker_buy_quote_volume` DECIMAL(32, 4) NOT NULL DEFAULT 0.0;")
if err != nil {
return err
}
@ -35,17 +35,17 @@ func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (
func downAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;")
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n DROP COLUMN `quote_volume`,\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;")
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n DROP COLUMN `quote_volume`,\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;")
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n DROP COLUMN `quote_volume`,\n DROP COLUMN `taker_buy_base_volume`,\n DROP COLUMN `taker_buy_quote_volume`;")
if err != nil {
return err
}

View File

@ -14,7 +14,17 @@ func init() {
func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 'up SQL query';")
_, err = tx.ExecContext(ctx, "ALTER TABLE `binance_klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `binance_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `binance_klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE `max_klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `max_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `max_klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;")
if err != nil {
return err
}
_, err = tx.ExecContext(ctx, "ALTER TABLE `okex_klines`\n ADD COLUMN `quote_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `okex_klines`\n ADD COLUMN `taker_buy_base_volume` DECIMAL NOT NULL DEFAULT 0.0;\nALTER TABLE `okex_klines`\n ADD COLUMN `taker_buy_quote_volume` DECIMAL NOT NULL DEFAULT 0.0;")
if err != nil {
return err
}
@ -25,10 +35,5 @@ func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (
func downAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 'down SQL query';")
if err != nil {
return err
}
return err
}

View File

@ -205,8 +205,8 @@ func (s *BacktestService) Insert(kline types.KLine) error {
return errors.New("kline.Exchange field should not be empty")
}
sql := "INSERT INTO `binance_klines` (`exchange`, `start_time`, `end_time`, `symbol`, `interval`, `open`, `high`, `low`, `close`, `closed`, `volume`)" +
"VALUES (:exchange, :start_time, :end_time, :symbol, :interval, :open, :high, :low, :close, :closed, :volume)"
sql := "INSERT INTO `binance_klines` (`exchange`, `start_time`, `end_time`, `symbol`, `interval`, `open`, `high`, `low`, `close`, `closed`, `volume`, `quote_volume`, `taker_buy_base_volume`, `taker_buy_quote_volume`)" +
"VALUES (:exchange, :start_time, :end_time, :symbol, :interval, :open, :high, :low, :close, :closed, :volume, :quote_volume, :taker_buy_base_volume, :taker_buy_quote_volume)"
sql = strings.ReplaceAll(sql, "binance_klines", kline.Exchange.String()+"_klines")
_, err := s.DB.NamedExec(sql, kline)

View File

@ -2,4 +2,5 @@
driver: mysql
dialect: mysql
dsn: "root@tcp(localhost:3306)/bbgo_dev?parseTime=true"
# dsn: "root@tcp(localhost:3306)/bbgo_backtest?parseTime=true"
migrationsDir: migrations/mysql