unofficial_tabdeal_api.utils

This module holds the utility functions needed by the TabdealClient class.

Functions

normalize_decimal(input_decimal)

Normalizes the fractions of a decimal value.

process_server_response(response)

Processes the raw response from server and converts it into python objects.

calculate_order_volume(*, asset_balance, order_price, ...)

Calculates the order volume based on the asset balance and order price.

calculate_usdt(*, variable_one, variable_two, operation)

Calculates the USDT value based on the operation.

isolated_symbol_to_tabdeal_symbol(isolated_symbol)

Converts the isolated symbol to Tabdeal symbol.

calculate_sl_tp_prices(*, margin_level, order_side, ...)

Calculates the Stop Loss and Take Profit price points.

find_order_by_id(*, orders_list, order_id)

Finds an order by its ID in the list of orders.

Module Contents

unofficial_tabdeal_api.utils.normalize_decimal(input_decimal)

Normalizes the fractions of a decimal value.

Removes excess trailing zeros and exponents

Parameters:

input_decimal (Decimal) – Input decimal

Returns:

Normalized decimal

Return type:

Decimal

async unofficial_tabdeal_api.utils.process_server_response(response)

Processes the raw response from server and converts it into python objects.

Parameters:

response (ClientResponse | str) – Response from server or a string

Returns:

a Dictionary or a list of dictionaries

Return type:

dict[str, Any] | list[dict[str, Any]]

unofficial_tabdeal_api.utils.calculate_order_volume(*, asset_balance, order_price, volume_fraction_allowed, required_precision=0, order_side)

Calculates the order volume based on the asset balance and order price.

Parameters:
  • asset_balance (Decimal) – Balance available in asset

  • order_price (Decimal) – Price of the order

  • volume_fraction_allowed (bool) – If volume fraction is allowed

  • required_precision (int) – Required precision for the order volume. Defaults to 0.

  • order_side (OrderSide) – Side of the order (BUY or SELL)

Returns:

Calculated order volume

Return type:

Decimal

unofficial_tabdeal_api.utils.calculate_usdt(*, variable_one, variable_two, operation)

Calculates the USDT value based on the operation.

Parameters:
  • variable_one (Decimal) – First variable

  • variable_two (Decimal) – Second variable

  • operation (MathOperation) – Math operation to perform

Returns:

Calculated USDT value

Return type:

Decimal

unofficial_tabdeal_api.utils.isolated_symbol_to_tabdeal_symbol(isolated_symbol)

Converts the isolated symbol to Tabdeal symbol.

Parameters:

isolated_symbol (str) – Isolated symbol

Returns:

Tabdeal symbol

Return type:

str

unofficial_tabdeal_api.utils.calculate_sl_tp_prices(*, margin_level, order_side, break_even_point, stop_loss_percent, take_profit_percent, price_required_precision, price_fraction_allowed)

Calculates the Stop Loss and Take Profit price points.

Parameters:
  • margin_level (Decimal) – Margin level of the order

  • order_side (OrderSide) – Side of the order

  • break_even_point (Decimal) – Price that yields no loss and no profit

  • stop_loss_percent (Decimal) – Percent of tolerate-able loss

  • take_profit_percent (Decimal) – Expected percent of profit

  • price_required_precision (int) – Required amount of precision for price by server

  • price_fraction_allowed (bool) – Is fractions allowed for price?

Returns:

a Tuple containing Stop Loss and Take Profit

Return type:

tuple[Decimal, Decimal]

unofficial_tabdeal_api.utils.find_order_by_id(*, orders_list, order_id)

Finds an order by its ID in the list of orders.

Parameters:
  • orders_list (list[dict[str, Any]]) – List of orders

  • order_id (str | int) – ID of the order to find

Returns:

The found order or None if not found

Return type:

dict[str, Any] | None