Skip to content

Commit

Permalink
okx: use static type for conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jan 23, 2025
1 parent 932f8cb commit c563216
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions pkg/exchange/okex/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,34 +251,32 @@ func toGlobalOrderStatus(state okexapi.OrderState) (types.OrderStatus, error) {
return "", fmt.Errorf("unknown or unsupported okex order state: %s", state)
}

func toLocalOrderType(orderType types.OrderType) (okexapi.OrderType, error) {
switch orderType {
case types.OrderTypeMarket:
return okexapi.OrderTypeMarket, nil

case types.OrderTypeLimit:
return okexapi.OrderTypeLimit, nil

case types.OrderTypeLimitMaker:
return okexapi.OrderTypePostOnly, nil
var localOrderTypeMap = map[types.OrderType]okexapi.OrderType{
types.OrderTypeMarket: okexapi.OrderTypeMarket,
types.OrderTypeLimit: okexapi.OrderTypeLimit,
types.OrderTypeLimitMaker: okexapi.OrderTypePostOnly,
}

func toLocalOrderType(orderType types.OrderType) (okexapi.OrderType, error) {
if ot, ok := localOrderTypeMap[orderType]; ok {
return ot, nil
}

return "", fmt.Errorf("unknown or unsupported okex order type: %s", orderType)
}

var globalOrderTypeMap = map[okexapi.OrderType]types.OrderType{
okexapi.OrderTypeMarket: types.OrderTypeMarket,
okexapi.OrderTypeLimit: types.OrderTypeLimit,
okexapi.OrderTypePostOnly: types.OrderTypeLimitMaker,
okexapi.OrderTypeFOK: types.OrderTypeLimit,
okexapi.OrderTypeIOC: types.OrderTypeLimit,
}

func toGlobalOrderType(orderType okexapi.OrderType) (types.OrderType, error) {
// IOC, FOK are only allowed with limit order type, so we assume the order type is always limit order for FOK, IOC orders
switch orderType {
case okexapi.OrderTypeMarket:
return types.OrderTypeMarket, nil

case okexapi.OrderTypeLimit, okexapi.OrderTypeFOK, okexapi.OrderTypeIOC:
return types.OrderTypeLimit, nil

case okexapi.OrderTypePostOnly:
return types.OrderTypeLimitMaker, nil

if ot, ok := globalOrderTypeMap[orderType]; ok {
return ot, nil
}

return "", fmt.Errorf("unknown or unsupported okex order type: %s", orderType)
Expand Down

0 comments on commit c563216

Please sign in to comment.