mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
pkg/exchange: support market order on bitget unfilled order conversion
This commit is contained in:
parent
ceb3091525
commit
51e38cf002
|
@ -189,10 +189,17 @@ func unfilledOrderToGlobalOrder(order v2.UnfilledOrder) (*types.Order, error) {
|
|||
qty := order.Size
|
||||
price := order.PriceAvg
|
||||
|
||||
// The market order will be executed immediately, so this check is used to handle corner cases.
|
||||
// 2023/11/05 The market order will be executed immediately, so this check is used to handle corner cases.
|
||||
// 2024/03/06 After placing a Market Order, we can retrieve it through the unfilledOrder API, so we still need to
|
||||
// handle the Market Order status.
|
||||
if orderType == types.OrderTypeMarket {
|
||||
qty = order.BaseVolume
|
||||
log.Warnf("!!! The price(%f) and quantity(%f) are not verified for market orders, because we only receive limit orders in the test environment !!!", price.Float64(), qty.Float64())
|
||||
price = order.PriceAvg
|
||||
if side == types.SideTypeBuy {
|
||||
qty, err = processMarketBuyQuantity(order.BaseVolume, order.QuoteVolume, order.PriceAvg, order.Size, order.Status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &types.Order{
|
||||
|
|
|
@ -227,7 +227,7 @@ func Test_unfilledOrderToGlobalOrder(t *testing.T) {
|
|||
}
|
||||
)
|
||||
|
||||
t.Run("succeeds", func(t *testing.T) {
|
||||
t.Run("succeeds with limit order", func(t *testing.T) {
|
||||
order, err := unfilledOrderToGlobalOrder(unfilledOrder)
|
||||
assert.NoError(err)
|
||||
assert.Equal(&types.Order{
|
||||
|
@ -251,6 +251,67 @@ func Test_unfilledOrderToGlobalOrder(t *testing.T) {
|
|||
}, order)
|
||||
})
|
||||
|
||||
t.Run("succeeds with market buy order", func(t *testing.T) {
|
||||
unfilledOrder2 := unfilledOrder
|
||||
unfilledOrder2.OrderType = v2.OrderTypeMarket
|
||||
unfilledOrder2.Side = v2.SideTypeBuy
|
||||
unfilledOrder2.Size = unfilledOrder2.PriceAvg.Mul(unfilledOrder2.Size)
|
||||
unfilledOrder2.PriceAvg = fixedpoint.Zero
|
||||
unfilledOrder2.Status = v2.OrderStatusNew
|
||||
|
||||
order, err := unfilledOrderToGlobalOrder(unfilledOrder2)
|
||||
assert.NoError(err)
|
||||
assert.Equal(&types.Order{
|
||||
SubmitOrder: types.SubmitOrder{
|
||||
ClientOrderID: "74b86af3-6098-479c-acac-bfb074c067f3",
|
||||
Symbol: "BTCUSDT",
|
||||
Side: types.SideTypeBuy,
|
||||
Type: types.OrderTypeMarket,
|
||||
Quantity: fixedpoint.Zero,
|
||||
Price: fixedpoint.Zero,
|
||||
TimeInForce: types.TimeInForceGTC,
|
||||
},
|
||||
Exchange: types.ExchangeBitget,
|
||||
OrderID: uint64(orderId),
|
||||
UUID: strconv.FormatInt(int64(orderId), 10),
|
||||
Status: types.OrderStatusNew,
|
||||
ExecutedQuantity: fixedpoint.Zero,
|
||||
IsWorking: true,
|
||||
CreationTime: types.Time(types.NewMillisecondTimestampFromInt(1660704288118).Time()),
|
||||
UpdateTime: types.Time(types.NewMillisecondTimestampFromInt(1660704288118).Time()),
|
||||
}, order)
|
||||
})
|
||||
|
||||
t.Run("succeeds with market sell order", func(t *testing.T) {
|
||||
unfilledOrder2 := unfilledOrder
|
||||
unfilledOrder2.OrderType = v2.OrderTypeMarket
|
||||
unfilledOrder2.Side = v2.SideTypeSell
|
||||
unfilledOrder2.PriceAvg = fixedpoint.Zero
|
||||
unfilledOrder2.Status = v2.OrderStatusNew
|
||||
|
||||
order, err := unfilledOrderToGlobalOrder(unfilledOrder2)
|
||||
assert.NoError(err)
|
||||
assert.Equal(&types.Order{
|
||||
SubmitOrder: types.SubmitOrder{
|
||||
ClientOrderID: "74b86af3-6098-479c-acac-bfb074c067f3",
|
||||
Symbol: "BTCUSDT",
|
||||
Side: types.SideTypeSell,
|
||||
Type: types.OrderTypeMarket,
|
||||
Quantity: fixedpoint.NewFromInt(5),
|
||||
Price: fixedpoint.Zero,
|
||||
TimeInForce: types.TimeInForceGTC,
|
||||
},
|
||||
Exchange: types.ExchangeBitget,
|
||||
OrderID: uint64(orderId),
|
||||
UUID: strconv.FormatInt(int64(orderId), 10),
|
||||
Status: types.OrderStatusNew,
|
||||
ExecutedQuantity: fixedpoint.Zero,
|
||||
IsWorking: true,
|
||||
CreationTime: types.Time(types.NewMillisecondTimestampFromInt(1660704288118).Time()),
|
||||
UpdateTime: types.Time(types.NewMillisecondTimestampFromInt(1660704288118).Time()),
|
||||
}, order)
|
||||
})
|
||||
|
||||
t.Run("failed to convert side", func(t *testing.T) {
|
||||
newOrder := unfilledOrder
|
||||
newOrder.Side = "xxx"
|
||||
|
|
Loading…
Reference in New Issue
Block a user