pkg/exchange: use new size instead of size

This commit is contained in:
edwin 2024-02-23 13:56:17 +08:00
parent 06c533f3d7
commit 5c7509523b
3 changed files with 20 additions and 17 deletions

View File

@ -391,7 +391,7 @@ func (o *Order) processMarketBuyQuantity() (fixedpoint.Value, error) {
if o.FillPrice.IsZero() {
return fixedpoint.Zero, fmt.Errorf("fillPrice for a partialFilled should not be zero")
}
return o.Size.Div(o.FillPrice), nil
return o.NewSize.Div(o.FillPrice), nil
case v2.OrderStatusFilled:
return o.AccBaseVolume, nil
@ -422,7 +422,7 @@ func (o *Order) toGlobalOrder() (types.Order, error) {
return types.Order{}, err
}
qty := o.Size
qty := o.NewSize
if orderType == types.OrderTypeMarket && side == types.SideTypeBuy {
qty, err = o.processMarketBuyQuantity()
if err != nil {

View File

@ -529,7 +529,7 @@ func Test_toGlobalTrade(t *testing.T) {
// "orderType":"limit",
// "side":"sell",
// "priceAvg":"1.4001",
// "size":"5",
// "newSize":"5",
// "amount":"7.0005",
// "feeDetail":{
// "deduction":"no",
@ -720,7 +720,7 @@ func TestOrder_processMarketBuyQuantity(t *testing.T) {
t.Run("calculate qty", func(t *testing.T) {
o := Order{
Size: fixedpoint.NewFromFloat(2),
NewSize: fixedpoint.NewFromFloat(2),
Trade: Trade{
FillPrice: fixedpoint.NewFromFloat(1),
},
@ -764,7 +764,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
InstId: "BGBUSDT",
OrderId: types.StrInt64(1107950489998626816),
ClientOrderId: "cc73aab9-1e44-4022-8458-60d8c6a08753",
Size: fixedpoint.NewFromFloat(39.0),
NewSize: fixedpoint.NewFromFloat(39.0),
Notional: fixedpoint.NewFromFloat(39.0),
OrderType: v2.OrderTypeMarket,
Force: v2.OrderForceGTC,
@ -783,7 +783,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
// "instId":"BGBUSDT",
// "orderId":"1107950489998626816",
// "clientOid":"cc73aab9-1e44-4022-8458-60d8c6a08753",
// "size":"39.0000",
// "newSize":"39.0000",
// "notional":"39.000000",
// "orderType":"market",
// "force":"gtc",
@ -818,7 +818,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
Symbol: "BGBUSDT",
Side: types.SideTypeBuy,
Type: types.OrderTypeMarket,
Quantity: newO.Size.Div(newO.FillPrice),
Quantity: newO.NewSize.Div(newO.FillPrice),
Price: newO.PriceAvg,
TimeInForce: types.TimeInForceGTC,
},
@ -838,7 +838,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
// "instId":"BGBUSDT",
// "orderId":"1107940456212631553",
// "clientOid":"088bb971-858e-48e2-b503-85c3274edd89",
// "size":"285.0000",
// "newSize":"285.0000",
// "orderType":"market",
// "force":"gtc",
// "side":"sell",
@ -875,7 +875,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
Symbol: "BGBUSDT",
Side: types.SideTypeSell,
Type: types.OrderTypeMarket,
Quantity: newO.Size,
Quantity: newO.NewSize,
Price: newO.PriceAvg,
TimeInForce: types.TimeInForceGTC,
},
@ -896,7 +896,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
// "orderId":"1107955329902481408",
// "clientOid":"c578164a-bf34-44ba-8bb7-a1538f33b1b8",
// "price":"0.49998",
// "size":"24.9990",
// "newSize":"24.9990",
// "notional":"24.999000",
// "orderType":"limit",
// "force":"gtc",
@ -934,7 +934,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
Symbol: "BGBUSDT",
Side: types.SideTypeBuy,
Type: types.OrderTypeLimit,
Quantity: newO.Size,
Quantity: newO.NewSize,
Price: newO.Price,
TimeInForce: types.TimeInForceGTC,
},
@ -955,7 +955,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
// "orderId":"1107936497259417600",
// "clientOid":"02d4592e-091c-4b5a-aef3-6a7cf57b5e82",
// "price":"0.48710",
// "size":"280.0000",
// "newSize":"280.0000",
// "orderType":"limit",
// "force":"gtc",
// "side":"sell",
@ -993,7 +993,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
Symbol: "BGBUSDT",
Side: types.SideTypeSell,
Type: types.OrderTypeLimit,
Quantity: newO.Size,
Quantity: newO.NewSize,
Price: newO.Price,
TimeInForce: types.TimeInForceGTC,
},
@ -1043,7 +1043,7 @@ func TestOrder_toGlobalTrade(t *testing.T) {
// "instId":"BGBUSDT",
// "orderId":"1107950489998626816",
// "clientOid":"cc73aab9-1e44-4022-8458-60d8c6a08753",
// "size":"39.0000",
// "newSize":"39.0000",
// "notional":"39.000000",
// "orderType":"market",
// "force":"gtc",
@ -1081,7 +1081,7 @@ func TestOrder_toGlobalTrade(t *testing.T) {
InstId: "BGBUSDT",
OrderId: types.StrInt64(1107950489998626816),
ClientOrderId: "cc73aab9-1e44-4022-8458-60d8c6a08753",
Size: fixedpoint.NewFromFloat(39.0),
NewSize: fixedpoint.NewFromFloat(39.0),
Notional: fixedpoint.NewFromFloat(39.0),
OrderType: v2.OrderTypeMarket,
Force: v2.OrderForceGTC,

View File

@ -485,8 +485,11 @@ type Order struct {
// OrderId are always numeric. It's confirmed with official customer service. https://t.me/bitgetOpenapi/24172
OrderId types.StrInt64 `json:"orderId"`
ClientOrderId string `json:"clientOid"`
// Size is base coin when orderType=limit; quote coin when orderType=market
Size fixedpoint.Value `json:"size"`
// NewSize represents the order quantity, following the specified rules:
// when orderType=limit, newSize represents the quantity of base coin,
// when orderType=marketandside=buy, newSize represents the quantity of quote coin,
// when orderType=marketandside=sell, newSize represents the quantity of base coin.
NewSize fixedpoint.Value `json:"newSize"`
// Buy amount, returned when buying at market price
Notional fixedpoint.Value `json:"notional"`
OrderType v2.OrderType `json:"orderType"`