Settlement Pool Deposit Tutorial
This tutorial relies on programming context established in Prerequisites and Setup. Settlement Pools can either be created ahead of time with specific counterparties, or created at the time of trading as part of the clearing flow.
Create a Settlement Pool
If you need to create a settlement pool with a new counterparty, or need another pool with different margin parameters, here's how you create one via the API:
from variational import MarginMode
other_company_id = "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a"
margin_params = {
"margin_mode": MarginMode.SIMPLE,
"params": {
"liquidation_penalty": "0.1",
"auto_liquidation": True,
"asset_params": {},
"default_asset_param": {
"futures_initial_margin": "0.02",
"futures_maintenance_margin": "0.01",
"futures_leverage": "1000000000",
"option_initial_margin": "0.15",
"option_initial_margin_min": "0.1",
"option_maintenance_margin": "0.075",
},
}
}
new_pool = client.create_settlement_pool(
pool_name="Tutorial pool",
company_other=other_company_id,
creator_params=margin_params,
other_params=margin_params,
).result
print(json.dumps(new_pool, indent=2))
Note that a new pool is always created in the pending
status. Before you can deposit funds, it needs to be created on-chain and transition to open
status. This will happen automatically, but can take a few seconds.
Use the helper to wait until the settlement pool becomes ready:
pool = poller.wait_for_settlement_pool(new_pool["pool_id"])
Make A Deposit
In order to deposit USDC into the pool, you need to sign and submit a ERC-2612 spending approval:
deposit_amount = 10000
permits.sign_and_submit_decimal(
pool_address=pool['data']['address'],
allowance=str(deposit_amount)
)
Next, you initiate a deposit transfer for the approved amount (or less):
from variational import TransferType
new_transfer = client.create_transfer(
asset="USDC",
qty=str(deposit_amount),
target_pool_location=pool["pool_id"],
# allocate these funds for trading with this counterparty
counterparty=other_company_id,
transfer_type=TransferType.DEPOSIT,
).result
print(json.dumps(new_transfer, indent=2))
Note that a transfer is created in pending
status. Use the helper to wait until the deposit happens on-chain and the status changes to confirmed
:
transfer = poller.wait_for_transfer(transfer['id'])
Verify
You can confirm that the deposit has been completed successfully by checking the settlement pool's balance:
pool = client.get_settlement_pools(id=pool["pool_id"]).result[0]
print(json.dumps(pool, indent=2))
Last updated