diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index e1c39af..032416d 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -1,4 +1,4 @@ -from typing import List, Dict, Optional, Literal, Any +from typing import * from dataclasses import dataclass diff --git a/bfxapi/websocket/types.py b/bfxapi/websocket/types.py index 063836a..ae082af 100644 --- a/bfxapi/websocket/types.py +++ b/bfxapi/websocket/types.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import * from dataclasses import dataclass diff --git a/examples/websocket/create_order.py b/examples/websocket/authenticated/submit_order.py similarity index 83% rename from examples/websocket/create_order.py rename to examples/websocket/authenticated/submit_order.py index 48f4957..ca671be 100644 --- a/examples/websocket/create_order.py +++ b/examples/websocket/authenticated/submit_order.py @@ -1,9 +1,9 @@ -# python -c "import examples.websocket.create_order" +# python -c "import examples.websocket.authenticated.submit_order" import os -from bfxapi.client import Client, WSS_HOST -from bfxapi.websocket.enums import Error, OrderType +from bfxapi import Client, WSS_HOST +from bfxapi.enums import Error, OrderType from bfxapi.websocket.types import Notification, Order bfx = Client( @@ -18,7 +18,7 @@ def on_wss_error(code: Error, msg: str): @bfx.wss.on("authenticated") async def on_authenticated(event): - print(f"Authentication: {event}.") + print(f"Authentication: {event}") await bfx.wss.inputs.submit_order( type=OrderType.EXCHANGE_LIMIT, diff --git a/examples/websocket/authenticated/wallets.py b/examples/websocket/authenticated/wallets.py new file mode 100644 index 0000000..039364a --- /dev/null +++ b/examples/websocket/authenticated/wallets.py @@ -0,0 +1,30 @@ +# python -c "import examples.websocket.authenticated.wallets" + +import os + +from bfxapi import Client +from bfxapi.enums import Error +from bfxapi.websocket.types import List, Wallet + +bfx = Client( + API_KEY=os.getenv("BFX_API_KEY"), + API_SECRET=os.getenv("BFX_API_SECRET"), + filter=["wallet"] +) + +@bfx.wss.on("wss-error") +def on_wss_error(code: Error, msg: str): + print(code, msg) + +@bfx.wss.on("wallet_snapshot") +def on_wallet_snapshot(wallets: List[Wallet]): + for wallet in wallets: + print(f"Wallet: {wallet.wallet_type} | {wallet.currency}") + print(f"Available balance: {wallet.available_balance}") + print(f"Wallet trade details: {wallet.trade_details}") + +@bfx.wss.on("wallet_update") +def on_wallet_update(wallet: Wallet): + print(f"Wallet update: {wallet}") + +bfx.wss.run() \ No newline at end of file diff --git a/examples/websocket/derivatives_status.py b/examples/websocket/public/derivatives_status.py similarity index 90% rename from examples/websocket/derivatives_status.py rename to examples/websocket/public/derivatives_status.py index 3099431..05a9556 100644 --- a/examples/websocket/derivatives_status.py +++ b/examples/websocket/public/derivatives_status.py @@ -1,4 +1,4 @@ -# python -c "import examples.websocket.derivatives_status" +# python -c "import examples.websocket.public.derivatives_status" from bfxapi import Client, PUB_WSS_HOST from bfxapi.websocket.enums import Error, Channel diff --git a/examples/websocket/order_book.py b/examples/websocket/public/order_book.py similarity index 97% rename from examples/websocket/order_book.py rename to examples/websocket/public/order_book.py index 55e4ae3..536ce7c 100644 --- a/examples/websocket/order_book.py +++ b/examples/websocket/public/order_book.py @@ -1,4 +1,4 @@ -# python -c "import examples.websocket.order_book" +# python -c "import examples.websocket.public.order_book" from collections import OrderedDict diff --git a/examples/websocket/raw_order_book.py b/examples/websocket/public/raw_order_book.py similarity index 96% rename from examples/websocket/raw_order_book.py rename to examples/websocket/public/raw_order_book.py index 3ce9c6d..7909a61 100644 --- a/examples/websocket/raw_order_book.py +++ b/examples/websocket/public/raw_order_book.py @@ -1,4 +1,4 @@ -# python -c "import examples.websocket.raw_order_book" +# python -c "import examples.websocket.public.raw_order_book" from collections import OrderedDict diff --git a/examples/websocket/ticker.py b/examples/websocket/public/ticker.py similarity index 90% rename from examples/websocket/ticker.py rename to examples/websocket/public/ticker.py index d4b4c91..b2eadc8 100644 --- a/examples/websocket/ticker.py +++ b/examples/websocket/public/ticker.py @@ -1,4 +1,4 @@ -# python -c "import examples.websocket.ticker" +# python -c "import examples.websocket.public.ticker" from bfxapi import Client, PUB_WSS_HOST diff --git a/examples/websocket/trades.py b/examples/websocket/public/trades.py similarity index 93% rename from examples/websocket/trades.py rename to examples/websocket/public/trades.py index 0a5291f..186c46b 100644 --- a/examples/websocket/trades.py +++ b/examples/websocket/public/trades.py @@ -1,4 +1,4 @@ -# python -c "import examples.websocket.trades" +# python -c "import examples.websocket.public.trades" from bfxapi import Client, PUB_WSS_HOST from bfxapi.websocket.enums import Error, Channel diff --git a/examples/websocket/wallet_balance.py b/examples/websocket/wallet_balance.py deleted file mode 100644 index 0e1b489..0000000 --- a/examples/websocket/wallet_balance.py +++ /dev/null @@ -1,30 +0,0 @@ -# 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() \ No newline at end of file