Skip to content

Instantly share code, notes, and snippets.

@sayon-bitquery
sayon-bitquery / main.py
Created June 10, 2021 15:23
Telegram bot message handlers
@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):
@sayon-bitquery
sayon-bitquery / main.py
Created June 10, 2021 15:24
Function which makes the Telegram bot run
bot.polling()
baseCurrency: {is: "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82"}
quoteCurrency: {is: "0x55d398326f99059ff775485246999027b3197955"}
@sayon-bitquery
sayon-bitquery / main.py
Created June 11, 2021 19:04
discord-bot: Importing the libraries
import discord
import os
import requests
import random
client = discord.Client()
@sayon-bitquery
sayon-bitquery / main.py
Created June 11, 2021 19:05
discord-bot: Creating an instance of the discord bot
BITQUERY_API_KEY = os.getenv('BITQUERY_API_KEY')
@sayon-bitquery
sayon-bitquery / .env
Created June 12, 2021 07:04
discord-bot: environment variable file
TOKEN=YOUR_BOT'S_SECRET_TOKEN_KEY
@sayon-bitquery
sayon-bitquery / .env
Created June 12, 2021 07:10
discord-bot: adding Bitquery GraphQL API key token
BITQUERY_API_KEY=YOUR_PERSONAL_BITQUERY_GRAPHQL_API_KEY
@sayon-bitquery
sayon-bitquery / main.py
Created June 12, 2021 07:15
discord-bot: The graphQL query
# The GraphQL query
query = """
{
ethereum(network: bsc) {
dexTrades(
baseCurrency: {is: "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82"}
quoteCurrency: {is: "0x55d398326f99059ff775485246999027b3197955"}
options: {desc: ["block.height", "transaction.index"], limit: 1}
) {
@sayon-bitquery
sayon-bitquery / main.py
Created June 12, 2021 07:18
discord-bot: GraphQL API key integrating function
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))
@sayon-bitquery
sayon-bitquery / main.py
Created June 12, 2021 07:20
discord-bot: taking the quotePrice and result of the GraphQL query
result = run_query(query) # Execute the query
quotePrice = result.get('data').get('ethereum').get('dexTrades')[0].get('quotePrice')