upside-python-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,205 @@
1
+ Metadata-Version: 2.4
2
+ Name: upside-python-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for the Upside decentralized perpetuals exchange (REST + WebSocket).
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: upside,perpetuals,dex,trading,eip712,websocket
8
+ Author: Upside
9
+ Author-email: dev@upsidemax.xyz
10
+ Requires-Python: >=3.9,<4.0
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Requires-Dist: eth-account (>=0.10,<0.14)
20
+ Requires-Dist: eth-utils (>=2.3.0)
21
+ Requires-Dist: requests (>=2.31.0)
22
+ Requires-Dist: typing-extensions (>=4.5.0) ; python_version < "3.11"
23
+ Requires-Dist: websocket-client (>=1.7.0,<2.0.0)
24
+ Project-URL: Documentation, https://docs.upsidemax.xyz
25
+ Project-URL: Homepage, https://docs.upsidemax.xyz
26
+ Project-URL: Repository, https://github.com/upsidemax/upside-python-sdk
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Upside Python SDK
30
+
31
+ A Python client for the [Upside](https://docs.upsidemax.xyz) decentralized
32
+ perpetuals exchange — REST reads (`POST /info`), signed writes (`POST /exchange`),
33
+ and realtime WebSocket streams.
34
+
35
+ - **EIP-712 request signing** (secp256k1) with the Agent and Typed paths — no API keys.
36
+ - **Synchronous REST** over `requests`, **threaded WebSocket** over `websocket-client`.
37
+ - Raw-dict responses, `TypedDict` inputs, full type hints (ships `py.typed`).
38
+ - Agent (API-wallet) delegation, TP/SL, leverage/margin, and collateral actions.
39
+
40
+ > The default environment is the **QA testnet** (`https://dev.upsidemax.xyz`).
41
+ > Contract IDs, scales, and tick/step sizes are server-assigned — always read
42
+ > them from `configs`, never hardcode.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install upside-python-sdk
48
+ ```
49
+
50
+ Requires Python 3.9+. Runtime dependencies: `requests`, `websocket-client`,
51
+ `eth-account`, `eth-utils`.
52
+
53
+ ## Quick start
54
+
55
+ ```python
56
+ from upside import Info, Exchange
57
+ from upside.utils import constants
58
+
59
+ # --- reads (no signing) ---
60
+ info = Info(base_url=constants.QA_API_URL)
61
+ cfg = info.configs()
62
+ contract = next(c for c in cfg["contracts"] if c["status"] == "Active")
63
+ asset = contract["contractId"]
64
+ print(info.market_state(asset))
65
+
66
+ # --- writes (EIP-712 signed) ---
67
+ exchange = Exchange("0x<private-key>", base_url=constants.QA_API_URL)
68
+
69
+ # Register (QA requires an invite code from the Upside team). A 10,000 USDC
70
+ # test airdrop lands within ~10s.
71
+ exchange.register_account(invite_code="<invite-code>")
72
+
73
+ # Place a resting limit buy. Prices/sizes are raw integer strings — scale them
74
+ # with the contract's priceScale / qtyScale from configs.
75
+ exchange.order(asset=asset, is_buy=True, size="10", price="50")
76
+ ```
77
+
78
+ ## Reading data — `Info`
79
+
80
+ All methods return the raw parsed JSON. See
81
+ [docs.upsidemax.xyz/info](https://docs.upsidemax.xyz/info/overview) for response shapes.
82
+
83
+ ```python
84
+ info.configs() # contracts, coins, scales, tiers (cache this)
85
+ info.l2_book(asset) # full order book snapshot
86
+ info.market_state(asset) # mark/oracle/last price, funding
87
+ info.candle_snapshot(asset, "1m", start, end) # historical OHLCV
88
+ info.user_account(account_id, market_deployer_id)
89
+ info.user_orders(account_id, market_deployer_id, contract_id=0)
90
+ info.orders_by_ids(market_deployer_id, ["8280"])
91
+ info.orders_by_cloids(account_id, market_deployer_id, ["1778844423064"])
92
+ info.user_agents(account_id)
93
+ info.user_market_deployers(account_id)
94
+ info.share_group_state()
95
+ ```
96
+
97
+ ## Trading — `Exchange`
98
+
99
+ ```python
100
+ from upside import Cloid
101
+
102
+ exchange.order(asset=1, is_buy=True, size="10", price="50", cloid=Cloid.from_int(1001))
103
+ exchange.market_order(asset=1, is_buy=False, size="5")
104
+ exchange.bulk_orders([...]) # up to 10 orders, one signature
105
+ exchange.cancel(asset=1, oid=15)
106
+ exchange.cancel_by_cloid(asset=1, cloid=1001)
107
+ exchange.cancel_all(asset=1)
108
+ exchange.modify(asset=1, oid=15, price="151", size="8")
109
+
110
+ exchange.update_leverage(asset=1, leverage=20)
111
+ exchange.update_margin_mode(asset=1, is_cross=False, is_hedge=True)
112
+ exchange.update_isolated_margin(asset=1, ntli=5000)
113
+
114
+ exchange.tp_sl(asset=1, tp_price="90000", sl_price="80000")
115
+ exchange.cancel_tp_sl(asset=1)
116
+ exchange.cancel_conditional(oid=123)
117
+
118
+ exchange.lock_collateral(market_deployer_id=1, coin_id=1, amount="1000")
119
+ exchange.transfer_between_deployers(1, 2, coin_id=1, amount="1000")
120
+ ```
121
+
122
+ ### Order placement is asynchronous
123
+
124
+ A batch returns `{"status": "accepted", "response": {"type": "order", "data": {"count": n}}}`
125
+ — **not** the resting order id. Read the resulting state from
126
+ `Info.user_orders` / `orders_by_cloids`, or the `orderUpdates` / `userFills`
127
+ WebSocket channels. Cancels, modifies, and margin actions respond synchronously.
128
+
129
+ ### HTTP 200 ≠ success
130
+
131
+ Gateway failures (bad signature, reused nonce, rate limit) raise `ClientError`
132
+ (4xx) / `ServerError` (5xx). Business rejections come back as HTTP 200 — a per-item
133
+ `error` string in `statuses[]`, or a non-zero `errorCode` in `response.data`.
134
+ Always inspect them.
135
+
136
+ ## Agent (API-wallet) delegation
137
+
138
+ Keep the master key offline; authorize a hot agent key to sign trades. The
139
+ server routes agent-signed actions to the master account.
140
+
141
+ ```python
142
+ response, agent_key = master.approve_agent(agent_name="bot1") # generates a fresh key
143
+ agent = Exchange(agent_key, base_url=constants.QA_API_URL, account_id=master.account_id)
144
+ agent.order(asset=1, is_buy=True, size="10", price="50")
145
+ master.revoke_agent(agent.address)
146
+ ```
147
+
148
+ ## WebSocket streams
149
+
150
+ ```python
151
+ info = Info(base_url=constants.QA_API_URL) # WS starts automatically
152
+
153
+ sid = info.subscribe({"type": "l2Book", "asset": "1"}, lambda m: print(m["data"]["bookVersion"]))
154
+ info.subscribe({"type": "trades", "asset": "1"}, print)
155
+ info.subscribe({"type": "orderUpdates", "user": "0x<address>"}, print) # private: pass the wallet address
156
+ info.subscribe({"type": "userFills", "user": "0x<address>"}, print)
157
+
158
+ info.unsubscribe({"type": "l2Book", "asset": "1"}, sid)
159
+ info.close()
160
+ ```
161
+
162
+ Channels: `l2Book`, `bbo`, `trades`, `candle`, `config` (public) and
163
+ `orderUpdates`, `openOrders`, `userFills` (per-address). The client pings every
164
+ 30s and auto-reconnects, replaying subscriptions. WebSocket does **not** push
165
+ position or balance changes — poll `userAccount` for those.
166
+
167
+ ## Signing
168
+
169
+ Every `/exchange` write is authorized by an EIP-712 signature over a fixed
170
+ domain (`Exchange` / `1` / chainId `9767` / zero verifying contract). The SDK
171
+ handles both paths automatically:
172
+
173
+ - **Typed path** — `registerAccount`, `approveAgent`, `revokeAgent`,
174
+ `lockCollateral`, `unlockCollateral`, `transferBetweenDeployers`.
175
+ - **Agent path** — every other action (canonical-JSON `actionHash`).
176
+
177
+ Nonces are strictly increasing millisecond timestamps managed per `Exchange`
178
+ instance (`NonceManager`). See
179
+ [docs.upsidemax.xyz/guide/authentication](https://docs.upsidemax.xyz/guide/authentication).
180
+
181
+ ## Examples
182
+
183
+ Runnable scripts live in [`examples/`](examples). Copy `config.json.example` to
184
+ `config.json`, set your test wallet and invite code, then:
185
+
186
+ ```bash
187
+ python examples/01_register_and_airdrop.py
188
+ python examples/03_place_and_cancel_order.py
189
+ python examples/06_websocket_streams.py
190
+ ```
191
+
192
+ ## Development
193
+
194
+ ```bash
195
+ make install # poetry install
196
+ make test # pytest
197
+ make lint # black --check + ruff
198
+ make typecheck # mypy
199
+ make check # all of the above
200
+ ```
201
+
202
+ ## License
203
+
204
+ MIT — see [LICENSE](LICENSE).
205
+
@@ -0,0 +1,15 @@
1
+ upside/__init__.py,sha256=Q62lDpSccn1GF5ahZLmNCLfNfNOVUrdAmx_3aUuXzYQ,1017
2
+ upside/api.py,sha256=EIPvzMBGLEmhKiv0CH15pxwgzNl97JP4baS32_28z9g,2415
3
+ upside/exchange.py,sha256=8apq2qmebea_nKyMthsoyXN2MKH0Q1CRP0nKdlopKio,17564
4
+ upside/info.py,sha256=keC6kJNHcdB_qAwMD9F4BYA2bCukWhFOE6DIehaCi-c,6765
5
+ upside/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ upside/utils/__init__.py,sha256=jq-M4UiFEwAU9pNdrUorIlyIezULD4-60QSCaYpJkFY,77
7
+ upside/utils/constants.py,sha256=anLaidwRY_h3Ab5K5ehB0I_4GPgzRbiFZp29edMzSX0,1382
8
+ upside/utils/error.py,sha256=jRrMRuB_5Kd9oHfje2mG0EJG1DR918WmgAoDnWz7dtw,1653
9
+ upside/utils/signing.py,sha256=KnpSqIag0Buw4HIpKGXx0XN4ZsX8X9AL76xI4X_jTAc,6482
10
+ upside/utils/types.py,sha256=OApXdNpMI-dImO-BynvAp3mI2v9cMrzjedr6JUtE9PE,3990
11
+ upside/websocket_manager.py,sha256=0ehNvA-RPuDvWJAJttlsePuMu7wKCnklmXeWl8eXyYs,8177
12
+ upside_python_sdk-0.1.0.dist-info/METADATA,sha256=hOBuPqapCP95d_2BUSrKFRxTCWBGoS_Y-qLZ7ZvYYUY,7652
13
+ upside_python_sdk-0.1.0.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
14
+ upside_python_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=emQnwrkEbEHvZ4NaTF26mBqLfG9wU5zQW5N_LgFtWko,1063
15
+ upside_python_sdk-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.4.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Upside
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.