diff --git a/examples/websocket/create_order.py b/examples/websocket/create_order.py new file mode 100644 index 0000000..7c7be64 --- /dev/null +++ b/examples/websocket/create_order.py @@ -0,0 +1,43 @@ +# python -c "from examples.websocket.create_order import *" + +import os + +from bfxapi.client import Client, Constants +from bfxapi.utils.cid import generate_unique_cid +from bfxapi.websocket.enums import Error, OrderType +from bfxapi.websocket.typings import Inputs + +bfx = Client( + WSS_HOST=Constants.WSS_HOST, + API_KEY=os.getenv("BFX_API_KEY"), + API_SECRET=os.getenv("BFX_API_SECRET") +) + +@bfx.wss.on("wss-error") +def on_wss_error(code: Error, msg: str): + print(code, msg) +@bfx.wss.on("authenticated") +async def on_open(event): + print(f"Auth event {event}") + + order: Inputs.Order.New = { + "gid": generate_unique_cid(), + "type": OrderType.EXCHANGE_LIMIT, + "symbol": "tBTCUST", + "amount": "0.1", + "price": "10000.0" + } + await bfx.wss.inputs.order_new(order) + + print(f"Order sent") +@bfx.wss.on("notification") +async def on_notification(notification): + print(f"Notification {notification}") +@bfx.wss.on("order_new") +async def on_order_new(order_new: Inputs.Order.New): + print(f"Order new {order_new}") +@bfx.wss.on("subscribed") +def on_subscribed(subscription): + print(f"Subscription successful <{subscription}>") + +bfx.wss.run() \ No newline at end of file diff --git a/examples/websocket/order_book.py b/examples/websocket/order_book.py index 372a3f6..0035cf8 100644 --- a/examples/websocket/order_book.py +++ b/examples/websocket/order_book.py @@ -1,10 +1,11 @@ +# python -c "from examples.websocket.order_book import *" + from collections import OrderedDict from typing import List from bfxapi import Client, Constants -from bfxapi.websocket import BfxWebsocketClient from bfxapi.websocket.enums import Channels, Error from bfxapi.websocket.typings import Subscriptions, TradingPairBook diff --git a/examples/websocket/raw_order_book.py b/examples/websocket/raw_order_book.py index 5a65d78..6cfc3c1 100644 --- a/examples/websocket/raw_order_book.py +++ b/examples/websocket/raw_order_book.py @@ -1,10 +1,11 @@ +# python -c "from examples.websocket.raw_order_book import *" + from collections import OrderedDict from typing import List from bfxapi import Client, Constants -from bfxapi.websocket import BfxWebsocketClient from bfxapi.websocket.enums import Channels, Error from bfxapi.websocket.typings import Subscriptions, TradingPairRawBook diff --git a/examples/websocket/ticker.py b/examples/websocket/ticker.py index ff8d899..5db8ed1 100644 --- a/examples/websocket/ticker.py +++ b/examples/websocket/ticker.py @@ -1,3 +1,5 @@ +# python -c "from examples.websocket.ticker import *" + import asyncio from bfxapi import Client, Constants @@ -16,4 +18,4 @@ def on_t_ticker_update(subscription: Subscriptions.TradingPairTicker, data: Trad async def open(): await bfx.wss.subscribe(Channels.TICKER, symbol="tBTCUSD") -asyncio.run(bfx.wss.start()) \ No newline at end of file +bfx.wss.run() \ No newline at end of file