├── requirements.txt ├── .gitattributes ├── dexscreener ├── __init__.py ├── guard_util.py ├── http_client.py ├── ratelimit.py ├── models.py └── client.py ├── README.md ├── LICENSE ├── setup.py ├── main.py └── .gitignore /requirements.txt: -------------------------------------------------------------------------------- 1 | pydantic>=2.7.1 2 | requests>=2.31.0 3 | aiohttp>=3.9.5 -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /dexscreener/__init__.py: -------------------------------------------------------------------------------- 1 | from .client import DexscreenerClient 2 | from .models import TokenPair 3 | -------------------------------------------------------------------------------- /dexscreener/guard_util.py: -------------------------------------------------------------------------------- 1 | 2 | def ensure_length_is_under(ls: list, max_count: int, message: str): 3 | if len(ls) > max_count: 4 | raise ValueError(message) 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # API Wrapper for [Dexscreener.com](https://docs.dexscreener.com/) 2 | 3 | ###### Pull requests GREATLY encouraged! 4 | 5 | [![Downloads](https://static.pepy.tech/badge/dexscreener/week)](https://pepy.tech/project/dexscreener) 6 | [![Downloads](https://static.pepy.tech/badge/dexscreener/month)](https://pepy.tech/project/dexscreener) 7 | [![Downloads](https://pepy.tech/badge/dexscreener)](https://pepy.tech/project/dexscreener) 8 | 9 | # Quick Start 10 | 11 | ```python 12 | from dexscreener import DexscreenerClient 13 | 14 | client = DexscreenerClient() 15 | 16 | pair = client.get_token_pair("harmony", "0xcd818813f038a4d1a27c84d24d74bbc21551fa83") 17 | 18 | pairs = client.get_token_pairs("0x2170Ed0880ac9A755fd29B2688956BD959F933F8") 19 | 20 | search = client.search_pairs("WBTC") 21 | ``` 22 | -------------------------------------------------------------------------------- /dexscreener/http_client.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from typing import Union 3 | import aiohttp 4 | 5 | from .ratelimit import RateLimiter 6 | 7 | 8 | class HttpClient: 9 | def __init__(self, calls: int, period: int, base_url: str = "https://api.dexscreener.io/latest"): 10 | self._limiter = RateLimiter(calls, period) 11 | self.base_url = base_url 12 | 13 | def _create_absolute_url(self, relative: str) -> str: 14 | return f"{self.base_url}/{relative}" 15 | 16 | def request(self, method, url, **kwargs) -> Union[list, dict]: 17 | url = self._create_absolute_url(url) 18 | 19 | with self._limiter: 20 | r = requests.request(method, url, **kwargs) 21 | 22 | return r.json() 23 | 24 | async def request_async(self, method, url, **kwargs): 25 | url = self._create_absolute_url(url) 26 | 27 | async with self._limiter: 28 | async with aiohttp.ClientSession() as session: 29 | async with session.request(method, url, **kwargs) as response: 30 | return await response.json() 31 | 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Joshua Nixon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import find_packages, setup 2 | 3 | 4 | def read_file(file): 5 | with open(file, "r") as fh: 6 | return fh.read() 7 | 8 | # pip install build twine 9 | # py -m build 10 | # py -m twine upload dist/* 11 | 12 | 13 | setup( 14 | name="dexscreener", 15 | packages=find_packages(), 16 | version="1.3", 17 | license="MIT", 18 | 19 | description="Python wrapper for the 'dexscreener.com' API", 20 | long_description=read_file("README.md"), 21 | long_description_content_type="text/markdown", 22 | 23 | author="Joshua Nixon", 24 | author_email="nixonjoshua98@gmail.com", 25 | 26 | url="https://github.com/nixonjoshua98/dexscreener", 27 | 28 | download_url="https://github.com/nixonjoshua98/dexscreener/releases", 29 | 30 | keywords=[ 31 | "dexscreener", 32 | "crypto", 33 | "cryptocurrency", 34 | "bitcoin" 35 | ], 36 | 37 | install_requires=[ 38 | "requests", 39 | "pydantic", 40 | "certifi", 41 | "aiohttp" 42 | ], 43 | 44 | classifiers=[ 45 | "Programming Language :: Python :: 3", 46 | "License :: OSI Approved :: MIT License", 47 | "Operating System :: OS Independent", 48 | "Development Status :: 5 - Production/Stable", 49 | "Intended Audience :: Developers", 50 | "Topic :: Software Development :: Build Tools", 51 | ], 52 | 53 | python_requires='>=3.9' 54 | ) 55 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | from dexscreener import DexscreenerClient 4 | 5 | 6 | async def main(): 7 | client = DexscreenerClient() 8 | 9 | token_profiles = client.get_latest_token_profiles() 10 | 11 | boosted_tokens = client.get_latest_boosted_tokens() 12 | 13 | most_active_tokens = client.get_tokens_most_active() 14 | 15 | paid_of_orders = client.get_orders_paid_of_token( 16 | "solana", 17 | "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" 18 | ) 19 | 20 | pair = await client.get_token_pair_async( 21 | "harmony", 22 | "0xcd818813f038a4d1a27c84d24d74bbc21551fa83" 23 | ) 24 | 25 | pairs = await client.get_token_pairs_async( 26 | "0x2170Ed0880ac9A755fd29B2688956BD959F933F8" 27 | ) 28 | 29 | pairs = await client.get_token_pair_list_async( 30 | "ethereum", 31 | ( 32 | "0xC2aDdA861F89bBB333c90c492cB837741916A225", 33 | "0x7BeA39867e4169DBe237d55C8242a8f2fcDcc387", 34 | ), 35 | ) 36 | 37 | search = await client.search_pairs_async("WBTC") 38 | 39 | pairs = await client.get_token_pairs_v1_async( 40 | "solana", 41 | "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN" 42 | ) 43 | 44 | search = await client.get_pairs_by_token_addresses_async( 45 | "solana", 46 | ("JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",), 47 | ) 48 | 49 | asyncio.new_event_loop().run_until_complete(main()) 50 | -------------------------------------------------------------------------------- /dexscreener/ratelimit.py: -------------------------------------------------------------------------------- 1 | import time 2 | import threading 3 | import collections 4 | import asyncio 5 | 6 | 7 | class RateLimiter: 8 | def __init__(self, max_calls, period): 9 | self.calls = collections.deque() 10 | 11 | self.period = period 12 | self.max_calls = max_calls 13 | 14 | self.sync_lock = threading.Lock() 15 | self.async_lock = asyncio.Lock() 16 | 17 | def __enter__(self): 18 | with self.sync_lock: 19 | sleep_time = self.get_sleep_time() 20 | 21 | if sleep_time > 0: 22 | time.sleep(sleep_time) 23 | 24 | return self 25 | 26 | def __exit__(self, exc_type, exc_val, exc_tb): 27 | with self.sync_lock: 28 | self._clear_calls() 29 | 30 | async def __aenter__(self): 31 | async with self.async_lock: 32 | sleep_time = self.get_sleep_time() 33 | 34 | if sleep_time > 0: 35 | await asyncio.sleep(sleep_time) 36 | 37 | return self 38 | 39 | async def __aexit__(self, exc_type, exc_val, exc_tb): 40 | async with self.async_lock: 41 | self._clear_calls() 42 | 43 | def get_sleep_time(self) -> float: 44 | if len(self.calls) >= self.max_calls: 45 | until = time.time() + self.period - self._timespan 46 | return until - time.time() 47 | 48 | return 0 49 | 50 | def _clear_calls(self): 51 | self.calls.append(time.time()) 52 | 53 | while self._timespan >= self.period: 54 | self.calls.popleft() 55 | 56 | @property 57 | def _timespan(self): 58 | return self.calls[-1] - self.calls[0] -------------------------------------------------------------------------------- /dexscreener/models.py: -------------------------------------------------------------------------------- 1 | from pydantic import BaseModel, Field 2 | from typing import Optional 3 | import datetime as dt 4 | 5 | 6 | class BaseToken(BaseModel): 7 | address: str 8 | name: str 9 | symbol: str 10 | 11 | 12 | class TransactionCount(BaseModel): 13 | buys: int 14 | sells: int 15 | 16 | 17 | class PairTransactionCounts(BaseModel): 18 | m5: TransactionCount 19 | h1: TransactionCount 20 | h6: TransactionCount 21 | h24: TransactionCount 22 | 23 | 24 | class _TimePeriodsFloat(BaseModel): 25 | m5: Optional[float] = 0.0 26 | h1: Optional[float] = 0.0 27 | h6: Optional[float] = 0.0 28 | h24: Optional[float] = 0.0 29 | 30 | 31 | class VolumeChangePeriods(_TimePeriodsFloat): 32 | ... 33 | 34 | 35 | class PriceChangePeriods(_TimePeriodsFloat): 36 | ... 37 | 38 | 39 | class Liquidity(BaseModel): 40 | usd: Optional[float] = None 41 | base: float 42 | quote: float 43 | 44 | 45 | class TokenPair(BaseModel): 46 | chain_id: str = Field(..., alias="chainId") 47 | dex_id: str = Field(..., alias="dexId") 48 | url: str = Field(...) 49 | pair_address: str = Field(..., alias="pairAddress") 50 | base_token: BaseToken = Field(..., alias="baseToken") 51 | quote_token: BaseToken = Field(..., alias="quoteToken") 52 | price_native: float = Field(..., alias="priceNative") 53 | price_usd: Optional[float] = Field(None, alias="priceUsd") 54 | transactions: PairTransactionCounts = Field(..., alias="txns") 55 | volume: VolumeChangePeriods 56 | price_change: PriceChangePeriods = Field(..., alias="priceChange") 57 | liquidity: Optional[Liquidity] = None 58 | fdv: Optional[float] = 0.0 59 | pair_created_at: Optional[dt.datetime] = Field(None, alias="pairCreatedAt") 60 | 61 | 62 | class TokenLink(BaseModel): 63 | type: Optional[str] = None 64 | label: Optional[str] = None 65 | url: Optional[str] = None 66 | 67 | 68 | class TokenInfo(BaseModel): 69 | url: str 70 | chain_id: str = Field(..., alias="chainId") 71 | token_address: str = Field(..., alias="tokenAddress") 72 | amount: float = 0.0 # Not sure if this is the best logic 73 | total_amount: float = Field(0.0, alias="totalAmount") 74 | icon: Optional[str] = None 75 | header: Optional[str] = None 76 | description: Optional[str] = None 77 | links: list[TokenLink] = [] 78 | 79 | 80 | class OrderInfo(BaseModel): 81 | type: str 82 | status: str 83 | payment_timestamp: int = Field(..., alias="paymentTimestamp") -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | # PyCharm 132 | /.idea 133 | -------------------------------------------------------------------------------- /dexscreener/client.py: -------------------------------------------------------------------------------- 1 | from typing import Iterable, List, Optional 2 | 3 | from .guard_util import ensure_length_is_under 4 | from .http_client import HttpClient 5 | from .models import OrderInfo, TokenInfo, TokenPair 6 | 7 | 8 | class DexscreenerClient: 9 | BASE_URL = "https://api.dexscreener.com" 10 | 11 | def __init__(self) -> None: 12 | self._client_60rpm: HttpClient = HttpClient( 13 | 60, 60, base_url=self.BASE_URL 14 | ) 15 | 16 | self._client_300rpm_root: HttpClient = HttpClient( 17 | 300, 60, base_url=self.BASE_URL 18 | ) 19 | self._client_300rpm: HttpClient = HttpClient( 20 | 300, 60, base_url=f"{self.BASE_URL}/latest" 21 | ) 22 | 23 | def get_latest_token_profiles(self) -> list[TokenInfo]: 24 | """ 25 | Get the latest token profiles 26 | 27 | https://api.dexscreener.com/token-profiles/latest/v1 28 | 29 | :return: 30 | Response as list of TokenInfo model 31 | """ 32 | resp = self._client_60rpm.request("GET", "token-profiles/latest/v1") 33 | return [TokenInfo(**token) for token in resp] 34 | 35 | async def get_latest_token_profiles_async(self) -> list[TokenInfo]: 36 | """ 37 | Async version of `get_latest_token_profiles` 38 | """ 39 | resp = await self._client_60rpm.request_async("GET", "token-profiles/latest/v1") 40 | return [TokenInfo(**token) for token in resp] 41 | 42 | def get_latest_boosted_tokens(self) -> list[TokenInfo]: 43 | """ 44 | Get the latest boosted tokens 45 | 46 | https://api.dexscreener.com/token-boosts/latest/v1 47 | 48 | :return: 49 | Response as list of TokenInfo model 50 | """ 51 | resp = self._client_60rpm.request("GET", "token-boosts/latest/v1") 52 | return [TokenInfo(**token) for token in resp] 53 | 54 | async def get_latest_boosted_tokens_async(self) -> list[TokenInfo]: 55 | """ 56 | Async version of `get_latest_boosted_tokens` 57 | """ 58 | resp = await self._client_60rpm.request_async("GET", "token-boosts/latest/v1") 59 | return [TokenInfo(**token) for token in resp] 60 | 61 | def get_tokens_most_active(self) -> list[TokenInfo]: 62 | """ 63 | Get the tokens with most active boosts 64 | 65 | https://api.dexscreener.com/token-boosts/top/v1 66 | 67 | :return: 68 | Response as list of TokenInfo model 69 | """ 70 | resp = self._client_60rpm.request("GET", "token-boosts/top/v1") 71 | return [TokenInfo(**token) for token in resp] 72 | 73 | async def get_tokens_most_active_async(self) -> list[TokenInfo]: 74 | """ 75 | Async version of `get_tokens_most_active` 76 | """ 77 | resp = await self._client_60rpm.request_async("GET", "token-boosts/top/v1") 78 | 79 | return [TokenInfo(**token) for token in resp] 80 | 81 | def get_orders_paid_of_token(self, chain_id: str, token_address: str) -> list[OrderInfo]: 82 | """ 83 | Check orders paid for of token 84 | 85 | https://api.dexscreener.com/orders/v1/solana/A55XjvzRU4KtR3Lrys8PpLZQvPojPqvnv5bJVHMYy3Jv 86 | 87 | :return: 88 | Response as list of OrderInfo model 89 | """ 90 | resp = self._client_60rpm.request("GET", f"orders/v1/{chain_id}/{token_address}") 91 | 92 | return [OrderInfo(**order) for order in resp] 93 | 94 | async def get_orders_paid_of_token_async(self, chain_id: str, token_address: str) -> list[OrderInfo]: 95 | """ 96 | Async version of `get_orders_paid_of_token` 97 | """ 98 | resp = await self._client_60rpm.request_async("GET", f"orders/v1/{chain_id}/{token_address}") 99 | 100 | return [OrderInfo(**order) for order in resp] 101 | 102 | def get_token_pair(self, chain: str, address: str) -> Optional[TokenPair]: 103 | """ 104 | Fetch a pair on the provided chain id 105 | 106 | https://api.dexscreener.com/latest/dex/pairs/bsc/0x7213a321F1855CF1779f42c0CD85d3D95291D34C 107 | 108 | :param chain: Chain id 109 | :param address: Token address 110 | :return: 111 | Response as TokenPair model 112 | """ 113 | resp = self._client_300rpm.request("GET", f"dex/pairs/{chain}/{address}") 114 | 115 | return TokenPair(**resp["pair"]) if resp["pair"] else None 116 | 117 | async def get_token_pair_async(self, chain: str, address: str) -> Optional[TokenPair]: 118 | """ 119 | Async version of `get_token_pair` 120 | """ 121 | resp = await self._client_300rpm.request_async("GET", f"dex/pairs/{chain}/{address}") 122 | 123 | return TokenPair(**resp["pair"]) if resp["pair"] else None 124 | 125 | def get_token_pair_list(self, chain: str, addresses: Iterable[str]) -> List[TokenPair]: 126 | """ 127 | Fetch multiple pairs on the provided chain id 128 | 129 | https://api.dexscreener.com/latest/dex/pairs/ethereum/0xC2aDdA861F89bBB333c90c492cB837741916A225,0x7BeA39867e4169DBe237d55C8242a8f2fcDcc387 130 | 131 | :param chain: Chain id 132 | :param addresses: Iterable of token addresses (up to 30) 133 | :return: 134 | Response as list of TokenPair models 135 | """ 136 | addresses_list = list(addresses) 137 | 138 | ensure_length_is_under(addresses_list, 30, "The maximum number of addresses allowed is 30.") 139 | 140 | resp = self._client_300rpm.request( 141 | "GET", 142 | f"dex/pairs/{chain}/{','.join(addresses_list)}") 143 | 144 | return [TokenPair(**pair) for pair in resp.get("pairs", [])] 145 | 146 | async def get_token_pair_list_async(self, chain: str, addresses: Iterable[str]) -> List[TokenPair]: 147 | """ 148 | Async version of `get_token_pairs` 149 | """ 150 | addresses_list = list(addresses) 151 | 152 | ensure_length_is_under(addresses_list, 30, "The maximum number of addresses allowed is 30.") 153 | 154 | resp = await self._client_300rpm.request_async( 155 | "GET", 156 | f"dex/pairs/{chain}/{','.join(addresses_list)}") 157 | 158 | return [TokenPair(**pair) for pair in resp.get("pairs", [])] 159 | 160 | def get_token_pairs(self, address: str) -> list[TokenPair]: 161 | """ 162 | Get pairs matching base token address 163 | 164 | https://api.dexscreener.com/latest/dex/tokens/0x2170Ed0880ac9A755fd29B2688956BD959F933F8 165 | 166 | :param address: Token address 167 | :return: 168 | Response as list of TokenPair model 169 | """ 170 | resp = self._client_300rpm.request("GET", f"dex/tokens/{address}") 171 | 172 | return [TokenPair(**pair) for pair in resp.get("pairs", [])] 173 | 174 | async def get_token_pairs_async(self, address: str) -> list[TokenPair]: 175 | """ 176 | Async version of `get_token_pairs` 177 | """ 178 | resp = await self._client_300rpm.request_async("GET", f"dex/tokens/{address}") 179 | 180 | return [TokenPair(**pair) for pair in resp.get("pairs", [])] 181 | 182 | def search_pairs(self, search_query: str) -> list[TokenPair]: 183 | """ 184 | Search for pairs matching query 185 | 186 | https://api.dexscreener.com/latest/dex/tokens/0x2170Ed0880ac9A755fd29B2688956BD959F933F8 187 | 188 | :param search_query: query (e.g.: WBTC or WBTC/USDC) 189 | :return: 190 | Response as list of TokenPair model 191 | """ 192 | resp = self._client_300rpm.request("GET", f"dex/search/?q={search_query}") 193 | 194 | return [TokenPair(**pair) for pair in resp.get("pairs", [])] 195 | 196 | async def search_pairs_async(self, search_query: str) -> list[TokenPair]: 197 | """ 198 | Async version of `search_pairs` 199 | """ 200 | resp = await self._client_300rpm.request_async("GET", f"dex/search/?q={search_query}") 201 | 202 | return [TokenPair(**pair) for pair in resp.get("pairs", [])] 203 | 204 | def get_pairs_by_token_addresses( 205 | self, chain_id: str, token_list: Iterable[str] 206 | ) -> list[TokenPair]: 207 | """ 208 | Get token information for multiple tokens by chain and addresses 209 | 210 | :param chain_id: Chain id eg: solana 211 | :param token_list: Iterable of token addresses (up to 30) eg: [0x2170Ed0880ac9A755fd29B2688956BD959F933F8, 0x7BeA39867e4169DBe237d55C8242a8f2fcDcc387] 212 | :return: 213 | Response as list of TokenPair model 214 | """ 215 | token_list_list = list(token_list) 216 | 217 | ensure_length_is_under(token_list_list, 30, "The maximum number of addresses allowed is 30.") 218 | 219 | csv_addresses = ",".join(token_list_list) 220 | 221 | resp = self._client_300rpm_root.request( 222 | "GET", f"tokens/v1/{chain_id}/{csv_addresses}" 223 | ) 224 | 225 | return [TokenPair(**pair) for pair in resp] 226 | 227 | async def get_pairs_by_token_addresses_async( 228 | self, chain_id: str, token_list: Iterable[str] 229 | ) -> list[TokenPair]: 230 | """ 231 | Async version of `get_pairs_by_token_addresses` 232 | 233 | :param chain_id: Chain id eg: solana 234 | :param token_list: Iterable of token addresses (up to 30) eg: [0x2170Ed0880ac9A755fd29B2688956BD959F933F8, 0x7BeA39867e4169DBe237d55C8242a8f2fcDcc387] 235 | :return: 236 | Response as list of TokenPair model 237 | """ 238 | token_list_list = list(token_list) 239 | 240 | ensure_length_is_under(token_list_list, 30, "The maximum number of addresses allowed is 30.") 241 | 242 | csv_addresses = ",".join(token_list_list) 243 | 244 | resp = await self._client_300rpm_root.request_async( 245 | "GET", f"tokens/v1/{chain_id}/{csv_addresses}" 246 | ) 247 | 248 | return [TokenPair(**pair) for pair in resp] 249 | 250 | def get_token_pairs_v1(self, chain_id: str, token_address: str) -> list[TokenPair]: 251 | """ 252 | Get token pairs by token address 253 | 254 | https://api.dexscreener.com/token-pairs/v1/{chainId}/{tokenAddress} 255 | 256 | :param chain_id: Chain id eg: solana 257 | :param token_address: Token address eg: JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN 258 | :return: 259 | Response as list of TokenPair model 260 | """ 261 | resp = self._client_300rpm_root.request( 262 | "GET", f"token-pairs/v1/{chain_id}/{token_address}" 263 | ) 264 | 265 | return [TokenPair(**pair) for pair in resp] 266 | 267 | async def get_token_pairs_v1_async( 268 | self, chain_id: str, token_address: str 269 | ) -> list[TokenPair]: 270 | """ 271 | Async version of `get_token_pairs_v1` 272 | """ 273 | resp = await self._client_300rpm_root.request_async( 274 | "GET", f"token-pairs/v1/{chain_id}/{token_address}" 275 | ) 276 | 277 | return [TokenPair(**pair) for pair in resp] 278 | --------------------------------------------------------------------------------