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.
Files changed (233) hide show
  1. kuest_sdk-0.13.0/.editorconfig +11 -0
  2. kuest_sdk-0.13.0/.env.example +15 -0
  3. kuest_sdk-0.13.0/.gitignore +16 -0
  4. kuest_sdk-0.13.0/.python-version +1 -0
  5. kuest_sdk-0.13.0/CLAUDE.md +3 -0
  6. kuest_sdk-0.13.0/COMPATIBILITY.md +28 -0
  7. kuest_sdk-0.13.0/LICENSE +21 -0
  8. kuest_sdk-0.13.0/PKG-INFO +103 -0
  9. kuest_sdk-0.13.0/README.md +62 -0
  10. kuest_sdk-0.13.0/SECURITY.md +22 -0
  11. kuest_sdk-0.13.0/UPSTREAM.md +4 -0
  12. kuest_sdk-0.13.0/examples/README.md +5 -0
  13. kuest_sdk-0.13.0/examples/__init__.py +0 -0
  14. kuest_sdk-0.13.0/examples/create_limit_order.py +65 -0
  15. kuest_sdk-0.13.0/examples/create_market_order.py +67 -0
  16. kuest_sdk-0.13.0/examples/crypto_twap_stream.py +41 -0
  17. kuest_sdk-0.13.0/examples/fetch_market.py +31 -0
  18. kuest_sdk-0.13.0/examples/lib/__init__.py +0 -0
  19. kuest_sdk-0.13.0/examples/lib/env.py +17 -0
  20. kuest_sdk-0.13.0/examples/lib/markets.py +99 -0
  21. kuest_sdk-0.13.0/examples/lib/tables.py +63 -0
  22. kuest_sdk-0.13.0/examples/list_markets.py +22 -0
  23. kuest_sdk-0.13.0/examples/list_positions.py +40 -0
  24. kuest_sdk-0.13.0/examples/market_prices.py +48 -0
  25. kuest_sdk-0.13.0/examples/pagination.py +27 -0
  26. kuest_sdk-0.13.0/examples/search.py +56 -0
  27. kuest_sdk-0.13.0/examples/stream_realtime_prices.py +44 -0
  28. kuest_sdk-0.13.0/pyproject.toml +127 -0
  29. kuest_sdk-0.13.0/src/market_sdk/__init__.py +663 -0
  30. kuest_sdk-0.13.0/src/market_sdk/_frames_bridge.py +14 -0
  31. kuest_sdk-0.13.0/src/market_sdk/_internal/__init__.py +0 -0
  32. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/__init__.py +0 -0
  33. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/_cursor.py +41 -0
  34. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/account.py +246 -0
  35. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/auth.py +206 -0
  36. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/builders.py +69 -0
  37. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/clob.py +247 -0
  38. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/combo_rfq.py +839 -0
  39. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/combos.py +160 -0
  40. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/data.py +716 -0
  41. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/exchange_asset.py +58 -0
  42. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/gamma.py +892 -0
  43. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/order_heartbeats.py +14 -0
  44. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/__init__.py +0 -0
  45. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/_numeric.py +27 -0
  46. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/allowance.py +102 -0
  47. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/cache.py +282 -0
  48. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/cancel.py +65 -0
  49. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/context.py +81 -0
  50. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/estimate.py +237 -0
  51. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/limit.py +167 -0
  52. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/market.py +432 -0
  53. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/market_data.py +293 -0
  54. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/math.py +48 -0
  55. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/orders.py +81 -0
  56. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/place.py +198 -0
  57. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/post.py +92 -0
  58. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/settlement.py +130 -0
  59. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/typed_data.py +213 -0
  60. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/orders/types.py +62 -0
  61. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/__init__.py +0 -0
  62. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/account.py +601 -0
  63. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/builders.py +162 -0
  64. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/chases.py +108 -0
  65. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/credentials.py +174 -0
  66. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/funds.py +115 -0
  67. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/paging.py +240 -0
  68. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/position_snapshots.py +115 -0
  69. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/public.py +310 -0
  70. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/signing.py +195 -0
  71. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/trading.py +509 -0
  72. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/perps/twaps.py +123 -0
  73. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/__init__.py +0 -0
  74. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/approvals.py +282 -0
  75. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/auth.py +93 -0
  76. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/calls.py +417 -0
  77. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/deployed.py +36 -0
  78. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/gasless.py +716 -0
  79. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/nonce.py +69 -0
  80. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/poll.py +119 -0
  81. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/positions.py +364 -0
  82. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/signing/__init__.py +0 -0
  83. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/signing/deposit_wallet.py +96 -0
  84. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/signing/proxy.py +59 -0
  85. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/signing/safe.py +110 -0
  86. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/relayer/submit.py +74 -0
  87. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/rewards.py +332 -0
  88. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/rfq.py +87 -0
  89. kuest_sdk-0.13.0/src/market_sdk/_internal/actions/session_keys.py +742 -0
  90. kuest_sdk-0.13.0/src/market_sdk/_internal/context.py +89 -0
  91. kuest_sdk-0.13.0/src/market_sdk/_internal/data_envelope.py +38 -0
  92. kuest_sdk-0.13.0/src/market_sdk/_internal/data_params.py +100 -0
  93. kuest_sdk-0.13.0/src/market_sdk/_internal/dispatch.py +417 -0
  94. kuest_sdk-0.13.0/src/market_sdk/_internal/environment.py +35 -0
  95. kuest_sdk-0.13.0/src/market_sdk/_internal/eoa/__init__.py +0 -0
  96. kuest_sdk-0.13.0/src/market_sdk/_internal/eoa/broadcast.py +166 -0
  97. kuest_sdk-0.13.0/src/market_sdk/_internal/eoa/rpc.py +360 -0
  98. kuest_sdk-0.13.0/src/market_sdk/_internal/gamma_paths.py +100 -0
  99. kuest_sdk-0.13.0/src/market_sdk/_internal/hmac.py +34 -0
  100. kuest_sdk-0.13.0/src/market_sdk/_internal/l1_auth.py +84 -0
  101. kuest_sdk-0.13.0/src/market_sdk/_internal/pagination.py +362 -0
  102. kuest_sdk-0.13.0/src/market_sdk/_internal/perps_session.py +1766 -0
  103. kuest_sdk-0.13.0/src/market_sdk/_internal/protocol.py +65 -0
  104. kuest_sdk-0.13.0/src/market_sdk/_internal/request.py +112 -0
  105. kuest_sdk-0.13.0/src/market_sdk/_internal/retry.py +44 -0
  106. kuest_sdk-0.13.0/src/market_sdk/_internal/rfq.py +802 -0
  107. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/__init__.py +0 -0
  108. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/__init__.py +0 -0
  109. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/heartbeat.py +62 -0
  110. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/market.py +209 -0
  111. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/market_protocol.py +124 -0
  112. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/user.py +213 -0
  113. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/clob/user_protocol.py +98 -0
  114. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/handle.py +143 -0
  115. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/merged_handle.py +153 -0
  116. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/perps/__init__.py +0 -0
  117. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/perps/heartbeat.py +65 -0
  118. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/perps/market.py +209 -0
  119. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/perps/market_protocol.py +125 -0
  120. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/__init__.py +1 -0
  121. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/heartbeat.py +39 -0
  122. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/manager.py +116 -0
  123. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/protocol.py +230 -0
  124. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/session.py +322 -0
  125. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/realtime/socket.py +225 -0
  126. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/reconnect.py +93 -0
  127. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/registry.py +73 -0
  128. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/rtds/__init__.py +0 -0
  129. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/rtds/heartbeat.py +60 -0
  130. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/rtds/manager.py +183 -0
  131. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/rtds/protocol.py +179 -0
  132. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/sports/__init__.py +0 -0
  133. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/sports/heartbeat.py +69 -0
  134. kuest_sdk-0.13.0/src/market_sdk/_internal/streams/sports/manager.py +173 -0
  135. kuest_sdk-0.13.0/src/market_sdk/_internal/validation.py +28 -0
  136. kuest_sdk-0.13.0/src/market_sdk/_internal/wallet.py +284 -0
  137. kuest_sdk-0.13.0/src/market_sdk/_internal/ws/__init__.py +11 -0
  138. kuest_sdk-0.13.0/src/market_sdk/_internal/ws/backoff.py +25 -0
  139. kuest_sdk-0.13.0/src/market_sdk/_internal/ws/connection.py +277 -0
  140. kuest_sdk-0.13.0/src/market_sdk/_internal/ws/heartbeat.py +26 -0
  141. kuest_sdk-0.13.0/src/market_sdk/_jupyter.py +72 -0
  142. kuest_sdk-0.13.0/src/market_sdk/auth.py +58 -0
  143. kuest_sdk-0.13.0/src/market_sdk/calls.py +45 -0
  144. kuest_sdk-0.13.0/src/market_sdk/clients/__init__.py +8 -0
  145. kuest_sdk-0.13.0/src/market_sdk/clients/_transport.py +621 -0
  146. kuest_sdk-0.13.0/src/market_sdk/clients/async_public.py +1816 -0
  147. kuest_sdk-0.13.0/src/market_sdk/clients/async_secure.py +4310 -0
  148. kuest_sdk-0.13.0/src/market_sdk/clients/public.py +1421 -0
  149. kuest_sdk-0.13.0/src/market_sdk/clients/secure.py +3529 -0
  150. kuest_sdk-0.13.0/src/market_sdk/environments.py +144 -0
  151. kuest_sdk-0.13.0/src/market_sdk/errors.py +181 -0
  152. kuest_sdk-0.13.0/src/market_sdk/frames/__init__.py +14 -0
  153. kuest_sdk-0.13.0/src/market_sdk/frames/_arrow.py +366 -0
  154. kuest_sdk-0.13.0/src/market_sdk/frames/_builtin_overrides.py +46 -0
  155. kuest_sdk-0.13.0/src/market_sdk/frames/_errors.py +10 -0
  156. kuest_sdk-0.13.0/src/market_sdk/frames/_overrides.py +48 -0
  157. kuest_sdk-0.13.0/src/market_sdk/frames/_pandas.py +103 -0
  158. kuest_sdk-0.13.0/src/market_sdk/frames/_polars.py +102 -0
  159. kuest_sdk-0.13.0/src/market_sdk/models/__init__.py +630 -0
  160. kuest_sdk-0.13.0/src/market_sdk/models/_validators.py +34 -0
  161. kuest_sdk-0.13.0/src/market_sdk/models/base.py +40 -0
  162. kuest_sdk-0.13.0/src/market_sdk/models/clob/__init__.py +141 -0
  163. kuest_sdk-0.13.0/src/market_sdk/models/clob/_validators.py +200 -0
  164. kuest_sdk-0.13.0/src/market_sdk/models/clob/account.py +250 -0
  165. kuest_sdk-0.13.0/src/market_sdk/models/clob/api_key.py +47 -0
  166. kuest_sdk-0.13.0/src/market_sdk/models/clob/builder.py +97 -0
  167. kuest_sdk-0.13.0/src/market_sdk/models/clob/cancel.py +16 -0
  168. kuest_sdk-0.13.0/src/market_sdk/models/clob/last_trade.py +44 -0
  169. kuest_sdk-0.13.0/src/market_sdk/models/clob/market_events.py +417 -0
  170. kuest_sdk-0.13.0/src/market_sdk/models/clob/notifications.py +493 -0
  171. kuest_sdk-0.13.0/src/market_sdk/models/clob/order_book.py +119 -0
  172. kuest_sdk-0.13.0/src/market_sdk/models/clob/order_heartbeats.py +18 -0
  173. kuest_sdk-0.13.0/src/market_sdk/models/clob/order_response.py +164 -0
  174. kuest_sdk-0.13.0/src/market_sdk/models/clob/orders.py +31 -0
  175. kuest_sdk-0.13.0/src/market_sdk/models/clob/relayer.py +105 -0
  176. kuest_sdk-0.13.0/src/market_sdk/models/clob/requests.py +67 -0
  177. kuest_sdk-0.13.0/src/market_sdk/models/clob/rewards.py +311 -0
  178. kuest_sdk-0.13.0/src/market_sdk/models/clob/user_events.py +257 -0
  179. kuest_sdk-0.13.0/src/market_sdk/models/collateral_return.py +146 -0
  180. kuest_sdk-0.13.0/src/market_sdk/models/data/__init__.py +172 -0
  181. kuest_sdk-0.13.0/src/market_sdk/models/data/activity.py +505 -0
  182. kuest_sdk-0.13.0/src/market_sdk/models/data/analytics.py +157 -0
  183. kuest_sdk-0.13.0/src/market_sdk/models/data/common.py +308 -0
  184. kuest_sdk-0.13.0/src/market_sdk/models/data/leaderboard.py +202 -0
  185. kuest_sdk-0.13.0/src/market_sdk/models/data/portfolio.py +410 -0
  186. kuest_sdk-0.13.0/src/market_sdk/models/data/resolutions.py +115 -0
  187. kuest_sdk-0.13.0/src/market_sdk/models/data/tokens.py +95 -0
  188. kuest_sdk-0.13.0/src/market_sdk/models/gamma/__init__.py +125 -0
  189. kuest_sdk-0.13.0/src/market_sdk/models/gamma/comment.py +127 -0
  190. kuest_sdk-0.13.0/src/market_sdk/models/gamma/common.py +436 -0
  191. kuest_sdk-0.13.0/src/market_sdk/models/gamma/event.py +530 -0
  192. kuest_sdk-0.13.0/src/market_sdk/models/gamma/market.py +668 -0
  193. kuest_sdk-0.13.0/src/market_sdk/models/gamma/profile.py +54 -0
  194. kuest_sdk-0.13.0/src/market_sdk/models/gamma/search.py +168 -0
  195. kuest_sdk-0.13.0/src/market_sdk/models/gamma/series.py +19 -0
  196. kuest_sdk-0.13.0/src/market_sdk/models/gamma/tag.py +22 -0
  197. kuest_sdk-0.13.0/src/market_sdk/models/perps/__init__.py +312 -0
  198. kuest_sdk-0.13.0/src/market_sdk/models/perps/_validators.py +68 -0
  199. kuest_sdk-0.13.0/src/market_sdk/models/perps/account.py +301 -0
  200. kuest_sdk-0.13.0/src/market_sdk/models/perps/builder_events.py +25 -0
  201. kuest_sdk-0.13.0/src/market_sdk/models/perps/builders.py +210 -0
  202. kuest_sdk-0.13.0/src/market_sdk/models/perps/chases.py +76 -0
  203. kuest_sdk-0.13.0/src/market_sdk/models/perps/credentials.py +46 -0
  204. kuest_sdk-0.13.0/src/market_sdk/models/perps/events.py +416 -0
  205. kuest_sdk-0.13.0/src/market_sdk/models/perps/funds.py +172 -0
  206. kuest_sdk-0.13.0/src/market_sdk/models/perps/market.py +418 -0
  207. kuest_sdk-0.13.0/src/market_sdk/models/perps/notifications.py +253 -0
  208. kuest_sdk-0.13.0/src/market_sdk/models/perps/orders.py +332 -0
  209. kuest_sdk-0.13.0/src/market_sdk/models/perps/position_snapshots.py +147 -0
  210. kuest_sdk-0.13.0/src/market_sdk/models/perps/requests.py +373 -0
  211. kuest_sdk-0.13.0/src/market_sdk/models/perps/results.py +41 -0
  212. kuest_sdk-0.13.0/src/market_sdk/models/perps/twaps.py +87 -0
  213. kuest_sdk-0.13.0/src/market_sdk/models/perps/types.py +132 -0
  214. kuest_sdk-0.13.0/src/market_sdk/models/price_events.py +201 -0
  215. kuest_sdk-0.13.0/src/market_sdk/models/rfq.py +150 -0
  216. kuest_sdk-0.13.0/src/market_sdk/models/rtds_events.py +382 -0
  217. kuest_sdk-0.13.0/src/market_sdk/models/sports_events.py +71 -0
  218. kuest_sdk-0.13.0/src/market_sdk/models/trading.py +46 -0
  219. kuest_sdk-0.13.0/src/market_sdk/models/types.py +200 -0
  220. kuest_sdk-0.13.0/src/market_sdk/pagination.py +340 -0
  221. kuest_sdk-0.13.0/src/market_sdk/perps.py +46 -0
  222. kuest_sdk-0.13.0/src/market_sdk/py.typed +0 -0
  223. kuest_sdk-0.13.0/src/market_sdk/rate_limit.py +38 -0
  224. kuest_sdk-0.13.0/src/market_sdk/rfq.py +534 -0
  225. kuest_sdk-0.13.0/src/market_sdk/session_keys.py +100 -0
  226. kuest_sdk-0.13.0/src/market_sdk/site_config.py +146 -0
  227. kuest_sdk-0.13.0/src/market_sdk/site_scope.py +226 -0
  228. kuest_sdk-0.13.0/src/market_sdk/streams/__init__.py +258 -0
  229. kuest_sdk-0.13.0/src/market_sdk/streams/_specs.py +633 -0
  230. kuest_sdk-0.13.0/src/market_sdk/transactions.py +186 -0
  231. kuest_sdk-0.13.0/src/market_sdk/types.py +9 -0
  232. kuest_sdk-0.13.0/src/market_sdk/version.py +8 -0
  233. kuest_sdk-0.13.0/uv.lock +1933 -0
@@ -0,0 +1,11 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+ indent_style = space
8
+ indent_size = 2
9
+
10
+ [*.py]
11
+ indent_size = 4
@@ -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,16 @@
1
+ .DS_Store
2
+ .env
3
+ .env.*
4
+ !.env.example
5
+ .venv/
6
+ __pycache__/
7
+ *.py[cod]
8
+ *.egg-info/
9
+ .pytest_cache/
10
+ .ruff_cache/
11
+ .coverage
12
+ coverage.xml
13
+ htmlcov/
14
+ dist/
15
+ build/
16
+ site/
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,3 @@
1
+ # Project Context
2
+
3
+ @./AGENTS.md
@@ -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.
@@ -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,4 @@
1
+ Upstream: https://github.com/Polymarket/py-sdk
2
+ Imported commit: 860ac384931ea55ed08a92219c9d27c02f6966cf
3
+ License: MIT; see LICENSE.
4
+ Adaptation: Kuest Engineering adapted the upstream code for the verified service API, contracts, and operator packaging.
@@ -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