Rewrite all websocket examples according to v3.0.0b3's changes.

This commit is contained in:
Davide Casale
2023-10-26 17:59:44 +02:00
parent 1ec6c49428
commit 1accf92c57
7 changed files with 111 additions and 84 deletions

View File

@@ -2,39 +2,39 @@
import os
from bfxapi import Client, WSS_HOST
from bfxapi.enums import Error, OrderType
from bfxapi import Client
from bfxapi.types import Notification, Order
bfx = Client(
wss_host=WSS_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
api_secret=os.getenv("BFX_API_SECRET"),
)
@bfx.wss.on("authenticated")
async def on_authenticated(event):
print(f"Authentication: {event}")
await bfx.wss.inputs.submit_order(
type=OrderType.EXCHANGE_LIMIT,
symbol="tBTCUSD",
amount="0.1",
price="10000.0"
type="EXCHANGE LIMIT", symbol="tBTCUSD", amount=0.165212, price=30264.0
)
print("The order has been sent.")
@bfx.wss.on("on-req-notification")
async def on_notification(notification: Notification[Order]):
print(f"Notification: {notification}.")
@bfx.wss.on("order_new")
async def on_order_new(order_new: Order):
print(f"Order new: {order_new}")
@bfx.wss.on("subscribed")
def on_subscribed(subscription):
print(f"Subscription successful for <{subscription}>.")
bfx.wss.run()

View File

@@ -1,19 +1,18 @@
# python -c "import examples.websocket.auth.wallets"
import os
from typing import List
from bfxapi import Client
from bfxapi.enums import Error
from bfxapi.types import Wallet
bfx = Client(
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET"),
filters=["wallet"]
filters=["wallet"],
)
@bfx.wss.on("wallet_snapshot")
def on_wallet_snapshot(wallets: List[Wallet]):
for wallet in wallets:
@@ -21,8 +20,10 @@ def on_wallet_snapshot(wallets: List[Wallet]):
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()