pkg/exchange: try to parse order id to integer

This commit is contained in:
Edwin 2023-07-27 17:39:50 +08:00
parent d8b8e7f2ac
commit 1760a5b8d6
3 changed files with 16 additions and 2 deletions

View File

@ -92,6 +92,9 @@ func TestClient(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
t.Logf("apiResp: %+v", apiResp) t.Logf("apiResp: %+v", apiResp)
_, err = strconv.ParseUint(apiResp.OrderId, 10, 64)
assert.NoError(t, err)
ordersResp, err := client.NewGetOpenOrderRequest().OrderLinkId(apiResp.OrderLinkId).Do(ctx) ordersResp, err := client.NewGetOpenOrderRequest().OrderLinkId(apiResp.OrderLinkId).Do(ctx)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, len(ordersResp.List), 1) assert.Equal(t, len(ordersResp.List), 1)

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"hash/fnv" "hash/fnv"
"math" "math"
"strconv"
"time" "time"
"github.com/c9s/bbgo/pkg/exchange/bybit/bybitapi" "github.com/c9s/bbgo/pkg/exchange/bybit/bybitapi"
@ -67,6 +68,13 @@ func toGlobalOrder(order bybitapi.Order) (*types.Order, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// linear and inverse : 42f4f364-82e1-49d3-ad1d-cd8cf9aa308d (UUID format)
// spot : 1468264727470772736 (only numbers)
// Now we only use spot trading.
orderIdNum, err := strconv.ParseUint(order.OrderId, 10, 64)
if err != nil {
return nil, fmt.Errorf("unexpected order id: %s, err: %v", order.OrderId, err)
}
return &types.Order{ return &types.Order{
SubmitOrder: types.SubmitOrder{ SubmitOrder: types.SubmitOrder{
@ -79,7 +87,7 @@ func toGlobalOrder(order bybitapi.Order) (*types.Order, error) {
TimeInForce: timeInForce, TimeInForce: timeInForce,
}, },
Exchange: types.ExchangeBybit, Exchange: types.ExchangeBybit,
OrderID: hashStringID(order.OrderId), OrderID: orderIdNum,
UUID: order.OrderId, UUID: order.OrderId,
Status: status, Status: status,
ExecutedQuantity: order.CumExecQty, ExecutedQuantity: order.CumExecQty,

View File

@ -3,6 +3,7 @@ package bybit
import ( import (
"fmt" "fmt"
"math" "math"
"strconv"
"testing" "testing"
"time" "time"
@ -231,6 +232,8 @@ func TestToGlobalOrder(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
working, err := isWorking(openOrder.OrderStatus) working, err := isWorking(openOrder.OrderStatus)
assert.NoError(t, err) assert.NoError(t, err)
orderIdNum, err := strconv.ParseUint(openOrder.OrderId, 10, 64)
assert.NoError(t, err)
exp := types.Order{ exp := types.Order{
SubmitOrder: types.SubmitOrder{ SubmitOrder: types.SubmitOrder{
@ -243,7 +246,7 @@ func TestToGlobalOrder(t *testing.T) {
TimeInForce: tif, TimeInForce: tif,
}, },
Exchange: types.ExchangeBybit, Exchange: types.ExchangeBybit,
OrderID: hashStringID(openOrder.OrderId), OrderID: orderIdNum,
UUID: openOrder.OrderId, UUID: openOrder.OrderId,
Status: status, Status: status,
ExecutedQuantity: openOrder.CumExecQty, ExecutedQuantity: openOrder.CumExecQty,