mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 23:04:21 +01:00
examples: add stop connection
This commit is contained in:
committed by
Jacob Plaster
parent
275cd1c75b
commit
b78f567d01
21
bfxapi/examples/ws/start_stop_connection.py
Normal file
21
bfxapi/examples/ws/start_stop_connection.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
import sys
|
||||
sys.path.append('../../../')
|
||||
|
||||
from bfxapi import Client
|
||||
|
||||
bfx = Client(
|
||||
logLevel='DEBUG',
|
||||
)
|
||||
|
||||
@bfx.ws.on('order_book_snapshot')
|
||||
async def log_snapshot(data):
|
||||
print ("Snapshot: {}".format(data))
|
||||
# stop the websocket once a snapshot is received
|
||||
await bfx.ws.stop()
|
||||
|
||||
async def start():
|
||||
await bfx.ws.subscribe('book', 'tBTCUSD')
|
||||
|
||||
bfx.ws.on('connected', start)
|
||||
bfx.ws.run()
|
||||
Reference in New Issue
Block a user