Skip to main content

Python SDK for Token Metrics AI API

Project description

Token Metrics AI API Python SDK

PyPI version Python versions License

The official Python SDK for Token Metrics AI API - providing professional investors and traders with comprehensive cryptocurrency analysis, AI-powered trading signals, market data, and advanced insights.

Features

  • Comprehensive Market Data: Access detailed information on thousands of cryptocurrencies
  • AI-Powered Analysis: Get trading and investment grades based on advanced AI models
  • Technical Indicators: Access technical analysis grades and quantitative metrics
  • Price Data: Retrieve historical OHLCV (Open, High, Low, Close, Volume) data
  • Trading Signals: Receive AI-generated long and short trading signals
  • AI Agent: Interact with Token Metrics' AI chatbot for market insights
  • AI Reports: Access detailed technical, fundamental, and trading reports
  • Simple Interface: Intuitive API with Pandas DataFrame integration

Installation

pip install tmai-api

Quick Start

from tmai_api import TokenMetricsClient

# Initialize the client with your API key
client = TokenMetricsClient(api_key="your-api-key")

# Get information for top cryptocurrencies
tokens = client.tokens.get(symbol="BTC,ETH")

# Get short-term trading grades
trader_grades = client.trader_grades.get(
    symbol="BTC,ETH",
    startDate="2023-10-01",
    endDate="2023-10-10"
)

# Get long-term investment grades
investor_grades = client.investor_grades.get(
    symbol="BTC,ETH", 
    startDate="2023-10-01",
    endDate="2023-10-10"
)

# Ask the AI agent a question
answer = client.ai_agent.get_answer_text("What is your analysis of Bitcoin?")

Data Analysis with Pandas

Convert API responses directly to Pandas DataFrames for easy analysis:

# Convert to DataFrame
tokens_df = client.tokens.get_dataframe(symbol="BTC,ETH")
trader_grades_df = client.trader_grades.get_dataframe(symbol="BTC,ETH")

# Analyze with Pandas
import pandas as pd

# Filter for specific tokens
bitcoin_data = trader_grades_df[trader_grades_df['TOKEN_SYMBOL'] == 'BTC']

# Plot grades over time
import matplotlib.pyplot as plt
bitcoin_data.plot(x='DATE', y='TM_TRADER_GRADE', figsize=(10, 6))
plt.title('Bitcoin Trading Grade Trend')
plt.show()

Available Endpoints

Endpoint Description Example
tokens Information about all supported tokens client.tokens.get(symbol="BTC,ETH")
hourly_ohlcv Hourly price and volume data client.hourly_ohlcv.get(symbol="BTC", startDate="2023-10-01", endDate="2023-10-10")
investor_grades Long-term investment ratings client.investor_grades.get(symbol="BTC,ETH", startDate="2023-10-01", endDate="2023-10-10")
trader_grades Short-term trading signals client.trader_grades.get(symbol="BTC,ETH", startDate="2023-10-01", endDate="2023-10-10")
trader_indices AI-generated trading portfolios client.trader_indices.get(startDate="2023-10-01", endDate="2023-10-10")
market_metrics Overall market sentiment data client.market_metrics.get(startDate="2023-10-01", endDate="2023-10-10")
ai_agent Interact with Token Metrics AI chatbot client.ai_agent.ask("What is your Bitcoin forecast?")
ai_reports AI-generated analysis reports client.ai_reports.get(symbol="BTC,ETH")
trading_signals AI-generated trading signals client.trading_signals.get(symbol="BTC,ETH", startDate="2023-10-01", endDate="2023-10-10", signal="1")

Detailed Usage Examples

Working with Trading Signals

# Get bullish trading signals (signal=1) for Bitcoin
signals = client.trading_signals.get_dataframe(
    symbol="BTC", 
    startDate="2023-10-01", 
    endDate="2023-10-10",
    signal="1"  # 1=Bullish, -1=Bearish
)

# Calculate potential returns
print(f"Average signal return: {signals['TRADING_SIGNALS_RETURNS'].mean():.2f}%")
print(f"Average holding return: {signals['HOLDING_RETURNS'].mean():.2f}%")

Getting AI-Generated Reports

# Get comprehensive AI reports for Ethereum
eth_reports = client.ai_reports.get(symbol="ETH")

# Access specific report sections
trader_report = eth_reports['data'][0]['TRADER_REPORT']
tech_report = eth_reports['data'][0]['TECHNOLOGY_REPORT']
fundamental_report = eth_reports['data'][0]['FUNDAMENTAL_REPORT']

print(f"Trading Report Excerpt:\n{trader_report[:200]}...")

Analyzing Market Metrics

# Get market sentiment metrics
metrics = client.market_metrics.get_dataframe(
    startDate="2023-10-01", 
    endDate="2023-10-10"
)

# Analyze Fear & Greed Index trends
plt.figure(figsize=(12, 6))
metrics.plot(x='DATE', y='FEAR_AND_GREED_VALUE', figsize=(10, 6))
plt.title('Crypto Fear & Greed Index')
plt.axhline(y=50, color='r', linestyle='-', alpha=0.3)
plt.show()

Authentication

All API requests require an API key. You can get your API key by signing up at Token Metrics.

# Initialize with your API key
client = TokenMetricsClient(api_key="your-api-key")

Error Handling

The SDK provides built-in error handling for API requests:

try:
    data = client.tokens.get(symbol="INVALID_SYMBOL")
except Exception as e:
    print(f"Error: {e}")
    # Handle the error appropriately

Requirements

  • Python 3.6+
  • requests package
  • pandas package

Documentation

For complete API documentation, visit:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This SDK is distributed under the MIT License. See the LICENSE file for details.


Token Metrics Logo

Empowering investors with AI-powered crypto insights

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tmai_api-0.3.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tmai_api-0.3.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file tmai_api-0.3.0.tar.gz.

File metadata

  • Download URL: tmai_api-0.3.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for tmai_api-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5922ccd2408ccee3e34d4949fc584d9148c992aaef1fe5e209f481418a13e6fd
MD5 50e51ae135815891b54db0b5a2cc0630
BLAKE2b-256 3972da263206bde8c20b30666e5cc1047a883aebd0cb87c74e29ca581878ead4

See more details on using hashes here.

File details

Details for the file tmai_api-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: tmai_api-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for tmai_api-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85b8e4a2056b27521e9919dbc6b47f96c677f79fc508ed9a7d5cb82a5aa13160
MD5 2de3d907644e0102fe6c40a555007348
BLAKE2b-256 38a6525d7ca6daf8105b1eac04cadea06d8dc2c24367a48a9ba3157a75cb2cb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page