mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
56fdf0a21f
i really don't know why I forgot this lol
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
)
|
|
|
|
func TestPositionService(t *testing.T) {
|
|
db, err := prepareDB(t)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
defer func() {
|
|
err := db.Close()
|
|
assert.NoError(t, err)
|
|
}()
|
|
|
|
xdb := sqlx.NewDb(db.DB, "sqlite3")
|
|
service := &PositionService{DB: xdb}
|
|
|
|
t.Run("minimal fields", func(t *testing.T) {
|
|
err = service.Insert(&types.Position{
|
|
Symbol: "BTCUSDT",
|
|
BaseCurrency: "BTC",
|
|
QuoteCurrency: "USDT",
|
|
AverageCost: fixedpoint.NewFromFloat(44000),
|
|
ChangedAt: time.Now(),
|
|
}, types.Trade{
|
|
Time: types.Time(time.Now()),
|
|
}, fixedpoint.Zero, fixedpoint.Zero)
|
|
assert.NoError(t, err)
|
|
})
|
|
|
|
t.Run("full fields", func(t *testing.T) {
|
|
err = service.Insert(&types.Position{
|
|
Symbol: "BTCUSDT",
|
|
BaseCurrency: "BTC",
|
|
QuoteCurrency: "USDT",
|
|
AverageCost: fixedpoint.NewFromFloat(44000),
|
|
Base: fixedpoint.NewFromFloat(0.1),
|
|
Quote: fixedpoint.NewFromFloat(-44000.0),
|
|
ChangedAt: time.Now(),
|
|
Strategy: "bollmaker",
|
|
StrategyInstanceID: "bollmaker-BTCUSDT-1m",
|
|
}, types.Trade{
|
|
ID: 9,
|
|
Exchange: types.ExchangeBinance,
|
|
Side: types.SideTypeSell,
|
|
Time: types.Time(time.Now()),
|
|
}, fixedpoint.NewFromFloat(10.9), fixedpoint.NewFromFloat(8.1))
|
|
assert.NoError(t, err)
|
|
})
|
|
|
|
}
|