Python SDK Reference

afp

Autonomous Futures Protocol Python SDK: afp-sdk

Classes:

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; use AFP_PRIVATE_KEY for private key authentication, AFP_KEYFILE and AFP_KEYFILE_PASSWORD for keyfile authentication.
  • rpc_url (str) – The URL of an Autonity RPC provider. Can also be set with the AFP_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 the AFP_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 the AFP_CHAIN_ID environment variable.
  • gas_limit (int) – The gasLimit parameter of blockchain transactions. Estimated with the eth_estimateGas JSON-RPC call if not specified. Its default value can be overridden with the AFP_GAS_LIMIT environment variable.
  • max_fee_per_gas (int) – The maxFeePerGas parameter of blockchain transactions in ton (wei) units. Defaults to baseFeePerGas from the return value of the eth_getBlock JSON-RPC call. Its default value can be overridden with the AFP_MAX_FEE_PER_GAS environment variable.
  • max_priority_fee_per_gas (int) – The maxPriorityFeePerGas parameter of blockchain transactions in ton (wei) units. Defaults to the return value of the eth_maxPriorityFeePerGas JSON-RPC call. Its default value can be overridden with the AFP_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 the AFP_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 the AFP_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 the AFP_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 the AFP_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 the AFP_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 the AFP_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

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 the AFP constructor.
  • exchange_url (str | None) – The REST API base URL of the exchange. Defaults to the value specified in the AFP constructor.

Raises:

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 the AFP constructor.

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 the AFP constructor.

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 the AFP constructor.
  • exchange_url (str | None) – The REST API base URL of the exchange. Defaults to the value specified in the AFP constructor.

Raises:

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: 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:

  • key_file (str) – The path to the keyfile.
  • password (str) – The password for decrypting the keyfile.

Functions:

Attributes:

afp.KeyfileAuthenticator.address

address = self._account.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:

afp.PrivateKeyAuthenticator.address

address = self._account.address

afp.PrivateKeyAuthenticator.sign_message

sign_message(message)

afp.PrivateKeyAuthenticator.sign_transaction

sign_transaction(params)