mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
grid2: add earnBase test case
This commit is contained in:
parent
120a22f0cd
commit
b515c24505
|
@ -533,6 +533,95 @@ func TestStrategy_handleOrderFilled(t *testing.T) {
|
|||
})
|
||||
})
|
||||
|
||||
t.Run("with fee token and EarnBase", func(t *testing.T) {
|
||||
gridQuantity := number(0.1)
|
||||
orderID := uint64(1)
|
||||
|
||||
s := newTestStrategy()
|
||||
s.Quantity = gridQuantity
|
||||
s.EarnBase = true
|
||||
s.grid = s.newGrid()
|
||||
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
mockService := mocks.NewMockExchangeOrderQueryService(mockCtrl)
|
||||
mockService.EXPECT().QueryOrderTrades(ctx, types.OrderQuery{
|
||||
Symbol: "BTCUSDT",
|
||||
OrderID: "1",
|
||||
}).Return([]types.Trade{
|
||||
{
|
||||
ID: 1,
|
||||
OrderID: orderID,
|
||||
Exchange: "binance",
|
||||
Price: number(11000.0),
|
||||
Quantity: gridQuantity,
|
||||
Symbol: "BTCUSDT",
|
||||
Side: types.SideTypeBuy,
|
||||
IsBuyer: true,
|
||||
FeeCurrency: "BTC",
|
||||
Fee: fixedpoint.Zero,
|
||||
},
|
||||
}, nil)
|
||||
|
||||
s.orderQueryService = mockService
|
||||
|
||||
orderExecutor := gridmocks.NewMockOrderExecutor(mockCtrl)
|
||||
|
||||
expectedSubmitOrder := types.SubmitOrder{
|
||||
Symbol: "BTCUSDT",
|
||||
Type: types.OrderTypeLimit,
|
||||
Side: types.SideTypeSell,
|
||||
Price: number(12_000.0),
|
||||
Quantity: number(0.09166666),
|
||||
TimeInForce: types.TimeInForceGTC,
|
||||
Market: s.Market,
|
||||
Tag: "grid",
|
||||
}
|
||||
orderExecutor.EXPECT().SubmitOrders(ctx, expectedSubmitOrder).Return([]types.Order{
|
||||
{SubmitOrder: expectedSubmitOrder},
|
||||
}, nil)
|
||||
|
||||
expectedSubmitOrder2 := types.SubmitOrder{
|
||||
Symbol: "BTCUSDT",
|
||||
Type: types.OrderTypeLimit,
|
||||
Side: types.SideTypeBuy,
|
||||
Price: number(11_000.0),
|
||||
Quantity: number(0.09999999),
|
||||
TimeInForce: types.TimeInForceGTC,
|
||||
Market: s.Market,
|
||||
Tag: "grid",
|
||||
}
|
||||
orderExecutor.EXPECT().SubmitOrders(ctx, expectedSubmitOrder2).Return([]types.Order{
|
||||
{SubmitOrder: expectedSubmitOrder2},
|
||||
}, nil)
|
||||
|
||||
s.orderExecutor = orderExecutor
|
||||
|
||||
s.handleOrderFilled(types.Order{
|
||||
SubmitOrder: types.SubmitOrder{
|
||||
Symbol: "BTCUSDT",
|
||||
Side: types.SideTypeBuy,
|
||||
Type: types.OrderTypeLimit,
|
||||
Quantity: gridQuantity,
|
||||
Price: number(11000.0),
|
||||
TimeInForce: types.TimeInForceGTC,
|
||||
},
|
||||
Exchange: "binance",
|
||||
OrderID: 1,
|
||||
Status: types.OrderStatusFilled,
|
||||
ExecutedQuantity: gridQuantity,
|
||||
})
|
||||
|
||||
s.handleOrderFilled(types.Order{
|
||||
SubmitOrder: expectedSubmitOrder,
|
||||
Exchange: "binance",
|
||||
OrderID: 2,
|
||||
Status: types.OrderStatusFilled,
|
||||
ExecutedQuantity: expectedSubmitOrder.Quantity,
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("with fee token and compound", func(t *testing.T) {
|
||||
gridQuantity := number(0.1)
|
||||
orderID := uint64(1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user