Skip to main content

DECIDE_FN

Constant DECIDE_FN 

Source
pub const DECIDE_FN: &str = "\
## To decide (micro100: Int, fair100: Int, edge100: Int, base_size: Int, max_order: Int, inventory: Int, pos_cap: Int, book_ok: Int) -> Int:
    Let mutable order_side be 0.
    Let mutable order_size be 0.
    If book_ok is equal to 1:
        If micro100 is greater than fair100 + edge100:
            Set order_side to 2.
            Set order_size to base_size.
        Otherwise:
            If micro100 is less than fair100 - edge100:
                Set order_side to 1.
                Set order_size to base_size.
    If order_size is greater than max_order:
        Set order_size to max_order.
    Let mutable signed_order be 0.
    If order_side is equal to 1:
        Set signed_order to order_size.
    If order_side is equal to 2:
        Set signed_order to 0 - order_size.
    Let projected be inventory + signed_order.
    Let mutable risk_ok be 1.
    If projected is greater than pos_cap:
        Set risk_ok to 0.
    If projected is less than 0 - pos_cap:
        Set risk_ok to 0.
    If risk_ok is equal to 0:
        Set signed_order to 0.
    Return signed_order.
";
Expand description

The HFT decision: microprice market-making, a fat-finger clamp and a position risk gate, returning the signed order (+buy / -sell / 0). No division — the microprice arrives normalized — so the body is compare / arithmetic / branch only.