engine/exchanges: Add GetCurrencyTradeURL wrapper func/gRPC endpoint (#1521)

* beginning the concept

* expands testing and implementations

* test standardisation, expansion

* more

* finish remainder, add rpc func

* lint

* grammar? I barely know her!

* wow i forgot something wow wow wow wow

* rm SendPayload

* enFixio!

* improve binance long-dated support

* update test design, update wrapper funcs

* adds kraken futures, adds bybit support

* fixes SIMPLE bugs

* s is for sucks

* fixed option url x2

* fixed silly test
This commit is contained in:
Scott
2024-05-03 17:01:17 +10:00
committed by GitHub
parent 0676c78bec
commit f1ff951199
83 changed files with 3922 additions and 2265 deletions

View File

@@ -37,6 +37,7 @@ const (
spotAPIURL = "https://sapi.binance.com"
cfuturesAPIURL = "https://dapi.binance.com"
ufuturesAPIURL = "https://fapi.binance.com"
tradeBaseURL = "https://www.binance.com/en/"
testnetSpotURL = "https://testnet.binance.vision/api"
testnetFutures = "https://testnet.binancefuture.com"

View File

@@ -3489,3 +3489,16 @@ func TestGetOpenInterest(t *testing.T) {
})
assert.ErrorIs(t, err, asset.ErrNotSupported)
}
func TestGetCurrencyTradeURL(t *testing.T) {
t.Parallel()
testexch.UpdatePairsOnce(t, b)
for _, a := range b.GetAssetTypes(false) {
pairs, err := b.CurrencyPairs.GetPairs(a, false)
require.NoError(t, err, "cannot get pairs for %s", a)
require.NotEmpty(t, pairs, "no pairs for %s", a)
resp, err := b.GetCurrencyTradeURL(context.Background(), a, pairs[0])
require.NoError(t, err)
assert.NotEmpty(t, resp)
}
}

View File

@@ -3046,3 +3046,67 @@ func (b *Binance) GetOpenInterest(ctx context.Context, k ...key.PairAsset) ([]fu
}
return result, nil
}
// GetCurrencyTradeURL returns the URL to the exchange's trade page for the given asset and currency pair
func (b *Binance) GetCurrencyTradeURL(ctx context.Context, a asset.Item, cp currency.Pair) (string, error) {
_, err := b.CurrencyPairs.IsPairEnabled(cp, a)
if err != nil {
return "", err
}
symbol, err := b.FormatSymbol(cp, a)
if err != nil {
return "", err
}
switch a {
case asset.USDTMarginedFutures:
var ct string
if !cp.Quote.Equal(currency.USDT) && !cp.Quote.Equal(currency.BUSD) {
ei, err := b.UExchangeInfo(ctx)
if err != nil {
return "", err
}
for i := range ei.Symbols {
if ei.Symbols[i].Symbol != symbol {
continue
}
switch ei.Symbols[i].ContractType {
case "CURRENT_QUARTER":
ct = "_QUARTER"
case "NEXT_QUARTER":
ct = "_BI-QUARTER"
}
symbol = ei.Symbols[i].Pair
break
}
}
return tradeBaseURL + "futures/" + symbol + ct, nil
case asset.CoinMarginedFutures:
var ct string
if !cp.Quote.Equal(currency.USDT) && !cp.Quote.Equal(currency.BUSD) {
ei, err := b.FuturesExchangeInfo(ctx)
if err != nil {
return "", err
}
for i := range ei.Symbols {
if ei.Symbols[i].Symbol != symbol {
continue
}
switch ei.Symbols[i].ContractType {
case "CURRENT_QUARTER":
ct = "_QUARTER"
case "NEXT_QUARTER":
ct = "_BI-QUARTER"
}
symbol = ei.Symbols[i].Pair
break
}
}
return tradeBaseURL + "delivery/" + symbol + ct, nil
case asset.Spot:
return tradeBaseURL + "trade/" + symbol + "?type=spot", nil
case asset.Margin:
return tradeBaseURL + "trade/" + symbol + "?type=cross", nil
default:
return "", fmt.Errorf("%w %v", asset.ErrNotSupported, a)
}
}