afp-sdk 0.3.0__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. afp_sdk-0.5.0/CHANGELOG.md +28 -0
  2. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/PKG-INFO +54 -50
  3. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/README.md +53 -49
  4. afp_sdk-0.5.0/afp/__init__.py +15 -0
  5. afp_sdk-0.5.0/afp/afp.py +210 -0
  6. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/api/admin.py +1 -14
  7. afp_sdk-0.5.0/afp/api/base.py +129 -0
  8. afp_sdk-0.3.0/afp/api/clearing.py → afp_sdk-0.5.0/afp/api/margin_account.py +172 -104
  9. afp_sdk-0.3.0/afp/api/builder.py → afp_sdk-0.5.0/afp/api/product.py +103 -41
  10. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/api/trading.py +18 -31
  11. afp_sdk-0.5.0/afp/auth.py +66 -0
  12. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/bankruptcy_facet.py +36 -0
  13. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/clearing_facet.py +28 -0
  14. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/facade.py +25 -13
  15. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/margin_account.py +108 -0
  16. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/product_registry.py +1 -48
  17. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/system_viewer.py +1 -7
  18. afp_sdk-0.5.0/afp/config.py +28 -0
  19. afp_sdk-0.5.0/afp/constants.py +52 -0
  20. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/decorators.py +3 -1
  21. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/exceptions.py +7 -3
  22. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/exchange.py +15 -7
  23. afp_sdk-0.3.0/afp/signing.py → afp_sdk-0.5.0/afp/hashing.py +4 -12
  24. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/schemas.py +9 -1
  25. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/validators.py +1 -0
  26. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/examples/cancel_order.py +5 -8
  27. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/examples/create_product.py +9 -9
  28. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/examples/execute_trade.py +13 -13
  29. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/pyproject.toml +5 -2
  30. afp_sdk-0.5.0/tests/__init__.py +25 -0
  31. afp_sdk-0.5.0/tests/assets/test.key +1 -0
  32. afp_sdk-0.5.0/tests/test_afp.py +42 -0
  33. afp_sdk-0.5.0/tests/test_base_api.py +126 -0
  34. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/tests/test_decorators.py +8 -6
  35. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/tests/test_exchange_client.py +3 -4
  36. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/tests/test_hashing.py +4 -4
  37. afp_sdk-0.5.0/tests/test_signing.py +26 -0
  38. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/uv.lock +1 -1
  39. afp_sdk-0.3.0/CHANGELOG.md +0 -64
  40. afp_sdk-0.3.0/afp/__init__.py +0 -10
  41. afp_sdk-0.3.0/afp/api/base.py +0 -76
  42. afp_sdk-0.3.0/afp/api/liquidation.py +0 -167
  43. afp_sdk-0.3.0/afp/config.py +0 -42
  44. afp_sdk-0.3.0/tests/__init__.py +0 -0
  45. afp_sdk-0.3.0/tests/test_login.py +0 -26
  46. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/.env.template +0 -0
  47. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/.envrc +0 -0
  48. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/LICENSE +0 -0
  49. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/api/__init__.py +0 -0
  50. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/__init__.py +0 -0
  51. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/auctioneer_facet.py +0 -0
  52. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/erc20.py +0 -0
  53. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/final_settlement_facet.py +0 -0
  54. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/margin_account_registry.py +0 -0
  55. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/mark_price_tracker_facet.py +0 -0
  56. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/oracle_provider.py +0 -0
  57. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/bindings/trading_protocol.py +0 -0
  58. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/enums.py +0 -0
  59. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/afp/py.typed +0 -0
  60. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/devenv.lock +0 -0
  61. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/devenv.nix +0 -0
  62. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/devenv.yaml +0 -0
  63. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/tests/test_schemas.py +0 -0
  64. {afp_sdk-0.3.0 → afp_sdk-0.5.0}/tests/test_validators.py +0 -0
