Download leveraged token data from TLX Fi
Install PyTLX using pip:
pip install pytlx
import pytlx as tlx
# Initialize a token by its ticker
token = tlx.Token("BTC5L")
# Fetch historical data for the token
data = token.history()
print(data)
The Token
class provides a Python interface for interacting with the TLX platform, fetching token data, contract information, and historical prices.
- Parameters:
ticker
(str): The token's identifier (e.g.,BTC5L
).
- Description:
Initializes the
Token
object for fetching leveraged token data.
- Description: Fetches all leveraged token contract addresses and related metadata from the smart contract on the Optimism blockchain.
- Returns:
A list of dictionaries containing contract address data:
addr
(str): Contract address.symbol
(str): Token symbol.- Other metadata fields as provided by the contract.
- Description: Retrieves the specific contract address associated with the initialized token's ticker.
- Returns:
str
: Contract address if the ticker is found.None
: If the ticker does not exist in the metadata.
-
Description: Fetches historical price data for the token using the TLX API.
-
Parameters:
granularity
(str): Data interval (e.g.,1d
,6h
).start
(str): Start date inYYYY-MM-DD
format (default:"1900-01-01"
).
-
Returns: A
pandas.DataFrame
with the following columns:Date
: The timestamp of the data point (index).Price
: The historical price of the token.
-
Raises:
ValueError
: If the ticker is invalid.HTTPError
: If the API call fails.
- Description: Retrieves all contract addresses and metadata for leveraged tokens by interacting with the Optimism smart contract.
- Returns:
A list of dictionaries with details:
addr
(str): Token contract address.symbol
(str): Token ticker.- Additional metadata like
totalSupply
,targetLeverage
, andisActive
.