mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2026-02-23 14:34:31 +01:00
Move subscriptions type hinting from bfxapi/websocket/types.py to bfxapi/websocket/subscriptions.py.
This commit is contained in:
@@ -6,8 +6,9 @@ from typing import List
|
||||
|
||||
from bfxapi import Client, Constants
|
||||
|
||||
from bfxapi.websocket import subscriptions
|
||||
from bfxapi.websocket.enums import Channels, Error
|
||||
from bfxapi.websocket.types import Subscriptions, TradingPairBook
|
||||
from bfxapi.websocket.types import TradingPairBook
|
||||
|
||||
class OrderBook(object):
|
||||
def __init__(self, symbols: List[str]):
|
||||
@@ -53,12 +54,12 @@ 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: List[TradingPairBook]):
|
||||
def on_t_book_snapshot(subscription: subscriptions.Book, snapshot: List[TradingPairBook]):
|
||||
for data in snapshot:
|
||||
order_book.update(subscription["symbol"], data)
|
||||
|
||||
@bfx.wss.on("t_book_update")
|
||||
def on_t_book_update(subscription: Subscriptions.Book, data: TradingPairBook):
|
||||
def on_t_book_update(subscription: subscriptions.Book, data: TradingPairBook):
|
||||
order_book.update(subscription["symbol"], data)
|
||||
|
||||
bfx.wss.run()
|
||||
@@ -6,8 +6,9 @@ from typing import List
|
||||
|
||||
from bfxapi import Client, Constants
|
||||
|
||||
from bfxapi.websocket import subscriptions
|
||||
from bfxapi.websocket.enums import Channels, Error
|
||||
from bfxapi.websocket.types import Subscriptions, TradingPairRawBook
|
||||
from bfxapi.websocket.types import TradingPairRawBook
|
||||
|
||||
class RawOrderBook(object):
|
||||
def __init__(self, symbols: List[str]):
|
||||
@@ -53,12 +54,12 @@ 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: List[TradingPairRawBook]):
|
||||
def on_t_raw_book_snapshot(subscription: subscriptions.Book, snapshot: List[TradingPairRawBook]):
|
||||
for data in snapshot:
|
||||
raw_order_book.update(subscription["symbol"], data)
|
||||
|
||||
@bfx.wss.on("t_raw_book_update")
|
||||
def on_t_raw_book_update(subscription: Subscriptions.Book, data: TradingPairRawBook):
|
||||
def on_t_raw_book_update(subscription: subscriptions.Book, data: TradingPairRawBook):
|
||||
raw_order_book.update(subscription["symbol"], data)
|
||||
|
||||
bfx.wss.run()
|
||||
@@ -1,13 +1,15 @@
|
||||
# python -c "from examples.websocket.ticker import *"
|
||||
|
||||
from bfxapi import Client, Constants
|
||||
|
||||
from bfxapi.websocket import subscriptions
|
||||
from bfxapi.websocket.enums import Channels
|
||||
from bfxapi.websocket.types import Subscriptions, TradingPairTicker
|
||||
from bfxapi.websocket.types import TradingPairTicker
|
||||
|
||||
bfx = Client(WSS_HOST=Constants.PUB_WSS_HOST)
|
||||
|
||||
@bfx.wss.on("t_ticker_update")
|
||||
def on_t_ticker_update(subscription: Subscriptions.TradingPairTicker, data: TradingPairTicker):
|
||||
def on_t_ticker_update(subscription: subscriptions.Ticker, data: TradingPairTicker):
|
||||
print(f"Subscription with channel ID: {subscription['chanId']}")
|
||||
|
||||
print(f"Data: {data}")
|
||||
|
||||
Reference in New Issue
Block a user