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
*, 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) AFP(
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_KEY
for private key authentication,AFP_KEYFILE
andAFP_KEYFILE_PASSWORD
for keyfile authentication. - rpc_url (
str
) – The URL of an Autonity RPC provider. Can also be set with theAFP_RPC_URL
environment 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_URL
environment 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_ID
environment variable. - gas_limit (
int
) – ThegasLimit
parameter of blockchain transactions. Estimated with theeth_estimateGas
JSON-RPC call if not specified. Its default value can be overridden with theAFP_GAS_LIMIT
environment variable. - max_fee_per_gas (
int
) – ThemaxFeePerGas
parameter of blockchain transactions in ton (wei) units. Defaults tobaseFeePerGas
from the return value of theeth_getBlock
JSON-RPC call. Its default value can be overridden with theAFP_MAX_FEE_PER_GAS
environment variable. - max_priority_fee_per_gas (
int
) – ThemaxPriorityFeePerGas
parameter of blockchain transactions in ton (wei) units. Defaults to the return value of theeth_maxPriorityFeePerGas
JSON-RPC call. Its default value can be overridden with theAFP_MAX_PRIORITY_FEE_PER_GAS
environment 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_SECONDS
environment 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_ADDRESS
environment 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_ADDRESS
environment 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_ADDRESS
environment 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_ADDRESS
environment 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_ADDRESS
environment 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
=None, exchange_url=None) Admin(authenticator
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 theAFP
constructor. - exchange_url (
str | None
) – The REST API base URL of the exchange. Defaults to the value specified in theAFP
constructor.
Raises:
AuthenticationError
– If the exchange rejects the login attempt.
afp.AFP.MarginAccount
=None) MarginAccount(authenticator
API for managing margin accounts.
Parameters:
- authenticator (
Authenticator
) – Authenticator for signing transactions sent to the Clearing System. Defaults to the authenticator specified in theAFP
constructor.
afp.AFP.Product
=None) Product(authenticator
API for managing products.
Parameters:
- authenticator (
Authenticator
) – Authenticator for signing transactions sent to the Clearing System. Defaults to the authenticator specified in theAFP
constructor.
afp.AFP.Trading
=None, exchange_url=None) Trading(authenticator
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 theAFP
constructor. - exchange_url (
str | None
) – The REST API base URL of the exchange. Defaults to the value specified in theAFP
constructor.
Raises:
AuthenticationError
– If the exchange rejects the login attempt.
afp.AFP.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))) config: Config
afp.AFPException
Bases: Exception
afp.Authenticator
Bases: Protocol
Functions:
Attributes:
afp.Authenticator.address
address: ChecksumAddress
afp.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
= self._account.address address
afp.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
= self._account.address address
afp.PrivateKeyAuthenticator.sign_message
sign_message(message)
afp.PrivateKeyAuthenticator.sign_transaction
sign_transaction(params)