Merge pull request #1542 from c9s/edwin/bitget/update-api

FIX: [bitget] use new size instead of size
This commit is contained in:
bailantaotao 2024-02-23 15:46:40 +08:00 committed by GitHub
commit 541496f3cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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() { if o.FillPrice.IsZero() {
return fixedpoint.Zero, fmt.Errorf("fillPrice for a partialFilled should not be zero") 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: case v2.OrderStatusFilled:
return o.AccBaseVolume, nil return o.AccBaseVolume, nil
@ -422,7 +422,7 @@ func (o *Order) toGlobalOrder() (types.Order, error) {
return types.Order{}, err return types.Order{}, err
} }
qty := o.Size qty := o.NewSize
if orderType == types.OrderTypeMarket && side == types.SideTypeBuy { if orderType == types.OrderTypeMarket && side == types.SideTypeBuy {
qty, err = o.processMarketBuyQuantity() qty, err = o.processMarketBuyQuantity()
if err != nil { if err != nil {

View File

@ -529,7 +529,7 @@ func Test_toGlobalTrade(t *testing.T) {
// "orderType":"limit", // "orderType":"limit",
// "side":"sell", // "side":"sell",
// "priceAvg":"1.4001", // "priceAvg":"1.4001",
// "size":"5", // "newSize":"5",
// "amount":"7.0005", // "amount":"7.0005",
// "feeDetail":{ // "feeDetail":{
// "deduction":"no", // "deduction":"no",
@ -720,7 +720,7 @@ func TestOrder_processMarketBuyQuantity(t *testing.T) {
t.Run("calculate qty", func(t *testing.T) { t.Run("calculate qty", func(t *testing.T) {
o := Order{ o := Order{
Size: fixedpoint.NewFromFloat(2), NewSize: fixedpoint.NewFromFloat(2),
Trade: Trade{ Trade: Trade{
FillPrice: fixedpoint.NewFromFloat(1), FillPrice: fixedpoint.NewFromFloat(1),
}, },
@ -764,7 +764,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
InstId: "BGBUSDT", InstId: "BGBUSDT",
OrderId: types.StrInt64(1107950489998626816), OrderId: types.StrInt64(1107950489998626816),
ClientOrderId: "cc73aab9-1e44-4022-8458-60d8c6a08753", ClientOrderId: "cc73aab9-1e44-4022-8458-60d8c6a08753",
Size: fixedpoint.NewFromFloat(39.0), NewSize: fixedpoint.NewFromFloat(39.0),
Notional: fixedpoint.NewFromFloat(39.0), Notional: fixedpoint.NewFromFloat(39.0),
OrderType: v2.OrderTypeMarket, OrderType: v2.OrderTypeMarket,
Force: v2.OrderForceGTC, Force: v2.OrderForceGTC,
@ -783,7 +783,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
// "instId":"BGBUSDT", // "instId":"BGBUSDT",
// "orderId":"1107950489998626816", // "orderId":"1107950489998626816",
// "clientOid":"cc73aab9-1e44-4022-8458-60d8c6a08753", // "clientOid":"cc73aab9-1e44-4022-8458-60d8c6a08753",
// "size":"39.0000", // "newSize":"39.0000",
// "notional":"39.000000", // "notional":"39.000000",
// "orderType":"market", // "orderType":"market",
// "force":"gtc", // "force":"gtc",
@ -818,7 +818,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
Symbol: "BGBUSDT", Symbol: "BGBUSDT",
Side: types.SideTypeBuy, Side: types.SideTypeBuy,
Type: types.OrderTypeMarket, Type: types.OrderTypeMarket,
Quantity: newO.Size.Div(newO.FillPrice), Quantity: newO.NewSize.Div(newO.FillPrice),
Price: newO.PriceAvg, Price: newO.PriceAvg,
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
}, },
@ -838,7 +838,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
// "instId":"BGBUSDT", // "instId":"BGBUSDT",
// "orderId":"1107940456212631553", // "orderId":"1107940456212631553",
// "clientOid":"088bb971-858e-48e2-b503-85c3274edd89", // "clientOid":"088bb971-858e-48e2-b503-85c3274edd89",
// "size":"285.0000", // "newSize":"285.0000",
// "orderType":"market", // "orderType":"market",
// "force":"gtc", // "force":"gtc",
// "side":"sell", // "side":"sell",
@ -875,7 +875,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
Symbol: "BGBUSDT", Symbol: "BGBUSDT",
Side: types.SideTypeSell, Side: types.SideTypeSell,
Type: types.OrderTypeMarket, Type: types.OrderTypeMarket,
Quantity: newO.Size, Quantity: newO.NewSize,
Price: newO.PriceAvg, Price: newO.PriceAvg,
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
}, },
@ -896,7 +896,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
// "orderId":"1107955329902481408", // "orderId":"1107955329902481408",
// "clientOid":"c578164a-bf34-44ba-8bb7-a1538f33b1b8", // "clientOid":"c578164a-bf34-44ba-8bb7-a1538f33b1b8",
// "price":"0.49998", // "price":"0.49998",
// "size":"24.9990", // "newSize":"24.9990",
// "notional":"24.999000", // "notional":"24.999000",
// "orderType":"limit", // "orderType":"limit",
// "force":"gtc", // "force":"gtc",
@ -934,7 +934,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
Symbol: "BGBUSDT", Symbol: "BGBUSDT",
Side: types.SideTypeBuy, Side: types.SideTypeBuy,
Type: types.OrderTypeLimit, Type: types.OrderTypeLimit,
Quantity: newO.Size, Quantity: newO.NewSize,
Price: newO.Price, Price: newO.Price,
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
}, },
@ -955,7 +955,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
// "orderId":"1107936497259417600", // "orderId":"1107936497259417600",
// "clientOid":"02d4592e-091c-4b5a-aef3-6a7cf57b5e82", // "clientOid":"02d4592e-091c-4b5a-aef3-6a7cf57b5e82",
// "price":"0.48710", // "price":"0.48710",
// "size":"280.0000", // "newSize":"280.0000",
// "orderType":"limit", // "orderType":"limit",
// "force":"gtc", // "force":"gtc",
// "side":"sell", // "side":"sell",
@ -993,7 +993,7 @@ func TestOrder_toGlobalOrder(t *testing.T) {
Symbol: "BGBUSDT", Symbol: "BGBUSDT",
Side: types.SideTypeSell, Side: types.SideTypeSell,
Type: types.OrderTypeLimit, Type: types.OrderTypeLimit,
Quantity: newO.Size, Quantity: newO.NewSize,
Price: newO.Price, Price: newO.Price,
TimeInForce: types.TimeInForceGTC, TimeInForce: types.TimeInForceGTC,
}, },
@ -1043,7 +1043,7 @@ func TestOrder_toGlobalTrade(t *testing.T) {
// "instId":"BGBUSDT", // "instId":"BGBUSDT",
// "orderId":"1107950489998626816", // "orderId":"1107950489998626816",
// "clientOid":"cc73aab9-1e44-4022-8458-60d8c6a08753", // "clientOid":"cc73aab9-1e44-4022-8458-60d8c6a08753",
// "size":"39.0000", // "newSize":"39.0000",
// "notional":"39.000000", // "notional":"39.000000",
// "orderType":"market", // "orderType":"market",
// "force":"gtc", // "force":"gtc",
@ -1081,7 +1081,7 @@ func TestOrder_toGlobalTrade(t *testing.T) {
InstId: "BGBUSDT", InstId: "BGBUSDT",
OrderId: types.StrInt64(1107950489998626816), OrderId: types.StrInt64(1107950489998626816),
ClientOrderId: "cc73aab9-1e44-4022-8458-60d8c6a08753", ClientOrderId: "cc73aab9-1e44-4022-8458-60d8c6a08753",
Size: fixedpoint.NewFromFloat(39.0), NewSize: fixedpoint.NewFromFloat(39.0),
Notional: fixedpoint.NewFromFloat(39.0), Notional: fixedpoint.NewFromFloat(39.0),
OrderType: v2.OrderTypeMarket, OrderType: v2.OrderTypeMarket,
Force: v2.OrderForceGTC, 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 are always numeric. It's confirmed with official customer service. https://t.me/bitgetOpenapi/24172
OrderId types.StrInt64 `json:"orderId"` OrderId types.StrInt64 `json:"orderId"`
ClientOrderId string `json:"clientOid"` ClientOrderId string `json:"clientOid"`
// Size is base coin when orderType=limit; quote coin when orderType=market // NewSize represents the order quantity, following the specified rules:
Size fixedpoint.Value `json:"size"` // 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 // Buy amount, returned when buying at market price
Notional fixedpoint.Value `json:"notional"` Notional fixedpoint.Value `json:"notional"`
OrderType v2.OrderType `json:"orderType"` OrderType v2.OrderType `json:"orderType"`