mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
grid2: add more test for spec
This commit is contained in:
parent
3a2dbc934b
commit
4c13171cb0
|
@ -286,18 +286,9 @@ func TestStrategy_checkRequiredInvestmentByAmount(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStrategy_calculateBaseQuoteInvestmentQuantity(t *testing.T) {
|
func TestStrategy_calculateBaseQuoteInvestmentQuantity(t *testing.T) {
|
||||||
t.Run("basic", func(t *testing.T) {
|
t.Run("1 sell", func(t *testing.T) {
|
||||||
s := newTestStrategy()
|
s := newTestStrategy()
|
||||||
s.Market = types.Market{
|
s.Market = newTestMarket("ETHUSDT")
|
||||||
BaseCurrency: "ETH",
|
|
||||||
QuoteCurrency: "USDT",
|
|
||||||
TickSize: number(0.01),
|
|
||||||
StepSize: number(0.00001),
|
|
||||||
PricePrecision: 2,
|
|
||||||
VolumePrecision: 6,
|
|
||||||
MinNotional: number(8.000),
|
|
||||||
MinQuantity: number(0.00030),
|
|
||||||
}
|
|
||||||
s.UpperPrice = number(200.0)
|
s.UpperPrice = number(200.0)
|
||||||
s.LowerPrice = number(100.0)
|
s.LowerPrice = number(100.0)
|
||||||
s.GridNum = 7
|
s.GridNum = 7
|
||||||
|
@ -318,10 +309,34 @@ func TestStrategy_calculateBaseQuoteInvestmentQuantity(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.InDelta(t, 0.5, quantity.Float64(), 0.0001)
|
assert.InDelta(t, 0.5, quantity.Float64(), 0.0001)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("6 sell", func(t *testing.T) {
|
||||||
|
s := newTestStrategy()
|
||||||
|
s.Market = newTestMarket("ETHUSDT")
|
||||||
|
s.UpperPrice = number(200.0)
|
||||||
|
s.LowerPrice = number(100.0)
|
||||||
|
s.GridNum = 7
|
||||||
|
s.Compound = true
|
||||||
|
|
||||||
|
lastPrice := number(95.0)
|
||||||
|
quoteInvestment := number(334.0) // 333.33
|
||||||
|
baseInvestment := number(0.5)
|
||||||
|
quantity, err := s.calculateBaseQuoteInvestmentQuantity(quoteInvestment, baseInvestment, lastPrice, []Pin{
|
||||||
|
Pin(number(100.00)),
|
||||||
|
Pin(number(116.67)),
|
||||||
|
Pin(number(133.33)),
|
||||||
|
Pin(number(150.00)),
|
||||||
|
Pin(number(166.67)),
|
||||||
|
Pin(number(183.33)),
|
||||||
|
Pin(number(200.00)),
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.InDelta(t, 0.08333, quantity.Float64(), 0.0001)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStrategy_calculateQuoteInvestmentQuantity(t *testing.T) {
|
func TestStrategy_calculateQuoteInvestmentQuantity(t *testing.T) {
|
||||||
|
|
||||||
t.Run("quote quantity", func(t *testing.T) {
|
t.Run("quote quantity", func(t *testing.T) {
|
||||||
// quoteInvestment = (10,000 + 11,000 + 12,000 + 13,000 + 14,000) * q
|
// quoteInvestment = (10,000 + 11,000 + 12,000 + 13,000 + 14,000) * q
|
||||||
// q = quoteInvestment / (10,000 + 11,000 + 12,000 + 13,000 + 14,000)
|
// q = quoteInvestment / (10,000 + 11,000 + 12,000 + 13,000 + 14,000)
|
||||||
|
@ -410,7 +425,33 @@ func TestStrategy_calculateQuoteInvestmentQuantity(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestMarket() types.Market {
|
func newTestMarket(symbol string) types.Market {
|
||||||
|
switch symbol {
|
||||||
|
case "BTCUSDT":
|
||||||
|
return types.Market{
|
||||||
|
BaseCurrency: "BTC",
|
||||||
|
QuoteCurrency: "USDT",
|
||||||
|
TickSize: number(0.01),
|
||||||
|
StepSize: number(0.00001),
|
||||||
|
PricePrecision: 2,
|
||||||
|
VolumePrecision: 8,
|
||||||
|
MinNotional: number(10.0),
|
||||||
|
MinQuantity: number(0.001),
|
||||||
|
}
|
||||||
|
case "ETHUSDT":
|
||||||
|
return types.Market{
|
||||||
|
BaseCurrency: "ETH",
|
||||||
|
QuoteCurrency: "USDT",
|
||||||
|
TickSize: number(0.01),
|
||||||
|
StepSize: number(0.00001),
|
||||||
|
PricePrecision: 2,
|
||||||
|
VolumePrecision: 6,
|
||||||
|
MinNotional: number(8.000),
|
||||||
|
MinQuantity: number(0.00030),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// default
|
||||||
return types.Market{
|
return types.Market{
|
||||||
BaseCurrency: "BTC",
|
BaseCurrency: "BTC",
|
||||||
QuoteCurrency: "USDT",
|
QuoteCurrency: "USDT",
|
||||||
|
@ -426,7 +467,7 @@ func newTestMarket() types.Market {
|
||||||
var testOrderID = uint64(0)
|
var testOrderID = uint64(0)
|
||||||
|
|
||||||
func newTestOrder(price, quantity fixedpoint.Value, side types.SideType) types.Order {
|
func newTestOrder(price, quantity fixedpoint.Value, side types.SideType) types.Order {
|
||||||
market := newTestMarket()
|
market := newTestMarket("BTCUSDT")
|
||||||
testOrderID++
|
testOrderID++
|
||||||
return types.Order{
|
return types.Order{
|
||||||
SubmitOrder: types.SubmitOrder{
|
SubmitOrder: types.SubmitOrder{
|
||||||
|
@ -450,7 +491,7 @@ func newTestOrder(price, quantity fixedpoint.Value, side types.SideType) types.O
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestStrategy() *Strategy {
|
func newTestStrategy() *Strategy {
|
||||||
market := newTestMarket()
|
market := newTestMarket("BTCUSDT")
|
||||||
|
|
||||||
s := &Strategy{
|
s := &Strategy{
|
||||||
logger: logrus.NewEntry(logrus.New()),
|
logger: logrus.NewEntry(logrus.New()),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user