unofficial_tabdeal_api¶
A Package to communicate with the Tabdeal platform
- copyright:
2025-present MohsenHNSJ
- license:
MIT, see LICENSE for more details
Submodules¶
- unofficial_tabdeal_api.authorization
- unofficial_tabdeal_api.base
- unofficial_tabdeal_api.constants
- unofficial_tabdeal_api.enums
- unofficial_tabdeal_api.exceptions
- unofficial_tabdeal_api.margin
- unofficial_tabdeal_api.models
- unofficial_tabdeal_api.order
- unofficial_tabdeal_api.tabdeal_client
- unofficial_tabdeal_api.utils
- unofficial_tabdeal_api.wallet
Classes¶
This is the class storing methods related to Authorization. |
|
This is the base class, stores GET and POST functions. |
|
This is the class storing methods related to Margin trading. |
|
This is the class storing methods related to Ordering. |
|
a client class to communicate with Tabdeal platform. |
|
This is the class storing methods related to account wallet. |
Package Contents¶
- class unofficial_tabdeal_api.AuthorizationClass(*, user_hash, authorization_key, _is_test=False)¶
Bases:
unofficial_tabdeal_api.base.BaseClassThis is the class storing methods related to Authorization.
- class unofficial_tabdeal_api.BaseClass(*, user_hash, authorization_key, _is_test=False)¶
This is the base class, stores GET and POST functions.
- _client_session: aiohttp.ClientSession¶
- _logger: logging.Logger¶
- async close()¶
Close the aiohttp client session.
- Return type:
None
- async __aenter__()¶
Enter the async context manager.
- Return type:
Self
- async __aexit__(exc_type, exc, tb)¶
Exit the async context manager and close the session.
- Parameters:
exc_type (type[BaseException] | None)
exc (BaseException | None)
tb (types.TracebackType | None)
- Return type:
None
- async _get_data_from_server(*, connection_url, queries=None)¶
Gets data from specified url and returns the parsed json back.
- async _post_data_to_server(*, connection_url, data)¶
Posts data to specified url and returns the result of request.
- async _check_response(response)¶
Check the server response and raise appropriate exception in case of an error.
- Parameters:
response (ClientResponse) – Response from server
- Raises:
AuthorizationError – Raised when the authorization key is invalid or expired
Error – Raised for all other errors
- Return type:
None
- _raise_specific_error(status_code, server_response)¶
Raise a specific exception based on the server response content.
- Parameters:
- Raises:
exc_class – The specific exception class to raise
RequestError – Raised for all other errors
- Return type:
None
- class unofficial_tabdeal_api.MarginClass(*, user_hash, authorization_key, _is_test=False)¶
Bases:
unofficial_tabdeal_api.base.BaseClassThis is the class storing methods related to Margin trading.
- async get_isolated_symbol_details(isolated_symbol)¶
Gets the full details of an isolated symbol from server and returns it as a dictionary.
- async get_margin_all_open_orders()¶
Gets all the open margin orders from server and returns it as a list of dictionaries.
- Returns:
a List of MarginOpenOrderModel items
- Return type:
- Raises:
TypeError – If the response is not a list.
- async get_margin_asset_id(isolated_symbol)¶
Gets the ID of a margin asset from server and returns it as an integer.
- async get_order_break_even_price(asset_id)¶
Gets the price point for an order which Tabdeal says it yields no profit and loss.
- Parameters:
asset_id (int) – Margin asset ID got from get_asset_id() function
- Returns:
The price as Decimal
- Return type:
Decimal
- Raises:
BreakEvenPriceNotFoundError – If no matching order is found.
- async get_margin_pair_id(isolated_symbol)¶
Gets the pair ID for a margin asset from server and returns it as an integer.
- async get_margin_asset_balance(isolated_symbol)¶
Gets the margin asset balance in USDT from server and returns it as Decimal value.
- async get_margin_asset_precision_requirements(isolated_symbol)¶
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.
- async is_margin_asset_trade_able(isolated_symbol)¶
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.
- async open_margin_order(order)¶
Opens a margin order.
- Parameters:
order (MarginOrderModel) – margin order object containing order details
- Raises:
TypeError – If the server response is not a dictionary or does not indicate success.
- Returns:
Order ID of the opened order
- Return type:
- async set_sl_tp_for_margin_order(*, margin_asset_id, stop_loss_price, take_profit_price)¶
Sets the stop loss and take profit points.
- Parameters:
margin_asset_id (int) – Margin Asset ID (7 digits or more)
stop_loss_price (Decimal) – Stop loss price
take_profit_price (Decimal) – Take profit price
- Returns:
None
- Return type:
None
- async does_margin_asset_have_active_order(isolated_symbol)¶
Checks whether the margin asset has an active order or not.
- async is_margin_order_filled(isolated_symbol)¶
Checks whether the isolated symbol’s order is filled or not.
- Parameters:
isolated_symbol (str) – Isolated margin symbol
- Raises:
MarginOrderNotFoundInActiveOrdersError – If the order is not found, we raise an exception
- Returns:
Is margin order filled?
- Return type:
- class unofficial_tabdeal_api.OrderClass(*, user_hash, authorization_key, _is_test=False)¶
Bases:
unofficial_tabdeal_api.base.BaseClassThis is the class storing methods related to Ordering.
- async get_orders_details_history(_max_history=500)¶
Gets the last 500(by default) orders details and returns them as a list.
- class unofficial_tabdeal_api.TabdealClient(*, user_hash, authorization_key, _is_test=False)¶
Bases:
unofficial_tabdeal_api.authorization.AuthorizationClass,unofficial_tabdeal_api.margin.MarginClass,unofficial_tabdeal_api.wallet.WalletClass,unofficial_tabdeal_api.order.OrderClassa client class to communicate with Tabdeal platform.
- async _validate_trade_conditions(order)¶
Validate trade conditions for a margin order.
- Parameters:
order (MarginOrderModel) – The margin order to validate.
- Returns:
True if the trade conditions are valid, False otherwise.
- Return type:
- async _open_order(order)¶
Open a margin order.
- Parameters:
order (MarginOrderModel) – The margin order to open.
- Returns:
None
- Return type:
None
- async _wait_for_order_fill(order)¶
Wait for the margin order to be filled.
- Parameters:
order (MarginOrderModel) – The margin order to wait for.
- Returns:
True if the order is filled, False otherwise.
- Return type:
- async _setup_stop_loss_take_profit(order)¶
Setup stop loss and take profit for a margin order.
- Parameters:
order (MarginOrderModel) – The margin order to setup SL/TP for.
- Returns:
The margin asset ID.
- Return type:
- async _wait_for_order_close(margin_asset_id)¶
Wait for the margin order to close.
- Parameters:
margin_asset_id (int) – The ID of the margin asset to wait for.
- Return type:
None
- async _withdraw_balance_if_requested(order)¶
Withdraw balance from margin asset to wallet if requested.
- Parameters:
order (MarginOrderModel) – The margin order containing the asset symbol.
- Return type:
None
- async trade_margin_order(*, order, withdraw_balance_after_trade)¶
Trade a margin order.
- Parameters:
order (MarginOrderModel) – MarginOrderModel object containing order details.
withdraw_balance_after_trade (bool) – Flag indicating whether to withdraw balance after trade.
- Returns:
Whether the trade was successful or not.
- Return type:
- class unofficial_tabdeal_api.WalletClass(*, user_hash, authorization_key, _is_test=False)¶
Bases:
unofficial_tabdeal_api.base.BaseClassThis is the class storing methods related to account wallet.
- async get_wallet_usdt_balance()¶
Gets the balance of wallet in USDT and returns it as Decimal.
- Returns:
Wallet USDT balance in Decimal
- Return type:
Decimal