mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
23
examples/websocket/derivatives_status.py
Normal file
23
examples/websocket/derivatives_status.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# python -c "import examples.websocket.derivatives_status"
|
||||
|
||||
from bfxapi import Client, PUB_WSS_HOST
|
||||
from bfxapi.websocket.enums import Error, Channel
|
||||
from bfxapi.websocket.types import DerivativesStatus
|
||||
|
||||
from bfxapi.websocket import subscriptions
|
||||
|
||||
bfx = Client(WSS_HOST=PUB_WSS_HOST)
|
||||
|
||||
@bfx.wss.on("derivatives_status_update")
|
||||
def on_derivatives_status_update(subscription: subscriptions.Status, data: DerivativesStatus):
|
||||
print(f"{subscription}:", data)
|
||||
|
||||
@bfx.wss.on("wss-error")
|
||||
def on_wss_error(code: Error, msg: str):
|
||||
print(code, msg)
|
||||
|
||||
@bfx.wss.once("open")
|
||||
async def open():
|
||||
await bfx.wss.subscribe(Channel.STATUS, key="deriv:tBTCF0:USTF0")
|
||||
|
||||
bfx.wss.run()
|
||||
29
examples/websocket/trades.py
Normal file
29
examples/websocket/trades.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# python -c "import examples.websocket.trades"
|
||||
|
||||
from bfxapi import Client, PUB_WSS_HOST
|
||||
from bfxapi.websocket.enums import Error, Channel
|
||||
from bfxapi.websocket.types import Candle, TradingPairTrade
|
||||
|
||||
from bfxapi.websocket import subscriptions
|
||||
|
||||
bfx = Client(WSS_HOST=PUB_WSS_HOST)
|
||||
|
||||
@bfx.wss.on("candles_update")
|
||||
def on_candles_update(subscription: subscriptions.Candles, candle: Candle):
|
||||
print(f"New candle: {candle}")
|
||||
|
||||
@bfx.wss.on("t_trade_executed")
|
||||
def on_t_trade_executed(subscription: subscriptions.Trades, trade: TradingPairTrade):
|
||||
print(f"New trade: {trade}")
|
||||
|
||||
@bfx.wss.on("wss-error")
|
||||
def on_wss_error(code: Error, msg: str):
|
||||
print(code, msg)
|
||||
|
||||
@bfx.wss.once("open")
|
||||
async def open():
|
||||
await bfx.wss.subscribe(Channel.CANDLES, key="trade:1m:tBTCUSD")
|
||||
|
||||
await bfx.wss.subscribe(Channel.TRADES, symbol="tBTCUSD")
|
||||
|
||||
bfx.wss.run()
|
||||
30
examples/websocket/wallet_balance.py
Normal file
30
examples/websocket/wallet_balance.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# python -c "import examples.websocket.wallet_balance"
|
||||
|
||||
import os
|
||||
|
||||
from typing import List
|
||||
|
||||
from bfxapi import Client, WSS_HOST
|
||||
from bfxapi.websocket.enums import Error
|
||||
from bfxapi.websocket.types import Wallet
|
||||
|
||||
bfx = Client(
|
||||
WSS_HOST=WSS_HOST,
|
||||
API_KEY=os.getenv("BFX_API_KEY"),
|
||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
||||
)
|
||||
|
||||
@bfx.wss.on("wallet_snapshot")
|
||||
def log_snapshot(wallets: List[Wallet]):
|
||||
for wallet in wallets:
|
||||
print(f"Balance: {wallet}")
|
||||
|
||||
@bfx.wss.on("wallet_update")
|
||||
def log_update(wallet: Wallet):
|
||||
print(f"Balance update: {wallet}")
|
||||
|
||||
@bfx.wss.on("wss-error")
|
||||
def on_wss_error(code: Error, msg: str):
|
||||
print(code, msg)
|
||||
|
||||
bfx.wss.run()
|
||||
Reference in New Issue
Block a user