Skip to content

Commit 3010961

Browse files
Add /examples/websocket/auth/calc.py demo to show how calc works.
1 parent 8f7d695 commit 3010961

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

examples/websocket/auth/calc.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# python -c "import examples.websocket.auth.calc"
2+
3+
import os
4+
5+
from bfxapi import Client
6+
from bfxapi.types import BaseMarginInfo, FundingInfo, SymbolMarginInfo
7+
8+
bfx = Client(
9+
api_key=os.getenv("BFX_API_KEY"),
10+
api_secret=os.getenv("BFX_API_SECRET"),
11+
)
12+
13+
14+
@bfx.wss.on("authenticated")
15+
async def on_authenticated(_):
16+
await bfx.wss.inputs.calc("margin_base")
17+
18+
await bfx.wss.inputs.calc("margin_sym_tBTCUSD")
19+
20+
await bfx.wss.inputs.calc("funding_sym_fUST")
21+
22+
23+
@bfx.wss.on("base_margin_info")
24+
def on_base_margin_info(data: BaseMarginInfo):
25+
print("Base margin info:", data)
26+
27+
28+
@bfx.wss.on("symbol_margin_info")
29+
def on_symbol_margin_info(data: SymbolMarginInfo):
30+
if data.symbol == "tBTCUSD":
31+
print("Symbol margin info:", data)
32+
33+
34+
@bfx.wss.on("funding_info_update")
35+
def on_funding_info_update(data: FundingInfo):
36+
if data.symbol == "fUST":
37+
print("Funding info update:", data)
38+
39+
40+
bfx.wss.run()

0 commit comments

Comments
 (0)