mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
testhelper: add more test helpers
This commit is contained in:
parent
f24a96c8c3
commit
960ea89d8c
43
pkg/testing/testhelper/market.go
Normal file
43
pkg/testing/testhelper/market.go
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package testhelper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var markets = map[string]types.Market{
|
||||||
|
"BTCUSDT": {
|
||||||
|
Symbol: "BTCUSDT",
|
||||||
|
PricePrecision: 2,
|
||||||
|
VolumePrecision: 8,
|
||||||
|
QuoteCurrency: "USDT",
|
||||||
|
BaseCurrency: "BTC",
|
||||||
|
MinNotional: fixedpoint.MustNewFromString("0.001"),
|
||||||
|
MinAmount: fixedpoint.MustNewFromString("10.0"),
|
||||||
|
MinQuantity: fixedpoint.MustNewFromString("0.001"),
|
||||||
|
TickSize: fixedpoint.MustNewFromString("0.01"),
|
||||||
|
},
|
||||||
|
|
||||||
|
"ETHUSDT": {
|
||||||
|
Symbol: "ETH",
|
||||||
|
PricePrecision: 2,
|
||||||
|
VolumePrecision: 8,
|
||||||
|
QuoteCurrency: "USDT",
|
||||||
|
BaseCurrency: "ETH",
|
||||||
|
MinNotional: fixedpoint.MustNewFromString("0.005"),
|
||||||
|
MinAmount: fixedpoint.MustNewFromString("10.0"),
|
||||||
|
MinQuantity: fixedpoint.MustNewFromString("0.001"),
|
||||||
|
TickSize: fixedpoint.MustNewFromString("0.01"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func Market(symbol string) types.Market {
|
||||||
|
market, ok := markets[symbol]
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Errorf("%s market not found, valid markets: %+v", symbol, markets))
|
||||||
|
}
|
||||||
|
|
||||||
|
return market
|
||||||
|
}
|
49
pkg/testing/testhelper/pricevolumeslice.go
Normal file
49
pkg/testing/testhelper/pricevolumeslice.go
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package testhelper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PriceVolumeSliceFromText(str string) (slice types.PriceVolumeSlice) {
|
||||||
|
lines := strings.Split(str, "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if len(line) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
cols := strings.SplitN(line, ",", 2)
|
||||||
|
if len(cols) < 2 {
|
||||||
|
panic(fmt.Errorf("column length should be 2, got %d", len(cols)))
|
||||||
|
}
|
||||||
|
|
||||||
|
price := fixedpoint.MustNewFromString(strings.TrimSpace(cols[0]))
|
||||||
|
volume := fixedpoint.MustNewFromString(strings.TrimSpace(cols[1]))
|
||||||
|
slice = append(slice, types.PriceVolume{
|
||||||
|
Price: price,
|
||||||
|
Volume: volume,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return slice
|
||||||
|
}
|
||||||
|
|
||||||
|
func PriceVolumeSlice(values ...fixedpoint.Value) (slice types.PriceVolumeSlice) {
|
||||||
|
if len(values)%2 != 0 {
|
||||||
|
panic("values should be paired")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(values); i += 2 {
|
||||||
|
slice = append(slice, types.PriceVolume{
|
||||||
|
Price: values[i],
|
||||||
|
Volume: values[i+1],
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return slice
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user