Skip to content

Conversation

@pabloecz
Copy link

@pabloecz pabloecz commented Nov 24, 2025

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.

  • Utilities:
    • Order book parsing (parse_raw_orderbook_summary): Add types; use list comprehensions; handle missing fields with get; set optional hash via get.
    • Hashing (generate_orderbook_summary_hash): Now pure (no side effects); copies object, clears hash, and computes SHA-256 over JSON.
    • Order JSON (order_to_json): Update signature; rename returned key from orderType to order_type.
    • Precision/validation:
      • is_tick_size_smaller: compare via Decimal instead of float.
      • price_valid: accept Decimal price and validate using Decimal arithmetic.

Written by Cursor Bugbot for commit f4e9be3. This will update automatically on new commits. Configure here.

@pabloecz pabloecz requested a review from a team as a code owner November 24, 2025 20:55

# 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")
Copy link

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.

Fix in Cursor Fix in Web

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}
Copy link

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.

Fix in Cursor Fix in Web

# 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()
Copy link

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.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant