dxsp.utils.contract_utils.ContractUtils#
- class dxsp.utils.contract_utils.ContractUtils(**kwargs)[source]#
Bases:
objectContract 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
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.
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 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:
- 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:
- 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]