Ultra-low-latency financial protocols (such as OUCH and ITCH) pack execution parameters into a compact 64-bit integer bitfield to minimize network packet serialization overhead and memory footprint.
The protocol defines the following layout for a 64-bit unsigned integer flags:
0 = Buy, 1 = Sell)1 = IOC, 2 = FOK, 3 = GTC, 4 = DAY)0 = False, 1 = True)0 = False, 1 = True)0 = False, 1 = True)Business Validation Rules:
IOC, 1) or Fill-or-Kill (FOK, 2). If violated, raise a ValueError('Post-Only incompatible with IOC/FOK').risk_tier >= 2. If violated, raise a ValueError('Hidden orders require risk_tier >= 2').Your Task
Implement two functions:
pack_order_flags(side: int, tif: int, post_only: bool, cod: bool, hidden: bool, algo_tag: int, risk_tier: int) -> intunpack_order_flags(packed: int) -> dict returning a dictionary with keys: ['side', 'tif', 'post_only', 'cod', 'hidden', 'algo_tag', 'risk_tier'].Constraints