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 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.4.0.tar.gz (13.9 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.4.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file tmai-api-0.4.0.tar.gz.

File metadata

  • Download URL: tmai-api-0.4.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for tmai-api-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5ad4bb3e3d7e69fec49c7bd8cee90f74b619232d80023e176fe61f1d5ba8d881
MD5 c8680fd708b97d5e0d5f5c4686dbae3d
BLAKE2b-256 1c62dc0c9559df0557708386d24b89b237883765e545c6dc64fe48ec621770ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tmai_api-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for tmai_api-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a47e7957a55b4e36db14b8f33c7c08792f0c953aaef496b0ef0671938dc0f586
MD5 8f07ba79e86e39977c2599447a7addec
BLAKE2b-256 81864930de500c34e48ba9a8422253e381ffc4860100a9da71bfbb50b36c80a2

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