mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
add stock manager tests
This commit is contained in:
parent
c7379e6fc0
commit
03595f2382
86
bbgo/stock_test.go
Normal file
86
bbgo/stock_test.go
Normal file
|
@ -0,0 +1,86 @@
|
|||
package bbgo
|
||||
|
||||
import (
|
||||
"github.com/c9s/bbgo/pkg/bbgo/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStockManager(t *testing.T) {
|
||||
|
||||
t.Run("stock", func(t *testing.T) {
|
||||
var trades = []types.Trade{
|
||||
{Symbol: "BTCUSDT", Price: 9100.0, Quantity: 0.05, IsBuyer: true},
|
||||
{Symbol: "BTCUSDT", Price: 9100.0, Quantity: 0.05, IsBuyer: true},
|
||||
{Symbol: "BTCUSDT", Price: 9200.0, Quantity: 0.01, IsBuyer: false},
|
||||
}
|
||||
|
||||
var stockManager = &StockManager{
|
||||
TradingFeeCurrency: "BNB",
|
||||
Symbol: "BTCUSDT",
|
||||
}
|
||||
|
||||
_, err := stockManager.LoadTrades(trades)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, stockManager.Stocks, 2)
|
||||
assert.Len(t, stockManager.PendingSells, 0)
|
||||
})
|
||||
|
||||
t.Run("sold out", func(t *testing.T) {
|
||||
var trades = []types.Trade{
|
||||
{Symbol: "BTCUSDT", Price: 9100.0, Quantity: 0.05, IsBuyer: true},
|
||||
{Symbol: "BTCUSDT", Price: 9200.0, Quantity: 0.05, IsBuyer: false},
|
||||
{Symbol: "BTCUSDT", Price: 9100.0, Quantity: 0.05, IsBuyer: true},
|
||||
{Symbol: "BTCUSDT", Price: 9200.0, Quantity: 0.05, IsBuyer: false},
|
||||
}
|
||||
|
||||
var stockManager = &StockManager{
|
||||
TradingFeeCurrency: "BNB",
|
||||
Symbol: "BTCUSDT",
|
||||
}
|
||||
|
||||
_, err := stockManager.LoadTrades(trades)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, stockManager.Stocks, 0)
|
||||
assert.Len(t, stockManager.PendingSells, 0)
|
||||
})
|
||||
|
||||
t.Run("oversell", func(t *testing.T) {
|
||||
var trades = []types.Trade{
|
||||
{Symbol: "BTCUSDT", Price: 9100.0, Quantity: 0.05, IsBuyer: true},
|
||||
{Symbol: "BTCUSDT", Price: 9200.0, Quantity: 0.05, IsBuyer: false},
|
||||
{Symbol: "BTCUSDT", Price: 9200.0, Quantity: 0.05, IsBuyer: false},
|
||||
}
|
||||
|
||||
var stockManager = &StockManager{
|
||||
TradingFeeCurrency: "BNB",
|
||||
Symbol: "BTCUSDT",
|
||||
}
|
||||
|
||||
_, err := stockManager.LoadTrades(trades)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, stockManager.Stocks, 0)
|
||||
assert.Len(t, stockManager.PendingSells, 1)
|
||||
})
|
||||
|
||||
|
||||
t.Run("loss sell", func(t *testing.T) {
|
||||
var trades = []types.Trade{
|
||||
{Symbol: "BTCUSDT", Price: 9100.0, Quantity: 0.05, IsBuyer: true},
|
||||
{Symbol: "BTCUSDT", Price: 9200.0, Quantity: 0.02, IsBuyer: false},
|
||||
{Symbol: "BTCUSDT", Price: 8000.0, Quantity: 0.01, IsBuyer: false},
|
||||
}
|
||||
|
||||
var stockManager = &StockManager{
|
||||
TradingFeeCurrency: "BNB",
|
||||
Symbol: "BTCUSDT",
|
||||
}
|
||||
|
||||
_, err := stockManager.LoadTrades(trades)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, stockManager.Stocks, 1)
|
||||
assert.Len(t, stockManager.PendingSells, 0)
|
||||
})
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user