mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
fix trade insertion for inserted_at field
This commit is contained in:
parent
6afde4808f
commit
00b9c3156f
|
@ -1,10 +1,10 @@
|
||||||
-- +up
|
-- +up
|
||||||
-- +begin
|
-- +begin
|
||||||
ALTER TABLE `trades` ADD COLUMN `inserted_at` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL AFTER `traded_at`;
|
ALTER TABLE `trades` ADD COLUMN `inserted_at` DATETIME(3) DEFAULT CURRENT_TIMESTAMP NOT NULL AFTER `traded_at`;
|
||||||
-- +end
|
-- +end
|
||||||
|
|
||||||
-- +begin
|
-- +begin
|
||||||
UPDATE `trades` SET `inserted_at`=`traded_at`;
|
UPDATE `trades` SET `inserted_at` = `traded_at`;
|
||||||
-- +end
|
-- +end
|
||||||
|
|
||||||
-- +down
|
-- +down
|
||||||
|
|
|
@ -27,7 +27,9 @@ func tableNameOf(record interface{}) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func placeholdersOf(record interface{}) []string {
|
func placeholdersOf(record interface{}) []string {
|
||||||
|
vt := reflect.ValueOf(record)
|
||||||
rt := reflect.TypeOf(record)
|
rt := reflect.TypeOf(record)
|
||||||
|
|
||||||
if rt.Kind() == reflect.Ptr {
|
if rt.Kind() == reflect.Ptr {
|
||||||
rt = rt.Elem()
|
rt = rt.Elem()
|
||||||
}
|
}
|
||||||
|
@ -39,6 +41,12 @@ func placeholdersOf(record interface{}) []string {
|
||||||
var dbFields []string
|
var dbFields []string
|
||||||
for i := 0; i < rt.NumField(); i++ {
|
for i := 0; i < rt.NumField(); i++ {
|
||||||
fieldType := rt.Field(i)
|
fieldType := rt.Field(i)
|
||||||
|
fieldValue := vt.Field(i)
|
||||||
|
|
||||||
|
if fieldType.Type.Kind() == reflect.Ptr && fieldValue.IsNil() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
||||||
if tag == "gid" || tag == "-" || tag == "" {
|
if tag == "gid" || tag == "-" || tag == "" {
|
||||||
continue
|
continue
|
||||||
|
@ -52,7 +60,9 @@ func placeholdersOf(record interface{}) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fieldsNamesOf(record interface{}) []string {
|
func fieldsNamesOf(record interface{}) []string {
|
||||||
|
vt := reflect.ValueOf(record)
|
||||||
rt := reflect.TypeOf(record)
|
rt := reflect.TypeOf(record)
|
||||||
|
|
||||||
if rt.Kind() == reflect.Ptr {
|
if rt.Kind() == reflect.Ptr {
|
||||||
rt = rt.Elem()
|
rt = rt.Elem()
|
||||||
}
|
}
|
||||||
|
@ -64,6 +74,13 @@ func fieldsNamesOf(record interface{}) []string {
|
||||||
var dbFields []string
|
var dbFields []string
|
||||||
for i := 0; i < rt.NumField(); i++ {
|
for i := 0; i < rt.NumField(); i++ {
|
||||||
fieldType := rt.Field(i)
|
fieldType := rt.Field(i)
|
||||||
|
fieldValue := vt.Field(i)
|
||||||
|
|
||||||
|
// skip value=nil field
|
||||||
|
if fieldType.Type.Kind() == reflect.Ptr && fieldValue.IsNil() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
||||||
if tag == "gid" || tag == "-" || tag == "" {
|
if tag == "gid" || tag == "-" || tag == "" {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -96,7 +96,7 @@ type Trade struct {
|
||||||
// PnL is the profit and loss value of the executed trade
|
// PnL is the profit and loss value of the executed trade
|
||||||
PnL sql.NullFloat64 `json:"pnl" db:"pnl"`
|
PnL sql.NullFloat64 `json:"pnl" db:"pnl"`
|
||||||
|
|
||||||
InsertedAt Time `json:"insertedAt" db:"inserted_at"`
|
InsertedAt *Time `json:"insertedAt" db:"inserted_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (trade Trade) CsvHeader() []string {
|
func (trade Trade) CsvHeader() []string {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user