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

@@ -268,6 +268,10 @@ func (f fExchange) GetHistoricCandlesExtended(_ context.Context, p currency.Pair
}, nil
}
func (f fExchange) GetCurrencyTradeURL(_ context.Context, _ asset.Item, _ currency.Pair) (string, error) {
return "https://google.com", nil
}
func (f fExchange) GetMarginRatesHistory(context.Context, *margin.RateHistoryRequest) (*margin.RateHistoryResponse, error) {
leet := decimal.NewFromInt(1337)
rates := []margin.Rate{
@@ -4290,3 +4294,55 @@ func TestRPCProxyAuthClient(t *testing.T) {
})
}
}
func TestGetCurrencyTradeURL(t *testing.T) {
t.Parallel()
em := NewExchangeManager()
exch, err := em.NewExchangeByName("binance")
require.NoError(t, err)
exch.SetDefaults()
b := exch.GetBase()
b.Name = fakeExchangeName
b.Enabled = true
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
err = b.CurrencyPairs.Store(asset.Spot, &currency.PairStore{
AssetEnabled: convert.BoolPtr(true),
Enabled: []currency.Pair{currency.NewPair(currency.BTC, currency.USDT)},
Available: []currency.Pair{currency.NewPair(currency.BTC, currency.USDT)},
RequestFormat: &currency.PairFormat{Uppercase: true},
ConfigFormat: &currency.PairFormat{Uppercase: true},
})
require.NoError(t, err)
fakeExchange := fExchange{
IBotExchange: exch,
}
err = em.Add(fakeExchange)
require.NoError(t, err)
s := RPCServer{Engine: &Engine{ExchangeManager: em}}
_, err = s.GetCurrencyTradeURL(context.Background(), nil)
assert.ErrorIs(t, err, common.ErrNilPointer)
req := &gctrpc.GetCurrencyTradeURLRequest{}
_, err = s.GetCurrencyTradeURL(context.Background(), req)
assert.ErrorIs(t, err, ErrExchangeNameIsEmpty)
req.Exchange = fakeExchangeName
_, err = s.GetCurrencyTradeURL(context.Background(), req)
assert.ErrorIs(t, err, asset.ErrNotSupported)
req.Asset = "spot"
_, err = s.GetCurrencyTradeURL(context.Background(), req)
assert.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
req.Pair = &gctrpc.CurrencyPair{
Delimiter: "-",
Base: "btc",
Quote: "usdt",
}
resp, err := s.GetCurrencyTradeURL(context.Background(), req)
assert.NoError(t, err)
assert.NotEmpty(t, resp.Url)
}