2022-05-31 09:08:52 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/exchange/binance"
|
|
|
|
"github.com/c9s/bbgo/pkg/testutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMarginService(t *testing.T) {
|
|
|
|
key, secret, ok := testutil.IntegrationTestConfigured(t, "BINANCE")
|
|
|
|
if !ok {
|
|
|
|
t.SkipNow()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ex := binance.New(key, secret)
|
|
|
|
ex.MarginSettings.IsMargin = true
|
|
|
|
ex.MarginSettings.IsIsolatedMargin = true
|
|
|
|
ex.MarginSettings.IsolatedMarginSymbol = "DOTUSDT"
|
|
|
|
|
2022-06-01 07:51:32 +00:00
|
|
|
logrus.SetLevel(logrus.ErrorLevel)
|
2022-05-31 09:08:52 +00:00
|
|
|
db, err := prepareDB(t)
|
2022-06-01 07:51:32 +00:00
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-05-31 09:08:52 +00:00
|
|
|
if err != nil {
|
2022-06-01 07:51:32 +00:00
|
|
|
t.Fail()
|
|
|
|
return
|
2022-05-31 09:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
dbx := sqlx.NewDb(db.DB, "sqlite3")
|
|
|
|
service := &MarginService{DB: dbx}
|
2022-06-01 07:51:32 +00:00
|
|
|
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
2022-05-31 09:08:52 +00:00
|
|
|
err = service.Sync(ctx, ex, "USDT", time.Date(2022, time.February, 1, 0, 0, 0, 0, time.UTC))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// sync second time to ensure that we can query records
|
|
|
|
err = service.Sync(ctx, ex, "USDT", time.Date(2022, time.February, 1, 0, 0, 0, 0, time.UTC))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|