mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
# python -c "from examples.websocket.create_order import *"
|
|
|
|
import os
|
|
|
|
from bfxapi.client import Client, Constants
|
|
from bfxapi.websocket.enums import Error, OrderType
|
|
from bfxapi.websocket.typings import Notification, Order
|
|
|
|
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_authenticated(event):
|
|
print(f"Authentication: {event}.")
|
|
|
|
await bfx.wss.inputs.submit_order(
|
|
type=OrderType.EXCHANGE_LIMIT,
|
|
symbol="tBTCUSD",
|
|
amount="0.1",
|
|
price="10000.0"
|
|
)
|
|
|
|
print("The order has been sent.")
|
|
|
|
@bfx.wss.on("on-req-notification")
|
|
async def on_notification(notification: Notification):
|
|
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() |