kuest-sdk 0.13.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.
- kuest_sdk-0.13.0/.editorconfig +11 -0
- kuest_sdk-0.13.0/.env.example +15 -0
- kuest_sdk-0.13.0/.gitignore +16 -0
- kuest_sdk-0.13.0/.python-version +1 -0
- kuest_sdk-0.13.0/CLAUDE.md +3 -0
- kuest_sdk-0.13.0/COMPATIBILITY.md +28 -0
- kuest_sdk-0.13.0/LICENSE +21 -0
- kuest_sdk-0.13.0/PKG-INFO +103 -0
- kuest_sdk-0.13.0/README.md +62 -0
- kuest_sdk-0.13.0/SECURITY.md +22 -0
- kuest_sdk-0.13.0/UPSTREAM.md +4 -0
- kuest_sdk-0.13.0/examples/README.md +5 -0
- kuest_sdk-0.13.0/examples/__init__.py +0 -0
- kuest_sdk-0.13.0/examples/create_limit_order.py +65 -0
- kuest_sdk-0.13.0/examples/create_market_order.py +67 -0
- kuest_sdk-0.13.0/examples/crypto_twap_stream.py +41 -0
- kuest_sdk-0.13.0/examples/fetch_market.py +31 -0
- kuest_sdk-0.13.0/examples/lib/__init__.py +0 -0
- kuest_sdk-0.13.0/examples/lib/env.py +17 -0
- kuest_sdk-0.13.0/examples/lib/markets.py +99 -0
- kuest_sdk-0.13.0/examples/lib/tables.py +63 -0
- kuest_sdk-0.13.0/examples/list_markets.py +22 -0
- kuest_sdk-0.13.0/examples/list_positions.py +40 -0
- kuest_sdk-0.13.0/examples/market_prices.py +48 -0
- kuest_sdk-0.13.0/examples/pagination.py +27 -0
- kuest_sdk-0.13.0/examples/search.py +56 -0
- kuest_sdk-0.13.0/examples/stream_realtime_prices.py +44 -0
- kuest_sdk-0.13.0/pyproject.toml +127 -0
- kuest_sdk-0.13.0/src/market_sdk/__init__.py +663 -0
- kuest_sdk-0.13.0/src/market_sdk/_frames_bridge.py +14 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/_cursor.py +41 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/account.py +246 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/auth.py +206 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/builders.py +69 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/clob.py +247 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/combo_rfq.py +839 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/combos.py +160 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/data.py +716 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/exchange_asset.py +58 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/gamma.py +892 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/order_heartbeats.py +14 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/_numeric.py +27 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/allowance.py +102 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/cache.py +282 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/cancel.py +65 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/context.py +81 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/estimate.py +237 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/limit.py +167 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/market.py +432 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/market_data.py +293 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/math.py +48 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/orders.py +81 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/place.py +198 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/post.py +92 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/settlement.py +130 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/typed_data.py +213 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/types.py +62 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/account.py +601 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/builders.py +162 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/chases.py +108 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/credentials.py +174 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/funds.py +115 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/paging.py +240 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/position_snapshots.py +115 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/public.py +310 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/signing.py +195 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/trading.py +509 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/twaps.py +123 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/approvals.py +282 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/auth.py +93 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/calls.py +417 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/deployed.py +36 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/gasless.py +716 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/nonce.py +69 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/poll.py +119 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/positions.py +364 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/signing/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/signing/deposit_wallet.py +96 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/signing/proxy.py +59 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/signing/safe.py +110 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/submit.py +74 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/rewards.py +332 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/rfq.py +87 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/actions/session_keys.py +742 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/context.py +89 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/data_envelope.py +38 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/data_params.py +100 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/dispatch.py +417 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/environment.py +35 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/eoa/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/eoa/broadcast.py +166 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/eoa/rpc.py +360 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/gamma_paths.py +100 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/hmac.py +34 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/l1_auth.py +84 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/pagination.py +362 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/perps_session.py +1766 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/protocol.py +65 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/request.py +112 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/retry.py +44 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/rfq.py +802 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/heartbeat.py +62 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/market.py +209 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/market_protocol.py +124 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/user.py +213 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/user_protocol.py +98 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/handle.py +143 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/merged_handle.py +153 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/perps/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/perps/heartbeat.py +65 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/perps/market.py +209 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/perps/market_protocol.py +125 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/__init__.py +1 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/heartbeat.py +39 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/manager.py +116 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/protocol.py +230 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/session.py +322 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/socket.py +225 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/reconnect.py +93 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/registry.py +73 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/rtds/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/rtds/heartbeat.py +60 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/rtds/manager.py +183 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/rtds/protocol.py +179 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/sports/__init__.py +0 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/sports/heartbeat.py +69 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/streams/sports/manager.py +173 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/validation.py +28 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/wallet.py +284 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/ws/__init__.py +11 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/ws/backoff.py +25 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/ws/connection.py +277 -0
- kuest_sdk-0.13.0/src/market_sdk/_internal/ws/heartbeat.py +26 -0
- kuest_sdk-0.13.0/src/market_sdk/_jupyter.py +72 -0
- kuest_sdk-0.13.0/src/market_sdk/auth.py +58 -0
- kuest_sdk-0.13.0/src/market_sdk/calls.py +45 -0
- kuest_sdk-0.13.0/src/market_sdk/clients/__init__.py +8 -0
- kuest_sdk-0.13.0/src/market_sdk/clients/_transport.py +621 -0
- kuest_sdk-0.13.0/src/market_sdk/clients/async_public.py +1816 -0
- kuest_sdk-0.13.0/src/market_sdk/clients/async_secure.py +4310 -0
- kuest_sdk-0.13.0/src/market_sdk/clients/public.py +1421 -0
- kuest_sdk-0.13.0/src/market_sdk/clients/secure.py +3529 -0
- kuest_sdk-0.13.0/src/market_sdk/environments.py +144 -0
- kuest_sdk-0.13.0/src/market_sdk/errors.py +181 -0
- kuest_sdk-0.13.0/src/market_sdk/frames/__init__.py +14 -0
- kuest_sdk-0.13.0/src/market_sdk/frames/_arrow.py +366 -0
- kuest_sdk-0.13.0/src/market_sdk/frames/_builtin_overrides.py +46 -0
- kuest_sdk-0.13.0/src/market_sdk/frames/_errors.py +10 -0
- kuest_sdk-0.13.0/src/market_sdk/frames/_overrides.py +48 -0
- kuest_sdk-0.13.0/src/market_sdk/frames/_pandas.py +103 -0
- kuest_sdk-0.13.0/src/market_sdk/frames/_polars.py +102 -0
- kuest_sdk-0.13.0/src/market_sdk/models/__init__.py +630 -0
- kuest_sdk-0.13.0/src/market_sdk/models/_validators.py +34 -0
- kuest_sdk-0.13.0/src/market_sdk/models/base.py +40 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/__init__.py +141 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/_validators.py +200 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/account.py +250 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/api_key.py +47 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/builder.py +97 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/cancel.py +16 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/last_trade.py +44 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/market_events.py +417 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/notifications.py +493 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/order_book.py +119 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/order_heartbeats.py +18 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/order_response.py +164 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/orders.py +31 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/relayer.py +105 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/requests.py +67 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/rewards.py +311 -0
- kuest_sdk-0.13.0/src/market_sdk/models/clob/user_events.py +257 -0
- kuest_sdk-0.13.0/src/market_sdk/models/collateral_return.py +146 -0
- kuest_sdk-0.13.0/src/market_sdk/models/data/__init__.py +172 -0
- kuest_sdk-0.13.0/src/market_sdk/models/data/activity.py +505 -0
- kuest_sdk-0.13.0/src/market_sdk/models/data/analytics.py +157 -0
- kuest_sdk-0.13.0/src/market_sdk/models/data/common.py +308 -0
- kuest_sdk-0.13.0/src/market_sdk/models/data/leaderboard.py +202 -0
- kuest_sdk-0.13.0/src/market_sdk/models/data/portfolio.py +410 -0
- kuest_sdk-0.13.0/src/market_sdk/models/data/resolutions.py +115 -0
- kuest_sdk-0.13.0/src/market_sdk/models/data/tokens.py +95 -0
- kuest_sdk-0.13.0/src/market_sdk/models/gamma/__init__.py +125 -0
- kuest_sdk-0.13.0/src/market_sdk/models/gamma/comment.py +127 -0
- kuest_sdk-0.13.0/src/market_sdk/models/gamma/common.py +436 -0
- kuest_sdk-0.13.0/src/market_sdk/models/gamma/event.py +530 -0
- kuest_sdk-0.13.0/src/market_sdk/models/gamma/market.py +668 -0
- kuest_sdk-0.13.0/src/market_sdk/models/gamma/profile.py +54 -0
- kuest_sdk-0.13.0/src/market_sdk/models/gamma/search.py +168 -0
- kuest_sdk-0.13.0/src/market_sdk/models/gamma/series.py +19 -0
- kuest_sdk-0.13.0/src/market_sdk/models/gamma/tag.py +22 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/__init__.py +312 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/_validators.py +68 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/account.py +301 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/builder_events.py +25 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/builders.py +210 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/chases.py +76 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/credentials.py +46 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/events.py +416 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/funds.py +172 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/market.py +418 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/notifications.py +253 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/orders.py +332 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/position_snapshots.py +147 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/requests.py +373 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/results.py +41 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/twaps.py +87 -0
- kuest_sdk-0.13.0/src/market_sdk/models/perps/types.py +132 -0
- kuest_sdk-0.13.0/src/market_sdk/models/price_events.py +201 -0
- kuest_sdk-0.13.0/src/market_sdk/models/rfq.py +150 -0
- kuest_sdk-0.13.0/src/market_sdk/models/rtds_events.py +382 -0
- kuest_sdk-0.13.0/src/market_sdk/models/sports_events.py +71 -0
- kuest_sdk-0.13.0/src/market_sdk/models/trading.py +46 -0
- kuest_sdk-0.13.0/src/market_sdk/models/types.py +200 -0
- kuest_sdk-0.13.0/src/market_sdk/pagination.py +340 -0
- kuest_sdk-0.13.0/src/market_sdk/perps.py +46 -0
- kuest_sdk-0.13.0/src/market_sdk/py.typed +0 -0
- kuest_sdk-0.13.0/src/market_sdk/rate_limit.py +38 -0
- kuest_sdk-0.13.0/src/market_sdk/rfq.py +534 -0
- kuest_sdk-0.13.0/src/market_sdk/session_keys.py +100 -0
- kuest_sdk-0.13.0/src/market_sdk/site_config.py +146 -0
- kuest_sdk-0.13.0/src/market_sdk/site_scope.py +226 -0
- kuest_sdk-0.13.0/src/market_sdk/streams/__init__.py +258 -0
- kuest_sdk-0.13.0/src/market_sdk/streams/_specs.py +633 -0
- kuest_sdk-0.13.0/src/market_sdk/transactions.py +186 -0
- kuest_sdk-0.13.0/src/market_sdk/types.py +9 -0
- kuest_sdk-0.13.0/src/market_sdk/version.py +8 -0
- kuest_sdk-0.13.0/uv.lock +1933 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Explicit endpoint configuration for a local integration.
|
|
2
|
+
SDK_CLOB_URL=
|
|
3
|
+
SDK_CLOB_WS_URL=
|
|
4
|
+
SDK_RELAYER_URL=
|
|
5
|
+
SDK_GAMMA_URL=
|
|
6
|
+
SDK_DATA_URL=
|
|
7
|
+
SDK_RPC_URL=
|
|
8
|
+
SDK_TOKEN_ID=
|
|
9
|
+
|
|
10
|
+
# Only use test credentials with controlled, approved endpoints.
|
|
11
|
+
SDK_PRIVATE_KEY=
|
|
12
|
+
SDK_DEPOSIT_WALLET=
|
|
13
|
+
SDK_BUILDER_API_KEY=
|
|
14
|
+
SDK_BUILDER_SECRET=
|
|
15
|
+
SDK_BUILDER_PASSPHRASE=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.11
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Local backend contract review
|
|
2
|
+
|
|
3
|
+
This review compares this SDK with local `clob` commit `a63ec4e0e9065faadb497d78621191c8f2f3bd65`, `relayer` commit `35b335aa2154db73336c12d5cff635a722c514ae`, `py-clob-client` commit `08f908211ff31bcab9e50088c827502678099d97`, and migration rules commit `9ac0b109e97c1de70c86b509ccf8dc3bb40fb891`. Service checkouts were read only. All contract tests use local mock transports; no authenticated live request or transaction was sent.
|
|
4
|
+
|
|
5
|
+
| Flow | Current service contract | SDK handling and evidence |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| CLOB auth | `clob/src/routes/auth.rs:23-41,232-286`: issue/derive with signed L1 headers; list is a plain string array; revoke returns `{revoked:true}`. | `_internal/actions/auth.py` parses these shapes; `test_auth_actions.py`, `test_auth_transport.py`, and `test_secure_api_keys_sync.py` check the client. |
|
|
8
|
+
| Builder credentials | `relayer/src/routes/auth.rs:45-76,201-205,232-286`: POST `/auth/builder-api-key` uses L1 auth and returns `apiKey/secret/passphrase`; GET and DELETE use L2 auth, with DELETE returning `{revoked:true}`. | `clients/secure.py`, `clients/async_secure.py`, and `_internal/actions/auth.py` send these to the relayer. Listing with the alternate relayer API-key mode fails locally. `test_backend_auth_contract.py` checks method, host, headers, and envelopes. Builder and CLOB keys are distinct. |
|
|
9
|
+
| Orders | `clob/src/routes/orders.rs:30-40,69-85` and `src/services/validation.rs:85-99`: POST `/order` or `/orders` (max 15), `owner` equals the CLOB API key, signature type 3, maker equals signer. `src/domain/eip712.rs:53-69` and `src/config.rs:156-157` define V2 typed data. | `_internal/actions/orders/post.py`, typed-data tests, and order unit tests cover payload and signing fields. HTTP `expiration` remains accepted by backend but is not in the V2 signed struct. No live order was posted. |
|
|
10
|
+
| Relayer | `relayer/src/routes/relayer.rs:45-60,72-75,390-505,614-665`: GET `/nonce?address=…&type=WALLET` returns `{nonce}`; POST `/submit` accepts Deposit Wallet calls and returns `transactionID/state`; GET `/transaction?id=…` returns an array with `transactionID`, `transactionHash`, `state`, and optional `failureReason`. | `_internal/actions/relayer/*`, `test_relayer_nonce_contract.py`, and `test_relayer_submit_poll.py` cover these shapes. Builder HMAC headers use `KUEST_BUILDER_*`, matching `relayer/src/routes/middleware.rs:16-26`. Safe/Proxy submissions fail locally. |
|
|
11
|
+
| Contracts and builder attribution | Migration rules `polymarket-to-kuest/AGENTS.md` fix Polygon 137, Circle USDC, the two CTF exchanges, and Deposit Wallet signing. `clob/src/routes/market_config.rs:1691-1705` accepts a bytes32 builder code. | `_internal/environment.py`, order typed-data tests, and `_internal/validation.py` use these values and encode a 20-byte builder address as bytes32. Four trading approvals target the two exchanges only. |
|
|
12
|
+
| Builder trades | `clob/src/routes/builder.rs:84-108,373-475` has no `builder_code` query filter; its response also differs from the upstream builder-trade model. | Four public client methods raise `UserInputError` before requesting `/builder/trades`; `test_builder_trades.py` checks the guard. This operation needs backend support before it can be enabled. |
|
|
13
|
+
|
|
14
|
+
The SDK defaults all hosts to `unconfigured.invalid`. Operator endpoints and Polygon RPC must be supplied explicitly. These offline checks validate request/response contracts against the local source snapshots, not deployed service state, credentials, wallet deployment, or real trading.
|
|
15
|
+
|
|
16
|
+
## Position operations and deliberate exclusions
|
|
17
|
+
|
|
18
|
+
| Operation | Contract evidence and SDK behavior |
|
|
19
|
+
| --- | --- |
|
|
20
|
+
| Standard CTF split / merge | `ConditionalTokens.sol:1404,1464` use the five-argument CTF ABI. Market `conditionId` and numeric CTF token IDs route to the deployed `conditional_tokens` address, with Circle USDC as collateral. Unit tests check target and calldata. |
|
|
21
|
+
| NegRisk CTF split / merge | `NegRiskAdapter.sol:135,165` accepts the same five-argument CTF ABI. Calls route to the deployed `neg_risk_adapter`; the adapter wraps Circle USDC internally. |
|
|
22
|
+
| Standard CTF redeem | `ConditionalTokens.sol:1517` accepts the four-argument CTF redeem ABI. The SDK calls Conditional Tokens directly. |
|
|
23
|
+
| NegRisk CTF redeem | `NegRiskAdapter.sol:239` accepts `redeemPositions(bytes32,uint256[])`. The SDK reads two outcome balances from the adapter's `balanceOfBatch` proxy and passes `[YES, NO]` to that contract. |
|
|
24
|
+
| Protocol V2 Router / combo legs / position ID | The upstream CombinatorialModule, PositionManager, and protocol V2 Router addresses are not verified deployments for this SDK. Explicit V2 markets, combo-leg split/merge, position-ID redeem, and batch merge by position IDs reject before signing or RPC. A numeric CTF token ID alone does **not** identify this protocol. Order EIP-712 version `2` is unrelated. |
|
|
25
|
+
| Session keys | `DepositWallet.sol` has on-chain signer authorization, but the specialized upstream session-key API has no verified service counterpart. Fetch, authorize, and revoke reject locally before HTTP or signing in both languages. |
|
|
26
|
+
| RFQ | The CLOB backend has ordinary RFQ routes. This SDK deliberately leaves RFQ disabled; upstream combo RFQ is also incompatible. These flows are not offered as supported integration paths. |
|
|
27
|
+
|
|
28
|
+
CTF split requires a USDC allowance to Conditional Tokens or NegRiskAdapter. NegRisk merge/redeem requires `setApprovalForAll` on Conditional Tokens for NegRiskAdapter. The four exchange trading approvals above do not cover these position permissions. Tests encode and inspect calls offline; no transaction was broadcast.
|
kuest_sdk-0.13.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Polymarket
|
|
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.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: kuest-sdk
|
|
3
|
+
Version: 0.13.0
|
|
4
|
+
Summary: Unified prediction-market client for Polygon CLOB and Deposit Wallet workflows
|
|
5
|
+
Project-URL: Upstream, https://github.com/Polymarket/py-sdk
|
|
6
|
+
Author-email: Polymarket Engineering <engineering@polymarket.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: client,prediction-markets,trading,web3
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: eth-abi<6,>=5
|
|
21
|
+
Requires-Dist: eth-account<1,>=0.13
|
|
22
|
+
Requires-Dist: eth-utils<6,>=4
|
|
23
|
+
Requires-Dist: httpx[http2]<1,>=0.27
|
|
24
|
+
Requires-Dist: msgpack<2,>=1
|
|
25
|
+
Requires-Dist: pydantic<3,>=2
|
|
26
|
+
Requires-Dist: typing-extensions<5,>=4.15
|
|
27
|
+
Requires-Dist: websockets<16,>=13
|
|
28
|
+
Provides-Extra: arrow
|
|
29
|
+
Requires-Dist: pyarrow<22,>=15; extra == 'arrow'
|
|
30
|
+
Provides-Extra: pandas
|
|
31
|
+
Requires-Dist: pandas<3,>=2; extra == 'pandas'
|
|
32
|
+
Requires-Dist: pyarrow<22,>=15; extra == 'pandas'
|
|
33
|
+
Provides-Extra: polars
|
|
34
|
+
Requires-Dist: polars<2,>=1; extra == 'polars'
|
|
35
|
+
Requires-Dist: pyarrow<22,>=15; extra == 'polars'
|
|
36
|
+
Provides-Extra: quant
|
|
37
|
+
Requires-Dist: pandas<3,>=2; extra == 'quant'
|
|
38
|
+
Requires-Dist: polars<2,>=1; extra == 'quant'
|
|
39
|
+
Requires-Dist: pyarrow<22,>=15; extra == 'quant'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
<h1 align="center">
|
|
43
|
+
<img src="https://github.com/user-attachments/assets/0cc687fb-89c4-43fa-a056-d89c307215ad" alt="Kuest" height="96" /><br/>
|
|
44
|
+
Python SDK
|
|
45
|
+
</h1>
|
|
46
|
+
|
|
47
|
+
This is the public Kuest source repository for the white-label unified Python SDK. The
|
|
48
|
+
package and imports remain neutral so operator distributions can carry their own identity.
|
|
49
|
+
|
|
50
|
+
The SDK combines market discovery, CLOB data and orders, and Deposit Wallet relayer
|
|
51
|
+
workflows on Polygon. It adapts the [upstream unified SDK](https://github.com/Polymarket/py-sdk)
|
|
52
|
+
for Kuest's deployed contracts and APIs. Live trading has not been verified.
|
|
53
|
+
|
|
54
|
+
## Supported scope
|
|
55
|
+
|
|
56
|
+
- Polygon mainnet (chain ID 137), Circle USDC, Conditional Tokens, and the configured CTF and Neg Risk exchanges.
|
|
57
|
+
- Orders use EIP-712 `CTF Exchange` version `2`, a verified Deposit Wallet as maker and signer, signature type `3`, and a CLOB API key as the order owner.
|
|
58
|
+
- Relayer submissions use builder credentials and `WALLET` or `WALLET-CREATE` payloads. Nonce and transaction reads use `/nonce` and `/transaction`.
|
|
59
|
+
- Standard and NegRisk CTF split, merge, and redeem use the deployed Conditional Tokens and NegRiskAdapter contracts. NegRisk redeem uses the adapter's YES/NO amount ABI. These calls require the caller's relevant USDC allowance or CTF operator approval; trading approvals for the exchanges do not grant those permissions.
|
|
60
|
+
- RFQ is intentionally disabled for this product, including the ordinary RFQ supported by the CLOB backend. Specialized session-key management and upstream protocol V2 Router position operations reject locally.
|
|
61
|
+
- Position-backed V3 orders, combo RFQ, collateral return, and Safe/Proxy relayer submissions fail locally. Perps, realtime, sports, bridge, and other upstream-only services are not configured.
|
|
62
|
+
- Builder-attributed trade listing fails locally because the current CLOB ignores `builder_code`; see [COMPATIBILITY.md](./COMPATIBILITY.md).
|
|
63
|
+
- All network endpoints default to `unconfigured.invalid`. An integrator must supply approved HTTPS/WSS service URLs and a Polygon RPC URL explicitly.
|
|
64
|
+
|
|
65
|
+
For a direct GitHub checkout, supply endpoint configuration explicitly. An operator ZIP
|
|
66
|
+
may include `.sdk/site-config.json` with the existing `site_url`, `builder_mode`,
|
|
67
|
+
`geoblock`, `builder_code`, and `order_metadata` fields. That file supplies operator
|
|
68
|
+
attribution and site checks without changing the public package name. It must contain
|
|
69
|
+
no private keys. A nonempty configured builder code takes precedence over a per-order
|
|
70
|
+
builder code, including the zero bytes32 value, which means no attribution.
|
|
71
|
+
`builder_mode=true` requires a nonzero code. Market discovery uses the configured site's active event list.
|
|
72
|
+
|
|
73
|
+
The source distribution is named `kuest-sdk`; Python imports remain `market_sdk`.
|
|
74
|
+
The distribution has not been published to PyPI.
|
|
75
|
+
|
|
76
|
+
## Read-only example
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import os
|
|
80
|
+
from market_sdk import PublicClient, configured_environment
|
|
81
|
+
|
|
82
|
+
environment = configured_environment(
|
|
83
|
+
clob_url=os.environ["SDK_CLOB_URL"],
|
|
84
|
+
clob_ws_url=os.environ["SDK_CLOB_WS_URL"],
|
|
85
|
+
relayer_url=os.environ["SDK_RELAYER_URL"],
|
|
86
|
+
gamma_url=os.environ["SDK_GAMMA_URL"],
|
|
87
|
+
data_url=os.environ["SDK_DATA_URL"],
|
|
88
|
+
rpc_url=os.environ["SDK_RPC_URL"],
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
with PublicClient(environment=environment) as client:
|
|
92
|
+
book = client.get_order_book(token_id=os.environ["SDK_TOKEN_ID"])
|
|
93
|
+
print(book)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Wallet deployment requires separate builder credentials. No live order or transaction tests have been run.
|
|
97
|
+
|
|
98
|
+
## Origin and license
|
|
99
|
+
|
|
100
|
+
Imported from [Polymarket/py-sdk](https://github.com/Polymarket/py-sdk) at commit [`860ac384931ea55ed08a92219c9d27c02f6966cf`](https://github.com/Polymarket/py-sdk/commit/860ac384931ea55ed08a92219c9d27c02f6966cf). See [UPSTREAM.md](./UPSTREAM.md). Original copyright and MIT terms remain in [LICENSE](./LICENSE).
|
|
101
|
+
|
|
102
|
+
Kuest Engineering adapted the upstream code for the verified service API,
|
|
103
|
+
contracts, and operator packaging.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<img src="https://github.com/user-attachments/assets/0cc687fb-89c4-43fa-a056-d89c307215ad" alt="Kuest" height="96" /><br/>
|
|
3
|
+
Python SDK
|
|
4
|
+
</h1>
|
|
5
|
+
|
|
6
|
+
This is the public Kuest source repository for the white-label unified Python SDK. The
|
|
7
|
+
package and imports remain neutral so operator distributions can carry their own identity.
|
|
8
|
+
|
|
9
|
+
The SDK combines market discovery, CLOB data and orders, and Deposit Wallet relayer
|
|
10
|
+
workflows on Polygon. It adapts the [upstream unified SDK](https://github.com/Polymarket/py-sdk)
|
|
11
|
+
for Kuest's deployed contracts and APIs. Live trading has not been verified.
|
|
12
|
+
|
|
13
|
+
## Supported scope
|
|
14
|
+
|
|
15
|
+
- Polygon mainnet (chain ID 137), Circle USDC, Conditional Tokens, and the configured CTF and Neg Risk exchanges.
|
|
16
|
+
- Orders use EIP-712 `CTF Exchange` version `2`, a verified Deposit Wallet as maker and signer, signature type `3`, and a CLOB API key as the order owner.
|
|
17
|
+
- Relayer submissions use builder credentials and `WALLET` or `WALLET-CREATE` payloads. Nonce and transaction reads use `/nonce` and `/transaction`.
|
|
18
|
+
- Standard and NegRisk CTF split, merge, and redeem use the deployed Conditional Tokens and NegRiskAdapter contracts. NegRisk redeem uses the adapter's YES/NO amount ABI. These calls require the caller's relevant USDC allowance or CTF operator approval; trading approvals for the exchanges do not grant those permissions.
|
|
19
|
+
- RFQ is intentionally disabled for this product, including the ordinary RFQ supported by the CLOB backend. Specialized session-key management and upstream protocol V2 Router position operations reject locally.
|
|
20
|
+
- Position-backed V3 orders, combo RFQ, collateral return, and Safe/Proxy relayer submissions fail locally. Perps, realtime, sports, bridge, and other upstream-only services are not configured.
|
|
21
|
+
- Builder-attributed trade listing fails locally because the current CLOB ignores `builder_code`; see [COMPATIBILITY.md](./COMPATIBILITY.md).
|
|
22
|
+
- All network endpoints default to `unconfigured.invalid`. An integrator must supply approved HTTPS/WSS service URLs and a Polygon RPC URL explicitly.
|
|
23
|
+
|
|
24
|
+
For a direct GitHub checkout, supply endpoint configuration explicitly. An operator ZIP
|
|
25
|
+
may include `.sdk/site-config.json` with the existing `site_url`, `builder_mode`,
|
|
26
|
+
`geoblock`, `builder_code`, and `order_metadata` fields. That file supplies operator
|
|
27
|
+
attribution and site checks without changing the public package name. It must contain
|
|
28
|
+
no private keys. A nonempty configured builder code takes precedence over a per-order
|
|
29
|
+
builder code, including the zero bytes32 value, which means no attribution.
|
|
30
|
+
`builder_mode=true` requires a nonzero code. Market discovery uses the configured site's active event list.
|
|
31
|
+
|
|
32
|
+
The source distribution is named `kuest-sdk`; Python imports remain `market_sdk`.
|
|
33
|
+
The distribution has not been published to PyPI.
|
|
34
|
+
|
|
35
|
+
## Read-only example
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import os
|
|
39
|
+
from market_sdk import PublicClient, configured_environment
|
|
40
|
+
|
|
41
|
+
environment = configured_environment(
|
|
42
|
+
clob_url=os.environ["SDK_CLOB_URL"],
|
|
43
|
+
clob_ws_url=os.environ["SDK_CLOB_WS_URL"],
|
|
44
|
+
relayer_url=os.environ["SDK_RELAYER_URL"],
|
|
45
|
+
gamma_url=os.environ["SDK_GAMMA_URL"],
|
|
46
|
+
data_url=os.environ["SDK_DATA_URL"],
|
|
47
|
+
rpc_url=os.environ["SDK_RPC_URL"],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
with PublicClient(environment=environment) as client:
|
|
51
|
+
book = client.get_order_book(token_id=os.environ["SDK_TOKEN_ID"])
|
|
52
|
+
print(book)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Wallet deployment requires separate builder credentials. No live order or transaction tests have been run.
|
|
56
|
+
|
|
57
|
+
## Origin and license
|
|
58
|
+
|
|
59
|
+
Imported from [Polymarket/py-sdk](https://github.com/Polymarket/py-sdk) at commit [`860ac384931ea55ed08a92219c9d27c02f6966cf`](https://github.com/Polymarket/py-sdk/commit/860ac384931ea55ed08a92219c9d27c02f6966cf). See [UPSTREAM.md](./UPSTREAM.md). Original copyright and MIT terms remain in [LICENSE](./LICENSE).
|
|
60
|
+
|
|
61
|
+
Kuest Engineering adapted the upstream code for the verified service API,
|
|
62
|
+
contracts, and operator packaging.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
Please do not report security vulnerabilities through public GitHub issues.
|
|
6
|
+
|
|
7
|
+
Use GitHub private vulnerability reporting for this repository. Include enough detail for us to understand and reproduce the issue, including:
|
|
8
|
+
|
|
9
|
+
- The affected package and version.
|
|
10
|
+
- A description of the vulnerability and potential impact.
|
|
11
|
+
- Reproduction steps or a proof of concept, if available.
|
|
12
|
+
- Any relevant environment details.
|
|
13
|
+
|
|
14
|
+
We will review reports and coordinate fixes before public disclosure.
|
|
15
|
+
|
|
16
|
+
## Supported Versions
|
|
17
|
+
|
|
18
|
+
Security fixes are focused on the latest published version and the current development branch.
|
|
19
|
+
|
|
20
|
+
## Public Issues
|
|
21
|
+
|
|
22
|
+
For non-security bugs, feature requests, and general feedback, use the repository's GitHub issue templates.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Python examples
|
|
2
|
+
|
|
3
|
+
These imported scripts are migration references. Some still assume position-backed markets or realtime services that are not configured in this SDK. Do not use their trading or subscription flows with live services until each example is verified for the target operator.
|
|
4
|
+
|
|
5
|
+
For the supported read-only workflow, see the [workspace README](../README.md). Use a verified Deposit Wallet for orders and keep CLOB credentials separate from builder relayer credentials. The [SDK scope](../docs/sdk-direction.md) lists supported operations.
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Build and sign a limit order — without posting it.
|
|
2
|
+
|
|
3
|
+
SDK_PRIVATE_KEY=0x... SDK_DEPOSIT_WALLET=0x... \
|
|
4
|
+
uv run python -m examples.create_limit_order
|
|
5
|
+
|
|
6
|
+
`create_limit_order` signs the order locally and returns it; it does NOT submit
|
|
7
|
+
to the exchange. Use `place_limit_order` (or `post_order`) to actually trade.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from examples.lib.env import require_env
|
|
13
|
+
from examples.lib.markets import OrderExampleMarketVersion, find_order_example_market
|
|
14
|
+
from examples.lib.tables import print_values_table
|
|
15
|
+
from market_sdk import SecureClient
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> None:
|
|
19
|
+
client = SecureClient.create(
|
|
20
|
+
private_key=require_env("SDK_PRIVATE_KEY"),
|
|
21
|
+
wallet=require_env("SDK_DEPOSIT_WALLET"),
|
|
22
|
+
)
|
|
23
|
+
with client:
|
|
24
|
+
selected = find_order_example_market(client)
|
|
25
|
+
market = selected.market
|
|
26
|
+
# CTF markets trade by token ID; position-backed V3 markets are unsupported.
|
|
27
|
+
asset_id = (
|
|
28
|
+
market.outcomes.yes.token_id
|
|
29
|
+
if selected.version is OrderExampleMarketVersion.V1
|
|
30
|
+
else market.outcomes.yes.position_id
|
|
31
|
+
)
|
|
32
|
+
if asset_id is None:
|
|
33
|
+
raise SystemExit("Selected market has no tradable YES asset.")
|
|
34
|
+
|
|
35
|
+
# `find_order_example_market` guarantees these are set. Bid one tick above
|
|
36
|
+
# zero and one minimum lot — a passive price that will rest on the book.
|
|
37
|
+
price = market.trading.minimum_tick_size
|
|
38
|
+
size = market.trading.minimum_order_size
|
|
39
|
+
if price is None or size is None:
|
|
40
|
+
raise SystemExit("Selected market is missing tick size or order size.")
|
|
41
|
+
order = client.create_limit_order(
|
|
42
|
+
asset_id=asset_id,
|
|
43
|
+
price=price,
|
|
44
|
+
size=size,
|
|
45
|
+
side="BUY",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
print("Signed limit order (built locally, not submitted):")
|
|
49
|
+
print_values_table(
|
|
50
|
+
{
|
|
51
|
+
"market": market.question or market.slug or market.id,
|
|
52
|
+
"minimumTickSize": price,
|
|
53
|
+
"minimumOrderSize": size,
|
|
54
|
+
"assetId": order.token_id,
|
|
55
|
+
"side": order.side,
|
|
56
|
+
"orderType": order.order_type,
|
|
57
|
+
"maker": order.maker,
|
|
58
|
+
"makerAmount": order.maker_amount,
|
|
59
|
+
"takerAmount": order.taker_amount,
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
main()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Build and sign a market order — without posting it.
|
|
2
|
+
|
|
3
|
+
SDK_PRIVATE_KEY=0x... SDK_DEPOSIT_WALLET=0x... \
|
|
4
|
+
uv run python -m examples.create_market_order
|
|
5
|
+
|
|
6
|
+
`create_market_order` signs the order locally and returns it; it does NOT submit
|
|
7
|
+
to the exchange. Use `place_market_order` (or `post_order`) to actually trade.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from examples.lib.env import require_env
|
|
13
|
+
from examples.lib.markets import OrderExampleMarketVersion, find_order_example_market
|
|
14
|
+
from examples.lib.tables import print_values_table
|
|
15
|
+
from market_sdk import SecureClient
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> None:
|
|
19
|
+
client = SecureClient.create(
|
|
20
|
+
private_key=require_env("SDK_PRIVATE_KEY"),
|
|
21
|
+
wallet=require_env("SDK_DEPOSIT_WALLET"),
|
|
22
|
+
)
|
|
23
|
+
with client:
|
|
24
|
+
selected = find_order_example_market(client)
|
|
25
|
+
market = selected.market
|
|
26
|
+
# CTF markets trade by token ID; position-backed V3 markets are unsupported.
|
|
27
|
+
asset_id = (
|
|
28
|
+
market.outcomes.yes.token_id
|
|
29
|
+
if selected.version is OrderExampleMarketVersion.V1
|
|
30
|
+
else market.outcomes.yes.position_id
|
|
31
|
+
)
|
|
32
|
+
if asset_id is None:
|
|
33
|
+
raise SystemExit("Selected market has no tradable YES asset.")
|
|
34
|
+
|
|
35
|
+
# `find_order_example_market` guarantees minimum_order_size is set.
|
|
36
|
+
amount = market.trading.minimum_order_size
|
|
37
|
+
if amount is None:
|
|
38
|
+
raise SystemExit("Selected market has no minimum order size.")
|
|
39
|
+
|
|
40
|
+
estimated_price = client.estimate_market_price(
|
|
41
|
+
asset_id=asset_id, side="BUY", amount=amount, order_type="FAK"
|
|
42
|
+
)
|
|
43
|
+
order = client.create_market_order(
|
|
44
|
+
asset_id=asset_id,
|
|
45
|
+
side="BUY",
|
|
46
|
+
amount=amount,
|
|
47
|
+
order_type="FAK",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
print("Signed market order (built locally, not submitted):")
|
|
51
|
+
print_values_table(
|
|
52
|
+
{
|
|
53
|
+
"market": market.question or market.slug or market.id,
|
|
54
|
+
"minimumOrderSize": amount,
|
|
55
|
+
"assetId": order.token_id,
|
|
56
|
+
"side": order.side,
|
|
57
|
+
"orderType": order.order_type,
|
|
58
|
+
"estimatedPrice": estimated_price,
|
|
59
|
+
"maker": order.maker,
|
|
60
|
+
"makerAmount": order.maker_amount,
|
|
61
|
+
"takerAmount": order.taker_amount,
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
main()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Stream 30-second and 60-second Chainlink TWAP prices.
|
|
2
|
+
|
|
3
|
+
uv run python -m examples.crypto_twap_stream
|
|
4
|
+
|
|
5
|
+
No credentials required. Stop the stream with Ctrl-C.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
|
|
10
|
+
from market_sdk import AsyncPublicClient
|
|
11
|
+
from market_sdk.streams import CryptoPricesChainlinkTwapSpec # pyright: ignore[reportDeprecated]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def main() -> None:
|
|
15
|
+
client = AsyncPublicClient()
|
|
16
|
+
try:
|
|
17
|
+
async with await client.subscribe(
|
|
18
|
+
[
|
|
19
|
+
CryptoPricesChainlinkTwapSpec( # pyright: ignore[reportDeprecated]
|
|
20
|
+
window_seconds=30,
|
|
21
|
+
symbols=["btc/usd", "eth/usd"],
|
|
22
|
+
),
|
|
23
|
+
CryptoPricesChainlinkTwapSpec( # pyright: ignore[reportDeprecated]
|
|
24
|
+
window_seconds=60,
|
|
25
|
+
symbols=["btc/usd", "eth/usd"],
|
|
26
|
+
),
|
|
27
|
+
]
|
|
28
|
+
) as stream:
|
|
29
|
+
async for event in stream:
|
|
30
|
+
print(
|
|
31
|
+
f"{event.payload.symbol} "
|
|
32
|
+
f"{event.payload.window_seconds}s "
|
|
33
|
+
f"{event.payload.value} "
|
|
34
|
+
f"(observed {event.payload.timestamp})"
|
|
35
|
+
)
|
|
36
|
+
finally:
|
|
37
|
+
await client.close()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Fetch a single market by slug and id.
|
|
2
|
+
|
|
3
|
+
uv run python -m examples.fetch_market
|
|
4
|
+
|
|
5
|
+
No credentials required. Discovers a few live markets, then re-fetches them.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from market_sdk import PublicClient
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> None:
|
|
14
|
+
with PublicClient() as client:
|
|
15
|
+
items = client.list_markets(page_size=3).first_page().items
|
|
16
|
+
if len(items) < 2:
|
|
17
|
+
raise SystemExit("Not enough live markets to demo lookups.")
|
|
18
|
+
|
|
19
|
+
slug0 = items[0].slug
|
|
20
|
+
if slug0 is None:
|
|
21
|
+
raise SystemExit("Discovered markets are missing slugs; try again.")
|
|
22
|
+
|
|
23
|
+
by_slug = client.get_market(slug=slug0)
|
|
24
|
+
by_id = client.get_market(id=str(items[1].id))
|
|
25
|
+
|
|
26
|
+
print(f"Slug lookup: {by_slug.question or by_slug.id}")
|
|
27
|
+
print(f"ID lookup: {by_id.question or by_id.id}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
main()
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Environment helpers for the examples.
|
|
2
|
+
|
|
3
|
+
The SDK does not load `.env` at runtime, so examples read credentials straight
|
|
4
|
+
from the environment. Export them in your shell (or `source` a `.env`).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def require_env(name: str) -> str:
|
|
13
|
+
"""Return the environment variable, or exit with a clear message if unset."""
|
|
14
|
+
value = os.environ.get(name, "").strip()
|
|
15
|
+
if not value:
|
|
16
|
+
raise SystemExit(f"{name} is required — set it in your environment to run this example.")
|
|
17
|
+
return value
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Find a live, tradable market for the order examples.
|
|
2
|
+
|
|
3
|
+
Port of the ts-sdk `findOrderExampleMarket` helper: scan liquid markets and
|
|
4
|
+
return the first binary market that has an order book, is accepting orders, has
|
|
5
|
+
a usable price band, and a non-empty book.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from enum import IntEnum
|
|
12
|
+
|
|
13
|
+
from market_sdk import ClobAssetId, Market, MarketSdkError, PublicClient, SecureClient
|
|
14
|
+
|
|
15
|
+
# Either client exposes the read methods this helper needs.
|
|
16
|
+
MarketLookupClient = PublicClient | SecureClient
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class OrderExampleMarketVersion(IntEnum):
|
|
20
|
+
V1 = 1
|
|
21
|
+
V2 = 2
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True, slots=True)
|
|
25
|
+
class OrderExampleMarket:
|
|
26
|
+
market: Market
|
|
27
|
+
version: OrderExampleMarketVersion
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def find_order_example_market(client: MarketLookupClient) -> OrderExampleMarket:
|
|
31
|
+
"""Return a liquid, order-book-enabled binary market suitable for order examples."""
|
|
32
|
+
paginator = client.list_markets(
|
|
33
|
+
closed=False,
|
|
34
|
+
liquidity_num_min=1000,
|
|
35
|
+
page_size=1000,
|
|
36
|
+
order="liquidityNum",
|
|
37
|
+
ascending=False,
|
|
38
|
+
sports_market_types=["moneyline", "spreads", "totals"],
|
|
39
|
+
)
|
|
40
|
+
for candidate in paginator.iter_items():
|
|
41
|
+
version = _order_example_market_version(client, candidate)
|
|
42
|
+
if version is not None:
|
|
43
|
+
return OrderExampleMarket(market=candidate, version=version)
|
|
44
|
+
raise SystemExit("Could not find a live market for the order example.")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _order_example_market_version(
|
|
48
|
+
client: MarketLookupClient, market: Market
|
|
49
|
+
) -> OrderExampleMarketVersion | None:
|
|
50
|
+
version = resolve_order_example_market_version(market)
|
|
51
|
+
if (
|
|
52
|
+
version is None
|
|
53
|
+
or market.state.enable_order_book is not True
|
|
54
|
+
or market.state.accepting_orders is not True
|
|
55
|
+
or market.trading.minimum_order_size is None
|
|
56
|
+
or market.trading.minimum_tick_size is None
|
|
57
|
+
or market.prices.best_ask is None
|
|
58
|
+
or market.prices.best_ask >= 1
|
|
59
|
+
or market.prices.best_bid is None
|
|
60
|
+
or market.prices.best_bid <= 0
|
|
61
|
+
):
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
asset_id = (
|
|
65
|
+
market.outcomes.yes.token_id
|
|
66
|
+
if version is OrderExampleMarketVersion.V1
|
|
67
|
+
else market.outcomes.yes.position_id
|
|
68
|
+
)
|
|
69
|
+
if asset_id is None:
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
book = client.get_order_book(asset_id=asset_id)
|
|
74
|
+
except MarketSdkError:
|
|
75
|
+
return None
|
|
76
|
+
return version if book.asks and book.bids else None
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def resolve_order_example_market_version(market: Market) -> OrderExampleMarketVersion | None:
|
|
80
|
+
"""Resolve whether an order example should use CTF token IDs or V2 position IDs."""
|
|
81
|
+
|
|
82
|
+
# CTF markets may also expose position IDs for Combos, so a complete token
|
|
83
|
+
# pair remains the V1 discriminant when both pairs are present.
|
|
84
|
+
if market.outcomes.yes.token_id is not None and market.outcomes.no.token_id is not None:
|
|
85
|
+
return OrderExampleMarketVersion.V1
|
|
86
|
+
if market.outcomes.yes.position_id is not None and market.outcomes.no.position_id is not None:
|
|
87
|
+
return OrderExampleMarketVersion.V2
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def market_yes_asset_id(market: Market) -> ClobAssetId | None:
|
|
92
|
+
"""Return the market's tradable YES asset using its outcome-pair representation."""
|
|
93
|
+
|
|
94
|
+
version = resolve_order_example_market_version(market)
|
|
95
|
+
if version is OrderExampleMarketVersion.V1:
|
|
96
|
+
return market.outcomes.yes.token_id
|
|
97
|
+
if version is OrderExampleMarketVersion.V2:
|
|
98
|
+
return market.outcomes.yes.position_id
|
|
99
|
+
return None
|