diff --git a/kucoin/async_client.py b/kucoin/async_client.py index e53f862..6edf593 100644 --- a/kucoin/async_client.py +++ b/kucoin/async_client.py @@ -469,12 +469,8 @@ async def get_symbol(self, symbol=None, **params): """ - data = {} - if symbol: - data["symbol"] = symbol - return await self._get( - "symbol", False, api_version=self.API_VERSION2, data=dict(data, **params) + "symbols/{}".format(symbol), False, api_version=self.API_VERSION2, **params ) async def get_ticker(self, symbol, **params): @@ -763,7 +759,7 @@ async def get_trade_histories(self, symbol, **params): return await self._get("market/histories", False, data=dict(data, **params)) - async def get_kline_data(self, symbol, kline_type="5min", start=None, end=None, **params): + async def get_klines(self, symbol, kline_type="5min", start=None, end=None, **params): """Get kline data https://www.kucoin.com/docs/rest/spot-trading/market-data/get-klines @@ -773,7 +769,7 @@ async def get_kline_data(self, symbol, kline_type="5min", start=None, end=None, :param symbol: Name of symbol e.g. KCS-BTC :type symbol: string - :param kline_type: type of symbol, type of candlestick patterns: 1min, 3min, 5min, 15min, 30min, 1hour, 2hour, + :param kline_type: type of candlestick patterns: 1min, 3min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 8hour, 12hour, 1day, 1week :type kline_type: string :param start: Start time as unix timestamp (optional) default start of day in UTC @@ -783,7 +779,7 @@ async def get_kline_data(self, symbol, kline_type="5min", start=None, end=None, .. code:: python - klines = client.get_kline_data('KCS-BTC', '5min', 1507479171, 1510278278) + klines = client.get_klines('KCS-BTC', '5min', 1507479171, 1510278278) :returns: ApiResponse @@ -1277,7 +1273,7 @@ async def futures_get_trade_histories(self, symbol, **params): ) async def futures_get_klines( - self, symbol, kline_type="5min", start=None, end=None, **params + self, symbol, kline_type=5, start=None, end=None, **params ): """Get kline data @@ -1287,9 +1283,8 @@ async def futures_get_klines( :param symbol: Name of symbol e.g. XBTUSDTM :type symbol: string - :param kline_type: type of symbol, type of candlestick patterns: 1min, 3min, 5min, 15min, 30min, 1hour, 2hour, - 4hour, 6hour, 8hour, 12hour, 1day, 1week - :type kline_type: string + :param kline_type: type of candlestick in minutes: 1, 5, 50 etc. + :type kline_type: int :param start: Start time as unix timestamp (optional) default start of day in UTC :type start: int :param end: End time as unix timestamp (optional) default now in UTC @@ -1297,7 +1292,7 @@ async def futures_get_klines( .. code:: python - klines = client.futures_get_klines('XBTUSDTM', '5min', 1507479171, 1510278278) + klines = client.futures_get_klines('XBTUSDTM', 5, 1507479171, 1510278278) :returns: ApiResponse @@ -8919,7 +8914,7 @@ async def get_fills( if limit: data["pageSize"] = limit - return await self._get("fills", False, data=dict(data, **params)) + return await self._get("fills", True, data=dict(data, **params)) async def get_recent_fills(self, **params): """Get a list of recent fills. @@ -9232,7 +9227,7 @@ async def futures_get_fills( if limit: data["pageSize"] = limit - return await self._get("fills", False, is_futures=True, data=dict(data, **params)) + return await self._get("fills", True, is_futures=True, data=dict(data, **params)) async def futures_get_recent_fills(self, symbol=None, **params): """Get a list of recent futures fills. @@ -9287,7 +9282,7 @@ async def futures_get_recent_fills(self, symbol=None, **params): data["symbol"] = symbol return await self._get( - "recentFills", False, is_futures=True, data=dict(data, **params) + "recentFills", True, is_futures=True, data=dict(data, **params) ) async def futures_get_active_order_value(self, symbol, **params): @@ -9324,7 +9319,7 @@ async def futures_get_active_order_value(self, symbol, **params): data = {"symbol": symbol} return await self._get( - "openOrderStatistics", False, is_futures=True, data=dict(data, **params) + "openOrderStatistics", True, is_futures=True, data=dict(data, **params) ) # Margin Info Endpoints @@ -9378,7 +9373,7 @@ async def margin_get_leverage_token_info(self, currency=None, **params): async def margin_get_all_trading_pairs_mark_prices(self, **params): """Get a list of trading pairs and their mark prices - https://www.kucoin.com/docs/rest/margin-trading/margin-info/get-all-trading-pairs-mark-price + https://www.kucoin.com/docs/rest/margin-trading/margin-info/get-all-margin-trading-pairs-mark-prices .. code:: python @@ -10295,7 +10290,7 @@ async def margin_lending_get_currency_info(self, currency=None, **params): return await self._get( "project/list", - False, + True, api_version=self.API_VERSION3, data=dict(data, **params), ) @@ -10341,7 +10336,7 @@ async def margin_lending_get_interest_rate(self, currency, **params): return await self._get( "project/marketInterestRatet", - False, + True, api_version=self.API_VERSION3, data=dict(data, **params), ) diff --git a/kucoin/client.py b/kucoin/client.py index 2357b9a..200f66c 100644 --- a/kucoin/client.py +++ b/kucoin/client.py @@ -361,13 +361,13 @@ def get_symbols(self, market=None, **params): https://www.kucoin.com/docs/rest/spot-trading/market-data/get-symbols-list - :param market: (optional) Name of market e.g. BTC + :param market: (optional) Name of market e.g. ETH-USDT :type market: string .. code:: python symbols = client.get_symbols() - symbols = client.get_symbols('USDS') + symbols = client.get_symbols('ETH-USDT') :returns: ApiResponse @@ -469,12 +469,8 @@ def get_symbol(self, symbol=None, **params): """ - data = {} - if symbol: - data["symbol"] = symbol - return self._get( - "symbol", False, api_version=self.API_VERSION2, data=dict(data, **params) + "symbols/{}".format(symbol), False, api_version=self.API_VERSION2, data=params ) def get_ticker(self, symbol, **params): @@ -763,7 +759,7 @@ def get_trade_histories(self, symbol, **params): return self._get("market/histories", False, data=dict(data, **params)) - def get_kline_data(self, symbol, kline_type="5min", start=None, end=None, **params): + def get_klines(self, symbol, kline_type="5min", start=None, end=None, **params): """Get kline data https://www.kucoin.com/docs/rest/spot-trading/market-data/get-klines @@ -773,7 +769,7 @@ def get_kline_data(self, symbol, kline_type="5min", start=None, end=None, **para :param symbol: Name of symbol e.g. KCS-BTC :type symbol: string - :param kline_type: type of symbol, type of candlestick patterns: 1min, 3min, 5min, 15min, 30min, 1hour, 2hour, + :param kline_type: type of candlestick patterns: 1min, 3min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 8hour, 12hour, 1day, 1week :type kline_type: string :param start: Start time as unix timestamp (optional) default start of day in UTC @@ -783,7 +779,7 @@ def get_kline_data(self, symbol, kline_type="5min", start=None, end=None, **para .. code:: python - klines = client.get_kline_data('KCS-BTC', '5min', 1507479171, 1510278278) + klines = client.get_klines('KCS-BTC', '5min', 1507479171, 1510278278) :returns: ApiResponse @@ -1277,7 +1273,7 @@ def futures_get_trade_histories(self, symbol, **params): ) def futures_get_klines( - self, symbol, kline_type="5min", start=None, end=None, **params + self, symbol, kline_type=5, start=None, end=None, **params ): """Get kline data @@ -1287,9 +1283,8 @@ def futures_get_klines( :param symbol: Name of symbol e.g. XBTUSDTM :type symbol: string - :param kline_type: type of symbol, type of candlestick patterns: 1min, 3min, 5min, 15min, 30min, 1hour, 2hour, - 4hour, 6hour, 8hour, 12hour, 1day, 1week - :type kline_type: string + :param kline_type: type of candlestick in minutes: 1, 5, 50 etc. + :type kline_type: int :param start: Start time as unix timestamp (optional) default start of day in UTC :type start: int :param end: End time as unix timestamp (optional) default now in UTC @@ -1297,7 +1292,7 @@ def futures_get_klines( .. code:: python - klines = client.futures_get_klines('XBTUSDTM', '5min', 1507479171, 1510278278) + klines = client.futures_get_klines('XBTUSDTM', 5, 1507479171, 1510278278) :returns: ApiResponse @@ -8923,7 +8918,7 @@ def get_fills( if limit: data["pageSize"] = limit - return self._get("fills", False, data=dict(data, **params)) + return self._get("fills", True, data=dict(data, **params)) def get_recent_fills(self, **params): """Get a list of recent fills. @@ -9236,7 +9231,7 @@ def futures_get_fills( if limit: data["pageSize"] = limit - return self._get("fills", False, is_futures=True, data=dict(data, **params)) + return self._get("fills", True, is_futures=True, data=dict(data, **params)) def futures_get_recent_fills(self, symbol=None, **params): """Get a list of recent futures fills. @@ -9291,7 +9286,7 @@ def futures_get_recent_fills(self, symbol=None, **params): data["symbol"] = symbol return self._get( - "recentFills", False, is_futures=True, data=dict(data, **params) + "recentFills", True, is_futures=True, data=dict(data, **params) ) def futures_get_active_order_value(self, symbol, **params): @@ -9328,7 +9323,7 @@ def futures_get_active_order_value(self, symbol, **params): data = {"symbol": symbol} return self._get( - "openOrderStatistics", False, is_futures=True, data=dict(data, **params) + "openOrderStatistics", True, is_futures=True, data=dict(data, **params) ) # Margin Info Endpoints @@ -9382,7 +9377,7 @@ def margin_get_leverage_token_info(self, currency=None, **params): def margin_get_all_trading_pairs_mark_prices(self, **params): """Get a list of trading pairs and their mark prices - https://www.kucoin.com/docs/rest/margin-trading/margin-info/get-all-trading-pairs-mark-price + https://www.kucoin.com/docs/rest/margin-trading/margin-info/get-all-margin-trading-pairs-mark-prices .. code:: python @@ -10299,7 +10294,7 @@ def margin_lending_get_currency_info(self, currency=None, **params): return self._get( "project/list", - False, + True, api_version=self.API_VERSION3, data=dict(data, **params), ) @@ -10345,7 +10340,7 @@ def margin_lending_get_interest_rate(self, currency, **params): return self._get( "project/marketInterestRatet", - False, + True, api_version=self.API_VERSION3, data=dict(data, **params), ) diff --git a/tests/test_public_endpoints.py b/tests/test_public_endpoints.py new file mode 100644 index 0000000..68ac9c9 --- /dev/null +++ b/tests/test_public_endpoints.py @@ -0,0 +1,291 @@ +import pytest + +def test_spot_status(client): + response = client.get_status() + assert response is not None + +@pytest.mark.asyncio() +async def test_spot_status_async(asyncClient): + response = await asyncClient.get_status() + assert response is not None + +def test_futures_status(client): + response = client.futures_get_status() + assert response is not None + +@pytest.mark.asyncio() +async def test_futures_status_async(asyncClient): + response = await asyncClient.futures_get_status() + assert response is not None + +def test_announcements(client): + response = client.get_announcements() + assert response is not None + +@pytest.mark.asyncio() +async def test_announcements_async(asyncClient): + response = await asyncClient.get_announcements() + assert response is not None + +def test_currencies(client): + response = client.get_currencies() + assert response is not None + +@pytest.mark.asyncio() +async def test_currencies_async(asyncClient): + response = await asyncClient.get_currencies() + assert response is not None + +def test_currency(client): + response = client.get_currency("BTC") + currency = response["currency"] + assert currency == "BTC" + +# todo: throws TypeError: Invalid variable type: value should be str, int or float, got None of type +# @pytest.mark.asyncio() +# async def test_currency_async(asyncClient): +# response = await asyncClient.get_currency("BTC") +# currency = response["currency"] +# assert currency == "BTC" + +def test_symbols(client): + response = client.get_symbols() + assert response is not None + +@pytest.mark.asyncio() +async def test_symbols_async(asyncClient): + response = await asyncClient.get_symbols() + assert response is not None + +def test_symbol(client): + response = client.get_symbol("ETH-USDT") + symbol = response["symbol"] + assert symbol == "ETH-USDT" + +@pytest.mark.asyncio() +async def test_symbol_async(asyncClient): + response = await asyncClient.get_symbol("ETH-USDT") + symbol = response["symbol"] + assert symbol == "ETH-USDT" + +def test_ticker(client): + response = client.get_ticker("ETH-USDT") + assert response is not None + +@pytest.mark.asyncio() +async def test_ticker_async(asyncClient): + response = await asyncClient.get_ticker("ETH-USDT") + assert response is not None + +def test_tickers(client): + response = client.get_tickers() + assert response is not None + +@pytest.mark.asyncio() +async def test_tickers_async(asyncClient): + response = await asyncClient.get_tickers() + assert response is not None + +def test_24hr_stats(client): + response = client.get_24hr_stats("ETH-USDT") + symbol = response["symbol"] + assert symbol == "ETH-USDT" + +@pytest.mark.asyncio() +async def test_24hr_stats_async(asyncClient): + response = await asyncClient.get_24hr_stats("ETH-USDT") + symbol = response["symbol"] + assert symbol == "ETH-USDT" + +def test_markets(client): + response = client.get_markets() + assert response is not None + +@pytest.mark.asyncio() +async def test_markets_async(asyncClient): + response = await asyncClient.get_markets() + assert response is not None + +def test_order_book(client): + response = client.get_order_book("ETH-USDT") + assert response is not None + +@pytest.mark.asyncio() +async def test_order_book_async(asyncClient): + response = await asyncClient.get_order_book("ETH-USDT") + assert response is not None + +def test_trade_histories(client): + response = client.get_trade_histories("ETH-USDT") + assert response is not None + +@pytest.mark.asyncio() +async def test_trade_histories_async(asyncClient): + response = await asyncClient.get_trade_histories("ETH-USDT") + assert response is not None + +def test_klines(client): + response = client.get_klines("ETH-USDT") + assert response is not None + +@pytest.mark.asyncio() +async def test_klines_async(asyncClient): + response = await asyncClient.get_klines("ETH-USDT") + assert response is not None + +def test_fiat_prices(client): + code = "BTC" + response = client.get_fiat_prices(None, code) + assert code in response + +@pytest.mark.asyncio() +async def test_fiat_prices_async(asyncClient): + code = "BTC" + response = await asyncClient.get_fiat_prices(None, code) + assert code in response + +def test_futures_symbol(client): + response = client.futures_get_symbol("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +@pytest.mark.asyncio() +async def test_futures_symbol_async(asyncClient): + response = await asyncClient.futures_get_symbol("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +def test_futures_symbols(client): + response = client.futures_get_symbols() + assert response is not None + +@pytest.mark.asyncio() +async def test_futures_symbols_async(asyncClient): + response = await asyncClient.futures_get_symbols() + assert response is not None + +def test_futures_tickers(client): + response = client.futures_get_tickers() + assert response is not None + +@pytest.mark.asyncio() +async def test_futures_tickers_async(asyncClient): + response = await asyncClient.futures_get_tickers() + assert response is not None + +def test_futures_ticker(client): + response = client.futures_get_ticker("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +@pytest.mark.asyncio() +async def test_futures_ticker_async(asyncClient): + response = await asyncClient.futures_get_ticker("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +def test_futures_order_book(client): + response = client.futures_get_order_book("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +@pytest.mark.asyncio() +async def test_futures_order_book_async(asyncClient): + response = await asyncClient.futures_get_order_book("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +def test_futures_full_order_book(client): + response = client.futures_get_full_order_book("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +@pytest.mark.asyncio() +async def test_futures_full_order_book_async(asyncClient): + response = await asyncClient.futures_get_full_order_book("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +def test_futures_trade_histories(client): + response = client.futures_get_trade_histories("ETHUSDTM") + assert response is not None + +@pytest.mark.asyncio() +async def test_futures_trade_histories_async(asyncClient): + response = await asyncClient.futures_get_trade_histories("ETHUSDTM") + assert response is not None + +def test_futures_klines(client): + response = client.futures_get_klines("ETHUSDTM") + assert response is not None + +@pytest.mark.asyncio() +async def test_futures_klines_async(asyncClient): + response = await asyncClient.futures_get_klines("ETHUSDTM") + assert response is not None + +def test_futures_interest_rate(client): + response = client.futures_get_interest_rate(".KXBT") + assert response is not None + +# todo: +# File "/opt/homebrew/lib/python3.11/site-packages/yarl/_url.py", line 946, in _query_var +# raise TypeError( +# TypeError: Invalid variable type: value should be str, int or float, got True of type +# @pytest.mark.asyncio() +# async def test_futures_interest_rate_async(asyncClient): +# response = await asyncClient.futures_get_interest_rate(".KXBT") +# assert response is not None + +def test_futures_index(client): + response = client.futures_get_index(".KXBT") + assert response is not None + +# todo: +# File "/opt/homebrew/lib/python3.11/site-packages/yarl/_url.py", line 946, in _query_var +# raise TypeError( +# TypeError: Invalid variable type: value should be str, int or float, got True of type +# @pytest.mark.asyncio() +# async def test_futures_index_async(asyncClient): +# response = await asyncClient.futures_get_index(".KXBT") +# assert response is not None + +def test_futures_mark_price(client): + response = client.futures_get_mark_price("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +@pytest.mark.asyncio() +async def test_futures_mark_price_async(asyncClient): + response = await asyncClient.futures_get_mark_price("ETHUSDTM") + symbol = response["symbol"] + assert symbol == "ETHUSDTM" + +def test_futures_premium_index(client): + response = client.futures_get_premium_index("ETHUSDTM") + assert response is not None + +# todo: +# TypeError: Invalid variable type: value should be str, int or float, got True of type +# @pytest.mark.asyncio() +# async def test_futures_premium_index_async(asyncClient): +# response = await asyncClient.futures_get_premium_index("ETHUSDTM") +# assert response is not None + +def test_margin_all_trading_pairs_mark_prices(client): + response = client.margin_get_all_trading_pairs_mark_prices() + assert response is not None + +@pytest.mark.asyncio() +def test_margin_all_trading_pairs_mark_prices_async(asyncClient): + response = asyncClient.margin_get_all_trading_pairs_mark_prices() + assert response is not None + +def test_futures_public_funding_history(client): + response = client.futures_get_public_funding_history('ETHUSDTM', start=1622505600000, end=1622592000000) + assert response is not None + +@pytest.mark.asyncio() +async def test_futures_public_funding_history_async(asyncClient): + response = await asyncClient.futures_get_public_funding_history('ETHUSDTM', start=1622505600000, end=1622592000000) + assert response is not None \ No newline at end of file