Python SDK Reference

afp

Autonomous Futures Protocol Python SDK.

Classes:

  • Admin – API for AutEx administration, restricted to AutEx admins.
  • Builder – API for building and submitting new products.
  • Clearing – API for managing margin accounts.
  • Liquidation – API for participating in liquidation auctions.
  • Trading – API for trading in the AutEx exchange.

afp.Admin

Bases: ExchangeAPI

API for AutEx administration, restricted to AutEx admins.

Authenticates with the exchange on creation.

Parameters:

  • private_key (str) – The private key of the exchange adminstrator account.

Raises:

Functions:

afp.Admin.approve_product

approve_product(product_id)

Approves a product for trading on the exchange.

Parameters:

  • product_id (str) –

Raises:

afp.Admin.delist_product

delist_product(product_id)

Delists a product from the exchange.

New order submissions of this product will be rejected.

Parameters:

  • product_id (str) –

Raises:

afp.Builder

Bases: ClearingSystemAPI

API for building and submitting new products.

Parameters:

  • private_key (str) – The private key of the blockchain account that submits the product.
  • autonity_rpc_url (str) – The URL of a JSON-RPC provider for Autonity. (HTTPS only.)

Functions:

  • create_product – Creates a product specification with the given product data.
  • product_state – Returns the current state of a product.
  • register_product – Submits a product specification to the clearing system.

afp.Builder.create_product

create_product(*, symbol, description, oracle_address, fsv_decimals, fsp_alpha, fsp_beta, fsv_calldata, start_time, earliest_fsp_submission_time, collateral_asset, tick_size, unit_value, initial_margin_requirement, maintenance_margin_requirement, offer_price_buffer, auction_bounty, tradeout_interval, extended_metadata)

Creates a product specification with the given product data.

The builder account’s address is derived from the private key; the price quotation symbol is retrieved from the collateral asset.

Parameters:

  • symbol (str) –
  • description (str) –
  • oracle_address (str) –
  • fsv_decimals (int) –
  • fsp_alpha (Decimal) –
  • fsp_beta (Decimal) –
  • fsv_calldata (str) –
  • start_time (datetime) –
  • earliest_fsp_submission_time (datetime) –
  • collateral_asset (str) –
  • tick_size (int) –
  • unit_value (Decimal) –
  • initial_margin_requirement (Decimal) –
  • maintenance_margin_requirement (Decimal) –
  • offer_price_buffer (Decimal) –
  • auction_bounty (Decimal) –
  • tradeout_interval (int) –
  • extended_metadata (str) –

Returns:

afp.Builder.product_state

product_state(product_id)

Returns the current state of a product.

Parameters:

  • product_id (str) – The ID of the product.

Returns:

afp.Builder.register_product

register_product(product)

Submits a product specification to the clearing system.

Parameters:

Returns:

  • str – The hash of the transaction.

afp.Clearing

Bases: ClearingSystemAPI

API for managing margin accounts.

Parameters:

  • private_key (str) – The private key of the blockchain account that manages the margin account.
  • autonity_rpc_url (str) – The URL of a JSON-RPC provider for Autonity. (HTTPS only.)

Functions:

  • authorize – Authorizes a blockchain account to submit intents to the clearing system
  • capital – Returns the amount of collateral tokens in the margin account associated
  • collateral_asset – Returns the collateral asset of a product.
  • deposit_into_margin_account – Deposits the specified amount of collateral tokens into the margin account
  • initiate_final_settlement – Initiate final settlement (closeout) process for the specified accounts.
  • maintenance_margin_available – Returns the maintenance margin available in the margin account associated
  • maintenance_margin_used – Returns the maintenance margin used in the margin account associated with
  • margin_account_equity – Returns the margin account equity in the margin account associated with the
  • position – Returns the parameters of a position in the margin account associated with
  • positions – Returns all positions in the margin account associated with the collateral
  • product_state – Returns the current state of a product.
  • profit_and_loss – Returns the profit and loss in the margin account associated with the
  • withdraw_from_margin_account – Withdraws the specified amount of collateral tokens from the margin account
  • withdrawable_amount – Returns the amount of collateral tokens withdrawable from the margin account

afp.Clearing.authorize

authorize(collateral_asset, intent_account_id)

