From bdc76e8db646b40302efee3b3b8071dd92736f1a Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 1 Jun 2022 15:51:32 +0800 Subject: [PATCH] types: add gid field --- pkg/service/db_test.go | 2 +- pkg/service/margin_test.go | 11 ++++++++--- pkg/service/reflect_test.go | 2 +- pkg/types/margin.go | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/service/db_test.go b/pkg/service/db_test.go index 34029a799..3093f7dd1 100644 --- a/pkg/service/db_test.go +++ b/pkg/service/db_test.go @@ -38,7 +38,7 @@ func prepareDB(t *testing.T) (*rockhopper.DB, error) { ctx := context.Background() err = rockhopper.Up(ctx, db, migrations, 0, 0) - assert.NoError(t, err) + assert.NoError(t, err, "should migrate successfully") return db, err } diff --git a/pkg/service/margin_test.go b/pkg/service/margin_test.go index 387577eac..5fa85265d 100644 --- a/pkg/service/margin_test.go +++ b/pkg/service/margin_test.go @@ -25,19 +25,24 @@ func TestMarginService(t *testing.T) { ex.MarginSettings.IsIsolatedMargin = true ex.MarginSettings.IsolatedMarginSymbol = "DOTUSDT" + logrus.SetLevel(logrus.ErrorLevel) db, err := prepareDB(t) + + assert.NoError(t, err) + if err != nil { - t.Fatal(err) + t.Fail() + return } defer db.Close() ctx := context.Background() - logrus.SetLevel(logrus.DebugLevel) - dbx := sqlx.NewDb(db.DB, "sqlite3") service := &MarginService{DB: dbx} + + logrus.SetLevel(logrus.DebugLevel) err = service.Sync(ctx, ex, "USDT", time.Date(2022, time.February, 1, 0, 0, 0, 0, time.UTC)) assert.NoError(t, err) diff --git a/pkg/service/reflect_test.go b/pkg/service/reflect_test.go index 9eb525ae9..fa19056b7 100644 --- a/pkg/service/reflect_test.go +++ b/pkg/service/reflect_test.go @@ -58,7 +58,7 @@ func Test_fieldsNamesOf(t *testing.T) { { name: "MarginInterest", args: args{record: &types.MarginInterest{}}, - want: []string{"exchange", "asset", "principle", "interest", "interest_rate", "isolated_symbol", "time"}, + want: []string{"gid", "exchange", "asset", "principle", "interest", "interest_rate", "isolated_symbol", "time"}, }, } for _, tt := range tests { diff --git a/pkg/types/margin.go b/pkg/types/margin.go index c517954d0..fbec9e2a0 100644 --- a/pkg/types/margin.go +++ b/pkg/types/margin.go @@ -60,6 +60,7 @@ type MarginBorrowRepayService interface { } type MarginInterest struct { + GID uint64 `json:"gid" db:"gid"` Exchange ExchangeName `json:"exchange" db:"exchange"` Asset string `json:"asset" db:"asset"` Principle fixedpoint.Value `json:"principle" db:"principle"` @@ -70,6 +71,7 @@ type MarginInterest struct { } type MarginLoan struct { + GID uint64 `json:"gid" db:"gid"` Exchange ExchangeName `json:"exchange" db:"exchange"` TransactionID uint64 `json:"transactionID" db:"transaction_id"` Asset string `json:"asset" db:"asset"` @@ -79,6 +81,7 @@ type MarginLoan struct { } type MarginRepay struct { + GID uint64 `json:"gid" db:"gid"` Exchange ExchangeName `json:"exchange" db:"exchange"` TransactionID uint64 `json:"transactionID" db:"transaction_id"` Asset string `json:"asset" db:"asset"` @@ -88,6 +91,7 @@ type MarginRepay struct { } type MarginLiquidation struct { + GID uint64 `json:"gid" db:"gid"` Exchange ExchangeName `json:"exchange" db:"exchange"` AveragePrice fixedpoint.Value `json:"averagePrice" db:"average_price"` ExecutedQuantity fixedpoint.Value `json:"executedQuantity" db:"executed_quantity"`