mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1660 from c9s/c9s/fix-trade-insertion
FIX: fix trade insertion for inserted_at field
This commit is contained in:
commit
6be38558e4
|
@ -4,7 +4,7 @@ ALTER TABLE `trades` ADD COLUMN `inserted_at` DATETIME DEFAULT CURRENT_TIMESTAMP
|
|||
-- +end
|
||||
|
||||
-- +begin
|
||||
UPDATE `trades` SET `inserted_at`=`traded_at`;
|
||||
UPDATE `trades` SET `inserted_at` = `traded_at`;
|
||||
-- +end
|
||||
|
||||
-- +down
|
||||
|
|
|
@ -648,7 +648,7 @@ func (environ *Environment) syncSession(
|
|||
log.Infof("syncing symbols %v from session %s", symbols, session.Name)
|
||||
|
||||
syncBufferPeriod := -defaultSyncBufferPeriod
|
||||
if environ.environmentConfig.SyncBufferPeriod != nil {
|
||||
if environ.environmentConfig != nil && environ.environmentConfig.SyncBufferPeriod != nil {
|
||||
syncBufferPeriod = -environ.environmentConfig.SyncBufferPeriod.Duration()
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ func up_main_tradesCreated(ctx context.Context, tx rockhopper.SQLExecutor) (err
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, "UPDATE `trades` SET `inserted_at`=`traded_at`;")
|
||||
_, err = tx.ExecContext(ctx, "UPDATE `trades` SET `inserted_at` = `traded_at`;")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -32,6 +32,11 @@ func placeholdersOf(record interface{}) []string {
|
|||
rt = rt.Elem()
|
||||
}
|
||||
|
||||
vt := reflect.ValueOf(record)
|
||||
if vt.Kind() == reflect.Ptr {
|
||||
vt = vt.Elem()
|
||||
}
|
||||
|
||||
if rt.Kind() != reflect.Struct {
|
||||
return nil
|
||||
}
|
||||
|
@ -39,6 +44,12 @@ func placeholdersOf(record interface{}) []string {
|
|||
var dbFields []string
|
||||
for i := 0; i < rt.NumField(); 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 == "gid" || tag == "-" || tag == "" {
|
||||
continue
|
||||
|
@ -57,6 +68,11 @@ func fieldsNamesOf(record interface{}) []string {
|
|||
rt = rt.Elem()
|
||||
}
|
||||
|
||||
vt := reflect.ValueOf(record)
|
||||
if vt.Kind() == reflect.Ptr {
|
||||
vt = vt.Elem()
|
||||
}
|
||||
|
||||
if rt.Kind() != reflect.Struct {
|
||||
return nil
|
||||
}
|
||||
|
@ -64,6 +80,13 @@ func fieldsNamesOf(record interface{}) []string {
|
|||
var dbFields []string
|
||||
for i := 0; i < rt.NumField(); 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 == "gid" || tag == "-" || tag == "" {
|
||||
continue
|
||||
|
|
|
@ -335,7 +335,7 @@ func (s *TradeService) Query(options QueryTradesOptions) ([]types.Trade, error)
|
|||
func (s *TradeService) Load(ctx context.Context, id int64) (*types.Trade, error) {
|
||||
var trade types.Trade
|
||||
|
||||
rows, err := s.DB.NamedQuery("SELECT * FROM trades WHERE id = :id", map[string]interface{}{
|
||||
rows, err := s.DB.NamedQueryContext(ctx, "SELECT * FROM trades WHERE id = :id", map[string]interface{}{
|
||||
"id": id,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -96,7 +96,7 @@ type Trade struct {
|
|||
// PnL is the profit and loss value of the executed trade
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user