mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-21 15:54:26 +01:00
Write Examples sub-section and Creating a new order paragraph in README.md.
This commit is contained in:
33
README.md
33
README.md
@@ -105,7 +105,8 @@ _Revoke your API-KEYs and API-SECRETs immediately if you think they might have b
|
||||
* [Using custom notifications](#using-custom-notifications)
|
||||
* [Setting up connection multiplexing](#setting-up-connection-multiplexing)
|
||||
|
||||
#### Examples
|
||||
### Examples
|
||||
* [Creating a new order](#creating-a-new-order)
|
||||
|
||||
## Instantiating the client
|
||||
|
||||
@@ -296,7 +297,37 @@ The use of more than 20 connections is not recommended.
|
||||
|
||||
# Examples
|
||||
|
||||
## Creating a new order
|
||||
|
||||
```python
|
||||
import os
|
||||
|
||||
from bfxapi import Client, WSS_HOST
|
||||
|
||||
from bfxapi.websocket.types import Notification, Order
|
||||
|
||||
bfx = Client(
|
||||
wss_host=WSS_HOST,
|
||||
api_key=os.getenv("BFX_API_KEY"),
|
||||
api_secret=os.getenv("BFX_API_SECRET")
|
||||
)
|
||||
|
||||
@bfx.wss.on("authenticated")
|
||||
async def on_authenticated(_):
|
||||
await bfx.wss.inputs.submit_order(
|
||||
type="EXCHANGE LIMIT", symbol="tBTCUSD", amount=0.165212, price=30264.0)
|
||||
|
||||
@bfx.wss.on("order_new")
|
||||
def on_order_new(order: Order):
|
||||
print(f"Successful new order for {order.symbol} at {order.price}$.")
|
||||
|
||||
@bfx.wss.on("on-req-notification")
|
||||
def on_notification(notification: Notification[Order]):
|
||||
if notification.status == "ERROR":
|
||||
raise Exception(f"Something went wrong: {notification.text}")
|
||||
|
||||
bfx.wss.run()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user