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:
Copy 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))
Output
Copy {
"company_id": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
"data": {
"address": null,
"name": "Tutorial pool",
"created_at": "2024-04-03T17:35:23.710289Z",
"company_creator": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
"positions": [],
"status": "pending",
"confirmed_by_transaction_id": null,
"parties": [
{
"company": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
"created_at": "2024-04-03T17:35:23.710289Z",
"address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"margin_usage": {
"balance": "0",
"margin_params": {
"margin_mode": "simple",
"params": {
"asset_params": {},
"auto_liquidation": true,
"default_asset_param": {
"futures_initial_margin": "0.02",
"futures_leverage": "20000",
"futures_maintenance_margin": "0.01",
"option_initial_margin": "0.15",
"option_initial_margin_min": "0.1",
"option_maintenance_margin": "0.075"
},
"liquidation_penalty": "0.1"
}
},
"margin_usage": {
"initial_margin": "0",
"maintenance_margin": "0"
},
"max_withdrawable_amount": "0"
},
"status": "pending",
"confirmed_by_transaction_id": null
},
{
"company": "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a",
"created_at": "2024-04-03T17:35:23.710289Z",
"address": "0xa0ee7a142d267c1f36714e4a8f75612f20a79720",
"margin_usage": {
"balance": "0",
"margin_params": {
"margin_mode": "simple",
"params": {
"asset_params": {},
"auto_liquidation": true,
"default_asset_param": {
"futures_initial_margin": "0.02",
"futures_leverage": "20000",
"futures_maintenance_margin": "0.01",
"option_initial_margin": "0.15",
"option_initial_margin_min": "0.1",
"option_maintenance_margin": "0.075"
},
"liquidation_penalty": "0.1"
}
},
"margin_usage": {
"initial_margin": "0",
"maintenance_margin": "0"
},
"max_withdrawable_amount": "0"
},
"status": "pending",
"confirmed_by_transaction_id": null
}
]
},
"pool_id": "6b2120ac-2aaf-40bc-b369-75d7e231c529"
}
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:
Copy 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:
Copy 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):
Copy 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))
Output
Copy {
"asset": "USDC",
"company": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
"created_at": "2024-04-03T17:40:49.491519Z",
"id": "5e3d6f7c-a787-40c2-a4c1-b6f35eb188a1",
"oracle_request_id": null,
"parent_quote_id": null,
"qty": "10000",
"reference_instrument": null,
"rfq_id": null,
"status": "pending",
"target_pool_location": "6b2120ac-2aaf-40bc-b369-75d7e231c529",
"counterparty": "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a",
"transfer_type": "deposit"
}
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
:
Copy 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:
Copy pool = client.get_settlement_pools(id=pool["pool_id"]).result[0]
print(json.dumps(pool, indent=2))
Output
Copy {
"company_id": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
"data": {
"address": "0x41574c5b15d67f95c7037a19cb7620c2643f2a98",
"name": "Tutorial pool",
"created_at": "2024-04-03T17:35:23.710289Z",
"company_creator": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
"positions": [],
"status": "open",
"confirmed_by_transaction_id": "0x8681959c118ea67dff6272da137aacdce4cdb87aaf06cae380842f19b8b0ac2b",
"parties": [
{
"company": "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8",
"created_at": "2024-04-03T17:35:23.710289Z",
"address": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"margin_usage": {
"balance": "10000",
"margin_params": {
"margin_mode": "simple",
"params": {
"asset_params": {},
"auto_liquidation": true,
"default_asset_param": {
"futures_initial_margin": "0.02",
"futures_leverage": "20000",
"futures_maintenance_margin": "0.01",
"option_initial_margin": "0.15",
"option_initial_margin_min": "0.1",
"option_maintenance_margin": "0.075"
},
"liquidation_penalty": "0.1"
}
},
"margin_usage": {
"initial_margin": "0",
"maintenance_margin": "0"
},
"max_withdrawable_amount": "10000"
},
"status": "confirmed",
"confirmed_by_transaction_id": "0x8681959c118ea67dff6272da137aacdce4cdb87aaf06cae380842f19b8b0ac2b"
},
{
"company": "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a",
"created_at": "2024-04-03T17:35:23.710289Z",
"address": "0xa0ee7a142d267c1f36714e4a8f75612f20a79720",
"margin_usage": {
"balance": "0",
"margin_params": {
"margin_mode": "simple",
"params": {
"asset_params": {},
"auto_liquidation": true,
"default_asset_param": {
"futures_initial_margin": "0.02",
"futures_leverage": "20000",
"futures_maintenance_margin": "0.01",
"option_initial_margin": "0.15",
"option_initial_margin_min": "0.1",
"option_maintenance_margin": "0.075"
},
"liquidation_penalty": "0.1"
}
},
"margin_usage": {
"initial_margin": "0",
"maintenance_margin": "0"
},
"max_withdrawable_amount": "0"
},
"status": "confirmed",
"confirmed_by_transaction_id": "0x8681959c118ea67dff6272da137aacdce4cdb87aaf06cae380842f19b8b0ac2b"
}
]
},
"pool_id": "6b2120ac-2aaf-40bc-b369-75d7e231c529"
}
Last updated 2 months ago