-
Notifications
You must be signed in to change notification settings - Fork 162
Update utilities.py #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update utilities.py #181
Conversation
|
|
||
| # Use SHA256 for modern cryptographic security. | ||
| # Assuming orderbook model provides a predictable JSON serialization (e.g., sorted keys). | ||
| hash_input = temp_orderbook.json().encode("utf-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Property accessed as method with parentheses
The code calls temp_orderbook.json() with parentheses, but json is defined as a @property in OrderBookSummary, not a method. Properties are accessed without parentheses like temp_orderbook.json. This will raise a TypeError stating that the string object is not callable.
| Converts an order object into a standardized JSON-like dictionary format. | ||
| Ensures 'orderType' follows Python's naming convention (snake_case). | ||
| """ | ||
| return {"order": order.dict(), "owner": owner, "order_type": order_type} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Dictionary key renamed breaks API contract
The dictionary key was changed from "orderType" to "order_type". This function is used in client.py to construct request bodies for API endpoints that expect "orderType" in camelCase. Changing to snake_case breaks the API contract and will cause order posting to fail.
| # Assuming orderbook model provides a predictable JSON serialization (e.g., sorted keys). | ||
| hash_input = temp_orderbook.json().encode("utf-8") | ||
|
|
||
| return hashlib.sha256(hash_input).hexdigest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Hash algorithm change breaks compatibility
The hash algorithm was changed from SHA-1 to SHA-256. While SHA-256 is more secure, this breaks compatibility with existing stored hashes. Any code comparing or verifying orderbook hashes will fail because new hashes won't match previously computed ones, potentially breaking hash-based validation or caching mechanisms.
Note
Refactors utilities to use safer parsing and Decimal precision, makes orderbook hash generation pure with SHA-256, and renames order JSON field to order_type.
parse_raw_orderbook_summary): Add types; use list comprehensions; handle missing fields withget; set optionalhashviaget.generate_orderbook_summary_hash): Now pure (no side effects); copies object, clearshash, and computes SHA-256 over JSON.order_to_json): Update signature; rename returned key fromorderTypetoorder_type.is_tick_size_smaller: compare viaDecimalinstead of float.price_valid: acceptDecimalprice and validate usingDecimalarithmetic.Written by Cursor Bugbot for commit f4e9be3. This will update automatically on new commits. Configure here.