unofficial_tabdeal_api ====================== .. py:module:: unofficial_tabdeal_api .. autoapi-nested-parse:: Unofficial Tabdeal API. -------------------------- A Package to communicate with the Tabdeal platform :copyright: (c) 2025-present MohsenHNSJ :license: MIT, see LICENSE for more details Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/unofficial_tabdeal_api/authorization/index /autoapi/unofficial_tabdeal_api/base/index /autoapi/unofficial_tabdeal_api/constants/index /autoapi/unofficial_tabdeal_api/enums/index /autoapi/unofficial_tabdeal_api/exceptions/index /autoapi/unofficial_tabdeal_api/margin/index /autoapi/unofficial_tabdeal_api/models/index /autoapi/unofficial_tabdeal_api/order/index /autoapi/unofficial_tabdeal_api/tabdeal_client/index /autoapi/unofficial_tabdeal_api/utils/index /autoapi/unofficial_tabdeal_api/wallet/index Classes ------- .. autoapisummary:: unofficial_tabdeal_api.AuthorizationClass unofficial_tabdeal_api.BaseClass unofficial_tabdeal_api.MarginClass unofficial_tabdeal_api.OrderClass unofficial_tabdeal_api.TabdealClient unofficial_tabdeal_api.WalletClass Package Contents ---------------- .. py:class:: AuthorizationClass(*, user_hash, authorization_key, _is_test = False) Bases: :py:obj:`unofficial_tabdeal_api.base.BaseClass` This is the class storing methods related to Authorization. .. py:method:: is_authorization_key_valid() :async: Checks the validity of provided authorization key. If the key is invalid or expired, return `False` If the key is working, return `True` :returns: `True` or `False` based on the result :rtype: bool .. py:class:: BaseClass(*, user_hash, authorization_key, _is_test = False) This is the base class, stores GET and POST functions. .. py:attribute:: _client_session :type: aiohttp.ClientSession .. py:attribute:: _logger :type: logging.Logger .. py:method:: close() :async: Close the aiohttp client session. .. py:method:: __aenter__() :async: Enter the async context manager. .. py:method:: __aexit__(exc_type, exc, tb) :async: Exit the async context manager and close the session. .. py:method:: _get_data_from_server(*, connection_url, queries = None) :async: Gets data from specified url and returns the parsed json back. :param connection_url: Url of the server to get data from :type connection_url: str :param queries: a Dictionary of queries. Defaults to None. :type queries: dict[str, Any] | None, optional :returns: a Dictionary or a list of dictionaries :rtype: dict[str, Any] | list[dict[str, Any]] .. py:method:: _post_data_to_server(*, connection_url, data) :async: Posts data to specified url and returns the result of request. :param connection_url: Url of server to post data to :type connection_url: str :param data: Stringed json data to send to server :type data: str :returns: A Dictionary or a list of dictionaries. :rtype: dict[str, Any] | list[dict[str, Any]] .. py:method:: _check_response(response) :async: Check the server response and raise appropriate exception in case of an error. :param response: Response from server :type response: ClientResponse :raises AuthorizationError: Raised when the authorization key is invalid or expired :raises Error: Raised for all other errors .. py:method:: _raise_specific_error(status_code, server_response) Raise a specific exception based on the server response content. :param status_code: The status code of the response :type status_code: int :param server_response: The content of the response :type server_response: str :raises exc_class: The specific exception class to raise :raises RequestError: Raised for all other errors .. py:class:: MarginClass(*, user_hash, authorization_key, _is_test = False) Bases: :py:obj:`unofficial_tabdeal_api.base.BaseClass` This is the class storing methods related to Margin trading. .. py:method:: get_isolated_symbol_details(isolated_symbol) :async: Gets the full details of an isolated symbol from server and returns it as a dictionary. :param isolated_symbol: Isolated symbol of margin asset. :type isolated_symbol: str :param example: BTCUSDT, MANAUSDT, BOMEUSDT, ... :returns: A model containing isolated symbol details :rtype: IsolatedSymbolDetailsModel :raises TypeError: If the response is not a dictionary or the response can't be validated. .. py:method:: get_margin_all_open_orders() :async: Gets all the open margin orders from server and returns it as a list of dictionaries. :returns: a List of `MarginOpenOrderModel` items :rtype: list[MarginOpenOrderModel] :raises TypeError: If the response is not a list. .. py:method:: get_margin_asset_id(isolated_symbol) :async: Gets the ID of a margin asset from server and returns it as an integer. :param isolated_symbol: Isolated symbol of margin asset. example: BTCUSDT, MANAUSDT, BOMEUSDT, ... :type isolated_symbol: str :returns: Margin asset ID as integer :rtype: int .. py:method:: get_order_break_even_price(asset_id) :async: Gets the price point for an order which Tabdeal says it yields no profit and loss. :param asset_id: Margin asset ID got from get_asset_id() function :type asset_id: int :returns: The price as Decimal :rtype: Decimal :raises BreakEvenPriceNotFoundError: If no matching order is found. .. py:method:: get_margin_pair_id(isolated_symbol) :async: Gets the pair ID for a margin asset from server and returns it as an integer. :param isolated_symbol: Isolated symbol of margin asset. :type isolated_symbol: str :param example: BTCUSDT, MANAUSDT, BOMEUSDT, ... :returns: Margin pair ID as integer :rtype: int :raises TypeError: If the response is not a dictionary. .. py:method:: get_margin_asset_balance(isolated_symbol) :async: Gets the margin asset balance in USDT from server and returns it as Decimal value. :param isolated_symbol: Isolated symbol of margin asset :type isolated_symbol: str :returns: Asset balance in USDT as Decimal :rtype: Decimal :raises TypeError: If the response is not a dictionary. .. py:method:: get_margin_asset_precision_requirements(isolated_symbol) :async: Gets the precision requirements of an asset from server and returns it as a tuple. First return value is precision for volume. Second return value is precision for price. :param isolated_symbol: Isolated symbol of margin asset :type isolated_symbol: str :returns: A Tuple containing precision requirements for (1)volume and (2)price :rtype: tuple[int, int] :raises TypeError: If the response is not a dictionary. .. py:method:: is_margin_asset_trade_able(isolated_symbol) :async: Gets the trade-able status of requested margin asset from server. Returns the status as boolean. If the asset is not found or not active for margin trading, returns False instead of raising an exception. :param isolated_symbol: Isolated symbol of margin asset :type isolated_symbol: str :returns: Is margin asset trade-able? :rtype: bool .. py:method:: open_margin_order(order) :async: Opens a margin order. :param order: margin order object containing order details :type order: MarginOrderModel :raises TypeError: If the server response is not a dictionary or does not indicate success. :returns: Order ID of the opened order :rtype: int .. py:method:: set_sl_tp_for_margin_order(*, margin_asset_id, stop_loss_price, take_profit_price) :async: Sets the stop loss and take profit points. :param margin_asset_id: Margin Asset ID (7 digits or more) :type margin_asset_id: int :param stop_loss_price: Stop loss price :type stop_loss_price: Decimal :param take_profit_price: Take profit price :type take_profit_price: Decimal :returns: None .. py:method:: does_margin_asset_have_active_order(isolated_symbol) :async: Checks whether the margin asset has an active order or not. :param isolated_symbol: Isolated symbol of margin asset :type isolated_symbol: str :returns: True if there is an active order, else False :rtype: bool .. py:method:: is_margin_order_filled(isolated_symbol) :async: Checks whether the isolated symbol's order is filled or not. :param isolated_symbol: Isolated margin symbol :type isolated_symbol: str :raises MarginOrderNotFoundInActiveOrdersError: If the order is not found, we raise an exception :returns: Is margin order filled? :rtype: bool .. py:class:: OrderClass(*, user_hash, authorization_key, _is_test = False) Bases: :py:obj:`unofficial_tabdeal_api.base.BaseClass` This is the class storing methods related to Ordering. .. py:method:: get_orders_details_history(_max_history = 500) :async: Gets the last 500(by default) orders details and returns them as a list. :param _max_history: Max number of histories. Defaults to 500. :type _max_history: int, optional :raises TypeError: If the server responds incorrectly :returns: A List of dictionaries :rtype: list[dict[str, Any]] .. py:method:: get_order_state(order_id) :async: Gets the state of the requested order and returns it as an OrderState enum. :param order_id: ID of the trade order :type order_id: int :returns: State of the order as enum :rtype: OrderState .. py:class:: TabdealClient(*, user_hash, authorization_key, _is_test = False) Bases: :py:obj:`unofficial_tabdeal_api.authorization.AuthorizationClass`, :py:obj:`unofficial_tabdeal_api.margin.MarginClass`, :py:obj:`unofficial_tabdeal_api.wallet.WalletClass`, :py:obj:`unofficial_tabdeal_api.order.OrderClass` a client class to communicate with Tabdeal platform. .. py:method:: _validate_trade_conditions(order) :async: Validate trade conditions for a margin order. :param order: The margin order to validate. :type order: MarginOrderModel :returns: True if the trade conditions are valid, False otherwise. :rtype: bool .. py:method:: _open_order(order) :async: Open a margin order. :param order: The margin order to open. :type order: MarginOrderModel :returns: None .. py:method:: _wait_for_order_fill(order) :async: Wait for the margin order to be filled. :param order: The margin order to wait for. :type order: MarginOrderModel :returns: True if the order is filled, False otherwise. :rtype: bool .. py:method:: _setup_stop_loss_take_profit(order) :async: Setup stop loss and take profit for a margin order. :param order: The margin order to setup SL/TP for. :type order: MarginOrderModel :returns: The margin asset ID. :rtype: int .. py:method:: _wait_for_order_close(margin_asset_id) :async: Wait for the margin order to close. :param margin_asset_id: The ID of the margin asset to wait for. :type margin_asset_id: int .. py:method:: _withdraw_balance_if_requested(order) :async: Withdraw balance from margin asset to wallet if requested. :param order: The margin order containing the asset symbol. :type order: MarginOrderModel .. py:method:: trade_margin_order(*, order, withdraw_balance_after_trade) :async: Trade a margin order. :param order: MarginOrderModel object containing order details. :type order: MarginOrderModel :param withdraw_balance_after_trade: Flag indicating whether to withdraw balance after trade. :type withdraw_balance_after_trade: bool :returns: Whether the trade was successful or not. :rtype: bool .. py:class:: WalletClass(*, user_hash, authorization_key, _is_test = False) Bases: :py:obj:`unofficial_tabdeal_api.base.BaseClass` This is the class storing methods related to account wallet. .. py:method:: get_wallet_usdt_balance() :async: Gets the balance of wallet in USDT and returns it as Decimal. :returns: Wallet USDT balance in Decimal :rtype: Decimal .. py:method:: transfer_usdt_from_wallet_to_margin_asset(*, transfer_amount, isolated_symbol) :async: Transfers USDT from wallet to margin asset. :param transfer_amount: Amount of USDT to transfer :type transfer_amount: Decimal :param isolated_symbol: Isolated symbol to transfer USDT to :type isolated_symbol: str .. py:method:: transfer_usdt_from_margin_asset_to_wallet(*, transfer_amount, isolated_symbol) :async: Transfers USDT from margin asset to wallet. :param transfer_amount: Amount of USDT to transfer :type transfer_amount: Decimal :param isolated_symbol: Isolated symbol to transfer USDT from :type isolated_symbol: str