mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
fix kline record insert fields
This commit is contained in:
parent
4bec8984c0
commit
b5c4fc3e4e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -782,20 +782,22 @@ func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval type
|
|||
var kLines []types.KLine
|
||||
for _, k := range resp {
|
||||
kLines = append(kLines, types.KLine{
|
||||
Exchange: types.ExchangeBinance,
|
||||
Symbol: symbol,
|
||||
Interval: interval,
|
||||
StartTime: time.Unix(0, k.OpenTime*int64(time.Millisecond)),
|
||||
EndTime: time.Unix(0, k.CloseTime*int64(time.Millisecond)),
|
||||
Open: util.MustParseFloat(k.Open),
|
||||
Close: util.MustParseFloat(k.Close),
|
||||
High: util.MustParseFloat(k.High),
|
||||
Low: util.MustParseFloat(k.Low),
|
||||
Volume: util.MustParseFloat(k.Volume),
|
||||
QuoteVolume: util.MustParseFloat(k.QuoteAssetVolume),
|
||||
LastTradeID: 0,
|
||||
NumberOfTrades: uint64(k.TradeNum),
|
||||
Closed: true,
|
||||
Exchange: types.ExchangeBinance,
|
||||
Symbol: symbol,
|
||||
Interval: interval,
|
||||
StartTime: time.Unix(0, k.OpenTime*int64(time.Millisecond)),
|
||||
EndTime: time.Unix(0, k.CloseTime*int64(time.Millisecond)),
|
||||
Open: util.MustParseFloat(k.Open),
|
||||
Close: util.MustParseFloat(k.Close),
|
||||
High: util.MustParseFloat(k.High),
|
||||
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,
|
||||
})
|
||||
}
|
||||
return kLines, nil
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user