![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
![]() |
|
この包括的なガイドでは、Python を使用した Telegram ボットの作成に着手し、ユーザーにリアルタイムの暗号更新を提供します。この細心の注意を払って作成されたボットは、選択した暗号通貨の最新価格だけでなく、豊富な追加データも提供します。このガイドを詳しく読んで、24 時間の価格変動、時価総額、取引量、過去の仮想通貨価格データなどの重要な市場指標をどのように取得して表示するかを調べてください。この重要な情報をすぐに利用できるため、自信を持って暗号通貨の領域をナビゲートし、十分な情報に基づいた意思決定を行うことができます。
Building a Crypto Telegram Bot with Real-Time Price Updates Utilizing Python
Python を使用したリアルタイムの価格更新を備えた暗号電報ボットの構築
In the rapidly evolving world of cryptocurrencies, staying abreast of market fluctuations and asset performance is paramount. To address this need, we present a comprehensive guide on constructing a Telegram bot that empowers users with real-time cryptocurrency updates. This bot not only provides instant access to current prices but also offers a wealth of additional information, such as market capitalization, trading volume, and historical price data.
急速に進化する仮想通貨の世界では、市場の変動と資産パフォーマンスに遅れをとらないことが最も重要です。このニーズに対処するために、ユーザーにリアルタイムの暗号通貨更新を提供する Telegram ボットの構築に関する包括的なガイドを提供します。このボットは、現在の価格に即座にアクセスできるだけでなく、時価総額、取引高、過去の価格データなどの豊富な追加情報も提供します。
Functionality Overview
機能の概要
Our Telegram Crypto Bot boasts an array of features designed to provide a comprehensive and real-time overview of the crypto market:
当社の Telegram Crypto Bot は、仮想通貨市場の包括的かつリアルタイムの概要を提供するように設計された一連の機能を備えています。
- Real-Time Crypto Market Data Retrieval: The bot seamlessly fetches and displays real-time market data for various cryptocurrencies, including current price, market cap, volume, and price change percentage.
- 24h High/Low Prices: Users can access the highest and lowest prices of a specific cryptocurrency over the past 24 hours, a crucial piece of information for active traders and investors.
- Supply Information: The bot retrieves and presents the circulating supply and total supply of a selected cryptocurrency, offering insights into its scarcity.
- Top Cryptocurrencies: To provide a quick overview of the leading cryptocurrencies, the bot displays the top 10 coins based on market cap.
- On-Chain DEX Pool Data: This advanced feature enables users to explore on-chain Decentralized Exchange (DEX) crypto liquidity pools, providing valuable insights into the DEX market.
Prerequisites
リアルタイムの暗号通貨市場データ取得: ボットは、現在の価格、時価総額、出来高、価格変動率など、さまざまな暗号通貨のリアルタイム市場データをシームレスに取得して表示します。24 時間の高値/安値: ユーザーは最高値と最低値にアクセスできます。過去 24 時間の特定の暗号通貨の価格。アクティブなトレーダーや投資家にとって重要な情報です。供給情報: ボットは、選択した暗号通貨の流通供給量と総供給量を取得して表示し、その希少性についての洞察を提供します。トップ暗号通貨:主要な暗号通貨の概要を簡単に提供するために、ボットは時価総額に基づいて上位 10 コインを表示します。オンチェーン DEX プール データ: この高度な機能により、ユーザーはオンチェーンの分散型取引所 (DEX) 暗号流動性プールを探索でき、貴重な情報を提供できます。 DEX 市場に関する洞察。前提条件
Before embarking on this project, ensure that the following prerequisites are met:
このプロジェクトに着手する前に、次の前提条件が満たされていることを確認してください。
- Python 3.7 or higher installed on your system. Python is a versatile and beginner-friendly programming language that will serve as the foundation for our bot.
- Telegram account. Telegram is a cloud-based instant messaging platform where our bot will reside.
- Basic understanding of Python programming. While this guide will provide in-depth instructions, a foundational understanding of Python syntax and concepts will enhance your experience.
- Text editor: Choose a text editor or Integrated Development Environment (IDE) of your choice, such as Visual Studio Code, Sublime Text, or Atom, to write your code.
- CoinGecko API: We will leverage the CoinGecko API to fetch the necessary crypto market data. CoinGecko offers a free Demo plan, providing 30 calls per minute and a monthly cap of 10,000 calls. Register for a CoinGecko account and apply for the Demo plan to obtain your API key.
Step 1: Telegram Bot Setup
Python 3.7 以降がシステムにインストールされていること。 Python は多用途で初心者に優しいプログラミング言語であり、bot.Telegram アカウントの基盤として機能します。 Telegram は、ボットが常駐するクラウドベースのインスタント メッセージング プラットフォームです。Python プログラミングの基本的な理解。このガイドでは詳細な手順が提供されますが、Python の構文と概念を基礎的に理解することで、エクスペリエンスが向上します。テキスト エディター: Visual Studio Code、Sublime Text、 CoinGecko API: CoinGecko API を活用して、必要な暗号市場データを取得します。 CoinGecko は、1 分あたり 30 件の通話と月間 10,000 件の通話の上限を提供する無料のデモ プランを提供しています。 CoinGecko アカウントに登録し、デモ プランに申請して API キーを取得します。ステップ 1: Telegram Bot のセットアップ
- Create a new bot on Telegram by searching for 'BotFather' and following the prompts. Provide a name and username for your bot.
- Upon successful creation, you will receive a token, which serves as your bot's authentication key for Telegram API requests.
Step 2: Installing Python Libraries
Telegram で「BotFather」を検索し、プロンプトに従って新しいボットを作成します。ボットの名前とユーザー名を指定します。作成が成功すると、Telegram API リクエストに対するボットの認証キーとして機能するトークンを受け取ります。ステップ 2: Python ライブラリのインストール
We will utilize two essential Python libraries:
2 つの重要な Python ライブラリを利用します。
python-telegram-bot
: This library facilitates interaction with the Telegram API.requests
: This library empowers HTTP requests to the CoinGecko API.
Install these libraries using pip:
python-telegram-bot: このライブラリは、Telegram API との対話を容易にします。requests: このライブラリは、CoinGecko API への HTTP リクエストを可能にします。pip を使用してこれらのライブラリをインストールします。
pip install python-telegram-bot requests
Step 3: Fetching Cryptocurrency Data
pip install python-telegram-botrequestsステップ 3: 暗号通貨データの取得
To access cryptocurrency data, we will employ the CoinGecko API, which provides comprehensive market insights beyond price information.
暗号通貨データにアクセスするには、価格情報を超えた包括的な市場洞察を提供する CoinGecko API を使用します。
Step 4: Writing the Bot Code
ステップ 4: ボット コードを作成する
Now that our bot is set up and the libraries are installed, let's delve into the Python code:
ボットがセットアップされ、ライブラリがインストールされたので、Python コードを詳しく見てみましょう。
# Import necessary libraries# 必要なライブラリをインポートする
import telebotテレボットをインポートする
from telebot import typesTelebot インポート タイプから
import requestsインポートリクエスト
# Define your CoinGecko API key# CoinGecko API キーを定義します
cg_api_key = "YOUR_API_KEY_HERE"cg_api_key = "YOUR_API_KEY_HERE"
# Define the main bot object# メインのボットオブジェクトを定義する
bot = telebot.TeleBot(cg_api_key)ボット = テレボット.TeleBot(cg_api_key);
# Define command handlers# コマンドハンドラーを定義する
@bot.message_handler(commands=['start'])@bot.message_handler(commands=['start'])
def start(message):def start(メッセージ):
# Welcome message# ウェルカムメッセージ
bot.send_message(message.chat.id, "Welcome to the Crypto Telegram Bot! Type /help for a list of commands.")bot.send_message(message.chat.id, "Crypto Telegram ボットへようこそ! /help と入力するとコマンドのリストが表示されます。")
@bot.message_handler(commands=['help'])@bot.message_handler(コマンド=['ヘルプ'])
def help(message):デフォルトヘルプ(メッセージ):
# Help message# ヘルプメッセージ
bot.send_message(message.chat.id, "Available commands:\n/data [crypto-name]: Get current data for a specific cryptocurrency.\n/high_low [crypto-name]: Get highest and lowest prices of a specific cryptocurrency in the last 24 hours.\n/supply [crypto-name]: Get circulating and total supply of a specific cryptocurrency.\n/ranks: Get the top 10 cryptocurrencies.\n/search_pools [query] [network] [attributes]: Get on-chain DEX pool data.")bot.send_message(message.chat.id, "利用可能なコマンド:\n/data [crypto-name]: 特定の暗号通貨の現在のデータを取得します。\n/high_low [crypto-name]: 特定の暗号通貨の最高値と最低価格を取得します過去 24 時間の暗号通貨。\n/supply [crypto-name]: 特定の暗号通貨の流通量と総供給量を取得します。\n/ranks: 上位 10 個の暗号通貨を取得します。\n/search_pools [クエリ] [ネットワーク] [属性]: オンチェーン DEX プール データを取得します。")
@bot.message_handler(commands=['data'])@bot.message_handler(commands=['data'])
def data(message):デフォルトデータ(メッセージ):
# Get current data for a specific cryptocurrency# 特定の暗号通貨の現在のデータを取得する
crypto_name = message.text.split()[1]crypto_name = message.text.split()[1]
data = get_crypto_data(crypto_name)データ = get_crypto_data(crypto_name)
if data:データの場合:
# Send the data to the user# データをユーザーに送信する
bot.send_message(message.chat.id, f"Current data for {crypto_name}:\nPrice: {data['current_price']} USD\nPrice Change (24h): {data['price_change_percentage_24h']}\nMarket Cap: {data['market_cap']} USD\nVolume (24h): {data['total_volume']} USD")bot.send_message(message.chat.id, f"{crypto_name} の現在のデータ:\n価格: {data['current_price']} USD\n価格変動 (24 時間): {data['price_change_percentage_24h']}\n時価総額: {data['market_cap']} 米ドル\n出来高 (24 時間): {data['total_volume']} 米ドル")
else:それ以外:
# Handle errors# エラーを処理する
bot.send_message(message.chat.id, "Invalid cryptocurrency name. Please try again.")bot.send_message(message.chat.id, "暗号通貨名が無効です。もう一度お試しください。")
@bot.message_handler(commands=['high_low'])@bot.message_handler(commands=['high_low'])
def high_low(message):def high_low(メッセージ):
# Get highest and lowest prices of a specific cryptocurrency in the last 24 hours# 過去 24 時間の特定の暗号通貨の最高価格と最低価格を取得します
crypto_name = message.text.split()[1]crypto_name = message.text.split()[1]
data = get_high_low(crypto_name)データ = get_high_low(crypto_name)
if data:データの場合:
# Send the data to the user# データをユーザーに送信する
bot.send_message(message.chat.id, f"Highest and lowest prices of {crypto_name} in the last 24 hours:\nHighest Price: {data['high']} USD\nLowest Price: {data['low']} USD")bot.send_message(message.chat.id, f"過去 24 時間の {crypto_name} の最高価格と最低価格:\n最高価格: {data['high']} USD\n最低価格: {data['low'] } 米ドル")
else:それ以外:
# Handle errors# エラーを処理する
bot.send_message(message.chat.id, "Invalid cryptocurrency name. Please try again.")bot.send_message(message.chat.id, "暗号通貨名が無効です。もう一度お試しください。")
@bot.message_handler(commands=['supply'])@bot.message_handler(コマンド=['供給'])
def supply(message):デフォルトの供給(メッセージ):
# Get circulating and total supply of a specific cryptocurrency# 特定の暗号通貨の流通量と総供給量を取得する
crypto_name = message.text.split()[1]crypto_name = message.text.split()[1]
data = get_supply(crypto_name)データ = get_supply(crypto_name)
if data:データの場合:
# Send the data to the user# データをユーザーに送信する
bot.send_message(message.chat.id, f"Supply data for {crypto_name}:\nCirculating Supply: {data['circulating_supply']}\nTotal Supply: {data['total_supply']}")bot.send_message(message.chat.id, f"{crypto_name} の供給データ:\n循環供給量: {data['circulated_supply']}\n総供給量: {data['total_supply']}")
else:それ以外:
# Handle errors# エラーを処理する
bot.send_message(message.chat.id, "Invalid cryptocurrency name. Please try again.")bot.send_message(message.chat.id, "暗号通貨名が無効です。もう一度お試しください。")
@bot.message_handler(commands=['ranks'])@bot.message_handler(commands=['ranks'])
def ranks(message):デフォルトランク(メッセージ):
# Get the top 10 cryptocurrencies# トップ 10 の暗号通貨を取得する
data = get_top_cryptos()データ = get_top_cryptos()
if data:データの場合:
# Send the data to the user# データをユーザーに送信する
top_10 = "\n".join([f"{i + 1}. {crypto['name']}" for i, crypto in enumerate(data)])top_10 = "\n".join([f"{i + 1}. {crypto['name']}" for i, crypto in enumerate(data)])
bot.send_message(message.chat.id, f"Top 10 Cryptocurrencies by Market Cap:\n{top_10}")bot.send_message(message.chat.id, f"時価総額別トップ 10 暗号通貨:\n{top_10}")
else:それ以外:
# Handle errors# エラーを処理する
bot.send_message(message.chat.id, "Unable to fetch the top 10 cryptocurrencies. Please try again later.")bot.send_message(message.chat.id, "上位 10 位の暗号通貨を取得できませんでした。後でもう一度お試しください。")
# Define functions to get data from CoinGecko API# CoinGecko API からデータを取得する関数を定義する
def get_crypto_data(crypto_name):def get_crypto_data(crypto_name):
# Get current data for a specific cryptocurrency# 特定の暗号通貨の現在のデータを取得する
response = requests.get("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=" + crypto_name)応答 = request.get("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=" + crypto_name)
if response.status_code == 200:response.status_code == 200の場合:
return response.json()[0]応答.json()[0]を返す
else:それ以外:
return Noneなしを返す
def get_high_low(crypto_name):def get_high_low(crypto_name):
# Get highest and lowest prices of a specific cryptocurrency in the last 24 hours# 過去 24 時間の特定の暗号通貨の最高価格と最低価格を取得します
response = requests.get("https://api.coingecko.com/api/v3/coins/" + crypto_name + "/ohlc?vs_currency=usd&days=1")応答 = request.get("https://api.coingecko.com/api/v3/coins/" + crypto_name + "/ohlc?vs_currency=usd&days=1")
if response.status_code == 200:response.status_code == 200の場合:
return response.json()[-1]応答.json()[-1]を返す
else:それ以外:
return Noneなしを返す
def get_supply(crypto_name):def get_supply(crypto_name):
# Get circulating and total supply of a specific cryptocurrency# 特定の暗号通貨の流通量と総供給量を取得する
response = requests.get("https://api.coingecko.com/api/v3/coins/" + crypto_name + "/market_chart?vs_currency=usd&days=1")応答 = request.get("https://api.coingecko.com/api/v3/coins/" + crypto_name + "/market_chart?vs_currency=usd&days=1")
if response.status_code == 200:response.status_code == 200の場合:
return response.json()['total_supply_and_circulating_supply']return response.json()['total_supply_and_circulated_supply']
else:それ以外:
return Noneなしを返す
def get_top_cryptos():def get_top_cryptos():
# Get the top 10 cryptocurrencies# トップ 10 の暗号通貨を取得する
response = requests.get("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=10")
応答 = request.get("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=10")
免責事項:info@kdj.com
提供される情報は取引に関するアドバイスではありません。 kdj.com は、この記事で提供される情報に基づいて行われた投資に対して一切の責任を負いません。暗号通貨は変動性が高いため、十分な調査を行った上で慎重に投資することを強くお勧めします。
このウェブサイトで使用されているコンテンツが著作権を侵害していると思われる場合は、直ちに当社 (info@kdj.com) までご連絡ください。速やかに削除させていただきます。