Authorizes a blockchain account to submit intents to the clearing system using the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.
  • intent_account_id (str) – The address of the intent account.

Returns:

  • str – The hash of the transaction.

afp.Clearing.capital

capital(collateral_asset)

Returns the amount of collateral tokens in the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.

Returns:

afp.Clearing.collateral_asset

collateral_asset(product_id)

Returns the collateral asset of a product.

Parameters:

  • product_id (str) – The ID of the product.

Returns:

afp.Clearing.deposit_into_margin_account

deposit_into_margin_account(collateral_asset, amount)

Deposits the specified amount of collateral tokens into the margin account associated with the collateral asset.

First approves the token transfer with the collateral token, then executes the transfer.

Parameters:

  • collateral_asset (str) – The address of the collateral token.
  • amount (Decimal) – The amount of collateral tokens to deposit.

Returns:

  • str – The hash of the approval transaction.
  • str – The hash of the deposit transaction.

afp.Clearing.initiate_final_settlement

initiate_final_settlement(product_id, accounts)

Initiate final settlement (closeout) process for the specified accounts.

The product must be in Final Settlement state. The accounts must hold non-zero positions in the product that offset each other (i.e. the sum of their position sizes is 0.)

Parameters:

  • product_id (str) – The ID of the product.
  • accounts (list of str) – List of margin account IDs to initiate settlement for.

Returns:

  • str – The hash of the transaction.

afp.Clearing.maintenance_margin_available

maintenance_margin_available(collateral_asset)

Returns the maintenance margin available in the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.

Returns:

afp.Clearing.maintenance_margin_used

maintenance_margin_used(collateral_asset)

Returns the maintenance margin used in the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.

Returns:

afp.Clearing.margin_account_equity

margin_account_equity(collateral_asset)

Returns the margin account equity in the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.

Returns:

afp.Clearing.position

position(collateral_asset, position_id)

Returns the parameters of a position in the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.
  • position_id (str) – The ID of the position.

Returns:

afp.Clearing.positions

positions(collateral_asset)

Returns all positions in the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.

Returns:

  • list of afp.schemas.Position

afp.Clearing.product_state

product_state(product_id)

Returns the current state of a product.

Parameters:

  • product_id (str) – The ID of the product.

Returns:

afp.Clearing.profit_and_loss

profit_and_loss(collateral_asset)

Returns the profit and loss in the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.

Returns:

afp.Clearing.withdraw_from_margin_account

withdraw_from_margin_account(collateral_asset, amount)

Withdraws the specified amount of collateral tokens from the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.
  • amount (Decimal) – The amount of collateral tokens to withdraw.

Returns:

  • str – The hash of the transaction.

afp.Clearing.withdrawable_amount

withdrawable_amount(collateral_asset)

Returns the amount of collateral tokens withdrawable from the margin account associated with the collateral asset.

Parameters:

  • collateral_asset (str) – The address of the collateral token.

Returns:

afp.Liquidation

Bases: ClearingSystemAPI

API for participating in liquidation auctions.

Parameters:

  • private_key (str) – The private key of the blockchain account that participates in a liquidation auction.
  • autonity_rpc_url (str) – The URL of a JSON-RPC provider for Autonity. (HTTPS only.)

Functions:

afp.Liquidation.auction_data

auction_data(margin_account_id, collateral_asset)

Returns information on a liquidation auction.

Parameters:

  • margin_account_id (str) – The ID of the margin account to be liquidated.
  • collateral_asset (str) – The address of the collateral token that the margin account is trading with.

Returns:

  • str – The hash of the transaction.

afp.Liquidation.create_bid

create_bid(product_id, price, quantity, side)

Create a bid to be submitted to a liquidation auction.

Parameters:

Returns:

afp.Liquidation.request_liquidation

request_liquidation(margin_account_id, collateral_asset)

Request a liquidation auction to be started.

Parameters:

  • margin_account_id (str) – The ID of the margin account to be liquidated.
  • collateral_asset (str) – The address of the collateral token that the margin account is trading with.

Returns:

  • str – The hash of the transaction.

afp.Liquidation.submit_bids

submit_bids(margin_account_id, collateral_asset, bids)

Submit bids to a liquidation auction.

Parameters:

  • margin_account_id (str) – The ID of the margin account that is being liquidated.
  • collateral_asset (str) – The address of the collateral token that the margin account is trading with.
  • bids (Iterable[Bid]) –

