Apply pylint's linting rules to examples/websocket/public/*.py.

This commit is contained in:
Davide Casale
2023-03-08 21:36:25 +01:00
parent 834a664034
commit d04ebb96d5
5 changed files with 23 additions and 23 deletions

View File

@@ -10,14 +10,14 @@ 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)
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():
async def on_open():
await bfx.wss.subscribe(Channel.STATUS, key="deriv:tBTCF0:USTF0")
bfx.wss.run()
bfx.wss.run()

View File

@@ -10,21 +10,21 @@ from bfxapi.websocket import subscriptions
from bfxapi.websocket.enums import Channel, Error
from bfxapi.websocket.types import TradingPairBook
class OrderBook(object):
class OrderBook:
def __init__(self, symbols: List[str]):
self.__order_book = {
symbol: {
symbol: {
"bids": OrderedDict(), "asks": OrderedDict()
} for symbol in symbols
}
def update(self, symbol: str, data: TradingPairBook) -> None:
price, count, amount = data.price, data.count, data.amount
kind = (amount > 0) and "bids" or "asks"
kind = "bids" if amount > 0 else "asks"
if count > 0:
self.__order_book[symbol][kind][price] = {
self.__order_book[symbol][kind][price] = {
"price": price,
"count": count,
"amount": amount
@@ -62,4 +62,4 @@ def on_t_book_snapshot(subscription: subscriptions.Book, snapshot: List[TradingP
def on_t_book_update(subscription: subscriptions.Book, data: TradingPairBook):
order_book.update(subscription["symbol"], data)
bfx.wss.run()
bfx.wss.run()

View File

@@ -10,21 +10,21 @@ from bfxapi.websocket import subscriptions
from bfxapi.websocket.enums import Channel, Error
from bfxapi.websocket.types import TradingPairRawBook
class RawOrderBook(object):
class RawOrderBook:
def __init__(self, symbols: List[str]):
self.__raw_order_book = {
symbol: {
symbol: {
"bids": OrderedDict(), "asks": OrderedDict()
} for symbol in symbols
}
def update(self, symbol: str, data: TradingPairRawBook) -> None:
order_id, price, amount = data.order_id, data.price, data.amount
kind = (amount > 0) and "bids" or "asks"
kind = "bids" if amount > 0 else "asks"
if price > 0:
self.__raw_order_book[symbol][kind][order_id] = {
self.__raw_order_book[symbol][kind][order_id] = {
"order_id": order_id,
"price": price,
"amount": amount
@@ -62,4 +62,4 @@ def on_t_raw_book_snapshot(subscription: subscriptions.Book, snapshot: List[Trad
def on_t_raw_book_update(subscription: subscriptions.Book, data: TradingPairRawBook):
raw_order_book.update(subscription["symbol"], data)
bfx.wss.run()
bfx.wss.run()

View File

@@ -15,7 +15,7 @@ def on_t_ticker_update(subscription: subscriptions.Ticker, data: TradingPairTick
print(f"Data: {data}")
@bfx.wss.once("open")
async def open():
async def on_open():
await bfx.wss.subscribe(Channel.TICKER, symbol="tBTCUSD")
bfx.wss.run()
bfx.wss.run()

View File

@@ -9,21 +9,21 @@ 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}")
def on_candles_update(_sub: 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}")
def on_t_trade_executed(_sub: 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():
async def on_open():
await bfx.wss.subscribe(Channel.CANDLES, key="trade:1m:tBTCUSD")
await bfx.wss.subscribe(Channel.TRADES, symbol="tBTCUSD")
bfx.wss.run()
bfx.wss.run()