Created
July 19, 2024 15:50
-
-
Save divyasshree-BQ/84bc875bf1c3c3e9088653d5c9b5d7eb to your computer and use it in GitHub Desktop.
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 asyncio | |
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", | |
headers={"Sec-WebSocket-Protocol": "graphql-ws"}) | |
# Establish the connection | |
await transport.connect() | |
print("Connected to WebSocket") | |
try: | |
general_df = pd.DataFrame() | |
print("General Table") | |
while True: | |
async for result in transport.subscribe( | |
gql(""" | |
subscription { | |
Solana { | |
General: DEXTradeByTokens { | |
Block { | |
Time | |
} | |
Trade { | |
Amount | |
Price | |
Currency { | |
Symbol | |
Name | |
} | |
Side { | |
Amount | |
Currency { | |
Symbol | |
Name | |
MetadataAddress | |
} | |
} | |
Dex { | |
ProgramAddress | |
ProtocolFamily | |
ProtocolName | |
} | |
Market { | |
MarketAddress | |
} | |
Order { | |
LimitAmount | |
LimitPrice | |
OrderId | |
} | |
PriceInUSD | |
} | |
} | |
} | |
} | |
""")): | |
if result.data: | |
new_data = pd.json_normalize( | |
result.data['Solana']['General']) | |
general_df = pd.concat([general_df, new_data], | |
ignore_index=True) | |
print(general_df) | |
finally: | |
await transport.close() | |
def main(): | |
asyncio.run(run_subscription()) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is giving me the bad request error