mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
okx: optimise GetFuturesPositionOrders (#1830)
Signed-off-by: Ye Sijun <junnplus@gmail.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
// var error definitions
|
||||
var (
|
||||
ErrInvalidContractSettlementType = errors.New("invalid contract settlement type")
|
||||
ErrContractNotSupported = errors.New("unsupported contract")
|
||||
)
|
||||
|
||||
// Contract holds details on futures contracts
|
||||
|
||||
@@ -2573,6 +2573,10 @@ func (ok *Okx) GetFuturesPositionOrders(ctx context.Context, req *futures.Positi
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
contractsMap := make(map[currency.Pair]*futures.Contract)
|
||||
for i := range contracts {
|
||||
contractsMap[contracts[i].Name] = &contracts[i]
|
||||
}
|
||||
for i := range req.Pairs {
|
||||
fPair, err := ok.FormatExchangeCurrency(req.Pairs[i], req.Asset)
|
||||
if err != nil {
|
||||
@@ -2580,18 +2584,12 @@ func (ok *Okx) GetFuturesPositionOrders(ctx context.Context, req *futures.Positi
|
||||
}
|
||||
instrumentType := GetInstrumentTypeFromAssetItem(req.Asset)
|
||||
|
||||
multiplier := 1.0
|
||||
var contractSettlementType futures.ContractSettlementType
|
||||
if req.Asset.IsFutures() {
|
||||
for j := range contracts {
|
||||
if !contracts[j].Name.Equal(fPair) {
|
||||
continue
|
||||
}
|
||||
multiplier = contracts[j].Multiplier
|
||||
contractSettlementType = contracts[j].SettlementType
|
||||
break
|
||||
}
|
||||
contract, exist := contractsMap[fPair]
|
||||
if !exist {
|
||||
return nil, fmt.Errorf("%w %v", futures.ErrContractNotSupported, fPair)
|
||||
}
|
||||
multiplier := contract.Multiplier
|
||||
contractSettlementType := contract.SettlementType
|
||||
|
||||
resp[i] = futures.PositionResponse{
|
||||
Pair: req.Pairs[i],
|
||||
@@ -2617,7 +2615,7 @@ func (ok *Okx) GetFuturesPositionOrders(ctx context.Context, req *futures.Positi
|
||||
return nil, err
|
||||
}
|
||||
for j := range positions {
|
||||
if req.Pairs[i].String() != positions[j].InstrumentID {
|
||||
if fPair.String() != positions[j].InstrumentID {
|
||||
continue
|
||||
}
|
||||
var orderStatus order.Status
|
||||
|
||||
Reference in New Issue
Block a user