dxsp.utils.contract_utils.ContractUtils#

class dxsp.utils.contract_utils.ContractUtils(**kwargs)[source]#

Bases: object

Contract Utils used to interact with the dex protocol

Parameters:
  • w3 (Optional[Web3]) – Web3

  • block_explorer_url (Optional[str]) – block_explorer_url

  • block_explorer_api (Optional[str]) – block_explorer_api

Returns:

ContractUtils

get_data()[source]#
search()[source]#
get_cg_platform()[source]#
get_tokenlist_data()[source]#
get_cg_data()[source]#
get_confirmation()[source]#

Initializes an instance of the class.

Parameters:
  • w3 (web3.Web3) – An instance of the web3.py library.

  • block_explorer_url (str) – The URL of the block explorer.

  • block_explorer_api (str) – The API endpoint of the block explorer.

Methods

get_cg_data(token)

Retrieves data for a given token from the CoinGecko API.

get_cg_platform()

Retrieves the platform associated with the current network.

get_confirmation(transaction_hash)

Returns trade confirmation.

get_data([symbol, contract_address])

Get data based on the provided symbol or contract address.

get_tokenlist_data(symbol)

Retrieves token data from a given token list URL based on the provided symbol.

initialize_platform()

Initialize the platform by making an API call to CoinGecko.

search(token)

Asynchronously searches for a token based on the given token parameter.

search_cg_data(token)

Asynchronously searches for CG data using the provided token.

search_tokenlist_data(token)

Asynchronously searches for tokenlist data based on a given token.

initialize_platform()[source]#

Initialize the platform by making an API call to CoinGecko. Call this method when the platform information is actually needed.

async get_data(symbol=None, contract_address=None)[source]#

Get data based on the provided symbol or contract address.

Parameters:
  • symbol (str) – The symbol to search for.

  • contract_address (str) – The contract address of the token.

Returns:

The token object containing the data if contract_address is provided. None: If neither symbol nor contract_address is provided.

Return type:

Token

get_cg_platform()[source]#

Retrieves the platform associated with the current network.

Returns:

The coingecko platform name of the platform associated with the current network, or None if no platform is found.

Return type:

str

Raises:

Exception – If an error occurs while retrieving the platform.

async search(token)[source]#

Asynchronously searches for a token based on the given token parameter.

Parameters:

token (str) – The token to search for.

Returns:

An instance of the Token class representing the found token.

Return type:

Token

Raises:

Exception – If the token is not found.

async search_tokenlist_data(token)[source]#

Asynchronously searches for tokenlist data based on a given token.

Parameters:

token (str) – The token to search for.

Returns:

An instance of the Token class

if the tokenlist data is found, else None. :rtype: Token or None

async get_tokenlist_data(symbol)[source]#

Retrieves token data from a given token list URL based on the provided symbol.

Parameters:

symbol (str) – The symbol of the token to search for.

Returns:

The token data if found, None otherwise.

Return type:

dict or None

async search_cg_data(token)[source]#

Asynchronously searches for CG data using the provided token.

Parameters:

token (Any) – The token to search for.

Returns:

The token instance if found on Coingecko, otherwise None.

Return type:

Optional[Token]

async get_cg_data(token)[source]#

Retrieves data for a given token from the CoinGecko API.

Parameters:

token (str) – The symbol of the token to retrieve data for.

Returns:

The data for the token on the specified platform,

or None if the token is not found or an error occurs.

Return type:

str or None

async get_confirmation(transaction_hash)[source]#

Returns trade confirmation.

Parameters:

transaction_hash (str) – The transaction hash

Returns:

The trade confirmation

Return type:

dict

Raises:

Exception – Error