Open a section from the left

Prepare an order

IdMint builds a restart-safe id. The fields are site, kind, the last digit of the trading day, a ten-second slot, and a serial number, packed into one 64-bit integer. The kind is defined by the caller.


pitlane::IdMint mint(/*site=*/1, /*kind=*/1);
uint64_t tag = mint.next(/*day_index=*/4, /*sec_of_day=*/10 * 3600);

normalize_gate fixes offset and direction before an order is stored. Cash products are forced to open. On SHFE and INE a plain close becomes close-yesterday. On the other futures exchanges, close-today and close-yesterday become a plain close. Wire sides 0, 2, 5, and 6 are long. Wire sides 1, 3, 4, and 7 are short. A limit price of 0 is rejected. Why on the result says why.


pitlane::GateForm form{};
std::snprintf(form.symbol, sizeof form.symbol, "rb2410.SHF");
form.side = static_cast<uint8_t>(pitlane::Side::Sell);
form.off = static_cast<int8_t>(pitlane::Off::Close);
form.px_mode = static_cast<int8_t>(pitlane::PxMode::Limit);
form.px = 3500;
form.qty = 2;
pitlane::GateResult gate = pitlane::normalize_gate(form);

split_lots turns one futures quantity into slices. The modes are TodayThenYdayThenOpen, CloseOnly, and YdayThenStop. Any other mode returns -1. A slice above the maximum lot is cut, and a slice below the minimum lot is dropped. split_against closes the opposite book first. CloseStyle::SplitYday (SHF, INE) separates today and yesterday. Plain uses one close. Quantity that those closes cannot cover opens, still cut by the maximum lot.

commodity_plan and index_plan each return one next order toward a target. Where today and yesterday are split, yesterday is closed first. index_plan uses yesterday equal to position minus quantity opened today. plan_px uses the ask for a buy and the bid for a sell. next_child_qty sizes the next child from the completion curve. A lag is shared by share_ppm. Once the parent is ahead by about a tenth, counting quantity already in flight, the next child is zero. price_at_quote_vwap is the touch VWAP, or one rung on the side the order would take, aligned to the tick. pre_px, post_px, and chasing_px return a price from that book only.

lock_future and lock_cash_sell freeze the quantity a close or a stock sell needs. book_fill applies a fill back onto today, yesterday, and the total. apply_open_fill increases the total and leaves yesterday unchanged, so the new quantity is today. apply_close_fill reduces the total; a plain close consumes free yesterday first, and a close-today leaves yesterday alone. roll_session moves the whole remaining book into yesterday. add_session_us adds time only inside continuous sessions.