currency/exchanges: Add bespoke exchange translator and pair matching helper (#1556)

* currency: translation and matching pairs

* Update exchanges/exchange_types.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits

* linter: fix?

* translation

* fix cherry pick

* gateio: translation for mbabydoge with 1e6 divisor

* okx: add translation

* cherry-pick: fix

* glorious: todos

* thrasher: nits

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
This commit is contained in:
Ryan O'Hara-Reid
2024-08-16 16:47:17 +10:00
committed by GitHub
parent 0becfbd0a6
commit facf291069
10 changed files with 251 additions and 10 deletions

View File

@@ -74,6 +74,32 @@ func (by *Bybit) SetDefaults() {
}
by.Features = exchange.Features{
CurrencyTranslations: currency.NewTranslations(
map[currency.Code]currency.Code{
currency.NewCode("10000000AIDOGE"): currency.AIDOGE,
currency.NewCode("1000000BABYDOGE"): currency.BABYDOGE,
currency.NewCode("1000000MOG"): currency.NewCode("MOG"),
currency.NewCode("10000COQ"): currency.NewCode("COQ"),
currency.NewCode("10000LADYS"): currency.NewCode("LADYS"),
currency.NewCode("10000NFT"): currency.NFT,
currency.NewCode("10000SATS"): currency.NewCode("SATS"),
currency.NewCode("10000STARL"): currency.STARL,
currency.NewCode("10000WEN"): currency.NewCode("WEN"),
currency.NewCode("1000APU"): currency.NewCode("APU"),
currency.NewCode("1000BEER"): currency.NewCode("BEER"),
currency.NewCode("1000BONK"): currency.BONK,
currency.NewCode("1000BTT"): currency.BTT,
currency.NewCode("1000FLOKI"): currency.FLOKI,
currency.NewCode("1000IQ50"): currency.NewCode("IQ50"),
currency.NewCode("1000LUNC"): currency.LUNC,
currency.NewCode("1000PEPE"): currency.PEPE,
currency.NewCode("1000RATS"): currency.NewCode("RATS"),
currency.NewCode("1000TURBO"): currency.NewCode("TURBO"),
currency.NewCode("1000XEC"): currency.XEC,
currency.NewCode("LUNA2"): currency.LUNA,
currency.NewCode("SHIB1000"): currency.SHIB,
},
),
Supports: exchange.FeaturesSupported{
REST: true,
Websocket: true,

View File

@@ -150,10 +150,11 @@ type WithdrawalHistory struct {
// Features stores the supported and enabled features
// for the exchange
type Features struct {
Supports FeaturesSupported
Enabled FeaturesEnabled
Subscriptions subscription.List
TradingRequirements protocol.TradingRequirements
Supports FeaturesSupported
Enabled FeaturesEnabled
Subscriptions subscription.List
CurrencyTranslations currency.Translations
TradingRequirements protocol.TradingRequirements
}
// FeaturesEnabled stores the exchange enabled features

View File

@@ -55,6 +55,9 @@ func (g *Gateio) SetDefaults() {
}
g.Features = exchange.Features{
CurrencyTranslations: currency.NewTranslations(map[currency.Code]currency.Code{
currency.NewCode("MBABYDOGE"): currency.BABYDOGE,
}),
TradingRequirements: protocol.TradingRequirements{
SpotMarketOrderAmountPurchaseQuotationOnly: true,
SpotMarketOrderAmountSellBaseOnly: true,

View File

@@ -65,6 +65,12 @@ func (ku *Kucoin) SetDefaults() {
log.Errorln(log.ExchangeSys, err)
}
ku.Features = exchange.Features{
CurrencyTranslations: currency.NewTranslations(map[currency.Code]currency.Code{
currency.XBT: currency.BTC,
currency.USDTM: currency.USDT,
currency.USDM: currency.USD,
currency.USDCM: currency.USDC,
}),
TradingRequirements: protocol.TradingRequirements{
ClientOrderID: true,
},

View File

@@ -3166,7 +3166,6 @@ func (ok *Okx) GetCandlestickData(ctx context.Context, instrumentID string, inte
return nil, errMissingInstrumentID
}
params.Set("instId", instrumentID)
var resp [][7]string
params.Set("limit", strconv.FormatInt(limit, 10))
if !before.IsZero() {
params.Set("before", strconv.FormatInt(before.UnixMilli(), 10))
@@ -3178,6 +3177,7 @@ func (ok *Okx) GetCandlestickData(ctx context.Context, instrumentID string, inte
if bar != "" {
params.Set("bar", bar)
}
var resp [][7]string
err := ok.SendHTTPRequest(ctx, exchange.RestSpot, rateLimit, http.MethodGet, common.EncodeURLValues(route, params), nil, &resp, false)
if err != nil {
return nil, err

View File

@@ -1241,7 +1241,7 @@ type AccountDetail struct {
AvailableBalance types.Number `json:"availBal"`
AvailableEquity types.Number `json:"availEq"`
CashBalance types.Number `json:"cashBal"` // Cash Balance
Currency string `json:"ccy"`
Currency currency.Code `json:"ccy"`
CrossLiab types.Number `json:"crossLiab"`
DiscountEquity types.Number `json:"disEq"`
EquityOfCurrency types.Number `json:"eq"`
@@ -1270,7 +1270,7 @@ type AccountPosition struct {
AvailablePosition string `json:"availPos"` // Position that can be closed Only applicable to MARGIN, FUTURES/SWAP in the long-short mode, OPTION in Simple and isolated OPTION in margin Account.
AveragePrice types.Number `json:"avgPx"`
CreationTime okxUnixMilliTime `json:"cTime"`
Currency string `json:"ccy"`
Currency currency.Code `json:"ccy"`
DeltaBS string `json:"deltaBS"` // deltaBlack-Scholes Greeks in dollars,only applicable to OPTION
DeltaPA string `json:"deltaPA"` // deltaGreeks in coins,only applicable to OPTION
GammaBS string `json:"gammaBS"` // gammaBlack-Scholes Greeks in dollars,only applicable to OPTION

View File

@@ -63,6 +63,11 @@ func (ok *Okx) SetDefaults() {
// Fill out the capabilities/features that the exchange supports
ok.Features = exchange.Features{
CurrencyTranslations: currency.NewTranslations(map[currency.Code]currency.Code{
currency.NewCode("USDT-SWAP"): currency.USDT,
currency.NewCode("USD-SWAP"): currency.USD,
currency.NewCode("USDC-SWAP"): currency.USDC,
}),
Supports: exchange.FeaturesSupported{
REST: true,
Websocket: true,
@@ -518,7 +523,7 @@ func (ok *Okx) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (acc
for i := range accountBalances {
for j := range accountBalances[i].Details {
currencyBalances = append(currencyBalances, account.Balance{
Currency: currency.NewCode(accountBalances[i].Details[j].Currency),
Currency: accountBalances[i].Details[j].Currency,
Total: accountBalances[i].Details[j].EquityOfCurrency.Float64(),
Hold: accountBalances[i].Details[j].FrozenBalance.Float64(),
Free: accountBalances[i].Details[j].AvailableBalance.Float64(),
@@ -1848,7 +1853,7 @@ func (ok *Okx) GetFuturesPositionSummary(ctx context.Context, req *futures.Posit
)
for i := range acc[0].Details {
if acc[0].Details[i].Currency != positionSummary.Currency {
if !acc[0].Details[i].Currency.Equal(positionSummary.Currency) {
continue
}
freeCollateral = acc[0].Details[i].AvailableBalance.Decimal()
@@ -1877,7 +1882,7 @@ func (ok *Okx) GetFuturesPositionSummary(ctx context.Context, req *futures.Posit
Asset: req.Asset,
MarginType: marginMode,
CollateralMode: collateralMode,
Currency: currency.NewCode(positionSummary.Currency),
Currency: positionSummary.Currency,
AvailableEquity: availableEquity,
CashBalance: cashBalance,
DiscountEquity: discountEquity,