Skip to content

Commit 43a2b31

Browse files
authored
Merge pull request #70 from x10xchange/bridged_withdrawal_example
Add bridged withdrawal example
2 parents de31466 + e234b22 commit 43a2b31

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

examples/05_bridged_withdrawal.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import logging.handlers
2+
from asyncio import run
3+
from decimal import Decimal
4+
5+
from examples.init_env import init_env
6+
from x10.perpetual.accounts import StarkPerpetualAccount
7+
from x10.perpetual.configuration import MAINNET_CONFIG
8+
from x10.perpetual.trading_client import PerpetualTradingClient
9+
10+
LOGGER = logging.getLogger()
11+
ENDPOINT_CONFIG = MAINNET_CONFIG
12+
13+
14+
# Bridged withdrawal example. Bridge disabled on sepolia, example works only on mainnet
15+
async def run_example():
16+
env_config = init_env()
17+
amount = 5
18+
target_chain = "ETH"
19+
20+
stark_account = StarkPerpetualAccount(
21+
api_key=env_config.api_key,
22+
public_key=env_config.public_key,
23+
private_key=env_config.private_key,
24+
vault=env_config.vault_id,
25+
)
26+
trading_client = PerpetualTradingClient(ENDPOINT_CONFIG, stark_account)
27+
LOGGER.info("Getting quote")
28+
quote = (await trading_client.account.get_bridge_quote(chain_in="STRK", chain_out=target_chain, amount=amount)).data
29+
if quote.fee > Decimal(2):
30+
LOGGER.info("Fee %s is too high", quote.fee)
31+
return
32+
LOGGER.info("Commiting quote")
33+
await trading_client.account.commit_bridge_quote(quote.id)
34+
LOGGER.info("Requesting withdrawal")
35+
withdrawal_id = (
36+
await trading_client.account.withdraw(
37+
amount=Decimal(amount),
38+
chain_id=target_chain,
39+
quote_id=quote.id,
40+
)
41+
).data
42+
43+
LOGGER.info("Withdrawal %s requested", withdrawal_id)
44+
45+
46+
if __name__ == "__main__":
47+
run(main=run_example())

0 commit comments

Comments
 (0)