mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
fix kline record insert fields
This commit is contained in:
parent
4bec8984c0
commit
b5c4fc3e4e
|
@ -1,35 +1,41 @@
|
||||||
-- +up
|
-- +up
|
||||||
-- +begin
|
-- +begin
|
||||||
ALTER TABLE `binance_klines`
|
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_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
|
-- +end
|
||||||
-- +begin
|
-- +begin
|
||||||
ALTER TABLE `max_klines`
|
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_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
|
-- +end
|
||||||
-- +begin
|
-- +begin
|
||||||
ALTER TABLE `okex_klines`
|
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_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
|
-- +end
|
||||||
|
|
||||||
-- +down
|
-- +down
|
||||||
-- +begin
|
-- +begin
|
||||||
ALTER TABLE `binance_klines`
|
ALTER TABLE `binance_klines`
|
||||||
|
DROP COLUMN `quote_volume`,
|
||||||
DROP COLUMN `taker_buy_base_volume`,
|
DROP COLUMN `taker_buy_base_volume`,
|
||||||
DROP COLUMN `taker_buy_quote_volume`;
|
DROP COLUMN `taker_buy_quote_volume`;
|
||||||
-- +end
|
-- +end
|
||||||
|
|
||||||
-- +begin
|
-- +begin
|
||||||
ALTER TABLE `max_klines`
|
ALTER TABLE `max_klines`
|
||||||
|
DROP COLUMN `quote_volume`,
|
||||||
DROP COLUMN `taker_buy_base_volume`,
|
DROP COLUMN `taker_buy_base_volume`,
|
||||||
DROP COLUMN `taker_buy_quote_volume`;
|
DROP COLUMN `taker_buy_quote_volume`;
|
||||||
-- +end
|
-- +end
|
||||||
|
|
||||||
-- +begin
|
-- +begin
|
||||||
ALTER TABLE `okex_klines`
|
ALTER TABLE `okex_klines`
|
||||||
|
DROP COLUMN `quote_volume`,
|
||||||
DROP COLUMN `taker_buy_base_volume`,
|
DROP COLUMN `taker_buy_base_volume`,
|
||||||
DROP COLUMN `taker_buy_quote_volume`;
|
DROP COLUMN `taker_buy_quote_volume`;
|
||||||
-- +end
|
-- +end
|
||||||
|
|
|
@ -1,10 +1,27 @@
|
||||||
-- +up
|
-- +up
|
||||||
-- +begin
|
-- +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
|
-- +end
|
||||||
|
|
||||||
-- +down
|
-- +down
|
||||||
|
|
||||||
-- +begin
|
|
||||||
SELECT 'down SQL query';
|
|
||||||
-- +end
|
|
||||||
|
|
|
@ -793,6 +793,8 @@ func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval type
|
||||||
Low: util.MustParseFloat(k.Low),
|
Low: util.MustParseFloat(k.Low),
|
||||||
Volume: util.MustParseFloat(k.Volume),
|
Volume: util.MustParseFloat(k.Volume),
|
||||||
QuoteVolume: util.MustParseFloat(k.QuoteAssetVolume),
|
QuoteVolume: util.MustParseFloat(k.QuoteAssetVolume),
|
||||||
|
TakerBuyBaseAssetVolume: util.MustParseFloat(k.TakerBuyBaseAssetVolume),
|
||||||
|
TakerBuyQuoteAssetVolume: util.MustParseFloat(k.TakerBuyQuoteAssetVolume),
|
||||||
LastTradeID: 0,
|
LastTradeID: 0,
|
||||||
NumberOfTrades: uint64(k.TradeNum),
|
NumberOfTrades: uint64(k.TradeNum),
|
||||||
Closed: true,
|
Closed: true,
|
||||||
|
|
|
@ -14,17 +14,17 @@ func init() {
|
||||||
func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
func upAddKlineTakerBuyColumns(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 `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 {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -35,17 +35,17 @@ func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (
|
||||||
func downAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
func downAddKlineTakerBuyColumns(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 `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 {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,17 @@ func init() {
|
||||||
func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
func upAddKlineTakerBuyColumns(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, "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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -25,10 +35,5 @@ func upAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (
|
||||||
func downAddKlineTakerBuyColumns(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
|
func downAddKlineTakerBuyColumns(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, "SELECT 'down SQL query';")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,8 +205,8 @@ func (s *BacktestService) Insert(kline types.KLine) error {
|
||||||
return errors.New("kline.Exchange field should not be empty")
|
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`)" +
|
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)"
|
"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")
|
sql = strings.ReplaceAll(sql, "binance_klines", kline.Exchange.String()+"_klines")
|
||||||
|
|
||||||
_, err := s.DB.NamedExec(sql, kline)
|
_, err := s.DB.NamedExec(sql, kline)
|
||||||
|
|
|
@ -2,4 +2,5 @@
|
||||||
driver: mysql
|
driver: mysql
|
||||||
dialect: mysql
|
dialect: mysql
|
||||||
dsn: "root@tcp(localhost:3306)/bbgo_dev?parseTime=true"
|
dsn: "root@tcp(localhost:3306)/bbgo_dev?parseTime=true"
|
||||||
|
# dsn: "root@tcp(localhost:3306)/bbgo_backtest?parseTime=true"
|
||||||
migrationsDir: migrations/mysql
|
migrationsDir: migrations/mysql
|
||||||
|
|
Loading…
Reference in New Issue
Block a user