Skip to content

Commit

Permalink
trade: add inserted_at column
Browse files Browse the repository at this point in the history
A trade may be missed initially and fetched after it has occurred.
  • Loading branch information
ycdesu committed May 31, 2024
1 parent 7bde48a commit 7cbfe7c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions migrations/mysql/20240531163411_trades_created.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- +up
-- +begin
ALTER TABLE `trades` ADD COLUMN `inserted_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;

-- +end

-- +down

-- +begin
ALTER TABLE `trades` DROP COLUMN `inserted_at`;
-- +end
10 changes: 10 additions & 0 deletions migrations/sqlite3/20240531163411_trades_created.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- +up
-- +begin
ALTER TABLE trades ADD COLUMN inserted_at DATETIME DEFAULT (datetime('now')) NOT NULL;
-- +end

-- +down

-- +begin
ALTER TABLE trades DROP COLUMN inserted_at;
-- +end
2 changes: 2 additions & 0 deletions pkg/types/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7cbfe7c

Please sign in to comment.