forked from sammchardy/python-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1575.py
More file actions
44 lines (30 loc) · 1.03 KB
/
1575.py
File metadata and controls
44 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from binance import ThreadedWebsocketManager, AsyncClient
import asyncio
api_key = ""
api_secret = ""
async def run_websocket_operations():
symbol = "BNBBTC"
# Create async client
client = await AsyncClient.create(api_key=api_key, api_secret=api_secret)
try:
# Get account status using async call
account = await client.ws_get_symbol_ticker(symbol=symbol)
print(f"account: {account}")
finally:
await client.close_connection()
def handle_socket_message(msg):
print(f"message type: {msg['e']}")
# print(msg)
def main():
# Start ThreadedWebsocketManager
twm = ThreadedWebsocketManager(api_key=api_key, api_secret=api_secret)
twm.start()
# Start kline socket
twm.start_kline_socket(callback=handle_socket_message, symbol="BNBBTC")
# Run async operations in a separate event loop
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(run_websocket_operations())
twm.join()
if __name__ == "__main__":
main()