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" : {
"creator_address" : "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266" ,
"creator_company_margin_usage" : {
"balance" : "0" ,
"company" : "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8" ,
"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"
} ,
"other_address" : "0xa0ee7a142d267c1f36714e4a8f75612f20a79720" ,
"other_company_margin_usage" : {
"balance" : "0" ,
"company" : "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a" ,
"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"
} ,
"pool_address" : null ,
"pool_name" : "Tutorial pool" ,
"positions" : [] ,
"status" : "pending"
} ,
"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' ][ 'pool_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" ],
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" ,
"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" : {
"creator_address" : "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266" ,
"creator_company_margin_usage" : {
"balance" : "10000" ,
"company" : "f58b3d2f-b5a6-488d-b8a9-dc2b1f782be8" ,
"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"
} ,
"other_address" : "0xa0ee7a142d267c1f36714e4a8f75612f20a79720" ,
"other_company_margin_usage" : {
"balance" : "0" ,
"company" : "1ebc7ece-093e-42aa-8cdf-028ccb1fc68a" ,
"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"
} ,
"pool_address" : "0x41574c5b15d67f95c7037a19cb7620c2643f2a98" ,
"pool_name" : "Tutorial pool" ,
"positions" : [] ,
"status" : "open"
} ,
"pool_id" : "6b2120ac-2aaf-40bc-b369-75d7e231c529"
}
Last updated 8 months ago