Funds & Withdrawals (Python)
Manage funds including withdrawals and account transfers.
[!NOTE] Deposits require Solana on-chain transactions via the Proton framework and cannot be done through the pure REST API. See the TypeScript SDK for deposit functionality.
Withdrawing Funds
Withdraw tokens from the exchange to your Solana wallet.
import requests
import schema_pb2
API_URL = "https://zo-devnet.n1.xyz"
def withdraw(session_id, session_key, token_id, amount):
"""
Withdraw tokens from the exchange.
Args:
token_id: Token to withdraw (e.g., 1 for USDC)
amount: Amount to withdraw (human-readable, e.g., 100 for 100 USDC)
"""
server_time = int(requests.get(f"{API_URL}/timestamp").json())
# Get token decimals
info = requests.get(f"{API_URL}/info").json()
token = next(t for t in info["tokens"] if t["tokenId"] == token_id)
decimals = token["decimals"]
# Convert to raw amount
amount_raw = int(amount * (10 ** decimals))
action = schema_pb2.Action()
action.current_timestamp = server_time
action.withdraw.session_id = session_id
action.withdraw.token_id = token_id
action.withdraw.amount = amount_raw
receipt = execute_action(action, session_key, session_sign)
if receipt.HasField("err"):
raise Exception(f"Withdraw failed: {schema_pb2.Error.Name(receipt.err)}")
print(f"Withdrawal initiated! Action ID: {receipt.action_id}")
return receipt
# Example: Withdraw 100 USDC
withdraw(
session_id=session_id,
session_key=session_key,
token_id=1, # USDC
amount=100
)Account Transfers
Transfer tokens between sub-accounts.
def transfer_between_accounts(session_id, session_key, token_id, amount, from_account, to_account):
"""
Transfer tokens between sub-accounts.
Args:
from_account: Source account ID
to_account: Destination account ID
"""
server_time = int(requests.get(f"{API_URL}/timestamp").json())
# Get token decimals
info = requests.get(f"{API_URL}/info").json()
token = next(t for t in info["tokens"] if t["tokenId"] == token_id)
decimals = token["decimals"]
amount_raw = int(amount * (10 ** decimals))
action = schema_pb2.Action()
action.current_timestamp = server_time
action.transfer.session_id = session_id
action.transfer.token_id = token_id
action.transfer.amount = amount_raw
action.transfer.from_account_id = from_account
action.transfer.to_account_id = to_account
receipt = execute_action(action, session_key, session_sign)
if receipt.HasField("err"):
raise Exception(f"Transfer failed: {schema_pb2.Error.Name(receipt.err)}")
print(f"Transfer complete! Action ID: {receipt.action_id}")
return receipt
# Example: Transfer 50 USDC from account 0 to account 1
transfer_between_accounts(
session_id=session_id,
session_key=session_key,
token_id=1,
amount=50,
from_account=0,
to_account=1
)Token Information
Get available tokens and their metadata:
def get_tokens():
"""Fetch available tokens with their IDs and decimals."""
resp = requests.get(f"{API_URL}/info")
tokens = resp.json()["tokens"]
for token in tokens:
print(f"{token['tokenId']}: {token['symbol']} ({token['decimals']} decimals)")
return tokens
# Common token IDs:
# 0 = (varies by deployment)
# 1 = USDCLast updated on