mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
examples: adds trades/candles example
This commit is contained in:
34
bfxapi/examples/subscribe_trades_candles.py
Normal file
34
bfxapi/examples/subscribe_trades_candles.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import sys
|
||||
sys.path.append('../')
|
||||
|
||||
from bfxapi.websockets.LiveWebsocket import LiveBfxWebsocket
|
||||
|
||||
'''
|
||||
This script requires you to run an instance of the bfx-hf-data-server on
|
||||
port 8899. For more info on how to setup the data-server please visit:
|
||||
https://github.com/bitfinexcom/bfx-hf-data-server
|
||||
'''
|
||||
|
||||
ws = LiveBfxWebsocket(
|
||||
logLevel='INFO'
|
||||
)
|
||||
|
||||
@ws.on('error')
|
||||
def log_error(err):
|
||||
print ("Error: {}".format(err))
|
||||
|
||||
@ws.on('new_candle')
|
||||
def log_candle(candle):
|
||||
print ("New candle: {}".format(candle))
|
||||
|
||||
@ws.on('new_trade')
|
||||
def log_trade(trade):
|
||||
print ("New trade: {}".format(trade))
|
||||
|
||||
def start():
|
||||
ws.subscribe('candles', 'tBTCUSD', timeframe='1m')
|
||||
ws.subscribe('trades', 'tBTCUSD')
|
||||
|
||||
ws.on('connected', start)
|
||||
ws.run()
|
||||
Reference in New Issue
Block a user