afp-sdk 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,180 @@
1
+ Metadata-Version: 2.4
2
+ Name: afp-sdk
3
+ Version: 0.1.0
4
+ Summary: Autonity Futures Protocol Python SDK
5
+ Keywords: autonity,web3,trading,crypto,prediction,forecast,markets
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Dist: decorator>=5.2.1
14
+ Requires-Dist: inflection>=0.5.1
15
+ Requires-Dist: pydantic>=2.10.6
16
+ Requires-Dist: requests>=2.32.0
17
+ Requires-Dist: siwe>=4.4.0
18
+ Requires-Dist: web3>=7.6.0
19
+ Requires-Python: >=3.11
20
+ Project-URL: Changes, https://github.com/autonity/afp-sdk/blob/master/CHANGELOG.md
21
+ Project-URL: Homepage, https://github.com/autonity/afp-sdk
22
+ Project-URL: Issues, https://github.com/autonity/afp-sdk/issues
23
+ Project-URL: Source, https://github.com/autonity/afp-sdk
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Autonity Futures Protocol Python SDK
27
+
28
+ ## Installation
29
+
30
+ This library is published on PyPI as the [afp-sdk](https://pypi.org/project/afp-sdk/)
31
+ package. It can be installed in a virtualenv with:
32
+
33
+ ```py
34
+ pip install afp-sdk
35
+ ```
36
+
37
+ ## Overview
38
+
39
+ The `afp` package consists of the following:
40
+
41
+ - `afp` top-level module: High-level API for interacting with the Clearing
42
+ System and the AutEx exchange.
43
+ - `afp.bindings` submodule: Low-level API that provides typed Python bindings
44
+ for the Clearing System smart contracts.
45
+
46
+ ## Usage
47
+
48
+ ### Preparation
49
+
50
+ In order to use the AFP system, traders need to prepare the following:
51
+
52
+ - The ID of a product to be traded.
53
+ - The address of the product's collateral token.
54
+ - An Autonity account for managing the margin account. It needs to hold a
55
+ 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.
57
+ - The address of an Autonity RPC provider. They can be found on
58
+ [Chainlist](https://chainlist.org/?search=autonity&testnets=true).
59
+
60
+ We can store those in the following constants (using random example IDs):
61
+
62
+ ```py
63
+ import os
64
+
65
+ PRODUCT_ID = "0x38d502bb683f53ec7c3d7a14b4aa47ac717659e121426131c0189c15bf4b9460"
66
+ 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"]
69
+ AUTONITY_RPC_URL = "https://bakerloo.autonity-apis.com"
70
+ ```
71
+
72
+ Account IDs (addresses) may be retrieved from the private keys with `eth_account`:
73
+
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
+ ```
80
+
81
+ ### Clearing API
82
+
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.
86
+
87
+ ```py
88
+ import afp
89
+
90
+ clearing = afp.Clearing(MARGIN_ACCOUNT_PRIVATE_KEY, AUTONITY_RPC_URL)
91
+ ```
92
+
93
+ Collateral can be deposited into the margin account with
94
+ `clearing.deposit_into_margin_account()`.
95
+
96
+ ```py
97
+ from decimal import Decimal
98
+
99
+ clearing.deposit_into_margin_account(COLLATERAL_ASSET, Decimal("100.00"))
100
+ print(clearing.capital(COLLATERAL_ASSET))
101
+ ```
102
+
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.
105
+
106
+ ```py
107
+ clearing.authorize(COLLATERAL_ASSET, INTENT_ACCOUNT_ID)
108
+ ```
109
+
110
+ ### Trading API
111
+
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.
115
+
116
+ ```py
117
+ trading = afp.Trading(INTENT_ACCOUNT_PRIVATE_KEY)
118
+ ```
119
+
120
+ To start trading a product, its parameters shall be retrieved from the server.
121
+
122
+ ```py
123
+ product = trading.product(PRODUCT_ID)
124
+ ```
125
+
126
+ Intents can be created with `trading.create_intent()`. Intent creation involves
127
+ hashing and signing the intent data. (The intent account's address is derived
128
+ from the private key specified in the `Trading` constructor.)
129
+
130
+ ```py
131
+ from datetime import datetime, timedelta
132
+ from decimal import Decimal
133
+
134
+ intent = trading.create_intent(
135
+ margin_account_id=MARGIN_ACCOUNT_ID,
136
+ product=product,
137
+ side="bid",
138
+ limit_price=Decimal("1.23"),
139
+ quantity=2,
140
+ max_trading_fee_rate=Decimal("0.1"),
141
+ good_until_time=datetime.now() + timedelta(hours=1),
142
+ )
143
+ ```
144
+
145
+ The intent expressing a limit order can then be submitted to the exchange with
146
+ `trading.submit_limit_order()` that returns the created order object.
147
+
148
+ ```py
149
+ order = trading.submit_limit_order(intent)
150
+ print(order)
151
+ ```
152
+
153
+ The exchange then performs various checks to ensure that the order is valid. To
154
+ ensure that the order has been accepted, its state can be polled with
155
+ `trading.order()`.
156
+
157
+ ```py
158
+ order = trading.order(order.id)
159
+ print(order.state)
160
+ ```
161
+
162
+ Fills of orders submitted by the authenticated intent account can be queried
163
+ with `trading.order_fills()`.
164
+
165
+ ```py
166
+ fills = trading.order_fills(product_id=PRODUCT_ID)
167
+ print(fills)
168
+ ```
169
+
170
+ See further code examples in the [examples](./examples/) directory.
171
+
172
+ ## Development
173
+
174
+ The package uses [`uv`](https://docs.astral.sh/uv/) as project manager.
175
+
176
+ - Dependecies can be installed with the `uv sync` command.
177
+ - Linters can be executed with the `uv run poe lint` command.
178
+ - Tests can be executed with the `uv run poe test` command.
179
+ - Distributions can be checked before release with the `uv run poe check-dist` command.
180
+ - Markdown API documentation can be generated with the `uv run poe doc-gen` command.
@@ -0,0 +1,34 @@
1
+ afp/__init__.py,sha256=4C2JZIu-rWZpMnp_rcVjJPI4v_R9GT1ISnlwoawhBjs,323
2
+ afp/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ afp/api/admin.py,sha256=7ymtCloff4UhyS-MAqA8_cndWlfZanjuGgPgkiV5Jhc,1526
4
+ afp/api/base.py,sha256=iS-sjAc9mME2qOMEvnB6T6x9L_8oeJnHY6h79xrbAOE,2632
5
+ afp/api/builder.py,sha256=4Kmulk2f4QAblLgmI0J6YYt-WuBoLSw3l2jY3Q6tNN8,7078
6
+ afp/api/clearing.py,sha256=nMVjayFkf0XYYP3aKAdgR6NaFSG4Cl_QsEuADRuIO7M,12922
7
+ afp/api/liquidation.py,sha256=CtME5524VVW9mXMMpORyUP205sTVqpLnHIPoTy2MGa8,5439
8
+ afp/api/trading.py,sha256=0nD3JnnQwmmFeZYRws1V4rfWCuxgwnY7O5uF-NZ3Mtc,9917
9
+ afp/bindings/__init__.py,sha256=ZkjAhZlasky0fZITtQp_xlgcO5H-8ZnyVWUQh5AZLpE,1153
10
+ afp/bindings/auctioneer_facet.py,sha256=99FmK35trfOIJGqJqyc1NnpG0KavhH0_jNufszZ9VhA,24013
11
+ afp/bindings/bankruptcy_facet.py,sha256=BufV6eE592aCqtTduDD7mHcLp_yuQWNI9d5HFvSTTSc,11344
12
+ afp/bindings/clearing_facet.py,sha256=GLBtquybV1FRvDNlYXgpcvlpgw9pvZ5UJbLOYKayPMU,34168
13
+ afp/bindings/erc20.py,sha256=-jw7ohcEbUL7g3PpK3-a5_7ClUDCDHt1bezm-w7exzo,10822
14
+ afp/bindings/facade.py,sha256=FDKY6XLYsK6suDmWSsP5cek8y4ycY4soo9R4udvG1MM,2019
15
+ afp/bindings/final_settlement_facet.py,sha256=gYJXiUyZ_-L8i8LHnPUmB3mBhLxHr8GAtKurwsCypa0,7699
16
+ afp/bindings/margin_account.py,sha256=ffkpf5HEXQCxiWuLpgDcHVAiaUVvbKU1Kt0K8tvgZcA,42461
17
+ afp/bindings/margin_account_registry.py,sha256=mx9sAU6HuC09d-LAf9bzP57HPLa3M6qXpN7Lj-uiXSc,18800
18
+ afp/bindings/mark_price_tracker_facet.py,sha256=vnVsAmpts_2Sv9Jmx3JlON8X8FJd9D2jOFhqSwXIA7A,2830
19
+ afp/bindings/oracle_provider.py,sha256=CMpVAXdUuTP_W9ZE297B-m9MjuW90yCOhNLMVl3kCf0,15863
20
+ afp/bindings/product_registry.py,sha256=HFWwbFKvXk0A2dZB6KBa0Ul8-vX9uvvtGj0dhRL9UUw,43701
21
+ afp/bindings/trading_protocol.py,sha256=XN9UbViMhVLIzFCTTgEW65GRF0finTjq-2iHrhtL3P8,39873
22
+ afp/config.py,sha256=3S7k49n4ZaRko3FX6Hw95r5L-sw2XiAjWtqYiX3Omx0,1017
23
+ afp/decorators.py,sha256=Ustc15RbXGYIEqDb9lXnd-bdhZJ8ZrztN4h_vjkLsG0,2692
24
+ afp/enums.py,sha256=4dglBx4Amcu0GrlJn0cIj-rp9uDHZGfDEP_vMAO02xo,485
25
+ afp/exceptions.py,sha256=RE8IE6akDgbar2PobdpOiBdGZZCYkb4jWf1ozJmdLaI,342
26
+ afp/exchange.py,sha256=l8Cartp0R4PPe6O_Wu10YDw-5P_PbaAkd7w-W5QrlWY,5272
27
+ afp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
+ afp/schemas.py,sha256=RQ-NkDOgFnoJXHIngiqAJCX88gu5qlkMu6lxnvVyYfI,4899
29
+ afp/signing.py,sha256=7fohnAvoiDA4ems_3OcVnr16OmYLSg9NnnCSzDplg6s,2235
30
+ afp/validators.py,sha256=zhOP0vYS2aXMKLsIVDwD6xwwCg0moIU5IhMlNHihWkM,1329
31
+ afp_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=ZdaKItgc2ppfqta2OJV0oHpSJiK87PUxmUkUo-_0SB8,1065
32
+ afp_sdk-0.1.0.dist-info/WHEEL,sha256=4n27za1eEkOnA7dNjN6C5-O2rUiw6iapszm14Uj-Qmk,79
33
+ afp_sdk-0.1.0.dist-info/METADATA,sha256=DFOCUhdg3ieK_6-bPwUKb48Jg6Cm1s-9oa528Hpck6c,5614
34
+ afp_sdk-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.8.13
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Autonity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.