Python SDK Reference
afp
Autonomous Futures Protocol Python SDK: afp-sdk
Classes:
- AFP – Application object for interacting with the AFP Clearing System and the AutEx
- AFPException –
- Authenticator –
- KeyfileAuthenticator – Authenticates with a private key read from an encrypted keyfile.
- PrivateKeyAuthenticator – Authenticates with a private key specified in a constructor argument.
afp.AFP
AFP(*, authenticator=None, rpc_url=defaults.RPC_URL, exchange_url=defaults.EXCHANGE_URL, chain_id=defaults.CHAIN_ID, gas_limit=defaults.GAS_LIMIT, max_fee_per_gas=defaults.MAX_FEE_PER_GAS, max_priority_fee_per_gas=defaults.MAX_PRIORITY_FEE_PER_GAS, timeout_seconds=defaults.TIMEOUT_SECONDS, clearing_diamond_address=defaults.CLEARING_DIAMOND_ADDRESS, margin_account_registry_address=defaults.MARGIN_ACCOUNT_REGISTRY_ADDRESS, oracle_provider_address=defaults.ORACLE_PROVIDER_ADDRESS, product_registry_address=defaults.PRODUCT_REGISTRY_ADDRESS, system_viewer_address=defaults.SYSTEM_VIEWER_ADDRESS)Application object for interacting with the AFP Clearing System and the AutEx exchange.
Parameters:
- authenticator (
Authenticator) – The default authenticator for signing transactions & messages. Can also be set with environment variables; useAFP_PRIVATE_KEYfor private key authentication,AFP_KEYFILEandAFP_KEYFILE_PASSWORDfor keyfile authentication. - rpc_url (
str) – The URL of an Autonity RPC provider. Can also be set with theAFP_RPC_URLenvironment variable. - exchange_url (
str) – The REST API base URL of the exchange. Defaults to the URL of the AutEx exchange. Its default value can be overridden with theAFP_EXCHANGE_URLenvironment variable. - chain_id (
str) – The chain ID of the Autonity network. Defauls to the chain ID of Autonity Mainnet. Its default value can be overridden with theAFP_CHAIN_IDenvironment variable. - gas_limit (
int) – ThegasLimitparameter of blockchain transactions. Estimated with theeth_estimateGasJSON-RPC call if not specified. Its default value can be overridden with theAFP_GAS_LIMITenvironment variable. - max_fee_per_gas (
int) – ThemaxFeePerGasparameter of blockchain transactions in ton (wei) units. Defaults tobaseFeePerGasfrom the return value of theeth_getBlockJSON-RPC call. Its default value can be overridden with theAFP_MAX_FEE_PER_GASenvironment variable. - max_priority_fee_per_gas (
int) – ThemaxPriorityFeePerGasparameter of blockchain transactions in ton (wei) units. Defaults to the return value of theeth_maxPriorityFeePerGasJSON-RPC call. Its default value can be overridden with theAFP_MAX_PRIORITY_FEE_PER_GASenvironment variable. - timeout_seconds (
int) – The number of seconds to wait for a blockchain transaction to be mined. Defaults to 10 seconds. Its default value can be overridden with theAFP_TIMEOUT_SECONDSenvironment variable. - clearing_diamond_address (
str) – The address of the ClearingDiamond contract. Defaults to the Autonity Mainnet deployment address. Its default value can be overridden with theAFP_CLEARING_DIAMOND_ADDRESSenvironment variable. - margin_account_registry_address (
str) – The address of the MarginAccountRegistry contract. Defaults to the Autonity Mainnet deployment address. Its default value can be overridden with theAFP_MARGIN_ACCOUNT_REGISTRY_ADDRESSenvironment variable. - oracle_provider_address (
str) – The address of the OracleProvider contract. Defaults to the Autonity Mainnet deployment address. Its default value can be overridden with theAFP_ORACLE_PROVIDER_ADDRESSenvironment variable. - product_registry_address (
str) – The address of the ProductRegistry contract. Defaults to the Autonity Mainnet deployment address. Its default value can be overridden with theAFP_PRODUCT_REGISTRY_ADDRESSenvironment variable. - system_viewer_address (
str) – The address of the SystemViewer contract. Defaults to the Autonity Mainnet deployment address. Its default value can be overridden with theAFP_SYSTEM_VIEWER_ADDRESSenvironment variable.
Functions:
- Admin – API for AutEx administration, restricted to AutEx admins.
- MarginAccount – API for managing margin accounts.
- Product – API for managing products.
- Trading – API for trading in the AutEx exchange.
Attributes:
afp.AFP.Admin
Admin(authenticator=None, exchange_url=None)API for AutEx administration, restricted to AutEx admins.
Authenticates with the exchange on creation.
Parameters:
- authenticator (
Authenticator) – Authenticator for authenticating with the AutEx exchange. Defaults to the authenticator specified in theAFPconstructor. - exchange_url (
str | None) – The REST API base URL of the exchange. Defaults to the value specified in theAFPconstructor.
Raises:
AuthenticationError– If the exchange rejects the login attempt.
afp.AFP.MarginAccount
MarginAccount(authenticator=None)API for managing margin accounts.
Parameters:
- authenticator (
Authenticator) – Authenticator for signing transactions sent to the Clearing System. Defaults to the authenticator specified in theAFPconstructor.
afp.AFP.Product
Product(authenticator=None)API for managing products.
Parameters:
- authenticator (
Authenticator) – Authenticator for signing transactions sent to the Clearing System. Defaults to the authenticator specified in theAFPconstructor.
afp.AFP.Trading
Trading(authenticator=None, exchange_url=None)API for trading in the AutEx exchange.
Authenticates with the exchange on creation.
Parameters:
- authenticator (
Authenticator) – Authenticator for signing intents and authenticating with the AutEx exchange. Defaults to the authenticator specified in theAFPconstructor. - exchange_url (
str | None) – The REST API base URL of the exchange. Defaults to the value specified in theAFPconstructor.
Raises:
AuthenticationError– If the exchange rejects the login attempt.
afp.AFP.config
config: Config = Config(authenticator=authenticator, exchange_url=exchange_url, rpc_url=rpc_url, chain_id=chain_id, gas_limit=gas_limit, max_fee_per_gas=max_fee_per_gas, max_priority_fee_per_gas=max_priority_fee_per_gas, timeout_seconds=timeout_seconds, clearing_diamond_address=(validate_address(clearing_diamond_address)), margin_account_registry_address=(validate_address(margin_account_registry_address)), oracle_provider_address=(validate_address(oracle_provider_address)), product_registry_address=(validate_address(product_registry_address)), system_viewer_address=(validate_address(system_viewer_address)))afp.AFPException
Bases: Exception
afp.Authenticator
Bases: Protocol
Functions:
Attributes:
afp.Authenticator.address
address: ChecksumAddressafp.Authenticator.sign_message
sign_message(message)afp.Authenticator.sign_transaction
sign_transaction(params)afp.KeyfileAuthenticator
KeyfileAuthenticator(key_file, password)Bases: PrivateKeyAuthenticator
Authenticates with a private key read from an encrypted keyfile.
Parameters:
Functions:
Attributes:
- address –
afp.KeyfileAuthenticator.address
address = self._account.addressafp.KeyfileAuthenticator.sign_message
sign_message(message)afp.KeyfileAuthenticator.sign_transaction
sign_transaction(params)afp.PrivateKeyAuthenticator
PrivateKeyAuthenticator(private_key)Bases: Authenticator
Authenticates with a private key specified in a constructor argument.
Parameters:
- private_key (
str) – The private key of a blockchain account.
Functions:
Attributes:
- address –
afp.PrivateKeyAuthenticator.address
address = self._account.addressafp.PrivateKeyAuthenticator.sign_message
sign_message(message)afp.PrivateKeyAuthenticator.sign_transaction
sign_transaction(params)