This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@bot.message_handler(func=greeting) | |
def send_message(message): | |
bot.send_message(message.chat.id, "Hey! Glad to see your. I am Bitquery Updated Coin Price Bot. Please type GET PRICE to see the latest Ethereum blockchain price.") | |
@bot.message_handler(func=updated_price) | |
def send_updated_price(message): | |
bot.send_message(message.chat.id, str(quotePrice)) | |
@bot.message_handler(func=thanks) | |
def send_thank_you(message): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bot.polling() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
baseCurrency: {is: "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82"} | |
quoteCurrency: {is: "0x55d398326f99059ff775485246999027b3197955"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
import os | |
import requests | |
import random | |
client = discord.Client() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BITQUERY_API_KEY = os.getenv('BITQUERY_API_KEY') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TOKEN=YOUR_BOT'S_SECRET_TOKEN_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BITQUERY_API_KEY=YOUR_PERSONAL_BITQUERY_GRAPHQL_API_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The GraphQL query | |
query = """ | |
{ | |
ethereum(network: bsc) { | |
dexTrades( | |
baseCurrency: {is: "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82"} | |
quoteCurrency: {is: "0x55d398326f99059ff775485246999027b3197955"} | |
options: {desc: ["block.height", "transaction.index"], limit: 1} | |
) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_query(query): | |
headers = {'X-API-KEY': BITQUERY_API_KEY} | |
request = requests.post('https://graphql.bitquery.io/', | |
json={'query': query}, headers=headers) | |
if request.status_code == 200: | |
return request.json() | |
else: | |
raise Exception('Query failed and return code is {}. {}'.format(request.status_code, | |
query)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result = run_query(query) # Execute the query | |
quotePrice = result.get('data').get('ethereum').get('dexTrades')[0].get('quotePrice') |