Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.0.0 #3

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions bpx/__async/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ 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,
blockchain: 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,
Expand All @@ -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,
Expand All @@ -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)
20 changes: 10 additions & 10 deletions bpx/__async/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
24 changes: 12 additions & 12 deletions bpx/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ 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,
blockchain: 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,
Expand All @@ -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,
Expand All @@ -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)
6 changes: 3 additions & 3 deletions bpx/http_client/async_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions bpx/http_client/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions bpx/http_client/sync_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 10 additions & 10 deletions bpx/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
5 changes: 3 additions & 2 deletions examples/account_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading
Loading