diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..262809a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "cSpell.words": [ + "APIKEY", + "Basiri", + "bnbusdt", + "btcusdt", + "coinex", + "isort", + "levelname", + "msecs", + "mypy", + "tabdeal", + "websockets" + ] +} \ No newline at end of file diff --git a/requirements/base.txt b/requirements/base.txt index a6f44bf..fea4046 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,2 +1,2 @@ -requests==2.27.1 +requests==2.28.0 websocket-client==1.3.3 diff --git a/setup.py b/setup.py index 272e451..d774159 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,6 @@ exclude=["tests", "*.tests", "*.tests.*", "tests.*"] ), install_requires=[req for req in requirements], - python_requires=">=3.6", + python_requires=">=3.7", include_package_data=True, ) diff --git a/tabdeal/client.py b/tabdeal/client.py index ea0ef74..3e12b2f 100644 --- a/tabdeal/client.py +++ b/tabdeal/client.py @@ -140,12 +140,12 @@ def _update_session_headers(self, headers): self.session.headers.update(headers) def client_get_orders( - self, - symbol: str = None, - start_time: int = None, - end_time: int = None, - limit: int = None, - url="allOrders" + self, + symbol: str = None, + start_time: int = None, + end_time: int = None, + limit: int = None, + url="allOrders", ): data = dict() @@ -177,12 +177,13 @@ def client_get_open_orders(self, symbol: str = None, url="openOrders"): data=data, ) - - def client_get_non_expired_all_orders(self, - start_time: int = None, - end_time: int = None, - limit: int = None, - url = "nonExpiredAllOrders"): + def client_get_non_expired_all_orders( + self, + start_time: int = None, + end_time: int = None, + limit: int = None, + url="nonExpiredAllOrders", + ): data = dict() if start_time: @@ -193,7 +194,7 @@ def client_get_non_expired_all_orders(self, if limit: data.update({"limit": limit}) - + return self.request( url=url, method=RequestTypes.GET, @@ -201,18 +202,19 @@ def client_get_non_expired_all_orders(self, data=data, ) - def client_get_paginated_open_orders(self, symbol: str = None, page: int = None, page_size: int = None, - url="paginatedOpenOrders"): + def client_get_paginated_open_orders( + self, + symbol: str = None, + page: int = None, + page_size: int = None, + url="paginatedOpenOrders", + ): data = dict() if not symbol else add_symbol_to_data(dict(), symbol) if page is not None: - data.update({ - 'page': page - }) + data.update({"page": page}) if page_size is not None: - data.update({ - 'page_size': page_size - }) + data.update({"page_size": page_size}) return self.request( url=url, @@ -252,7 +254,11 @@ def get_order(self, symbol: str, order_id: int = None, client_order_id: str = No ) def cancel_order( - self, symbol: str, order_id: int = None, client_order_id: str = None, url="order" + self, + symbol: str, + order_id: int = None, + client_order_id: str = None, + url="order", ): data = dict() diff --git a/tabdeal/isolated_margin.py b/tabdeal/isolated_margin.py index 4cb3c5e..5fc6a11 100644 --- a/tabdeal/isolated_margin.py +++ b/tabdeal/isolated_margin.py @@ -10,12 +10,8 @@ class IsolatedMargin(Client): # Isolated Margin def transfer( - self, - asset: str, - symbol: str, - amount: str, - trans_from: str, - trans_to: str): + self, asset: str, symbol: str, amount: str, trans_from: str, trans_to: str + ): data = { "asset": asset, @@ -32,15 +28,23 @@ def transfer( data=data, ) - def transfer_spot_to_isolated_margin(self, asset: str, - symbol: str, - amount: str): - return self.transfer(asset=asset, symbol=symbol, amount=amount, trans_from="SPOT", trans_to="ISOLATED_MARGIN") + def transfer_spot_to_isolated_margin(self, asset: str, symbol: str, amount: str): + return self.transfer( + asset=asset, + symbol=symbol, + amount=amount, + trans_from="SPOT", + trans_to="ISOLATED_MARGIN", + ) - def transfer_isolated_margin_to_spot(self, asset: str, - symbol: str, - amount: str): - return self.transfer(asset=asset, symbol=symbol, amount=amount, trans_from="ISOLATED_MARGIN", trans_to="SPOT") + def transfer_isolated_margin_to_spot(self, asset: str, symbol: str, amount: str): + return self.transfer( + asset=asset, + symbol=symbol, + amount=amount, + trans_from="ISOLATED_MARGIN", + trans_to="SPOT", + ) def get_isolated_margin_account(self, symbols=None, tabdeal_symbols=None): symbols_str = "" @@ -59,25 +63,29 @@ def get_isolated_margin_account(self, symbols=None, tabdeal_symbols=None): url="margin/isolated/account/", method=RequestTypes.GET, security_type=SecurityTypes.TRADE, - data=data + data=data, ) def get_all_assets( - self, + self, ): return self.request( url="margin/allAssets", method=RequestTypes.GET, - security_type=SecurityTypes.NONE + security_type=SecurityTypes.NONE, ) - def get_transfers(self, asset: str = None, symbol: str = None, type: str = None, - start_time: int = None, - end_time: int = None, - size: int = None, - current: int = None - ): + def get_transfers( + self, + asset: str = None, + symbol: str = None, + type: str = None, + start_time: int = None, + end_time: int = None, + size: int = None, + current: int = None, + ): data = {} if asset: data["asset"] = asset @@ -102,15 +110,15 @@ def get_transfers(self, asset: str = None, symbol: str = None, type: str = None, ) def create_margin_order( - self, - symbol: str, - side: OrderSides, - type: OrderTypes, - borrow_quantity: str, - quantity: str, - client_order_id: str = None, - price: str = None, - stop_price: str = None + self, + symbol: str, + side: OrderSides, + type: OrderTypes, + borrow_quantity: str, + quantity: str, + client_order_id: str = None, + price: str = None, + stop_price: str = None, ): data = { @@ -119,7 +127,7 @@ def create_margin_order( "quantity": quantity, "price": 0 if not price else price, "stopPrice": 0 if not stop_price else stop_price, - "borrow_quantity": 0 if not borrow_quantity else borrow_quantity + "borrow_quantity": 0 if not borrow_quantity else borrow_quantity, } add_symbol_to_data(data, symbol) @@ -138,29 +146,47 @@ def get_open_margin_orders(self, symbol: str = None): return self.client_get_open_orders(symbol=symbol, url="margin/openOrders") def cancel_margin_order( - self, symbol: str, order_id: int = None, client_order_id: str = None + self, symbol: str, order_id: int = None, client_order_id: str = None ): - return self.cancel_order(symbol=symbol, order_id=order_id, client_order_id=client_order_id, url="margin/order") + return self.cancel_order( + symbol=symbol, + order_id=order_id, + client_order_id=client_order_id, + url="margin/order", + ) - def get_margin_order(self, symbol: str, order_id: int = None, client_order_id: str = None): - return self.get_order(symbol=symbol, order_id=order_id, client_order_id=client_order_id) + def get_margin_order( + self, symbol: str, order_id: int = None, client_order_id: str = None + ): + return self.get_order( + symbol=symbol, order_id=order_id, client_order_id=client_order_id + ) def get_all_margin_orders( - self, - symbol: str, - start_time: int = None, - end_time: int = None, - limit: int = None, + self, + symbol: str, + start_time: int = None, + end_time: int = None, + limit: int = None, + ): + return self.client_get_orders( + symbol=symbol, + start_time=start_time, + end_time=end_time, + limit=limit, + url="margin/allOrders", + ) + + def get_margin_repay_details( + self, + asset: str = None, + isolatedSymbol: str = None, + txId: str = None, + start_time: int = None, + end_time: int = None, + size: int = None, + current: int = None, ): - return self.client_get_orders(symbol=symbol, start_time=start_time, end_time=end_time, limit=limit, - url="margin/allOrders") - - def get_margin_repay_details(self, asset: str = None, isolatedSymbol: str = None, txId: str = None, - start_time: int = None, - end_time: int = None, - size: int = None, - current: int = None - ): data = {} if asset: data["asset"] = asset @@ -184,7 +210,7 @@ def get_margin_repay_details(self, asset: str = None, isolatedSymbol: str = None data=data, ) - def get_margin_loan_details(self, asset: str, tx_id: str=None): + def get_margin_loan_details(self, asset: str, tx_id: str = None): data = {"asset": asset} if tx_id is not None: data["tx_id"] = tx_id @@ -195,12 +221,15 @@ def get_margin_loan_details(self, asset: str, tx_id: str=None): data=data, ) - def get_margin_force_liquidation_rec(self, isolatedSymbol: str = None, txId: str = None, - start_time: int = None, - end_time: int = None, - size: int = None, - current: int = None - ): + def get_margin_force_liquidation_rec( + self, + isolatedSymbol: str = None, + txId: str = None, + start_time: int = None, + end_time: int = None, + size: int = None, + current: int = None, + ): data = {} if start_time: data["startTime"] = start_time @@ -222,12 +251,15 @@ def get_margin_force_liquidation_rec(self, isolatedSymbol: str = None, txId: str data=data, ) - def get_interests(self, asset: str = None, isolatedSymbol: str = None, - start_time: int = None, - end_time: int = None, - size: int = None, - current: int = None - ): + def get_interests( + self, + asset: str = None, + isolatedSymbol: str = None, + start_time: int = None, + end_time: int = None, + size: int = None, + current: int = None, + ): data = {} if asset: data["asset"] = asset diff --git a/tabdeal/spot.py b/tabdeal/spot.py index 674e60d..8da457e 100644 --- a/tabdeal/spot.py +++ b/tabdeal/spot.py @@ -43,23 +43,30 @@ def new_order( def get_open_orders(self, symbol: str = None): return self.client_get_open_orders(symbol=symbol) - def get_paginated_open_orders(self, symbol: str = None, page: int = None, page_size: int = None): - return self.client_get_paginated_open_orders(symbol=symbol, page=page, page_size=page_size) + def get_paginated_open_orders( + self, symbol: str = None, page: int = None, page_size: int = None + ): + return self.client_get_paginated_open_orders( + symbol=symbol, page=page, page_size=page_size + ) def get_orders( - self, - symbol: str = None, - start_time: int = None, - end_time: int = None, - limit: int = None, + self, + symbol: str = None, + start_time: int = None, + end_time: int = None, + limit: int = None, ): - return self.client_get_orders(symbol=symbol, start_time=start_time, end_time=end_time, limit=limit) - - def get_non_expired_all_orders(self, start_time: int = None, - end_time: int = None, - limit: int = None): - return self.client_get_non_expired_all_orders(start_time=start_time, end_time=end_time, limit=limit) + return self.client_get_orders( + symbol=symbol, start_time=start_time, end_time=end_time, limit=limit + ) + def get_non_expired_all_orders( + self, start_time: int = None, end_time: int = None, limit: int = None + ): + return self.client_get_non_expired_all_orders( + start_time=start_time, end_time=end_time, limit=limit + ) def cancel_open_orders(self, symbol: str): return self.client_cancel_open_orders(symbol=symbol)