mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-18 22:34:21 +01:00
Rewrite, edit and organize examples/websocket demos.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from typing import List, Dict, Optional, Literal, Any
|
||||
from typing import *
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Optional
|
||||
from typing import *
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@@ -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,
|
||||
30
examples/websocket/authenticated/wallets.py
Normal file
30
examples/websocket/authenticated/wallets.py
Normal file
@@ -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()
|
||||
@@ -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
|
||||
@@ -1,4 +1,4 @@
|
||||
# python -c "import examples.websocket.order_book"
|
||||
# python -c "import examples.websocket.public.order_book"
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# python -c "import examples.websocket.ticker"
|
||||
# python -c "import examples.websocket.public.ticker"
|
||||
|
||||
from bfxapi import Client, PUB_WSS_HOST
|
||||
|
||||
@@ -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
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user