unofficial_tabdeal_api.margin

This module holds the MarginClass.

Classes

MarginClass

This is the class storing methods related to Margin trading.

Module Contents

class unofficial_tabdeal_api.margin.MarginClass(*, user_hash, authorization_key, _is_test=False)

Bases: unofficial_tabdeal_api.base.BaseClass

This is the class storing methods related to Margin trading.

Parameters:
  • user_hash (str)

  • authorization_key (str)

  • _is_test (bool)

async get_isolated_symbol_details(isolated_symbol)

Gets the full details of an isolated symbol from server and returns it as a dictionary.

Parameters:
  • isolated_symbol (str) – Isolated symbol of margin asset.

  • example – BTCUSDT, MANAUSDT, BOMEUSDT, …

Returns:

A model containing isolated symbol details

Return type:

IsolatedSymbolDetailsModel

Raises:

TypeError – If the response is not a dictionary or the response can’t be validated.

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:

list[MarginOpenOrderModel]

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.

Parameters:

isolated_symbol (str) – Isolated symbol of margin asset. example: BTCUSDT, MANAUSDT, BOMEUSDT, …

Returns:

Margin asset ID as integer

Return type:

int

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.

Parameters:
  • isolated_symbol (str) – Isolated symbol of margin asset.

  • example – BTCUSDT, MANAUSDT, BOMEUSDT, …

Returns:

Margin pair ID as integer

Return type:

int

Raises:

TypeError – If the response is not a dictionary.

async get_margin_asset_balance(isolated_symbol)

Gets the margin asset balance in USDT from server and returns it as Decimal value.

Parameters:

isolated_symbol (str) – Isolated symbol of margin asset

Returns:

Asset balance in USDT as Decimal

Return type:

Decimal

Raises:

TypeError – If the response is not a dictionary.

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.

Parameters:

isolated_symbol (str) – Isolated symbol of margin asset

Returns:

A Tuple containing precision requirements for (1)volume and (2)price

Return type:

tuple[int, int]

Raises:

TypeError – If the response is not a dictionary.

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.

Parameters:

isolated_symbol (str) – Isolated symbol of margin asset

Returns:

Is margin asset trade-able?

Return type:

bool

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:

int

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.

Parameters:

isolated_symbol (str) – Isolated symbol of margin asset

Returns:

True if there is an active order, else False

Return type:

bool

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:

bool