diff --git a/bpx/account.py b/bpx/account.py index c4b2433..5111f4c 100644 --- a/bpx/account.py +++ b/bpx/account.py @@ -25,8 +25,10 @@ def get_balances(self, window: Optional[int] = None): https://docs.backpack.exchange/#tag/Capital/operation/get_balances """ - url, headers = super().get_balances(window) - return self.http_client.get(url, headers=headers) + request_config = super().get_balances(window) + return self.http_client.get( + url=request_config.url, headers=request_config.headers + ) def get_deposits( self, @@ -41,8 +43,12 @@ def get_deposits( https://docs.backpack.exchange/#tag/Capital/operation/get_deposits """ - url, headers, params = super().get_deposits(limit, offset, window, from_, to) - return self.http_client.get(url, headers=headers, params=params) + request_config = super().get_deposits(limit, offset, window, from_, to) + return self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) def get_deposit_address(self, blockchain: str, window: Optional[int] = None): """ @@ -50,8 +56,12 @@ def get_deposit_address(self, blockchain: str, window: Optional[int] = None): https://docs.backpack.exchange/#tag/Capital/operation/get_deposit_address """ - url, headers, params = super().get_deposit_address(blockchain, window) - return self.http_client.get(url, headers=headers, params=params) + request_config = super().get_deposit_address(blockchain, window) + return self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) def get_withdrawals( self, @@ -66,8 +76,12 @@ def get_withdrawals( https://docs.backpack.exchange/#tag/Capital/operation/get_withdrawals """ - url, headers, params = super().get_withdrawals(limit, offset, from_, to, window) - return self.http_client.get(url, headers=headers, params=params) + request_config = super().get_withdrawals(limit, offset, from_, to, window) + return self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) def withdrawal( self, @@ -82,23 +96,33 @@ def withdrawal( https://docs.backpack.exchange/#tag/Capital/operation/request_withdrawal """ - url, headers, params = super().withdrawal( + request_config = super().withdrawal( address, symbol, blockchain, quantity, window ) - return self.http_client.post(url, headers=headers, data=params) + return self.http_client.post( + url=request_config.url, + headers=request_config.headers, + data=request_config.data, + ) def get_order_history_query( - self, symbol: str, limit: int = 100, offset: int = 0, window: Optional[int] = None + self, + symbol: str, + limit: int = 100, + offset: int = 0, + window: Optional[int] = None, ): """ Returns orders history of a specified symbol https://docs.backpack.exchange/#tag/History/operation/get_order_history """ - url, headers, params = super().get_order_history_query( - symbol, limit, offset, window + request_config = super().get_order_history_query(symbol, limit, offset, window) + return self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, ) - return self.http_client.get(url, headers=headers, params=params) def get_fill_history_query( self, @@ -114,10 +138,14 @@ def get_fill_history_query( https://docs.backpack.exchange/#tag/History/operation/get_fills """ - url, headers, params = super().get_fill_history_query( + request_config = super().get_fill_history_query( symbol, limit, offset, from_, to, window ) - return self.http_client.get(url, headers=headers, params=params) + return self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) def get_open_order( self, @@ -131,10 +159,12 @@ def get_open_order( https://docs.backpack.exchange/#tag/Order/operation/get_order """ - url, headers, params = super().get_open_order( - symbol, order_id, client_id, window + request_config = super().get_open_order(symbol, order_id, client_id, window) + return self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, ) - return self.http_client.get(url, headers=headers, params=params) def execute_order( self, @@ -156,7 +186,7 @@ def execute_order( https://docs.backpack.exchange/#tag/Order/operation/execute_order """ - url, headers, params = super().execute_order( + request_config = super().execute_order( symbol, side, order_type, @@ -170,7 +200,11 @@ def execute_order( post_only, window, ) - return self.http_client.post(url, headers=headers, data=params) + return self.http_client.post( + url=request_config.url, + headers=request_config.headers, + data=request_config.data, + ) def cancel_order( self, @@ -184,8 +218,12 @@ def cancel_order( https://docs.backpack.exchange/#tag/Order/operation/cancel_order """ - url, headers, params = super().cancel_order(symbol, order_id, client_id, window) - return self.http_client.delete(url, headers=headers, data=params) + request_config = super().cancel_order(symbol, order_id, client_id, window) + return self.http_client.delete( + url=request_config.url, + headers=request_config.headers, + data=request_config.data, + ) def get_open_orders(self, symbol: str, window: Optional[int] = None): """ @@ -193,8 +231,12 @@ def get_open_orders(self, symbol: str, window: Optional[int] = None): https://docs.backpack.exchange/#tag/Order/operation/get_open_orders """ - url, headers, params = super().get_open_orders(symbol, window) - return self.http_client.get(url, headers=headers, params=params) + request_config = super().get_open_orders(symbol, window) + return self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) def cancel_all_orders(self, symbol: str, window: Optional[int] = None): """ @@ -202,5 +244,9 @@ def cancel_all_orders(self, symbol: str, window: Optional[int] = None): https://docs.backpack.exchange/#tag/Order/operation/cancel_open_orders """ - url, headers, params = super().cancel_all_orders(symbol, window) - return self.http_client.delete(url, headers=headers, data=params) + request_config = super().cancel_all_orders(symbol, window) + return self.http_client.delete( + url=request_config.url, + headers=request_config.headers, + data=request_config.data, + ) diff --git a/bpx/async_/account.py b/bpx/async_/account.py index cadc524..3355002 100644 --- a/bpx/async_/account.py +++ b/bpx/async_/account.py @@ -25,8 +25,10 @@ async def get_balances(self, window: Optional[int] = None): https://docs.backpack.exchange/#tag/Capital/operation/get_balances """ - url, headers = super().get_balances(window) - return await self.http_client.get(url, headers=headers) + request_config = super().get_balances(window) + return await self.http_client.get( + url=request_config.url, headers=request_config.headers + ) async def get_deposits( self, @@ -41,8 +43,12 @@ async def get_deposits( https://docs.backpack.exchange/#tag/Capital/operation/get_deposits """ - url, headers, params = super().get_deposits(limit, offset, window) - return await self.http_client.get(url, headers=headers, params=params) + request_config = super().get_deposits(limit, offset, window) + return await self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) async def get_deposit_address(self, blockchain: str, window: Optional[int] = None): """ @@ -50,8 +56,12 @@ async def get_deposit_address(self, blockchain: str, window: Optional[int] = Non https://docs.backpack.exchange/#tag/Capital/operation/get_deposit_address """ - url, headers, params = super().get_deposit_address(blockchain, window) - return await self.http_client.get(url, headers=headers, params=params) + request_config = super().get_deposit_address(blockchain, window) + return await self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) async def get_withdrawals( self, @@ -66,8 +76,12 @@ async def get_withdrawals( https://docs.backpack.exchange/#tag/Capital/operation/get_withdrawals """ - url, headers, params = super().get_withdrawals(limit, offset, from_, to, window) - return await self.http_client.get(url, headers=headers, params=params) + request_config = super().get_withdrawals(limit, offset, from_, to, window) + return await self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) async def withdrawal( self, @@ -82,23 +96,33 @@ async def withdrawal( https://docs.backpack.exchange/#tag/Capital/operation/request_withdrawal """ - url, headers, params = super().withdrawal( + request_config = super().withdrawal( address, symbol, blockchain, quantity, window ) - return await self.http_client.post(url, headers=headers, data=params) + return await self.http_client.post( + url=request_config.url, + headers=request_config.headers, + data=request_config.data, + ) async def get_order_history_query( - self, symbol: str, limit: int = 100, offset: int = 0, window: Optional[int] = None + self, + symbol: str, + limit: int = 100, + offset: int = 0, + window: Optional[int] = None, ): """ Returns orders history of a specified symbol https://docs.backpack.exchange/#tag/History/operation/get_order_history """ - url, headers, params = super().get_order_history_query( - symbol, limit, offset, window + request_config = super().get_order_history_query(symbol, limit, offset, window) + return await self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, ) - return await self.http_client.get(url, headers=headers, params=params) async def get_fill_history_query( self, @@ -114,10 +138,14 @@ async def get_fill_history_query( https://docs.backpack.exchange/#tag/History/operation/get_fills """ - url, headers, params = super().get_fill_history_query( + request_config = super().get_fill_history_query( symbol, limit, offset, from_, to, window ) - return await self.http_client.get(url, headers=headers, params=params) + return await self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) async def get_open_order( self, @@ -131,10 +159,12 @@ async def get_open_order( https://docs.backpack.exchange/#tag/Order/operation/get_order """ - url, headers, params = super().get_open_order( - symbol, order_id, client_id, window + request_config = super().get_open_order(symbol, order_id, client_id, window) + return await self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, ) - return await self.http_client.get(url, headers=headers, params=params) async def execute_order( self, @@ -156,7 +186,7 @@ async def execute_order( https://docs.backpack.exchange/#tag/Order/operation/execute_order """ - url, headers, params = super().execute_order( + request_config = super().execute_order( symbol, side, order_type, @@ -170,7 +200,11 @@ async def execute_order( post_only, window, ) - return await self.http_client.post(url, headers=headers, data=params) + return await self.http_client.post( + url=request_config.url, + headers=request_config.headers, + data=request_config.data, + ) async def cancel_order( self, @@ -184,8 +218,12 @@ async def cancel_order( https://docs.backpack.exchange/#tag/Order/operation/cancel_order """ - url, headers, params = super().cancel_order(symbol, order_id, client_id, window) - return await self.http_client.delete(url, headers=headers, data=params) + request_config = super().cancel_order(symbol, order_id, client_id, window) + return await self.http_client.delete( + url=request_config.url, + headers=request_config.headers, + data=request_config.data, + ) async def get_open_orders(self, symbol: str, window: Optional[int] = None): """ @@ -193,8 +231,12 @@ async def get_open_orders(self, symbol: str, window: Optional[int] = None): https://docs.backpack.exchange/#tag/Order/operation/get_open_orders """ - url, headers, params = super().get_open_orders(symbol, window) - return await self.http_client.get(url, headers=headers, params=params) + request_config = super().get_open_orders(symbol, window) + return await self.http_client.get( + url=request_config.url, + headers=request_config.headers, + params=request_config.params, + ) async def cancel_all_orders(self, symbol: str, window: Optional[int] = None): """ @@ -202,5 +244,9 @@ async def cancel_all_orders(self, symbol: str, window: Optional[int] = None): https://docs.backpack.exchange/#tag/Order/operation/cancel_open_orders """ - url, headers, params = super().cancel_all_orders(symbol, window) - return await self.http_client.delete(url, headers=headers, data=params) + request_config = super().cancel_all_orders(symbol, window) + return await self.http_client.delete( + url=request_config.url, + headers=request_config.headers, + data=request_config.data, + ) diff --git a/bpx/async_/public.py b/bpx/async_/public.py index cf646b6..d4cf868 100644 --- a/bpx/async_/public.py +++ b/bpx/async_/public.py @@ -8,7 +8,9 @@ class Public(BasePublic): def __init__( - self, proxy: Optional[str] = None, http_client: AsyncHttpClient = default_http_client + self, + proxy: Optional[str] = None, + http_client: AsyncHttpClient = default_http_client, ): self.http_client = http_client self.http_client.proxy = proxy diff --git a/bpx/base/base_account.py b/bpx/base/base_account.py index e9694cc..a535365 100644 --- a/bpx/base/base_account.py +++ b/bpx/base/base_account.py @@ -1,9 +1,10 @@ from cryptography.hazmat.primitives.asymmetric import ed25519 import base64 from typing import Optional +from bpx.models.request_configuration import RequestConfiguration from time import time from bpx.exceptions import * -from bpx.enums import * +from bpx.constants.enums import * class BaseAccount: @@ -23,15 +24,16 @@ def __init__(self, public_key: str, secret_key: str, window: int, debug: bool): self.window = window self.debug = debug - def get_balances(self, window: Optional[int] = None): + def get_balances(self, window: Optional[int] = None) -> RequestConfiguration: """ - Returns the url, headers and request parameters for getting account balances + Returns the url, headers for getting account balances https://docs.backpack.exchange/#tag/Capital/operation/get_balances """ headers = self._headers({}, "balanceQuery", window=window) url = self.BPX_API_URL + "api/v1/capital" - return url, headers + request_config = RequestConfiguration(url=url, headers=headers) + return request_config def get_deposits( self, @@ -40,7 +42,7 @@ def get_deposits( from_: Optional[int] = None, to: Optional[int] = None, window: Optional[int] = None, - ): + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for getting account deposits @@ -60,9 +62,12 @@ def get_deposits( params["to"] = to headers = self._headers(params, "depositQueryAll", window=window) url = self.BPX_API_URL + "wapi/v1/capital/deposits" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, params=params) + return request_config - def get_deposit_address(self, blockchain: str, window: Optional[int] = None): + def get_deposit_address( + self, blockchain: str, window: Optional[int] = None + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for getting a deposit address @@ -73,7 +78,8 @@ def get_deposit_address(self, blockchain: str, window: Optional[int] = None): params = {"blockchain": blockchain} headers = self._headers(params, "depositAddressQuery", window=window) url = self.BPX_API_URL + "wapi/v1/capital/deposit/address" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, params=params) + return request_config def get_withdrawals( self, @@ -82,7 +88,7 @@ def get_withdrawals( from_: Optional[int] = None, to: Optional[int] = None, window: Optional[int] = None, - ): + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for getting account withdrawals @@ -99,7 +105,8 @@ def get_withdrawals( params["to"] = to headers = self._headers(params, "withdrawalQueryAll", window=window) url = self.BPX_API_URL + "wapi/v1/capital/withdrawals" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, params=params) + return request_config def withdrawal( self, @@ -108,7 +115,7 @@ def withdrawal( blockchain: str, quantity: str, window: Optional[int] = None, - ): + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for withdrawing funds @@ -124,11 +131,12 @@ def withdrawal( } headers = self._headers(params, "withdraw", window=window) url = self.BPX_API_URL + "wapi/v1/capital/withdrawals" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, data=params) + return request_config def get_order_history_query( self, symbol: str, limit: int, offset: int, window: Optional[int] - ): + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for getting account order history @@ -141,7 +149,8 @@ def get_order_history_query( params = {"symbol": symbol, "limit": limit, "offset": offset} headers = self._headers(params, "orderHistoryQueryAll", window=window) url = self.BPX_API_URL + "wapi/v1/history/orders" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, params=params) + return request_config def get_fill_history_query( self, @@ -151,7 +160,7 @@ def get_fill_history_query( from_: Optional[int] = None, to: Optional[int] = None, window: Optional[int] = None, - ): + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for getting account fill history @@ -179,7 +188,8 @@ def get_fill_history_query( params["to"] = to headers = self._headers(params, "fillHistoryQueryAll", window=window) url = self.BPX_API_URL + "wapi/v1/history/fills" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, params=params) + return request_config def get_open_order( self, @@ -187,7 +197,7 @@ def get_open_order( order_id: Optional[str] = None, client_id: Optional[int] = None, window: Optional[int] = None, - ): + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for getting account open orders @@ -201,7 +211,8 @@ def get_open_order( params["clientId"] = str(client_id) headers = self._headers(params, "orderQuery", window=window) url = self.BPX_API_URL + "api/v1/order" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, params=params) + return request_config def execute_order( self, @@ -217,7 +228,7 @@ def execute_order( client_id: Optional[int] = None, post_only: Optional[bool] = None, window: Optional[int] = None, - ): + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for placing a new order @@ -250,7 +261,8 @@ def execute_order( params["clientId"] = client_id headers = self._headers(params, "orderExecute", window=window) url = self.BPX_API_URL + "api/v1/order" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, data=params) + return request_config def cancel_order( self, @@ -258,7 +270,7 @@ def cancel_order( order_id: Optional[str] = None, client_id: Optional[int] = None, window: Optional[int] = None, - ): + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for cancelling an existing order @@ -271,9 +283,12 @@ def cancel_order( params["clientId"] = str(client_id) headers = self._headers(params, "orderCancel", window=window) url = self.BPX_API_URL + "api/v1/order" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, data=params) + return request_config - def get_open_orders(self, symbol: str, window: Optional[int] = None): + def get_open_orders( + self, symbol: str, window: Optional[int] = None + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for getting account open orders @@ -282,9 +297,12 @@ def get_open_orders(self, symbol: str, window: Optional[int] = None): params = {"symbol": symbol} headers = self._headers(params, "orderQueryAll", window=window) url = self.BPX_API_URL + "api/v1/orders" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, params=params) + return request_config - def cancel_all_orders(self, symbol: str, window: Optional[int] = None): + def cancel_all_orders( + self, symbol: str, window: Optional[int] = None + ) -> RequestConfiguration: """ Returns the url, headers and request parameters for cancelling all open orders for a specific symbol @@ -293,9 +311,13 @@ def cancel_all_orders(self, symbol: str, window: Optional[int] = None): params = {"symbol": symbol} headers = self._headers(params, "orderCancelAll", window=window) url = self.BPX_API_URL + "api/v1/orders" - return url, headers, params + request_config = RequestConfiguration(url=url, headers=headers, data=params) + return request_config def _headers(self, params: dict, instruction: str, window: Optional[int]) -> dict: + """ + Returns headers for the given instruction and params + """ window = self.window if window is None else window timestamp = int(time() * 1e3) encoded_signature = self._sign(params, instruction, timestamp, window) @@ -311,6 +333,9 @@ def _headers(self, params: dict, instruction: str, window: Optional[int]) -> dic return headers def _sign(self, params: dict, instruction: str, timestamp: int, window: int): + """ + Returns encoded signature for given parameters, instruction, timestamp and window + """ sign_str = f"instruction={instruction}" sorted_params = "&".join( f"{key}={value}" for key, value in sorted(params.items()) diff --git a/bpx/base/base_public.py b/bpx/base/base_public.py index 3f2124e..b398185 100644 --- a/bpx/base/base_public.py +++ b/bpx/base/base_public.py @@ -1,14 +1,14 @@ from bpx.exceptions import * -from bpx.enums import * +from bpx.constants.enums import * class BasePublic: BASE_URL = "https://api.backpack.exchange/" - def _endpoint(self, path): + def _endpoint(self, path) -> str: return f"{self.BASE_URL}{path}" - def get_assets_url(self): + def get_assets_url(self) -> str: """ Returns URL for getting assets @@ -16,7 +16,7 @@ def get_assets_url(self): """ return self._endpoint("api/v1/assets") - def get_markets_url(self): + def get_markets_url(self) -> str: """ Returns URL for getting markets @@ -24,7 +24,7 @@ def get_markets_url(self): """ return self._endpoint("api/v1/markets") - def get_ticker_url(self, symbol): + def get_ticker_url(self, symbol) -> str: """ Returns URL for getting ticker information for a specified market @@ -32,13 +32,14 @@ def get_ticker_url(self, symbol): """ return self._endpoint(f"api/v1/ticker?symbol={symbol}") - def get_depth_url(self, symbol): + def get_depth_url(self, symbol) -> str: """ Returns URL for getting depth for a specified market https://docs.backpack.exchange/#tag/Markets/operation/get_depth """ return self._endpoint(f"api/v1/depth?symbol={symbol}") + # currently not available # def get_collateral_summaries_for_all_assets(self): # """ @@ -57,7 +58,7 @@ def get_depth_url(self, symbol): # url = f"api/v1/collateral?asset={asset}" # return self._endpoint(url) - def get_klines_url(self, symbol, interval, start_time, end_time): + def get_klines_url(self, symbol, interval, start_time, end_time) -> str: """ Returns URL for getting klines for a specified market @@ -74,7 +75,7 @@ def get_klines_url(self, symbol, interval, start_time, end_time): url += f"&endTime={end_time}" return self._endpoint(url) - def get_status_url(self): + def get_status_url(self) -> str: """ Returns URL for getting status information @@ -82,7 +83,7 @@ def get_status_url(self): """ return self._endpoint("api/v1/status") - def get_ping_url(self): + def get_ping_url(self) -> str: """ Returns URL for getting pong if endpoint is reachable @@ -90,7 +91,7 @@ def get_ping_url(self): """ return self._endpoint("api/v1/ping") - def get_time_url(self): + def get_time_url(self) -> str: """ Returns URL for getting current server time @@ -98,7 +99,7 @@ def get_time_url(self): """ return self._endpoint("api/v1/time") - def get_recent_trades_url(self, symbol, limit=100): + def get_recent_trades_url(self, symbol, limit=100) -> str: """ Returns URL for getting recent trades for a specified market @@ -108,7 +109,7 @@ def get_recent_trades_url(self, symbol, limit=100): raise LimitValueError return self._endpoint(f"api/v1/trades?symbol={symbol}&limit={limit}") - def get_history_trades_url(self, symbol, limit=100, offset=0): + def get_history_trades_url(self, symbol, limit=100, offset=0) -> str: """ Returns URL for getting historical trades for a specified market diff --git a/bpx/constants/__init__.py b/bpx/constants/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bpx/enums/__init__.py b/bpx/constants/enums.py similarity index 97% rename from bpx/enums/__init__.py rename to bpx/constants/enums.py index 8b70c3f..f460232 100644 --- a/bpx/enums/__init__.py +++ b/bpx/constants/enums.py @@ -1,4 +1,5 @@ from enum import Enum +from typing import Optional class Blockchain(Enum): diff --git a/bpx/http_client/async_http_client.py b/bpx/http_client/async_http_client.py index ee55529..40b23e2 100644 --- a/bpx/http_client/async_http_client.py +++ b/bpx/http_client/async_http_client.py @@ -1,5 +1,5 @@ import aiohttp -from bpx.http_client.http_client import HttpClient +from bpx.http_client.base.http_client import HttpClient import json import certifi import ssl diff --git a/bpx/http_client/base/__init__.py b/bpx/http_client/base/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bpx/http_client/http_client.py b/bpx/http_client/base/http_client.py similarity index 100% rename from bpx/http_client/http_client.py rename to bpx/http_client/base/http_client.py diff --git a/bpx/http_client/sync_http_client.py b/bpx/http_client/sync_http_client.py index acfb983..cc10953 100644 --- a/bpx/http_client/sync_http_client.py +++ b/bpx/http_client/sync_http_client.py @@ -1,5 +1,5 @@ import requests -from bpx.http_client.http_client import HttpClient +from bpx.http_client.base.http_client import HttpClient import json diff --git a/bpx/models/__init__.py b/bpx/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bpx/models/request_configuration.py b/bpx/models/request_configuration.py new file mode 100644 index 0000000..77d985f --- /dev/null +++ b/bpx/models/request_configuration.py @@ -0,0 +1,15 @@ +from typing import Optional + + +class RequestConfiguration: + def __init__( + self, + url: str, + headers: Optional[dict] = None, + params: Optional[dict] = None, + data: Optional[dict] = None, + ): + self.url = url + self.headers = headers + self.params = params + self.data = data diff --git a/pyproject.toml b/pyproject.toml index 568690b..6b98a11 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bpx-py" -version = "1.2.0" +version = "1.2.1" description = "Backpack API SDK tool" authors = ["sndmndss "] readme = "README.md" diff --git a/tests/test_base_account.py b/tests/test_base_account.py index 8daaff1..5d1fa6c 100644 --- a/tests/test_base_account.py +++ b/tests/test_base_account.py @@ -26,9 +26,9 @@ def test_initialization(account): def test_get_balances(account): - url, headers = account.get_balances(window=10000) - assert url == "https://api.backpack.exchange/api/v1/capital" - assert "X-API-Key" in headers + request_config = account.get_balances(window=10000) + assert request_config.url == "https://api.backpack.exchange/api/v1/capital" + assert "X-API-Key" in request_config.headers def test_get_deposits(account): @@ -38,28 +38,28 @@ def test_get_deposits(account): with pytest.raises(NegativeValueError): account.get_deposits(limit=100, offset=-1, window=10000) - url, headers, params = account.get_deposits(limit=100, offset=0, window=10000) - assert url == "https://api.backpack.exchange/wapi/v1/capital/deposits" - assert params["limit"] == 100 - assert params["offset"] == 0 + request_config = account.get_deposits(limit=100, offset=0, window=10000) + assert request_config.url == "https://api.backpack.exchange/wapi/v1/capital/deposits" + assert request_config.params["limit"] == 100 + assert request_config.params["offset"] == 0 def test_get_deposit_address(account): with pytest.raises(InvalidBlockchainValue): account.get_deposit_address(blockchain="invalid_blockchain", window=10000) - url, headers, params = account.get_deposit_address( + request_config = account.get_deposit_address( blockchain="Bitcoin", window=10000 ) - assert url == "https://api.backpack.exchange/wapi/v1/capital/deposit/address" - assert params["blockchain"] == "Bitcoin" + assert request_config.url == "https://api.backpack.exchange/wapi/v1/capital/deposit/address" + assert request_config.params["blockchain"] == "Bitcoin" def test_signing(account): with patch.object(account, "_sign", return_value="mock_signature") as mock_sign: - _, headers = account.get_balances(window=10000) + request_config = account.get_balances(window=10000) mock_sign.assert_called_once() - assert headers["X-Signature"] == "mock_signature" + assert request_config.headers["X-Signature"] == "mock_signature" def test_withdrawal(account): @@ -72,13 +72,13 @@ def test_withdrawal(account): window=10000, ) - url, headers, params = account.withdrawal( + request_config = account.withdrawal( address="1BitcoinAddress", symbol="BTC", blockchain="Bitcoin", quantity="1.0", window=10000, ) - assert url == "https://api.backpack.exchange/wapi/v1/capital/withdrawals" - assert params["address"] == "1BitcoinAddress" - assert params["blockchain"] == "Bitcoin" + assert request_config.url == "https://api.backpack.exchange/wapi/v1/capital/withdrawals" + assert request_config.data["address"] == "1BitcoinAddress" + assert request_config.data["blockchain"] == "Bitcoin"