diff --git a/bpx/__async/account.py b/bpx/__async/account.py index bfcf3d6..616e058 100644 --- a/bpx/__async/account.py +++ b/bpx/__async/account.py @@ -20,19 +20,19 @@ def __init__(self, async def get_balances(self, window: int = None): url, headers = super().get_balances(window) - return await self.get(url, headers=headers) + return await self._get(url, headers=headers) async def deposits(self, limit: int = 100, offset: int = 0, window: int = None): url, headers, params = super().deposits(limit, offset, window) - return await self.get(url, headers=headers, params=params) + return await self._get(url, headers=headers, params=params) async def get_deposit_address(self, blockchain: str, window: int = None): url, headers, params = super().get_deposit_address(blockchain, window) - return await self.get(url, headers=headers, params=params) + return await self._get(url, headers=headers, params=params) async def get_withdrawals(self, limit: int = 100, offset: int = 0, window: int = None): url, headers, params = super().get_withdrawals(limit, offset, window) - return await self.get(url, headers=headers, params=params) + return await self._get(url, headers=headers, params=params) async def withdrawal(self, address: str, symbol: str, @@ -40,11 +40,11 @@ async def withdrawal(self, address: str, quantity: str, window: int = None): url, headers, params = super().withdrawal(address, symbol, blockchain, quantity, window) - return await self.post(url, headers=headers, data=params) + return await self._post(url, headers=headers, data=params) async def get_order_history_query(self, symbol: str, limit: int = 100, offset: int = 0, window: int = None): url, headers, params = super().get_order_history_query(symbol, limit, offset, window) - return await self.get(url, headers=headers, params=params) + return await self._get(url, headers=headers, params=params) async def get_fill_history_query(self, symbol: str, limit: int = 100, @@ -58,14 +58,14 @@ async def get_fill_history_query(self, symbol: str, __from, to, window) - return await self.get(url, headers=headers, params=params) + return await self._get(url, headers=headers, params=params) async def get_open_order(self, symbol: str, order_id: str = None, client_id: int = None, window: int = None): url, headers, params = super().get_open_order(symbol, order_id, client_id, window) - return await self.get(url, headers=headers, params=params) + return await self._get(url, headers=headers, params=params) async def execute_order(self, symbol: str, side: str, @@ -85,19 +85,19 @@ async def execute_order(self, symbol: str, price, trigger_price, self_trade_prevention, quote_quantity, client_id, post_only, window) - return await self.post(url, headers=headers, data=params) + return await self._post(url, headers=headers, data=params) async def cancel_order(self, symbol: str, order_id: str = None, client_id: int = None, window: int = None): url, headers, params = super().cancel_order(symbol, order_id, client_id, window) - return await self.delete(url, headers=headers, data=params) + return await self._delete(url, headers=headers, data=params) async def get_open_orders(self, symbol: str = None, window: int = None): url, headers, params = super().get_open_orders(symbol, window) - return await self.get(url, headers=headers, params=params) + return await self._get(url, headers=headers, params=params) async def cancel_all_orders(self, symbol: str, window: int = None): url, headers, params = super().cancel_all_orders(symbol, window) - return await self.delete(url, headers=headers, data=params) + return await self._delete(url, headers=headers, data=params) diff --git a/bpx/__async/public.py b/bpx/__async/public.py index 8a70754..bd15fee 100644 --- a/bpx/__async/public.py +++ b/bpx/__async/public.py @@ -8,31 +8,31 @@ def __init__(self, proxy: str = None): AsyncHttpClient.__init__(self, proxy=proxy) async def get_assets(self): - return await self.get(self.get_assets_url()) + return await self._get(self.get_assets_url()) async def get_markets(self): - return await self.get(self.get_markets_url()) + return await self._get(self.get_markets_url()) async def get_ticker(self, symbol: str): - return await self.get(self.get_ticker_url(symbol)) + return await self._get(self.get_ticker_url(symbol)) async def get_depth(self, symbol: str): - return await self.get(self.get_depth_url(symbol)) + return await self._get(self.get_depth_url(symbol)) async def get_klines(self, symbol: str, interval: str, start_time=0, end_time=0): - return await self.get(self.get_klines_url(symbol, interval, start_time, end_time)) + return await self._get(self.get_klines_url(symbol, interval, start_time, end_time)) async def get_status(self): - return await self.get(self.get_status_url()) + return await self._get(self.get_status_url()) async def get_ping(self): - return await self.get(self.get_ping_url()) + return await self._get(self.get_ping_url()) async def get_time(self): - return await self.get(self.get_time_url()) + return await self._get(self.get_time_url()) async def get_recent_trades(self, symbol: str, limit=100): - return await self.get(self.get_recent_trades_url(symbol, limit)) + return await self._get(self.get_recent_trades_url(symbol, limit)) async def get_history_trades(self, symbol: str, limit=100, offset=0): - return await self.get(self.get_history_trades_url(symbol, limit, offset)) + return await self._get(self.get_history_trades_url(symbol, limit, offset)) diff --git a/bpx/account.py b/bpx/account.py index 98dac11..a521ff0 100644 --- a/bpx/account.py +++ b/bpx/account.py @@ -20,19 +20,19 @@ def __init__(self, def get_balances(self, window: int = None): url, headers = super().get_balances(window) - return self.get(url, headers=headers) + return self._get(url, headers=headers) def deposits(self, limit: int = 100, offset: int = 0, window: int = None): url, headers, params = super().deposits(limit, offset, window) - return self.get(url, headers=headers, params=params) + return self._get(url, headers=headers, params=params) def get_deposit_address(self, blockchain: str, window: int = None): url, headers, params = super().get_deposit_address(blockchain, window) - return self.get(url, headers=headers, params=params) + return self._get(url, headers=headers, params=params) def get_withdrawals(self, limit: int = 100, offset: int = 0, window: int = None): url, headers, params = super().get_withdrawals(limit, offset, window) - return self.get(url, headers=headers, params=params) + return self._get(url, headers=headers, params=params) def withdrawal(self, address: str, symbol: str, @@ -40,11 +40,11 @@ def withdrawal(self, address: str, quantity: str, window: int = None): url, headers, params = super().withdrawal(address, symbol, blockchain, quantity, window) - return self.post(url, headers=headers, data=params) + return self._post(url, headers=headers, data=params) def get_order_history_query(self, symbol: str, limit: int = 100, offset: int = 0, window: int = None): url, headers, params = super().get_order_history_query(symbol, limit, offset, window) - return self.get(url, headers=headers, params=params) + return self._get(url, headers=headers, params=params) def get_fill_history_query(self, symbol: str, limit: int = 100, @@ -58,14 +58,14 @@ def get_fill_history_query(self, symbol: str, __from, to, window) - return self.get(url, headers=headers, params=params) + return self._get(url, headers=headers, params=params) def get_open_order(self, symbol: str, order_id: str = None, client_id: int = None, window: int = None): url, headers, params = super().get_open_order(symbol, order_id, client_id, window) - return self.get(url, headers=headers, params=params) + return self._get(url, headers=headers, params=params) def execute_order(self, symbol: str, side: str, @@ -85,19 +85,19 @@ def execute_order(self, symbol: str, price, trigger_price, self_trade_prevention, quote_quantity, client_id, post_only, window) - return self.post(url, headers=headers, data=params) + return self._post(url, headers=headers, data=params) def cancel_order(self, symbol: str, order_id: str = None, client_id: int = None, window: int = None): url, headers, params = super().cancel_order(symbol, order_id, client_id, window) - return self.delete(url, headers=headers, data=params) + return self._delete(url, headers=headers, data=params) def get_open_orders(self, symbol: str = None, window: int = None): url, headers, params = super().get_open_orders(symbol, window) - return self.get(url, headers=headers, params=params) + return self._get(url, headers=headers, params=params) def cancel_all_orders(self, symbol: str, window: int = None): url, headers, params = super().cancel_all_orders(symbol, window) - return self.delete(url, headers=headers, data=params) + return self._delete(url, headers=headers, data=params) diff --git a/bpx/http_client/async_http_client.py b/bpx/http_client/async_http_client.py index 638ad31..fdf6a8b 100644 --- a/bpx/http_client/async_http_client.py +++ b/bpx/http_client/async_http_client.py @@ -10,7 +10,7 @@ class AsyncHttpClient(HttpClient): def __init__(self, proxy: str = ""): self.proxy = proxy - async def get(self, url, headers=None, params=None): + async def _get(self, url, headers=None, params=None): ssl_context = ssl.create_default_context(cafile=certifi.where()) async with aiohttp.ClientSession() as session: async with session.get(url, proxy=self.proxy, params=params, @@ -23,7 +23,7 @@ async def get(self, url, headers=None, params=None): except aiohttp.client_exceptions.ContentTypeError: return await response.text() - async def post(self, url, headers=None, data=None): + async def _post(self, url, headers=None, data=None): ssl_context = ssl.create_default_context(cafile=certifi.where()) async with aiohttp.ClientSession() as session: async with session.post(url, proxy=self.proxy, headers=headers, @@ -36,7 +36,7 @@ async def post(self, url, headers=None, data=None): except aiohttp.client_exceptions.ContentTypeError: return await response.text() - async def delete(self, url, headers=None, data=None): + async def _delete(self, url, headers=None, data=None): ssl_context = ssl.create_default_context(cafile=certifi.where()) async with aiohttp.ClientSession() as session: async with session.delete(url, proxy=self.proxy, headers=headers, diff --git a/bpx/http_client/http_client.py b/bpx/http_client/http_client.py index 9f8946f..bb7d2bc 100644 --- a/bpx/http_client/http_client.py +++ b/bpx/http_client/http_client.py @@ -3,16 +3,16 @@ class HttpClient(abc.ABC): @abc.abstractmethod - def get(self, url, headers=None, params=None): + def _get(self, url, headers=None, params=None): """Perform a GET request.""" pass @abc.abstractmethod - def post(self, url, headers=None, data=None): + def _post(self, url, headers=None, data=None): """Perform a POST request.""" pass @abc.abstractmethod - def delete(self, url, headers=None): + def _delete(self, url, headers=None): """Perform a DELETE request""" pass diff --git a/bpx/http_client/sync_http_client.py b/bpx/http_client/sync_http_client.py index 0e8ca2f..b42c2b8 100644 --- a/bpx/http_client/sync_http_client.py +++ b/bpx/http_client/sync_http_client.py @@ -7,21 +7,21 @@ class SyncHttpClient(HttpClient): def __init__(self, proxies: dict = None): self.proxies = proxies - def get(self, url, headers=None, params=None): + def _get(self, url, headers=None, params=None): response = requests.get(url=url, proxies=self.proxies, headers=headers, params=params) try: return response.json() except json.JSONDecodeError: return response.text - def post(self, url, headers=None, data=None): + def _post(self, url, headers=None, data=None): response = requests.post(url=url, proxies=self.proxies, headers=headers, data=json.dumps(data)) try: return response.json() except json.JSONDecodeError: return response.text - def delete(self, url, headers=None, data=None): + def _delete(self, url, headers=None, data=None): response = requests.delete(url, proxies=self.proxies, headers=headers, data=json.dumps(data)) try: return response.json() diff --git a/bpx/public.py b/bpx/public.py index a629c5c..e0ef883 100644 --- a/bpx/public.py +++ b/bpx/public.py @@ -8,31 +8,31 @@ def __init__(self, proxy: dict = None): SyncHttpClient.__init__(self, proxies=proxy) def get_assets(self): - return self.get(self.get_assets_url()) + return self._get(self.get_assets_url()) def get_markets(self): - return self.get(self.get_markets_url()) + return self._get(self.get_markets_url()) def get_ticker(self, symbol: str): - return self.get(self.get_ticker_url(symbol)) + return self._get(self.get_ticker_url(symbol)) def get_depth(self, symbol: str): - return self.get(self.get_depth_url(symbol)) + return self._get(self.get_depth_url(symbol)) def get_klines(self, symbol: str, interval: str, start_time=0, end_time=0): - return self.get(self.get_klines_url(symbol, interval, start_time, end_time)) + return self._get(self.get_klines_url(symbol, interval, start_time, end_time)) def get_status(self): - return self.get(self.get_status_url()) + return self._get(self.get_status_url()) def get_ping(self): - return self.get(self.get_ping_url()) + return self._get(self.get_ping_url()) def get_time(self): - return self.get(self.get_time_url()) + return self._get(self.get_time_url()) def get_recent_trades(self, symbol: str, limit=100): - return self.get(self.get_recent_trades_url(symbol, limit)) + return self._get(self.get_recent_trades_url(symbol, limit)) def get_history_trades(self, symbol: str, limit=100, offset=0): - return self.get(self.get_history_trades_url(symbol, limit, offset)) + return self._get(self.get_history_trades_url(symbol, limit, offset)) diff --git a/examples/account_example.py b/examples/account_example.py index 0c7a875..bda62de 100644 --- a/examples/account_example.py +++ b/examples/account_example.py @@ -11,12 +11,13 @@ def account_example(): print(account.get_fill_history_query("SOL_USDC", limit=999)) print(account.get_withdrawals()) print(account.execute_order("SOL_USDC", "Bid", "Limit", 0.01, time_in_force="IOC", price=1, window=10000)) - print(account.deposits(limit=1, offset=0, window=5000)) + print(account.deposits(limit=100, offset=0, window=5000)) print(account.get_balances()) print(account.get_deposit_address("Solana")) print(account.get_order_history_query("SOL_USDC")) - print(account.get_open_order("SOL_USDC", "32142131231")) + print(account.get_open_order("SOL_USDC", "13241231242")) print(account.cancel_order("SOL_USDC", "12313213")) print(account.cancel_all_orders("SOL_USDC")) + account_example() diff --git a/poetry.lock b/poetry.lock index 50ff652..91b8e77 100644 --- a/poetry.lock +++ b/poetry.lock @@ -87,6 +87,7 @@ files = [ [package.dependencies] aiosignal = ">=1.1.2" +async-timeout = {version = ">=4.0,<5.0", markers = "python_version < \"3.11\""} attrs = ">=17.3.0" frozenlist = ">=1.1.1" multidict = ">=4.5,<7.0" @@ -109,6 +110,17 @@ files = [ [package.dependencies] frozenlist = ">=1.1.0" +[[package]] +name = "async-timeout" +version = "4.0.3" +description = "Timeout context manager for asyncio programs" +optional = false +python-versions = ">=3.7" +files = [ + {file = "async-timeout-4.0.3.tar.gz", hash = "sha256:4640d96be84d82d02ed59ea2b7105a0f7b33abe8703703cd0ab0bf87c427522f"}, + {file = "async_timeout-4.0.3-py3-none-any.whl", hash = "sha256:7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028"}, +] + [[package]] name = "attrs" version = "23.2.0" @@ -367,6 +379,20 @@ ssh = ["bcrypt (>=3.1.5)"] test = ["certifi", "pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-xdist"] test-randomorder = ["pytest-randomly"] +[[package]] +name = "exceptiongroup" +version = "1.2.1" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.2.1-py3-none-any.whl", hash = "sha256:5258b9ed329c5bbdd31a309f53cbfb0b155341807f6ff7606a1e801a891b29ad"}, + {file = "exceptiongroup-1.2.1.tar.gz", hash = "sha256:a4785e48b045528f5bfe627b6ad554ff32def154f42372786903b7abcfe1aa16"}, +] + +[package.extras] +test = ["pytest (>=6)"] + [[package]] name = "frozenlist" version = "1.4.1" @@ -624,13 +650,33 @@ files = [ [package.dependencies] colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} iniconfig = "*" packaging = "*" pluggy = ">=1.5,<2.0" +tomli = {version = ">=1", markers = "python_version < \"3.11\""} [package.extras] dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +[[package]] +name = "pytest-asyncio" +version = "0.23.6" +description = "Pytest support for asyncio" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pytest-asyncio-0.23.6.tar.gz", hash = "sha256:ffe523a89c1c222598c76856e76852b787504ddb72dd5d9b6617ffa8aa2cde5f"}, + {file = "pytest_asyncio-0.23.6-py3-none-any.whl", hash = "sha256:68516fdd1018ac57b846c9846b954f0393b26f094764a28c955eabb0536a4e8a"}, +] + +[package.dependencies] +pytest = ">=7.0.0,<9" + +[package.extras] +docs = ["sphinx (>=5.3)", "sphinx-rtd-theme (>=1.0)"] +testing = ["coverage (>=6.2)", "hypothesis (>=5.7.1)"] + [[package]] name = "pytest-mock" version = "3.14.0" @@ -669,6 +715,17 @@ urllib3 = ">=1.21.1,<3" socks = ["PySocks (>=1.5.6,!=1.5.7)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] + [[package]] name = "urllib3" version = "2.2.1" @@ -791,5 +848,5 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" -python-versions = "^3.12" -content-hash = "eb7c4215190dd99c7b28959b7f09dc9ff63951b1f2c82f63cbe77fec0e5ba72a" +python-versions = "^3.8" +content-hash = "83c57d0e18657f2852dc5631cd44e1868907beb9b6465d41651a764d5813c226" diff --git a/pyproject.toml b/pyproject.toml index 1c2cf29..c148bc0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bpx-py" -version = "0.2.0" +version = "1.0.0" description = "Backpack API SDK tool" authors = ["sndmndss "] readme = "README.md" @@ -35,6 +35,7 @@ cryptography = "^42.0.5" [tool.poetry.group.dev.dependencies] pytest = "^8.2.0" pytest-mock = "^3.14.0" +pytest-asyncio = "^0.23.6" [build-system] requires = ["poetry-core"] diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..2ae338a --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,3 @@ +pytest==8.2.0 +pytest-asyncio==0.23.6 +pytest-mock==3.14.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 870bff5..e634ebf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,9 +12,6 @@ multidict==6.0.5 packaging==24.0 pluggy==1.5.0 pycparser==2.22 -pytest==8.2.0 -pytest-mock==3.14.0 requests==2.31.0 -setuptools==69.5.1 urllib3==2.2.1 yarl==1.9.4 diff --git a/tests/test__async_account.py b/tests/test__async_account.py new file mode 100644 index 0000000..e7a1457 --- /dev/null +++ b/tests/test__async_account.py @@ -0,0 +1,71 @@ +import pytest +from bpx.__async.account import Account +import os + +public_key = os.getenv("PUBLIC_KEY") +secret_key = os.getenv("SECRET_KEY") + +@pytest.fixture +def account_client(): + return Account(public_key, secret_key, window=10000) + +@pytest.mark.asyncio +async def test_fill_history_query(account_client: Account): + fills = await account_client.get_fill_history_query("SOL_USDC", limit=50) + assert len(fills) == 50 + +@pytest.mark.asyncio +async def test_get_withdrawal(account_client: Account): + withdrawal = await account_client.get_withdrawals(limit=3) + assert isinstance(withdrawal, list) + assert len(withdrawal) == 3 + +@pytest.mark.asyncio +async def test_execute_order(account_client: Account): + order = await account_client.execute_order(symbol="SOL_USDC", + order_type="Limit", + side="Bid", + quantity=0.01, + price=0.01, + time_in_force="IOC") + assert isinstance(order, dict) + +@pytest.mark.asyncio +async def test_deposits(account_client: Account): + deposits = await account_client.deposits(limit=3) + assert isinstance(deposits, list) + assert len(deposits) == 3 + +@pytest.mark.asyncio +async def test_get_balances(account_client: Account): + balances = await account_client.get_balances() + assert isinstance(balances, dict) + assert balances + +@pytest.mark.asyncio +async def test_get_deposit_address(account_client: Account): + address = await account_client.get_deposit_address("Solana") + assert isinstance(address, dict) + assert address + +@pytest.mark.asyncio +async def test_get_order_history_query(account_client: Account): + orders = await account_client.get_order_history_query("SOL_USDC", limit=5) + assert isinstance(orders, list) + assert len(orders) == 5 + +@pytest.mark.asyncio +async def test_get_open_order(account_client: Account): + order = await account_client.get_open_order("BTC_USDC", "112355467178868736") + assert isinstance(order, dict) + assert order["price"] == "1" + +@pytest.mark.asyncio +async def test_cancel_order(account_client: Account): + status = await account_client.cancel_order("SOL_USDC", order_id="1") + assert status == "Order not found" + +@pytest.mark.asyncio +async def test_cancel_all_orders(account_client: Account): + cancelled_orders = await account_client.cancel_all_orders("SOL_USDC") + assert isinstance(cancelled_orders, list) \ No newline at end of file diff --git a/tests/test__async_public.py b/tests/test__async_public.py new file mode 100644 index 0000000..4b54785 --- /dev/null +++ b/tests/test__async_public.py @@ -0,0 +1,60 @@ +import pytest +from bpx.__async.public import Public + +@pytest.fixture +def public_client(): + return Public() + +@pytest.mark.asyncio +async def test_get_assets_returns_list(public_client: Public): + assets = await public_client.get_assets() + assert isinstance(assets, list) + +@pytest.mark.asyncio +async def test_get_markets_returns_list(public_client: Public): + markets = await public_client.get_markets() + assert isinstance(markets, list) + +@pytest.mark.asyncio +async def test_get_ticker_returns_dict(public_client: Public): + ticker = await public_client.get_ticker("SOL_USDC") + assert isinstance(ticker, dict) + +@pytest.mark.asyncio +async def test_get_depth_returns_dict(public_client: Public): + depth = await public_client.get_depth("SOL_USDC") + assert isinstance(depth, dict) + +@pytest.mark.asyncio +async def test_get_klines_returns_list(public_client: Public): + klines = await public_client.get_klines("BTC_USDC", "1d") + assert isinstance(klines, list) + +@pytest.mark.asyncio +async def test_get_status_returns_dict(public_client: Public): + status = await public_client.get_status() + assert isinstance(status, dict) + assert status["status"] == "Ok" + +@pytest.mark.asyncio +async def test_get_ping_returns_pong(public_client: Public): + pong = await public_client.get_ping() + assert pong == "pong" + +@pytest.mark.asyncio +async def test_get_time_returns_int(public_client: Public): + time = await public_client.get_time() + if isinstance(time, str): + assert time.isdigit() + else: + assert isinstance(time, int) + +@pytest.mark.asyncio +async def test_get_recent_trades_returns_list(public_client: Public): + recent_trades = await public_client.get_recent_trades("SOL_USDC") + assert isinstance(recent_trades, list) + +@pytest.mark.asyncio +async def test_get_history_trades_returns_list(public_client: Public): + history_trades = await public_client.get_history_trades("WEN_USDC") + assert isinstance(history_trades, list) diff --git a/tests/test_account.py b/tests/test_account.py new file mode 100644 index 0000000..c8b220e --- /dev/null +++ b/tests/test_account.py @@ -0,0 +1,72 @@ +import pytest +from bpx.account import Account +import os + +public_key = os.getenv("PUBLIC_KEY") +secret_key = os.getenv("SECRET_KEY") + + +@pytest.fixture +def account_client(): + return Account(public_key, secret_key, window=10000) + + +def test_fill_history_query(account_client: Account): + fills = account_client.get_fill_history_query("SOL_USDC", limit=50) + assert len(fills) == 50 + + +def test_get_withdrawal(account_client: Account): + withdrawal = account_client.get_withdrawals(limit=3) + assert isinstance(withdrawal, list) + assert len(withdrawal) == 3 + + +def test_execute_order(account_client: Account): + order = account_client.execute_order(symbol="SOL_USDC", + order_type="Limit", + side="Bid", + quantity=0.01, + price=0.01, + time_in_force="IOC") + assert isinstance(order, dict) + + +def test_deposits(account_client: Account): + deposits = account_client.deposits(limit=3) + assert isinstance(deposits, list) + assert len(deposits) == 3 + + +def test_get_balances(account_client: Account): + balances = account_client.get_balances() + assert isinstance(balances, dict) + assert balances + + +def test_get_deposit_address(account_client: Account): + address = account_client.get_deposit_address("Solana") + assert isinstance(address, dict) + assert address + + +def test_get_order_history_query(account_client: Account): + orders = account_client.get_order_history_query("SOL_USDC", limit=5) + assert isinstance(orders, list) + assert len(orders) == 5 + + +def test_get_open_order(account_client: Account): + order = account_client.get_open_order("BTC_USDC", "112355467178868736") + assert isinstance(order, dict) + assert order["price"] == "1" + + +def test_cancel_order(account_client: Account): + status = account_client.cancel_order("SOL_USDC", order_id="1") + assert status == "Order not found" + + +def test_cancel_all_orders(account_client: Account): + cancelled_orders = account_client.cancel_all_orders("SOL_USDC") + assert isinstance(cancelled_orders, list) diff --git a/tests/test_public.py b/tests/test_public.py index 8de620e..af66032 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -7,44 +7,49 @@ def public_client(): return Public() -def test_get_assets_returns_list(public_client): +def test_get_assets_returns_list(public_client: Public): assets = public_client.get_assets() assert isinstance(assets, list) -def test_get_markets_returns_list(public_client): +def test_get_markets_returns_list(public_client: Public): assert isinstance(public_client.get_markets(), list) -def test_get_ticker_returns_dict(public_client): +def test_get_ticker_returns_dict(public_client: Public): assert isinstance(public_client.get_ticker("SOL_USDC"), dict) -def test_get_depth_returns_dict(public_client): +def test_get_depth_returns_dict(public_client: Public): assert isinstance(public_client.get_depth("SOL_USDC"), dict) -def test_get_klines_returns_list(public_client): +def test_get_klines_returns_list(public_client: Public): assert isinstance(public_client.get_klines("BTC_USDC", "1d"), list) -def test_get_status_returns_dict(public_client): +def test_get_status_returns_dict(public_client: Public): status = public_client.get_status() assert isinstance(status, dict) assert status["status"] == "Ok" -def test_get_ping_returns_pong(public_client): - assert public_client.get_ping() == "pong" +def test_get_ping_returns_pong(public_client: Public): + pong = public_client.get_ping() + assert pong == "pong" -def test_get_time_returns_int(public_client): - assert isinstance(public_client.get_time(), int) +def test_get_time_returns_int(public_client: Public): + time = public_client.get_time() + if isinstance(time, str): + assert time.isdigit() + else: + assert isinstance(time, int) -def test_get_recent_trades_returns_list(public_client): +def test_get_recent_trades_returns_list(public_client: Public): assert isinstance(public_client.get_recent_trades("SOL_USDC"), list) -def test_get_history_trades_returns_list(public_client): +def test_get_history_trades_returns_list(public_client: Public): assert isinstance(public_client.get_history_trades("WEN_USDC"), list)