Returns:

  • str – The hash of the transaction.

afp.Trading

Bases: ExchangeAPI

API for trading in the AutEx exchange.

Authenticates with the exchange on creation.

Parameters:

  • private_key (str) – The private key of the account that submits intents to the exchange.

Raises:

Functions:

  • create_intent – Creates an intent with the given intent data, generates its hash and signs it
  • iter_market_depth – Subscribes to updates of the depth of market for the given product.
  • iter_order_fills – Subscribes to the authenticated account’s new order fills that match the
  • market_depth – Retrieves the depth of market for the given product.
  • open_orders – Retrieves all open and partially filled limit orders that have been submitted
  • order – Retrieves an order by its ID from the orders that have been submitted by the
  • order_fills – Retrieves the authenticated account’s order fills that match the given
  • product – Retrieves a product for trading by its ID.
  • products – Retrieves the products approved for trading on the exchange.
  • submit_cancel_order – Sends a cancellation order to the exchange.
  • submit_limit_order – Sends an intent expressing a limit order to the exchange.

afp.Trading.create_intent

create_intent(*, product, side, limit_price, quantity, max_trading_fee_rate, good_until_time, margin_account_id=None, rounding=None)

Creates an intent with the given intent data, generates its hash and signs it with the configured account’s private key.

The intent account’s address is derived from the private key. The intent account is assumed to be the same as the margin account if the margin account ID is not specified.

The limit price must have at most as many fractional digits as the product’s tick size, or if rounding is specified then the limit price is rounded to the appropriate number of fractional digits. rounding may be one of ROUND_CEILING, ROUND_FLOOR, ROUND_UP, ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_DOWN, ROUND_HALF_EVEN and ROUND_05UP; see the rounding modes of the decimal module of the Python Standard Library.

Parameters:

  • product (ExchangeProduct) –
  • side (str) –
  • limit_price (Decimal) –
  • quantity (Decimal) –
  • max_trading_fee_rate (Decimal) –
  • good_until_time (datetime) –
  • margin_account_id (str) –
  • rounding (str) – A rounding mode of the decimal module or None for no rounding.

Returns:

afp.Trading.iter_market_depth

iter_market_depth(product_id)

Subscribes to updates of the depth of market for the given product.

Returns a generator that yields the updated market depth data as it is published by the exhange.

Parameters:

  • product_id (str) –

Yields:

Raises:

afp.Trading.iter_order_fills

iter_order_fills(*, product_id=None, margin_account_id=None, intent_hash=None)

Subscribes to the authenticated account’s new order fills that match the given parameters.

Returns a generator that yields new order fills as they are published by the exchange. A new order fill gets publised as soon as there is a match in the order book, before the trade is submitted to clearing.

Parameters:

  • product_id (str) –
  • margin_account_id (str) –
  • intent_hash (str) –

Yields:

afp.Trading.market_depth

market_depth(product_id)

Retrieves the depth of market for the given product.

Parameters:

  • product_id (str) –

Returns:

Raises:

afp.Trading.open_orders

open_orders()

Retrieves all open and partially filled limit orders that have been submitted by the authenticated account.

Returns:

  • list of afp.schemas.Order

afp.Trading.order

order(order_id)

Retrieves an order by its ID from the orders that have been submitted by the authenticated account.

Parameters:

  • order_id (str) –

Returns:

Raises:

afp.Trading.order_fills

order_fills(*, product_id=None, margin_account_id=None, intent_hash=None, start=None, end=None)

Retrieves the authenticated account’s order fills that match the given parameters.

Parameters:

Returns:

  • list of afp.schemas.OrderFill

afp.Trading.product

product(product_id)

Retrieves a product for trading by its ID.

Parameters:

  • product_id (str) –

Returns:

Raises:

afp.Trading.products

products()

Retrieves the products approved for trading on the exchange.

Returns:

  • list of afp.schemas.ExchangeProduct

afp.Trading.submit_cancel_order

submit_cancel_order(intent_hash)

Sends a cancellation order to the exchange.

Parameters:

  • intent_hash (str) –

Returns:

Raises:

afp.Trading.submit_limit_order

submit_limit_order(intent)

Sends an intent expressing a limit order to the exchange.

Parameters:

Returns:

Raises: