mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
trade: add inserted_at column
A trade may be missed initially and fetched after it has occurred.
This commit is contained in:
parent
5098c3ac35
commit
49d567c8f2
14
migrations/mysql/20240531163411_trades_created.sql
Normal file
14
migrations/mysql/20240531163411_trades_created.sql
Normal file
|
@ -0,0 +1,14 @@
|
|||
-- +up
|
||||
-- +begin
|
||||
ALTER TABLE `trades` ADD COLUMN `inserted_at` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL AFTER `traded_at`;
|
||||
-- +end
|
||||
|
||||
-- +begin
|
||||
UPDATE `trades` SET `inserted_at`=`traded_at`;
|
||||
-- +end
|
||||
|
||||
-- +down
|
||||
|
||||
-- +begin
|
||||
ALTER TABLE `trades` DROP COLUMN `inserted_at`;
|
||||
-- +end
|
23
migrations/sqlite3/20240531163411_trades_created.sql
Normal file
23
migrations/sqlite3/20240531163411_trades_created.sql
Normal file
|
@ -0,0 +1,23 @@
|
|||
-- +up
|
||||
-- +begin
|
||||
ALTER TABLE trades ADD COLUMN inserted_at TEXT;
|
||||
|
||||
UPDATE trades SET inserted_at = traded_at;
|
||||
|
||||
CREATE TRIGGER set_inserted_at
|
||||
AFTER INSERT ON trades
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE trades
|
||||
SET inserted_at = datetime('now')
|
||||
WHERE rowid = NEW.rowid;
|
||||
END;
|
||||
|
||||
-- +end
|
||||
|
||||
-- +down
|
||||
|
||||
-- +begin
|
||||
DROP TRIGGER set_inserted_at;
|
||||
ALTER TABLE trades DROP COLUMN inserted_at;
|
||||
-- +end
|
|
@ -95,6 +95,8 @@ type Trade struct {
|
|||
|
||||
// PnL is the profit and loss value of the executed trade
|
||||
PnL sql.NullFloat64 `json:"pnl" db:"pnl"`
|
||||
|
||||
InsertedAt Time `db:"inserted_at"`
|
||||
}
|
||||
|
||||
func (trade Trade) CsvHeader() []string {
|
||||
|
|
Loading…
Reference in New Issue
Block a user