Skip to content

Commit

Permalink
GateIO: Fix GetFuturesContractDetails for Deliveries
Browse files Browse the repository at this point in the history
Was returning the product of all the contracts, so 1444 instead of 38
contracts.
  • Loading branch information
gbjk committed Jan 4, 2025
1 parent 50448ec commit 282c54b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
26 changes: 12 additions & 14 deletions exchanges/gateio/gateio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3186,22 +3186,20 @@ func TestForceFileStandard(t *testing.T) {
func TestGetFuturesContractDetails(t *testing.T) {
t.Parallel()
_, err := g.GetFuturesContractDetails(context.Background(), asset.Spot)
if !errors.Is(err, futures.ErrNotFuturesAsset) {
t.Error(err)
}
require.ErrorIs(t, err, futures.ErrNotFuturesAsset)

_, err = g.GetFuturesContractDetails(context.Background(), asset.PerpetualContract)
if !errors.Is(err, asset.ErrNotSupported) {
t.Error(err)
}
require.ErrorIs(t, err, futures.ErrNotSupported)

Check failure on line 3192 in exchanges/gateio/gateio_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: futures.ErrNotSupported (typecheck)

Check failure on line 3192 in exchanges/gateio/gateio_test.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, amd64, true, false)

undefined: futures.ErrNotSupported

Check failure on line 3192 in exchanges/gateio/gateio_test.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (ubuntu-latest, 386, true, true)

undefined: futures.ErrNotSupported

Check failure on line 3192 in exchanges/gateio/gateio_test.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-latest, amd64, true, true)

undefined: futures.ErrNotSupported

Check failure on line 3192 in exchanges/gateio/gateio_test.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (macos-13, amd64, true, true)

undefined: futures.ErrNotSupported

Check failure on line 3192 in exchanges/gateio/gateio_test.go

View workflow job for this annotation

GitHub Actions / GoCryptoTrader back-end (windows-latest, amd64, true, true)

undefined: futures.ErrNotSupported

_, err = g.GetFuturesContractDetails(context.Background(), asset.DeliveryFutures)
if !errors.Is(err, nil) {
t.Error(err)
}
_, err = g.GetFuturesContractDetails(context.Background(), asset.Futures)
if !errors.Is(err, nil) {
t.Error(err)
}
exp, err := g.GetAllDeliveryContracts(context.Background(), currency.USDT)
require.NoError(t, err, "GetAllDeliveryContracts must not error")
c, err := g.GetFuturesContractDetails(context.Background(), asset.DeliveryFutures)
require.NoError(t, err, "GetFuturesContractDetails must not error for DeliveryFutures")
assert.Equal(t, len(exp), len(c), "GetFuturesContractDetails should return same number of Delivery contracts as exist")

c, err = g.GetFuturesContractDetails(context.Background(), asset.Futures)
require.NoError(t, err, "GetFuturesContractDetails must not error for DeliveryFutures")
assert.NotEmpty(t, c, "GetFuturesContractDetails should return same number of Future contracts as exist")
}

func TestGetLatestFundingRates(t *testing.T) {
Expand Down
29 changes: 12 additions & 17 deletions exchanges/gateio/gateio_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2127,28 +2127,26 @@ func (g *Gateio) GetFuturesContractDetails(ctx context.Context, item asset.Item)
}
return resp, nil
case asset.DeliveryFutures:
var resp []futures.Contract
contracts, err := g.GetAllDeliveryContracts(ctx, currency.USDT)
if err != nil {
return nil, err
}
contractsToAdd := make([]futures.Contract, len(contracts))
for j := range contracts {
var name, underlying currency.Pair
name, err = currency.NewPairFromString(contracts[j].Name)
resp := make([]futures.Contract, len(contracts))
for i := range contracts {
name, err := currency.NewPairFromString(contracts[i].Name)
if err != nil {
return nil, err
}
underlying, err = currency.NewPairFromString(contracts[j].Underlying)
underlying, err := currency.NewPairFromString(contracts[i].Underlying)
if err != nil {
return nil, err
}
var ct futures.ContractType
// no start information, inferring it based on contract type
// gateio also reuses contracts for kline data, cannot use a lookup to see the first trade
var s, e time.Time
e = contracts[j].ExpireTime.Time()
switch contracts[j].Cycle {
var s time.Time
e := contracts[i].ExpireTime.Time()
ct := futures.LongDated
switch contracts[i].Cycle {
case "WEEKLY":
ct = futures.Weekly
s = e.Add(-kline.OneWeek.Duration())
Expand All @@ -2161,25 +2159,22 @@ func (g *Gateio) GetFuturesContractDetails(ctx context.Context, item asset.Item)
case "BI-QUARTERLY":
ct = futures.HalfYearly
s = e.Add(-kline.SixMonth.Duration())
default:
ct = futures.LongDated
}
contractsToAdd[j] = futures.Contract{
resp[i] = futures.Contract{
Exchange: g.Name,
Name: name,
Underlying: underlying,
Asset: item,
StartDate: s,
EndDate: e,
SettlementType: futures.Linear,
IsActive: !contracts[j].InDelisting,
IsActive: !contracts[i].InDelisting,
Type: ct,
SettlementCurrencies: currency.Currencies{currency.USDT},
MarginCurrency: currency.Code{},
Multiplier: contracts[j].QuantoMultiplier.Float64(),
MaxLeverage: contracts[j].LeverageMax.Float64(),
Multiplier: contracts[i].QuantoMultiplier.Float64(),
MaxLeverage: contracts[i].LeverageMax.Float64(),
}
resp = append(resp, contractsToAdd...)
}
return resp, nil
}
Expand Down

0 comments on commit 282c54b

Please sign in to comment.