From ea3eefd32c211a23d5e62748cf5746699b1a4907 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Fri, 16 Dec 2022 18:42:59 +0100 Subject: [PATCH] Apply refactoring with new standards in examples/websockets/*.py demos. --- examples/websocket/order_book.py | 8 +++++--- examples/websocket/raw_order_book.py | 8 +++++--- examples/websocket/ticker.py | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/websocket/order_book.py b/examples/websocket/order_book.py index a100c2b..edb765e 100644 --- a/examples/websocket/order_book.py +++ b/examples/websocket/order_book.py @@ -1,13 +1,15 @@ from collections import OrderedDict +from typing import List + from bfxapi import Client, Constants from bfxapi.websocket import BfxWebsocketClient from bfxapi.websocket.enums import Channels, Errors -from bfxapi.websocket.typings import Subscriptions, TradingPairBooks, TradingPairBook +from bfxapi.websocket.typings import Subscriptions, TradingPairBook class OrderBook(object): - def __init__(self, symbols: list[str]): + def __init__(self, symbols: List[str]): self.__order_book = { symbol: { "bids": OrderedDict(), "asks": OrderedDict() @@ -50,7 +52,7 @@ def on_subscribed(subscription): print(f"Subscription successful for pair <{subscription['pair']}>") @bfx.wss.on("t_book_snapshot") -def on_t_book_snapshot(subscription: Subscriptions.Book, snapshot: TradingPairBooks): +def on_t_book_snapshot(subscription: Subscriptions.Book, snapshot: List[TradingPairBook]): for data in snapshot: order_book.update(subscription["symbol"], data) diff --git a/examples/websocket/raw_order_book.py b/examples/websocket/raw_order_book.py index fe10490..b34ae8e 100644 --- a/examples/websocket/raw_order_book.py +++ b/examples/websocket/raw_order_book.py @@ -1,13 +1,15 @@ from collections import OrderedDict +from typing import List + from bfxapi import Client, Constants from bfxapi.websocket import BfxWebsocketClient from bfxapi.websocket.enums import Channels, Errors -from bfxapi.websocket.typings import Subscriptions, TradingPairRawBooks, TradingPairRawBook +from bfxapi.websocket.typings import Subscriptions, TradingPairRawBook class RawOrderBook(object): - def __init__(self, symbols: list[str]): + def __init__(self, symbols: List[str]): self.__raw_order_book = { symbol: { "bids": OrderedDict(), "asks": OrderedDict() @@ -50,7 +52,7 @@ def on_subscribed(subscription): print(f"Subscription successful for pair <{subscription['pair']}>") @bfx.wss.on("t_raw_book_snapshot") -def on_t_raw_book_snapshot(subscription: Subscriptions.Book, snapshot: TradingPairRawBooks): +def on_t_raw_book_snapshot(subscription: Subscriptions.Book, snapshot: List[TradingPairRawBook]): for data in snapshot: raw_order_book.update(subscription["symbol"], data) diff --git a/examples/websocket/ticker.py b/examples/websocket/ticker.py index 4e5d8e7..107e367 100644 --- a/examples/websocket/ticker.py +++ b/examples/websocket/ticker.py @@ -1,14 +1,14 @@ import asyncio from bfxapi import Client, Constants -from bfxapi.websocket import Channels +from bfxapi.websocket.enums import Channels from bfxapi.websocket.typings import Subscriptions, TradingPairTicker bfx = Client(WSS_HOST=Constants.PUB_WSS_HOST) @bfx.wss.on("t_ticker_update") def on_t_ticker_update(subscription: Subscriptions.TradingPairsTicker, data: TradingPairTicker): - print(f"Subscription channel ID: {subscription['chanId']}") + print(f"Subscription with channel ID: {subscription['chanId']}") print(f"Data: {data}")