@@ -0,0 +1,28 @@
1
+ ## [v0.5.0] - 2025-09-18
2
+
3
+ ### Added
4
+
5
+ - Add key file authentication. ([#22](https://github.com/autonity/afp-sdk/pull/22))
6
+
7
+ ### Changed
8
+
9
+ - Complete rework of the API and configuration management with breaking non backwards compatible changes. See the API reference. ([#22](https://github.com/autonity/afp-sdk/pull/22))
10
+
11
+ ## [v0.4.0] - 2025-09-17
12
+
13
+ ### Added
14
+
15
+ - Add `product_id` argument to `Trading.open_orders()` for filtering orders by product ([#21](https://github.com/autonity/afp-sdk/pull/21))
16
+ - Add new contract events to contract bindings ([#21](https://github.com/autonity/afp-sdk/pull/21))
17
+
18
+ ### Removed
19
+
20
+ - Remove the `offer_price_buffer` product parameter from `Builder.create_product()` ([#23](https://github.com/autonity/afp-sdk/pull/23))
21
+
22
+ ## [v0.3.0] - 2025-09-05
23
+
24
+ _First public release for Forecastathon._
25
+
26
+ [v0.5.0]: https://github.com/autonity/afp-sdk/releases/tag/v0.5.0
27
+ [v0.4.0]: https://github.com/autonity/afp-sdk/releases/tag/v0.4.0
28
+ [v0.3.0]: https://github.com/autonity/afp-sdk/releases/tag/v0.3.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: afp-sdk
3
- Version: 0.3.0
3
+ Version: 0.5.0
4
4
  Summary: Autonomous Futures Protocol Python SDK
5
5
  Keywords: autonity,web3,trading,crypto,prediction,forecast,markets
6
6
  License-Expression: MIT
@@ -25,6 +25,10 @@ Description-Content-Type: text/markdown
25
25
 
26
26
  # Autonomous Futures Protocol Python SDK
27
27
 
28
+ Decentralized clearing and creation of Forecast Futures on any timeseries.
29
+
30
+ ![CI](https://github.com/autonity/afp-sdk/actions/workflows/ci.yml/badge.svg)
31
+
28
32
  ## Installation
29
33
 
30
34
  This library is published on PyPI as the [afp-sdk](https://pypi.org/project/afp-sdk/)
@@ -34,6 +38,11 @@ package. It can be installed in a virtualenv with:
34
38
  pip install afp-sdk
35
39
  ```
36
40
 
41
+ ## Documentation
42
+
43
+ See [afp.autonity.org](https://afp.autonity.org/) for the Autonomous Futures Protocol
44
+ documentation, including the Python SDK reference.
45
+
37
46
  ## Overview
38
47
 
39
48
  The `afp` package consists of the following:
@@ -43,6 +52,13 @@ The `afp` package consists of the following:
43
52
  - `afp.bindings` submodule: Low-level API that provides typed Python bindings
44
53
  for the Clearing System smart contracts.
45
54
 
55
+ ## Configuration
56
+
57
+ By default the SDK communicates with the AFP Clearing System contracts on
58
+ Autonity Mainnet, and the AutEx Exchange. Connection parameters can be
59
+ overridden via the `afp.AFP` constructor and environment variables; see the
60
+ documentation of the `afp.AFP` class for the available parameters.
61
+
46
62
  ## Usage
47
63
 
48
64
  ### Preparation
@@ -53,7 +69,8 @@ In order to trade in the AFP system, traders need to prepare the following:
53
69
  - The address of the product's collateral token.
54
70
  - An Autonity account for managing the margin account. It needs to hold a
55
71
  balance in ATN (for paying gas fee) and in the product's collateral token.
56
- - An Autonity account for signing intents. The two accounts can be the same.
72
+ - An Autonity account for signing intents and submitting trades to the
73
+ exchange. The two accounts can be the same.
57
74
  - The address of an Autonity RPC provider. They can be found on
58
75
  [Chainlist](https://chainlist.org/?search=autonity).
59
76
 
@@ -64,57 +81,60 @@ import os
64
81
 
65
82
  PRODUCT_ID = "0x38d502bb683f53ec7c3d7a14b4aa47ac717659e121426131c0189c15bf4b9460"
66
83
  COLLATERAL_ASSET = "0xD1A1e4035a164cF42228A8aAaBC2c0Ac9e49687B"
67
- MARGIN_ACCOUNT_PRIVATE_KEY = os.environ["MARGIN_ACCOUNT_PRIVATE_KEY"]
68
- INTENT_ACCOUNT_PRIVATE_KEY = os.environ["INTENT_ACCOUNT_PRIVATE_KEY"]
84
+ PRIVATE_KEY = os.environ["PRIVATE_KEY"]
69
85
  AUTONITY_RPC_URL = "https://bakerloo.autonity-apis.com"
70
86
  ```
71
87
 
72
- Account IDs (addresses) may be retrieved from the private keys with `eth_account`:
88
+ ### Configuration
73
89
 
74
- ```py
75
- from eth_account import Account
76
-
77
- MARGIN_ACCOUNT_ID = Account.from_key(MARGIN_ACCOUNT_PRIVATE_KEY).address
78
- INTENT_ACCOUNT_ID = Account.from_key(INTENT_ACCOUNT_PRIVATE_KEY).address
79
- ```
90
+ An application instance can be created with the `afp.AFP()` constructor. An instance
91
+ is associated with a trading venue and a margin account.
80
92
 
81
- ### Clearing API
93
+ The required constructor arguments are the RPC provider URL and the authenticator of
94
+ the blockchain account that manages the margin account.
82
95
 
83
- Functions of the Clearing API can be accessed via the `afp.Clearing`
84
- session object. It connects to the specified Autonity RPC provider and
85
- communicates with the Clearing System smart contracts.
96
+ An "authenticator" is a service that implements the `afp.Authenticator` protocol.
97
+ Available options are `afp.PrivateKeyAuthenticator` that reads the private key
98
+ from a constructor argument, and `afp.KeyfileAuthenticator` that reads the private
99
+ key from an encrypted keyfile.
86
100
 
87
101
  ```py
88
102
  import afp
89
103
 
90
- clearing = afp.Clearing(MARGIN_ACCOUNT_PRIVATE_KEY, AUTONITY_RPC_URL)
104
+ app = afp.AFP(
105
+ rpc_url=AUTONITY_RPC_URL,
106
+ authenticator=afp.PrivateKeyAuthenticator(PRIVATE_KEY),
107
+ )
91
108
  ```
92
109
 
93
- Collateral can be deposited into the margin account with
94
- `clearing.deposit_into_margin_account()`.
110
+ ### Margin Account API
95
111
 
96
- ```py
97
- from decimal import Decimal
112
+ Margin accounts can be managed via the `MarginAccount` session object. It
113
+ connects to the specified Autonity RPC provider and communicates with the
114
+ Clearing System smart contracts.
98
115
 
99
- clearing.deposit_into_margin_account(COLLATERAL_ASSET, Decimal("100.00"))
100
- print(clearing.capital(COLLATERAL_ASSET))
116
+ ```py
117
+ margin_account = app.MarginAccount()
101
118
  ```
102
119
 
103
- The intent account should be authorized to submit orders. This is only required
104
- if the intent account and the margin account are different.
120
+ Collateral can be deposited into the margin account with `margin_account.deposit()`.
105
121
 
106
122
  ```py
107
- clearing.authorize(COLLATERAL_ASSET, INTENT_ACCOUNT_ID)
123
+ from decimal import Decimal
124
+
125
+ margin_account.deposit(COLLATERAL_ASSET, Decimal("100.00"))
126
+ print(margin_account.capital(COLLATERAL_ASSET))
108
127
  ```
109
128
 
110
129
  ### Trading API
111
130
 
112
- The functions of the trading API can be accessed via the `afp.Trading` session
113
- object. It communicates with the AutEx exchange and authenticates on creation with
114
- the intent account's private key.
131
+ Functions of the trading API can be accessed via the `Trading` session object.
132
+ It communicates with the AutEx exchange and authenticates on creation with the
133
+ intent account's private key. The intent account authenticator is optional, it
134
+ defaults to the authenticator set in the `AFP` constructor.
115
135
 
116
136
  ```py
117
- trading = afp.Trading(INTENT_ACCOUNT_PRIVATE_KEY)
137
+ trading = app.Trading()
118
138
  ```
119
139
 
120
140
  To start trading a product, its parameters shall be retrieved from the server.
@@ -169,28 +189,12 @@ print(fills)
169
189
 
170
190
  See further code examples in the [examples](./examples/) directory.
171
191
 
172
- ## Configuration
173
-
174
- By default the SDK communicates with the AFP Clearing System contracts on
175
- Autonity Mainnet, and the AutEx Exchange. Connection parameters can be
176
- overridden with the following environment variables:
177
-
178
- ```sh
179
- AFP_EXCHANGE_URL=
180
- AFP_CHAIN_ID=
181
- AFP_CLEARING_DIAMOND_ADDRESS=
182
- AFP_MARGIN_ACCOUNT_REGISTRY_ADDRESS=
183
- AFP_ORACLE_PROVIDER_ADDRESS=
184
- AFP_PRODUCT_REGISTRY_ADDRESS=
185
- AFP_SYSTEM_VIEWER_ADDRESS=
186
- ```
187
-
188
192
  ## Development
189
193
 
190
194
  The package uses [`uv`](https://docs.astral.sh/uv/) as project manager.
191
195
 
192
- - Dependecies can be installed with the `uv sync` command.
193
- - Linters can be executed with the `uv run poe lint` command.
194
- - Tests can be executed with the `uv run poe test` command.
195
- - Distributions can be checked before release with the `uv run poe check-dist` command.
196
- - Markdown API documentation can be generated with the `uv run poe doc-gen` command.
196
+ - Install dependencies with the `uv sync` command.
197
+ - Execute linters with the `uv run poe lint` command.
198
+ - Run tests with the `uv run poe test` command.
199
+ - Check distributions before release with the `uv run poe check-dist` command.
200
+ - Generate markdown API documentation with the `uv run poe doc-gen` command.
@@ -1,5 +1,9 @@
1
1
  # Autonomous Futures Protocol Python SDK
2
2
 
3
+ Decentralized clearing and creation of Forecast Futures on any timeseries.
4
+
5
+ ![CI](https://github.com/autonity/afp-sdk/actions/workflows/ci.yml/badge.svg)
6
+
3
7
  ## Installation
4
8
 
5
9
  This library is published on PyPI as the [afp-sdk](https://pypi.org/project/afp-sdk/)
@@ -9,6 +13,11 @@ package. It can be installed in a virtualenv with:
9
13
  pip install afp-sdk
10
14
  ```
11
15
 
16
+ ## Documentation
17
+
18
+ See [afp.autonity.org](https://afp.autonity.org/) for the Autonomous Futures Protocol
19
+ documentation, including the Python SDK reference.
20
+
12
21
  ## Overview
13
22
 
14
23
  The `afp` package consists of the following:
@@ -18,6 +27,13 @@ The `afp` package consists of the following:
18
27
  - `afp.bindings` submodule: Low-level API that provides typed Python bindings
19
28
  for the Clearing System smart contracts.
20
29
 
30
+ ## Configuration
31
+
32
+ By default the SDK communicates with the AFP Clearing System contracts on
33
+ Autonity Mainnet, and the AutEx Exchange. Connection parameters can be
34
+ overridden via the `afp.AFP` constructor and environment variables; see the
35
+ documentation of the `afp.AFP` class for the available parameters.
36
+
21
37
  ## Usage
22
38
 
23
39
  ### Preparation
@@ -28,7 +44,8 @@ In order to trade in the AFP system, traders need to prepare the following:
28
44
  - The address of the product's collateral token.
29
45
  - An Autonity account for managing the margin account. It needs to hold a
30
46
  balance in ATN (for paying gas fee) and in the product's collateral token.
31
- - An Autonity account for signing intents. The two accounts can be the same.
47
+ - An Autonity account for signing intents and submitting trades to the
48
+ exchange. The two accounts can be the same.
32
49
  - The address of an Autonity RPC provider. They can be found on
33
50
  [Chainlist](https://chainlist.org/?search=autonity).
34
51
 
@@ -39,57 +56,60 @@ import os
39
56
 
40
57
  PRODUCT_ID = "0x38d502bb683f53ec7c3d7a14b4aa47ac717659e121426131c0189c15bf4b9460"
41
58
  COLLATERAL_ASSET = "0xD1A1e4035a164cF42228A8aAaBC2c0Ac9e49687B"
42
- MARGIN_ACCOUNT_PRIVATE_KEY = os.environ["MARGIN_ACCOUNT_PRIVATE_KEY"]
43
- INTENT_ACCOUNT_PRIVATE_KEY = os.environ["INTENT_ACCOUNT_PRIVATE_KEY"]
59
+ PRIVATE_KEY = os.environ["PRIVATE_KEY"]
44
60
  AUTONITY_RPC_URL = "https://bakerloo.autonity-apis.com"
45
61
  ```
46
62
 
47
- Account IDs (addresses) may be retrieved from the private keys with `eth_account`:
63
+ ### Configuration
48
64
 
49
- ```py
50
- from eth_account import Account
51
-
52
- MARGIN_ACCOUNT_ID = Account.from_key(MARGIN_ACCOUNT_PRIVATE_KEY).address
53
- INTENT_ACCOUNT_ID = Account.from_key(INTENT_ACCOUNT_PRIVATE_KEY).address
54
- ```
65
+ An application instance can be created with the `afp.AFP()` constructor. An instance
66
+ is associated with a trading venue and a margin account.
55
67
 
56
- ### Clearing API
68
+ The required constructor arguments are the RPC provider URL and the authenticator of
69
+ the blockchain account that manages the margin account.
57
70
 
58
- Functions of the Clearing API can be accessed via the `afp.Clearing`
59
- session object. It connects to the specified Autonity RPC provider and
60
- communicates with the Clearing System smart contracts.
71
+ An "authenticator" is a service that implements the `afp.Authenticator` protocol.
72
+ Available options are `afp.PrivateKeyAuthenticator` that reads the private key
73
+ from a constructor argument, and `afp.KeyfileAuthenticator` that reads the private
74
+ key from an encrypted keyfile.
61
75
 
62
76
  ```py
63
77
  import afp
64
78
 
65
- clearing = afp.Clearing(MARGIN_ACCOUNT_PRIVATE_KEY, AUTONITY_RPC_URL)
79
+ app = afp.AFP(
80
+ rpc_url=AUTONITY_RPC_URL,
81
+ authenticator=afp.PrivateKeyAuthenticator(PRIVATE_KEY),
82
+ )
66
83
  ```
67
84
 
68
- Collateral can be deposited into the margin account with
69
- `clearing.deposit_into_margin_account()`.
85
+ ### Margin Account API
70
86
 
71
- ```py
72
- from decimal import Decimal
87
+ Margin accounts can be managed via the `MarginAccount` session object. It
88
+ connects to the specified Autonity RPC provider and communicates with the
89
+ Clearing System smart contracts.
73
90
 
74
- clearing.deposit_into_margin_account(COLLATERAL_ASSET, Decimal("100.00"))
75
- print(clearing.capital(COLLATERAL_ASSET))
91
+ ```py
92
+ margin_account = app.MarginAccount()
76
93
  ```
77
94
 
78
- The intent account should be authorized to submit orders. This is only required
79
- if the intent account and the margin account are different.
95
+ Collateral can be deposited into the margin account with `margin_account.deposit()`.
80
96
 
81
97
  ```py
82
- clearing.authorize(COLLATERAL_ASSET, INTENT_ACCOUNT_ID)
98
+ from decimal import Decimal
99
+
100
+ margin_account.deposit(COLLATERAL_ASSET, Decimal("100.00"))
101
+ print(margin_account.capital(COLLATERAL_ASSET))
83
102
  ```
84
103
 
85
104
  ### Trading API
86
105
 
87
- The functions of the trading API can be accessed via the `afp.Trading` session
88
- object. It communicates with the AutEx exchange and authenticates on creation with
89
- the intent account's private key.
106
+ Functions of the trading API can be accessed via the `Trading` session object.
107
+ It communicates with the AutEx exchange and authenticates on creation with the
108
+ intent account's private key. The intent account authenticator is optional, it
109
+ defaults to the authenticator set in the `AFP` constructor.
90
110
 
91
111
  ```py
92
- trading = afp.Trading(INTENT_ACCOUNT_PRIVATE_KEY)
112
+ trading = app.Trading()
93
113
  ```
94
114
 
95
115
  To start trading a product, its parameters shall be retrieved from the server.
@@ -144,28 +164,12 @@ print(fills)
144
164
 
145
165
  See further code examples in the [examples](./examples/) directory.
146
166
 
147
- ## Configuration
148
-
149
- By default the SDK communicates with the AFP Clearing System contracts on
150
- Autonity Mainnet, and the AutEx Exchange. Connection parameters can be
151
- overridden with the following environment variables:
152
-
153
- ```sh
154
- AFP_EXCHANGE_URL=
155
- AFP_CHAIN_ID=
156
- AFP_CLEARING_DIAMOND_ADDRESS=
157
- AFP_MARGIN_ACCOUNT_REGISTRY_ADDRESS=
158
- AFP_ORACLE_PROVIDER_ADDRESS=
159
- AFP_PRODUCT_REGISTRY_ADDRESS=
160
- AFP_SYSTEM_VIEWER_ADDRESS=
161
- ```
162
-
163
167
  ## Development
164
168
 
165
169
  The package uses [`uv`](https://docs.astral.sh/uv/) as project manager.
166
170
 
167
- - Dependecies can be installed with the `uv sync` command.
168
- - Linters can be executed with the `uv run poe lint` command.
169
- - Tests can be executed with the `uv run poe test` command.
170
- - Distributions can be checked before release with the `uv run poe check-dist` command.
171
- - Markdown API documentation can be generated with the `uv run poe doc-gen` command.
171
+ - Install dependencies with the `uv sync` command.
172
+ - Execute linters with the `uv run poe lint` command.
173
+ - Run tests with the `uv run poe test` command.
174
+ - Check distributions before release with the `uv run poe check-dist` command.
175
+ - Generate markdown API documentation with the `uv run poe doc-gen` command.
@@ -0,0 +1,15 @@
1
+ """Autonomous Futures Protocol Python SDK."""
2
+
3
+ from . import bindings
4
+ from .afp import AFP
5
+ from .auth import Authenticator, KeyfileAuthenticator, PrivateKeyAuthenticator
6
+ from .exceptions import AFPException
7
+
8
+ __all__ = (
9
+ "bindings",
10
+ "AFP",
11
+ "AFPException",
12
+ "Authenticator",
13
+ "KeyfileAuthenticator",
14
+ "PrivateKeyAuthenticator",
15
+ )
@@ -0,0 +1,210 @@
1
+ from .auth import Authenticator, KeyfileAuthenticator, PrivateKeyAuthenticator
2
+ from .config import Config
3
+ from .api.admin import Admin
4
+ from .api.margin_account import MarginAccount
5
+ from .api.product import Product
6
+ from .api.trading import Trading
7
+ from .constants import defaults
8
+ from .exceptions import ConfigurationError
9
+ from .validators import validate_address
10
+
11
+
12
+ class AFP:
13
+ """Application object for interacting with the AFP Clearing System and the AutEx
14
+ exchange.
15
+
16
+ Parameters
17
+ ----------
18
+ authenticator : afp.Authenticator, optional
19
+ The default authenticator for signing transactions & messages. Can also be set
20
+ with environment variables; use `AFP_PRIVATE_KEY` for private key
21
+ authentication, `AFP_KEYFILE` and `AFP_KEYFILE_PASSWORD` for keyfile
22
+ authentication.
23
+ rpc_url : str, optional
24
+ The URL of an Autonity RPC provider. Can also be set with the `AFP_RPC_URL`
25
+ environment variable.
26
+ exchange_url : str, optional
27
+ The REST API base URL of the exchange. Defaults to the URL of the AutEx
28
+ exchange. Its default value can be overridden with the `AFP_EXCHANGE_URL`
29
+ environment variable.
30
+ chain_id : str, optional
31
+ The chain ID of the Autonity network. Defauls to the chain ID of Autonity
32
+ Mainnet. Its default value can be overridden with the `AFP_CHAIN_ID` environment
33
+ variable.
34
+ gas_limit : int, optional
35
+ The `gasLimit` parameter of blockchain transactions. Estimated with the
36
+ `eth_estimateGas` JSON-RPC call if not specified. Its default value can be
37
+ overridden with the `AFP_GAS_LIMIT` environment variable.
38
+ max_fee_per_gas : int, optional
39
+ The `maxFeePerGas` parameter of blockchain transactions in ton (wei) units.
40
+ Defaults to `baseFeePerGas` from the return value of the `eth_getBlock` JSON-RPC
41
+ call. Its default value can be overridden with the `AFP_MAX_FEE_PER_GAS`
42
+ environment variable.
43
+ max_priority_fee_per_gas : int, optional
44
+ The `maxPriorityFeePerGas` parameter of blockchain transactions in ton (wei)
45
+ units. Defaults to the return value of the `eth_maxPriorityFeePerGas` JSON-RPC
46
+ call. Its default value can be overridden with the
47
+ `AFP_MAX_PRIORITY_FEE_PER_GAS` environment variable.
48
+ timeout_seconds: int, optional
49
+ The number of seconds to wait for a blockchain transaction to be mined.
50
+ Defaults to 10 seconds. Its default value can be overridden with the
51
+ `AFP_TIMEOUT_SECONDS` environment variable.
52
+ clearing_diamond_address : str, optional
53
+ The address of the ClearingDiamond contract. Defaults to the Autonity Mainnet
54
+ deployment address. Its default value can be overridden with the
55
+ `AFP_CLEARING_DIAMOND_ADDRESS` environment variable.
56
+ margin_account_registry_address : str, optional
57
+ The address of the MarginAccountRegistry contract. Defaults to the Autonity
58
+ Mainnet deployment address. Its default value can be overridden with the
59
+ `AFP_MARGIN_ACCOUNT_REGISTRY_ADDRESS` environment variable.
60
+ oracle_provider_address : str, optional
61
+ The address of the OracleProvider contract. Defaults to the Autonity Mainnet
62
+ deployment address. Its default value can be overridden with the
63
+ `AFP_ORACLE_PROVIDER_ADDRESS` environment variable.
64
+ product_registry_address: str, optional
65
+ The address of the ProductRegistry contract. Defaults to the Autonity Mainnet
66
+ deployment address. Its default value can be overridden with the
67
+ `AFP_PRODUCT_REGISTRY_ADDRESS` environment variable.
68
+ system_viewer_address: str, optional
69
+ The address of the SystemViewer contract. Defaults to the Autonity Mainnet
70
+ deployment address. Its default value can be overridden with the
71
+ `AFP_SYSTEM_VIEWER_ADDRESS` environment variable.
72
+ """
73
+
74
+ config: Config
75
+
76
+ def __init__(
77
+ self,
78
+ *,
79
+ authenticator: Authenticator | None = None,
80
+ rpc_url: str | None = defaults.RPC_URL,
81
+ exchange_url: str = defaults.EXCHANGE_URL,
82
+ chain_id: int = defaults.CHAIN_ID,
83
+ gas_limit: int | None = defaults.GAS_LIMIT,
84
+ max_fee_per_gas: int | None = defaults.MAX_FEE_PER_GAS,
85
+ max_priority_fee_per_gas: int | None = defaults.MAX_PRIORITY_FEE_PER_GAS,
86
+ timeout_seconds: int = defaults.TIMEOUT_SECONDS,
87
+ clearing_diamond_address: str = defaults.CLEARING_DIAMOND_ADDRESS,
88
+ margin_account_registry_address: str = defaults.MARGIN_ACCOUNT_REGISTRY_ADDRESS,
89
+ oracle_provider_address: str = defaults.ORACLE_PROVIDER_ADDRESS,
90
+ product_registry_address: str = defaults.PRODUCT_REGISTRY_ADDRESS,
91
+ system_viewer_address: str = defaults.SYSTEM_VIEWER_ADDRESS,
92
+ ) -> None:
93
+ if authenticator is None:
94
+ authenticator = _default_authenticator()
95
+
96
+ self.config = Config(
97
+ authenticator=authenticator,
98
+ exchange_url=exchange_url,
99
+ rpc_url=rpc_url,
100
+ chain_id=chain_id,
101
+ gas_limit=gas_limit,
102
+ max_fee_per_gas=max_fee_per_gas,
103
+ max_priority_fee_per_gas=max_priority_fee_per_gas,
104
+ timeout_seconds=timeout_seconds,
105
+ clearing_diamond_address=validate_address(clearing_diamond_address),
106
+ margin_account_registry_address=validate_address(
107
+ margin_account_registry_address
108
+ ),
109
+ oracle_provider_address=validate_address(oracle_provider_address),
110
+ product_registry_address=validate_address(product_registry_address),
111
+ system_viewer_address=validate_address(system_viewer_address),
112
+ )
113
+
114
+ def __repr__(self) -> str:
115
+ return f"AFP(config={repr(self.config)})"
116
+
117
+ # Clearing APIs
118
+
119
+ def MarginAccount(
120
+ self, authenticator: Authenticator | None = None
121
+ ) -> MarginAccount:
122
+ """API for managing margin accounts.
123
+
124
+ Parameters
125
+ ----------
126
+ authenticator : afp.Authenticator, optional
127
+ Authenticator for signing transactions sent to the Clearing System.
128
+ Defaults to the authenticator specified in the `AFP` constructor.
129
+ """
130
+ return MarginAccount(self.config, authenticator=authenticator)
131
+
132
+ def Product(self, authenticator: Authenticator | None = None) -> Product:
133
+ """API for managing products.
134
+
135
+ Parameters
136
+ ----------
137
+ authenticator : afp.Authenticator, optional
138
+ Authenticator for signing transactions sent to the Clearing System.
139
+ Defaults to the authenticator specified in the `AFP` constructor.
140
+ """
141
+ return Product(self.config, authenticator=authenticator)
142
+
143
+ # Exchange APIs
144
+
145
+ def Admin(
146
+ self,
147
+ authenticator: Authenticator | None = None,
148
+ exchange_url: str | None = None,
149
+ ) -> Admin:
150
+ """API for AutEx administration, restricted to AutEx admins.
151
+
152
+ Authenticates with the exchange on creation.
153
+
154
+ Parameters
155
+ ----------
156
+ authenticator : afp.Authenticator, optional
157
+ Authenticator for authenticating with the AutEx exchange. Defaults to the
158
+ authenticator specified in the `AFP` constructor.
159
+ exchange_url: str, optional
160
+ The REST API base URL of the exchange. Defaults to the value specified in
161
+ the `AFP` constructor.
162
+
163
+ Raises
164
+ ------
165
+ afp.exceptions.AuthenticationError
166
+ If the exchange rejects the login attempt.
167
+ """
168
+ return Admin(
169
+ self.config, authenticator=authenticator, exchange_url=exchange_url
170
+ )
171
+
172
+ def Trading(
173
+ self,
174
+ authenticator: Authenticator | None = None,
175
+ exchange_url: str | None = None,
176
+ ) -> Trading:
177
+ """API for trading in the AutEx exchange.
178
+
179
+ Authenticates with the exchange on creation.
180
+
181
+ Parameters
182
+ ----------
183
+ authenticator : afp.Authenticator, optional
184
+ Authenticator for signing intents and authenticating with the AutEx
185
+ exchange. Defaults to the authenticator specified in the `AFP` constructor.
186
+ exchange_url: str, optional
187
+ The REST API base URL of the exchange. Defaults to the value specified in
188
+ the `AFP` constructor.
189
+
190
+ Raises
191
+ ------
192
+ afp.exceptions.AuthenticationError
193
+ If the exchange rejects the login attempt.
194
+ """
195
+ return Trading(
196
+ self.config, authenticator=authenticator, exchange_url=exchange_url
197
+ )
198
+
199
+
200
+ def _default_authenticator() -> Authenticator | None:
201
+ if defaults.PRIVATE_KEY is not None and defaults.KEYFILE is not None:
202
+ raise ConfigurationError(
203
+ "Only one of AFP_PRIVATE_KEY and AFP_KEYFILE environment "
204
+ "variables should be specified"
205
+ )
206
+ if defaults.PRIVATE_KEY is not None:
207
+ return PrivateKeyAuthenticator(defaults.PRIVATE_KEY)
208
+ if defaults.KEYFILE is not None:
209
+ return KeyfileAuthenticator(defaults.KEYFILE, defaults.KEYFILE_PASSWORD)
210
+ return None
@@ -5,20 +5,7 @@ from .base import ExchangeAPI
5
5
 
6
6
 
7
7
  class Admin(ExchangeAPI):
8
- """API for AutEx administration, restricted to AutEx admins.
9
-
10
- Authenticates with the exchange on creation.
11
-
12
- Parameters
13
- ----------
14
- private_key : str
15
- The private key of the exchange adminstrator account.
16
-
17
- Raises
18
- ------
19
- afp.exceptions.AuthenticationError
20
- If the exchange rejects the login attempt.
21
- """
8
+ """API for AutEx administration, restricted to AutEx admins."""
22
9
 
23
10
  @refresh_token_on_expiry
24
11
  def approve_product(self, product_id: str) -> None: