Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DELETE: [okx] rm redundant codes #1551

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 0 additions & 85 deletions pkg/exchange/okex/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"strconv"
"strings"

"github.com/pkg/errors"
"go.uber.org/multierr"

"github.com/c9s/bbgo/pkg/exchange/okex/okexapi"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
Expand Down Expand Up @@ -124,31 +121,6 @@ func toLocalSideType(side types.SideType) okexapi.SideType {
return okexapi.SideType(strings.ToLower(string(side)))
}

func segmentOrderDetails(orderDetails []okexapi.OrderDetails) (trades, orders []okexapi.OrderDetails) {
for _, orderDetail := range orderDetails {
if len(orderDetail.LastTradeID) > 0 {
trades = append(trades, orderDetail)
}
orders = append(orders, orderDetail)
}
return trades, orders
}

func toGlobalTrades(orderDetails []okexapi.OrderDetails) ([]types.Trade, error) {
var trades []types.Trade
var err error
for _, orderDetail := range orderDetails {
trade, err2 := toGlobalTrade(&orderDetail)
if err2 != nil {
err = multierr.Append(err, err2)
continue
}
trades = append(trades, *trade)
}

return trades, nil
}

func tradeToGlobal(trade okexapi.Trade) types.Trade {
side := toGlobalSide(trade.Side)
return types.Trade{
Expand Down Expand Up @@ -246,22 +218,6 @@ func orderDetailToGlobal(order *okexapi.OrderDetail) (*types.Order, error) {
}, nil
}

func toGlobalOrders(orderDetails []okexapi.OrderDetails) ([]types.Order, error) {
var orders []types.Order
var err error
for _, orderDetail := range orderDetails {

o, err2 := toGlobalOrder(&orderDetail)
if err2 != nil {
err = multierr.Append(err, err2)
continue
}
orders = append(orders, *o)
}

return orders, err
}

func toGlobalOrderStatus(state okexapi.OrderState) (types.OrderStatus, error) {
switch state {
case okexapi.OrderStateCanceled:
Expand Down Expand Up @@ -395,44 +351,3 @@ func toGlobalOrder(okexOrder *okexapi.OrderDetails) (*types.Order, error) {
IsIsolated: false,
}, nil
}

func toGlobalTrade(orderDetail *okexapi.OrderDetails) (*types.Trade, error) {
// Should use tradeId, but okex use billId to perform pagination, so use billID as tradeID instead.
billID := orderDetail.BillID

orderID, err := strconv.ParseInt(orderDetail.OrderID, 10, 64)
if err != nil {
return nil, errors.Wrapf(err, "error parsing ordId value: %s", orderDetail.OrderID)
}

side := toGlobalSide(orderDetail.Side)

isMargin := false
if orderDetail.InstrumentType == okexapi.InstrumentTypeMARGIN {
isMargin = true
}

isFuture := false
if orderDetail.InstrumentType == okexapi.InstrumentTypeFutures {
isFuture = true
}

return &types.Trade{
ID: uint64(billID),
OrderID: uint64(orderID),
Exchange: types.ExchangeOKEx,
Price: orderDetail.LastFilledPrice,
Quantity: orderDetail.LastFilledQuantity,
QuoteQuantity: orderDetail.LastFilledPrice.Mul(orderDetail.LastFilledQuantity),
Symbol: toGlobalSymbol(orderDetail.InstrumentID),
Side: side,
IsBuyer: side == types.SideTypeBuy,
IsMaker: orderDetail.ExecutionType == "M",
Time: types.Time(orderDetail.LastFilledTime),
Fee: orderDetail.LastFilledFee,
FeeCurrency: orderDetail.LastFilledFeeCurrency,
IsMargin: isMargin,
IsFutures: isFuture,
IsIsolated: false,
}, nil
}
Loading