mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 16:55:15 +00:00
grid2: add timeout context to the fixer
This commit is contained in:
parent
bd5e98e543
commit
2efdee9347
|
@ -26,7 +26,7 @@ func newProfitFixer(grid *Grid, symbol string, historyService types.ExchangeTrad
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix fixes the total quote profit of the given grid
|
// Fix fixes the total quote profit of the given grid
|
||||||
func (f *ProfitFixer) Fix(ctx context.Context, since, until time.Time, initialOrderID uint64, profitStats *GridProfitStats) error {
|
func (f *ProfitFixer) Fix(parent context.Context, since, until time.Time, initialOrderID uint64, profitStats *GridProfitStats) error {
|
||||||
// reset profit
|
// reset profit
|
||||||
profitStats.TotalQuoteProfit = fixedpoint.Zero
|
profitStats.TotalQuoteProfit = fixedpoint.Zero
|
||||||
profitStats.ArbitrageCount = 0
|
profitStats.ArbitrageCount = 0
|
||||||
|
@ -40,6 +40,9 @@ func (f *ProfitFixer) Fix(ctx context.Context, since, until time.Time, initialOr
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(parent, 15*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
q := &batch.ClosedOrderBatchQuery{ExchangeTradeHistoryService: f.historyService}
|
q := &batch.ClosedOrderBatchQuery{ExchangeTradeHistoryService: f.historyService}
|
||||||
orderC, errC := q.Query(ctx, f.symbol, since, until, initialOrderID)
|
orderC, errC := q.Query(ctx, f.symbol, since, until, initialOrderID)
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ func TestProfitFixer(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
mockHistoryService := mocks.NewMockExchangeTradeHistoryService(mockCtrl)
|
mockHistoryService := mocks.NewMockExchangeTradeHistoryService(mockCtrl)
|
||||||
|
|
||||||
mockHistoryService.EXPECT().QueryClosedOrders(ctx, "ETHUSDT", mustNewTime("2022-01-01T00:00:00Z"), mustNewTime("2022-01-07T00:00:00Z"), uint64(0)).
|
mockHistoryService.EXPECT().QueryClosedOrders(gomock.Any(), "ETHUSDT", mustNewTime("2022-01-01T00:00:00Z"), mustNewTime("2022-01-07T00:00:00Z"), uint64(0)).
|
||||||
Return([]types.Order{
|
Return([]types.Order{
|
||||||
newClosedLimitOrder("ETHUSDT", types.SideTypeBuy, number(1800.0), number(0.1), mustNewTime("2022-01-01T00:01:00Z")),
|
newClosedLimitOrder("ETHUSDT", types.SideTypeBuy, number(1800.0), number(0.1), mustNewTime("2022-01-01T00:01:00Z")),
|
||||||
newClosedLimitOrder("ETHUSDT", types.SideTypeBuy, number(1700.0), number(0.1), mustNewTime("2022-01-01T00:01:00Z")),
|
newClosedLimitOrder("ETHUSDT", types.SideTypeBuy, number(1700.0), number(0.1), mustNewTime("2022-01-01T00:01:00Z")),
|
||||||
|
@ -71,7 +71,7 @@ func TestProfitFixer(t *testing.T) {
|
||||||
newClosedLimitOrder("ETHUSDT", types.SideTypeSell, number(1905.0), number(0.1), mustNewTime("2022-01-01T00:03:00Z")),
|
newClosedLimitOrder("ETHUSDT", types.SideTypeSell, number(1905.0), number(0.1), mustNewTime("2022-01-01T00:03:00Z")),
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
mockHistoryService.EXPECT().QueryClosedOrders(ctx, "ETHUSDT", mustNewTime("2022-01-01T00:03:00Z"), mustNewTime("2022-01-07T00:00:00Z"), uint64(5)).
|
mockHistoryService.EXPECT().QueryClosedOrders(gomock.Any(), "ETHUSDT", mustNewTime("2022-01-01T00:03:00Z"), mustNewTime("2022-01-07T00:00:00Z"), uint64(5)).
|
||||||
Return([]types.Order{
|
Return([]types.Order{
|
||||||
newClosedLimitOrder("ETHUSDT", types.SideTypeBuy, number(1900.0), number(0.1), mustNewTime("2022-01-01T00:04:00Z")),
|
newClosedLimitOrder("ETHUSDT", types.SideTypeBuy, number(1900.0), number(0.1), mustNewTime("2022-01-01T00:04:00Z")),
|
||||||
newClosedLimitOrder("ETHUSDT", types.SideTypeBuy, number(1800.0), number(0.1), mustNewTime("2022-01-01T00:04:00Z")),
|
newClosedLimitOrder("ETHUSDT", types.SideTypeBuy, number(1800.0), number(0.1), mustNewTime("2022-01-01T00:04:00Z")),
|
||||||
|
@ -80,7 +80,7 @@ func TestProfitFixer(t *testing.T) {
|
||||||
newClosedLimitOrder("ETHUSDT", types.SideTypeSell, number(1900.0), number(0.1), mustNewTime("2022-01-01T00:08:00Z")),
|
newClosedLimitOrder("ETHUSDT", types.SideTypeSell, number(1900.0), number(0.1), mustNewTime("2022-01-01T00:08:00Z")),
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
mockHistoryService.EXPECT().QueryClosedOrders(ctx, "ETHUSDT", mustNewTime("2022-01-01T00:08:00Z"), mustNewTime("2022-01-07T00:00:00Z"), uint64(10)).
|
mockHistoryService.EXPECT().QueryClosedOrders(gomock.Any(), "ETHUSDT", mustNewTime("2022-01-01T00:08:00Z"), mustNewTime("2022-01-07T00:00:00Z"), uint64(10)).
|
||||||
Return([]types.Order{}, nil)
|
Return([]types.Order{}, nil)
|
||||||
|
|
||||||
grid := NewGrid(number(1000.0), number(2000.0), number(11), number(0.01))
|
grid := NewGrid(number(1000.0), number(2000.0), number(11), number(0.01))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user