query = """
subscription {
EVM(network: bsc) {
Transfers {
Block {
Number
Transfer {
Currency {
Symbol
Amount
This code block defines the GraphQL subscription query, which is sent to the Bitquery API to subscribe to the Binance Smart Chain network’s Transfer events.
Step 6: Make an asynchronous subscription request
asyncio.run(ws.subscribe(query=query, handle=callback))
This code block makes an asynchronous subscription request to the Bitquery API with the defined subscription query and the handle
parameter set to callback
. The handle
parameter specifies the function that should be called when new data is received.
Output on Terminal
auth_token = "Bearer YOUR_ACCESS_TOKEN"
ws = GraphqlClient(endpoint="wss://streaming.bitquery.io/graphql", headers={"Authorization": auth_token})
def callback(response):
print("got new OHLC data:")
print(response)
async def subscribe_to_transfers():
query = """
subscription {
EVM(network: bsc) {
Transfers {
Block {
Number
Transfer {
Currency {
Symbol
Amount
await ws.subscribe(query=query, handle=callback)
asyncio.run(subscribe_to_transfers())
This code uses OAuth for authentication by setting the authorization header with a Bearer token. Make sure to replace YOUR_ACCESS_TOKEN
with your actual access token.
how i get all tokens data
below is my query and i want to get all data in python code can you please help me
subscription MyQuery {
Solana {
DEXTradeByTokens(
where: {Trade: {Currency: {MintAddress: {is: “3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump”}}, Side: {Currency: {MintAddress: {is: “So11111111111111111111111111111111111111112”}}}, Dex: {ProgramAddress: {is: “675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8”}}}, Transaction: {Result: {Success: true}}}
Block {
Trade {
Currency {
Symbol
Amount
PriceAgainstSideCurrency: Price
PriceInUSD
Side {
Currency {
Symbol
Amount
Transaction {
Maker: Signer
Signature
import pandas as pd
from gql import Client, gql
from gql.transport.websockets import WebsocketsTransport
async def run_subscription():
# Setup WebSocket connection
transport = WebsocketsTransport(
url="wss://streaming.bitquery.io/eap?token=your_token",
This file has been truncated. show original
i have one problem when i used the below code in my vscode then the code not giving me the correct data and when i run the query on bitquery ide then the code giving me the right data
why this is happening can you please help me.
import asyncio
from python_graphql_client import GraphqlClient
import time
auth_token = “Bearer ory_at_ejrB_FthB0Q35uZfO–6P8LXpRPjLKKYSW04wNyY6iA.HYMJAp9bSjFhB1KAgaPn3PazCbiSCCA_cwb5bBu2GmA”
ws = GraphqlClient(endpoint=“wss://streaming.bitquery.io/eap”, headers={“Authorization”: auth_token})
def callback(response):
print(“got new OHLC data:”)
print(response)
time.sleep(20)
async def subscribe_to_transfers():
query = “”"
subscription MyQuery {
Solana {
DEXTradeByTokens(
where: {Trade: {Currency: {MintAddress: {is: “B6DuEXoYuzqYTTscrGUGDCK1t9tGkH7Ud1yQq65AC6A8”}}, Side: {Currency: {MintAddress: {is: “So11111111111111111111111111111111111111112”}}}, Dex: {ProgramAddress: {is: “675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8”}}}, Transaction: {Result: {Success: true}}}
Block {
Trade {
Currency {
Symbol
Amount
PriceAgainstSideCurrency: Price
PriceInUSD
Side {
Currency {
Symbol
Amount
Transaction {
Maker: Signer
Signature
await ws.subscribe(query=query, handle=callback)
asyncio.run(subscribe_to_transfers())
i have one problem when i used the below code in my vscode then the code not giving me the correct data and when i run the query on bitquery ide then the code giving me the right data
why this is happening can you please help me.
import asyncio
from python_graphql_client import GraphqlClient
import time
auth_token = “Bearer ory_at_ejrB_FthB0Q35uZfO–6P8LXpRPjLKKYSW04wNyY6iA.HYMJAp9bSjFhB1KAgaPn3PazCbiSCCA_cwb5bBu2GmA”
ws = GraphqlClient(endpoint=“wss://streaming.bitquery.io/eap”, headers={“Authorization”: auth_token})
def callback(response):
print(“got new OHLC data:”)
print(response)
time.sleep(20)
async def subscribe_to_transfers():
query = “”"
subscription MyQuery {
Solana {
DEXTradeByTokens(
where: {Trade: {Currency: {MintAddress: {is: “B6DuEXoYuzqYTTscrGUGDCK1t9tGkH7Ud1yQq65AC6A8”}}, Side: {Currency: {MintAddress: {is: “So11111111111111111111111111111111111111112”}}}, Dex: {ProgramAddress: {is: “675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8”}}}, Transaction: {Result: {Success: true}}}
Block {
Trade {
Currency {
Symbol
Amount
PriceAgainstSideCurrency: Price
PriceInUSD
Side {
Currency {
Symbol
Amount
Transaction {
Maker: Signer
Signature
await ws.subscribe(query=query, handle=callback)
asyncio.run(subscribe_to_transfers())