Skip to content

Commit

Permalink
typing for older python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sndmndss committed Aug 28, 2024
1 parent b6fa411 commit 4942edc
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 83 deletions.
55 changes: 28 additions & 27 deletions bpx/account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from bpx.base.base_account import BaseAccount
from bpx.http_client.sync_http_client import SyncHttpClient
from typing import Optional

http_client = SyncHttpClient()

Expand All @@ -10,15 +11,15 @@ def __init__(
public_key: str,
secret_key: str,
window: int = 5000,
proxy: dict = {},
proxy: Optional[dict] = None,
debug: bool = False,
default_http_client: SyncHttpClient = http_client,
):
super().__init__(public_key, secret_key, window, debug)
self.http_client = default_http_client
self.http_client.proxies = proxy

def get_balances(self, window: int | None = None):
def get_balances(self, window: Optional[int] = None):
"""
Returns the account balances
Expand All @@ -31,9 +32,9 @@ def get_deposits(
self,
limit: int = 100,
offset: int = 0,
from_: int | None = None,
to: int | None = None,
window: int | None = None,
from_: Optional[int] = None,
to: Optional[int] = None,
window: Optional[int] = None,
):
"""
Returns the account deposits
Expand All @@ -43,7 +44,7 @@ def get_deposits(
url, headers, params = super().get_deposits(limit, offset, window, from_, to)
return self.http_client.get(url, headers=headers, params=params)

def get_deposit_address(self, blockchain: str, window: int | None = None):
def get_deposit_address(self, blockchain: str, window: Optional[int] = None):
"""
Returns the deposit address for a specified blockchain
Expand All @@ -56,9 +57,9 @@ def get_withdrawals(
self,
limit: int = 100,
offset: int = 0,
from_: int | None = None,
to: int | None = None,
window: int | None = None,
from_: Optional[int] = None,
to: Optional[int] = None,
window: Optional[int] = None,
):
"""
Returns the account withdrawals
Expand All @@ -74,7 +75,7 @@ def withdrawal(
symbol: str,
blockchain: str,
quantity: str,
window: int | None = None,
window: Optional[int] = None,
):
"""
Posts withdrawal and returns withdrawal status
Expand All @@ -87,7 +88,7 @@ def withdrawal(
return self.http_client.post(url, headers=headers, data=params)

def get_order_history_query(
self, symbol: str, limit: int = 100, offset: int = 0, window: int | None = None
self, symbol: str, limit: int = 100, offset: int = 0, window: Optional[int] = None
):
"""
Returns orders history of a specified symbol
Expand All @@ -104,9 +105,9 @@ def get_fill_history_query(
symbol: str,
limit: int = 100,
offset: int = 0,
from_: int | None = None,
to: int | None = None,
window: int | None = None,
from_: Optional[int] = None,
to: Optional[int] = None,
window: Optional[int] = None,
):
"""
Returns fills history of a specified symbol
Expand All @@ -121,9 +122,9 @@ def get_fill_history_query(
def get_open_order(
self,
symbol: str,
order_id: str | None = None,
client_id: int | None = None,
window: int | None = None,
order_id: Optional[str] = None,
client_id: Optional[int] = None,
window: Optional[int] = None,
):
"""
Returns open orders of a specified symbol
Expand All @@ -140,15 +141,15 @@ def execute_order(
symbol: str,
side: str,
order_type: str,
quantity: float | None = None,
time_in_force: str | None = None,
quantity: Optional[float] = None,
time_in_force: Optional[str] = None,
price: float = 0,
trigger_price: float = 0,
self_trade_prevention: str = "RejectBoth",
quote_quantity: float | None = None,
client_id: int | None = None,
quote_quantity: Optional[float] = None,
client_id: Optional[int] = None,
post_only: bool | None = None,
window: int | None = None,
window: Optional[int] = None,
):
"""
Posts order and returns the status of the executed order
Expand All @@ -174,9 +175,9 @@ def execute_order(
def cancel_order(
self,
symbol: str,
order_id: str | None = None,
client_id: int | None = None,
window: int | None = None,
order_id: Optional[str] = None,
client_id: Optional[int] = None,
window: Optional[int] = None,
):
"""
Cancels an existing order
Expand All @@ -186,7 +187,7 @@ def cancel_order(
url, headers, params = super().cancel_order(symbol, order_id, client_id, window)
return self.http_client.delete(url, headers=headers, data=params)

def get_open_orders(self, symbol: str, window: int | None = None):
def get_open_orders(self, symbol: str, window: Optional[int] = None):
"""
Returns open orders of a specified symbol
Expand All @@ -195,7 +196,7 @@ def get_open_orders(self, symbol: str, window: int | None = None):
url, headers, params = super().get_open_orders(symbol, window)
return self.http_client.get(url, headers=headers, params=params)

def cancel_all_orders(self, symbol: str, window: int | None = None):
def cancel_all_orders(self, symbol: str, window: Optional[int] = None):
"""
Cancels all existing orders of a specified symbol
Expand Down
55 changes: 28 additions & 27 deletions bpx/async_/account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from bpx.base.base_account import BaseAccount
from bpx.http_client.async_http_client import AsyncHttpClient
from typing import Optional

default_http_client = AsyncHttpClient()

Expand All @@ -10,15 +11,15 @@ def __init__(
public_key: str,
secret_key: str,
window: int = 5000,
proxy: str | None = None,
proxy: Optional[str] = None,
debug: bool = False,
http_client: AsyncHttpClient = default_http_client,
):
super().__init__(public_key, secret_key, window, debug)
self.http_client = http_client
self.http_client.proxy = proxy

async def get_balances(self, window: int | None = None):
async def get_balances(self, window: Optional[int] = None):
"""
Returns the account balances
Expand All @@ -31,9 +32,9 @@ async def get_deposits(
self,
limit: int = 100,
offset: int = 0,
from_: int | None = None,
to: int | None = None,
window: int | None = None,
from_: Optional[int] = None,
to: Optional[int] = None,
window: Optional[int] = None,
):
"""
Returns the account deposits
Expand All @@ -43,7 +44,7 @@ async def get_deposits(
url, headers, params = super().get_deposits(limit, offset, window)
return await self.http_client.get(url, headers=headers, params=params)

async def get_deposit_address(self, blockchain: str, window: int | None = None):
async def get_deposit_address(self, blockchain: str, window: Optional[int] = None):
"""
Returns the deposit address for a specified blockchain
Expand All @@ -56,9 +57,9 @@ async def get_withdrawals(
self,
limit: int = 100,
offset: int = 0,
from_: int | None = None,
to: int | None = None,
window: int | None = None,
from_: Optional[int] = None,
to: Optional[int] = None,
window: Optional[int] = None,
):
"""
Returns the account withdrawals
Expand All @@ -74,7 +75,7 @@ async def withdrawal(
symbol: str,
blockchain: str,
quantity: str,
window: int | None = None,
window: Optional[int] = None,
):
"""
Posts withdrawal and returns withdrawal status
Expand All @@ -87,7 +88,7 @@ async def withdrawal(
return await self.http_client.post(url, headers=headers, data=params)

async def get_order_history_query(
self, symbol: str, limit: int = 100, offset: int = 0, window: int | None = None
self, symbol: str, limit: int = 100, offset: int = 0, window: Optional[int] = None
):
"""
Returns orders history of a specified symbol
Expand All @@ -104,9 +105,9 @@ async def get_fill_history_query(
symbol: str,
limit: int = 100,
offset: int = 0,
from_: int | None = None,
to: int | None = None,
window: int | None = None,
from_: Optional[int] = None,
to: Optional[int] = None,
window: Optional[int] = None,
):
"""
Returns fills history of a specified symbol
Expand All @@ -121,9 +122,9 @@ async def get_fill_history_query(
async def get_open_order(
self,
symbol: str,
order_id: str | None = None,
client_id: int | None = None,
window: int | None = None,
order_id: Optional[str] = None,
client_id: Optional[int] = None,
window: Optional[int] = None,
):
"""
Returns open orders of a specified symbol
Expand All @@ -140,15 +141,15 @@ async def execute_order(
symbol: str,
side: str,
order_type: str,
quantity: float | None = None,
time_in_force: str | None = None,
quantity: Optional[float] = None,
time_in_force: Optional[str] = None,
price: float = 0,
trigger_price: float = 0,
self_trade_prevention: str = "RejectBoth",
quote_quantity: float | None = None,
client_id: int | None = None,
quote_quantity: Optional[float] = None,
client_id: Optional[int] = None,
post_only: bool | None = None,
window: int | None = None,
window: Optional[int] = None,
):
"""
Posts order and returns the status of the executed order
Expand All @@ -174,9 +175,9 @@ async def execute_order(
async def cancel_order(
self,
symbol: str,
order_id: str | None = None,
client_id: int | None = None,
window: int | None = None,
order_id: Optional[str] = None,
client_id: Optional[int] = None,
window: Optional[int] = None,
):
"""
Cancels an existing order
Expand All @@ -186,7 +187,7 @@ async def 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)

async def get_open_orders(self, symbol: str, window: int | None = None):
async def get_open_orders(self, symbol: str, window: Optional[int] = None):
"""
Returns open orders of a specified symbol
Expand All @@ -195,7 +196,7 @@ async def get_open_orders(self, symbol: str, window: int | None = None):
url, headers, params = super().get_open_orders(symbol, window)
return await self.http_client.get(url, headers=headers, params=params)

async def cancel_all_orders(self, symbol: str, window: int | None = None):
async def cancel_all_orders(self, symbol: str, window: Optional[int] = None):
"""
Cancels all existing orders of a specified symbol
Expand Down
2 changes: 1 addition & 1 deletion bpx/async_/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Public(BasePublic):

def __init__(
self, proxy: str = None, http_client: AsyncHttpClient = default_http_client
self, proxy: str | None = None, http_client: AsyncHttpClient = default_http_client
):
self.http_client = http_client
self.http_client.proxy = proxy
Expand Down
Loading

0 comments on commit 4942edc

Please sign in to comment.