Registry / web-framework / py-order-utils

py-order-utils

JSON →
library0.3.2pypypi✓ verified 24d ago

Python utilities used to generate and sign orders for Polymarket's Exchange. The library facilitates interaction with Polymarket's Central Limit Order Book (CLOB) by providing tools for order building, signing, and data structuring. The current version is 0.3.2, with releases primarily driven by smart contract updates and critical bug fixes, indicating an active but demand-driven release cadence.

pip install py-order-utils
INSTALL
IMPORT
SIG · PY-ORDER-UTILS
P
py-order-utils
web-frameworkpythonv0.3.2
Install
7.4s avg
Import
4852ms
Disk
71MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 5.102s · 69.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.4s · import 4.602s · 73MB
71MB installed
● package 71MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OrderBuilder
from py_order_utils.builders import OrderBuilder
Signer
from py_order_utils.signer import Signer
OrderData
from py_order_utils.models import OrderData
Assumed path based on common Python package structure for models/data classes. Not explicitly shown in quickstart snippet but necessary.

This quickstart demonstrates how to initialize the `Signer` and `OrderBuilder` classes, construct a sample `OrderData` object with placeholder values, and generate a signed order suitable for submission to Polymarket's CLOB API. Ensure environment variables for `POLYMARKET_PRIVATE_KEY`, `POLYMARKET_RPC_URL`, `POLYMARKET_EXCHANGE_ADDRESS`, and `POLYMARKET_CHAIN_ID` are set for a runnable example.

import os import json from web3 import Web3 from py_order_utils.builders import OrderBuilder from py_order_utils.signer import Signer from py_order_utils.models import OrderData, SignedOrder # Configuration (replace with your actual values or environment variables) PRIVATE_KEY = os.environ.get('POLYMARKET_PRIVATE_KEY', '0x...') # Your Ethereum private key RPC_URL = os.environ.get('POLYMARKET_RPC_URL', 'https://rpc-amoy.polygon.technology/') # e.g., Polygon Amoy RPC URL EXCHANGE_ADDRESS = os.environ.get('POLYMARKET_EXCHANGE_ADDRESS', '0x...') # Polymarket CLOB Exchange Contract Address CHAIN_ID = int(os.environ.get('POLYMARKET_CHAIN_ID', '80002')) # e.g., 80002 for Polygon Amoy def main(): if PRIVATE_KEY == '0x...' or EXCHANGE_ADDRESS == '0x...': print("Please configure POLYMARKET_PRIVATE_KEY, POLYMARKET_RPC_URL, EXCHANGE_ADDRESS, and CHAIN_ID environment variables.") return w3 = Web3(Web3.HTTPProvider(RPC_URL)) if not w3.is_connected(): print(f"Failed to connect to RPC at {RPC_URL}") return print(f"Connected to chain ID: {w3.eth.chain_id}") signer_instance = Signer(PRIVATE_KEY) builder = OrderBuilder(EXCHANGE_ADDRESS, CHAIN_ID, signer_instance) # Example OrderData payload (replace with actual order parameters) order_data = OrderData( maker='0x' + signer_instance.address[2:], # Your wallet address taker='0x0000000000000000000000000000000000000000', # Taker address (0x0 for open orders) longToken='0x...', # Address of the long token for the market shortToken='0x...', # Address of the short token for the market longTokenAmount='1000000000000000000', # 1 Long Token (example: 1e18 wei) shortTokenAmount='500000000000000000', # 0.5 Short Token (example: 0.5e18 wei) salt=w3.eth.get_block('latest').number, # Unique salt for the order expiry=w3.eth.get_block('latest').timestamp + 3600, # Expires in 1 hour feeRate='0', # Example fee rate isPostOnly=False, market='0x...', # Market contract address minAmountReceived='0' # Minimum amount to receive ) try: # Create and sign the order signed_order: SignedOrder = builder.build_signed_order(order_data) # Generate the Order and Signature JSON to be sent to the CLOB API print("\n--- Signed Order JSON ---") print(json.dumps(signed_order.dict(), indent=2)) except Exception as e: print(f"An error occurred: {e}") if __name__ == '__main__': main()
Debug
Known issues
breakingBreaking change in cryptographic dependencies. Version 0.3.1 replaced `pysha3` with compatible libraries.
fix
Users upgrading from versions prior to 0.3.1 should ensure their environment is free of `pysha3` dependencies if experiencing import errors or unexpected behavior. The library now uses standard `web3.py` and `eth-account` cryptographic primitives internally, which should resolve compatibility issues.
affects: <0.3.1
breakingMajor contract migrations (e.g., to Amoy testnet) frequently require updates to contract addresses and ABIs.
fix
Always use the latest stable version of `py-order-utils`. Ensure that `EXCHANGE_ADDRESS`, `CHAIN_ID`, and any token/market addresses used in `OrderData` are up-to-date with the current Polymarket deployment. Refer to Polymarket's official documentation or contract repositories for the latest addresses.
affects: All versions, specifically v0.3.0 and prior.
gotchaSignature formatting for submissions must include the '0x' prefix.
fix
As of v0.3.2, the library explicitly forces the signature to include the '0x' prefix. If manually handling signatures or using older versions, ensure the signature string is prefixed with '0x' before sending to APIs or contracts.
affects: <0.3.2
breakingFrequent updates to `OrderData` schema, including new required fields like `minAmountReceived` and `timeInForce`.
fix
Always review the `OrderData` model definition in the library or the latest release notes when upgrading. Ensure all required fields are present and correctly formatted in your order payloads to avoid validation errors.
affects: v0.0.14, v0.0.23, v0.1.0, v0.1.1, and potentially future releases.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'py_order_utils'
This error occurs when the Python interpreter cannot find the `py_order_utils` package, typically because it was not installed, or the import statement uses the incorrect package name (e.g., `py-order-utils` instead of `py_order_utils`).
fix
Ensure the library is correctly installed using pip: `pip install py-order-utils` (note the hyphen for installation), and that the import statements use underscores: `from py_order_utils.builders import OrderBuilder`.
invalid signature
This message is often an API response from the Polymarket CLOB, indicating that the order signature generated by `py-order-utils` is deemed invalid by the exchange, possibly due to incorrect order parameters, wrong private key, or issues with network/chain ID.
fix
Verify that all `OrderData` parameters (e.g., `exchange_address`, `chain_id`, `private_key`, `nonce`, `salt`) are correct and consistent with the Polymarket API requirements and the intended order. Double-check the private key used for signing.
AttributeError: 'str' object has no attribute 'api_secret'
This `AttributeError` typically arises when attempting to access an attribute like `api_secret` (or similar, such as `api_key` or `api_passphrase`) on a string object, suggesting that an API credential or a related object was expected to be a structured object but was incorrectly treated as a plain string.
fix
Ensure that the object holding API credentials is correctly parsed or constructed (e.g., from a dictionary or a dedicated credentials object) and that you are accessing its attributes correctly, rather than trying to access object attributes directly on a string representation of the credentials.
Upgrade
Version history
0.3.2latest on PyPI · released Jul 29, 2024
Audit
Dependencies
web3requiredCore dependency for Ethereum interaction, contract calls, and transaction signing.
eth-accountrequiredUsed for managing Ethereum private keys and signing messages/transactions.
eth-utilsrequiredProvides utility functions for common Ethereum operations.
Agent activity
10 hits · last 30 days
node
8
Amazon
1
Resources
py-order-utils — pip install py-order-utils · libregistry