bbgo_origin/pkg/service/profit_test.go

42 lines
936 B
Go
Raw Permalink Normal View History

2022-03-04 16:27:44 +00:00
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 TestProfitService(t *testing.T) {
db, err := prepareDB(t)
if err != nil {
t.Fatal(err)
}
defer db.Close()
xdb := sqlx.NewDb(db.DB, "sqlite3")
service := &ProfitService{DB: xdb}
err = service.Insert(types.Profit{
2022-03-04 17:39:53 +00:00
Symbol: "BTCUSDT",
2022-03-04 16:27:44 +00:00
BaseCurrency: "BTC",
QuoteCurrency: "USDT",
2022-03-04 16:28:13 +00:00
AverageCost: fixedpoint.NewFromFloat(44000),
2022-03-04 16:27:44 +00:00
Profit: fixedpoint.NewFromFloat(1.01),
NetProfit: fixedpoint.NewFromFloat(0.98),
TradeID: 99,
2022-03-04 17:39:53 +00:00
Side: types.SideTypeSell,
2022-03-04 16:27:44 +00:00
Price: fixedpoint.NewFromFloat(44300),
Quantity: fixedpoint.NewFromFloat(0.001),
2022-03-04 17:39:53 +00:00
QuoteQuantity: fixedpoint.NewFromFloat(44.0),
2022-03-04 16:27:44 +00:00
Exchange: types.ExchangeMax,
2022-03-04 17:39:53 +00:00
TradedAt: time.Now(),
2022-03-04 16:27:44 +00:00
})
assert.NoError(t, err)
}