10. The order book
The engine ships three order-book implementations, one per market-data depth level, and the export layer mirrors them behind a single handle type. A book is always created for one declared contract, enforces that contract's tick grid on every price it accepts, and consumes one flat message format. What differs between the three levels is exactly how much microstructure each one retains — nothing else: the message protocol, the price discipline and the error surface are identical across all three.
Three depths, one model
The three levels form a strict containment hierarchy. Each level keeps everything the previous one keeps and adds one further degree of resolution.
- L1 aggregates each side as a whole. It keeps the side valuation — the sum of price times quantity over every resting order — plus an order registry keyed by order id, used to validate incoming messages and reject those that reference an unknown originating order. There are no price levels, no queues and no per-level storage of any kind.
- L2 splits each side into price levels. The price of every resting order — and therefore its exact contribution to the side's value — is known, but an order's position inside its level's queue is not.
- L3 keeps the full FIFO queue of orders inside each price level. This is complete per-order depth: every order's price, quantity and queue position are recoverable.
A useful mental picture is a triangle. The best bid and offer sit at the apex; the altitude dropped from that apex splits the triangle into the bid side and the ask side. Descending from the apex along either side means walking away from the best price into progressively deeper levels. L1 sees only the two half-triangles as solid shapes, L2 sees the horizontal slices through them, and L3 sees the individual orders queued inside each slice.
| Level | Side aggregate | Price levels | FIFO queue per level |
|---|---|---|---|
| L1 | yes | no | no |
| L2 | yes | yes | no |
| L3 | yes | yes | yes |
BBO is a message, not a book method
The level split above follows how real exchange feeds are structured, and one consequence of that research is deliberate: no book in this engine derives the best bid and offer for you, and L1 refuses level reads entirely.
The industry evidence is consistent. NASDAQ TotalView-ITCH 5.0 is a per-order depth feed — add, cancel, delete, execute, replace — with no separate top-of-book message inside it; the BBO is reconstructed from the book, and NASDAQ sells top of book as a distinct product. IEX is the cleanest example: it ships two separate protocols, TOPS carrying the top of book (best bid and ask with aggregated size, plus the last trade) and DEEP carrying the depth of book (aggregated size at every price level, plus the last trade). CME MDP 3.0 offers Market by Price and Market by Order views, and its top of book is simply level 1 of the price-aggregated book — again no dedicated message.
The conclusion these feeds share: a size-bearing BBO — best price together with the volume resting at it — is always the top of a price-aggregated ladder. No real product publishes "a per-side total with no price grouping, plus a BBO", because maintaining a correct BBO incrementally requires a sorted price structure, and a sorted price structure is a ladder — the defining property of L2. The engine therefore draws the same line: L1, which has no ladder, provides no BBO, and its level readers refuse with a diagnostic that names L2 and L3 as the levels that do. The tse_book_imbalance_to_bound, tse_book_imbalance_to_depth, tse_book_side_stats_to_bound and tse_book_levels_top calls all carry this restriction.
The top of book instead travels the way exchanges ship it — as a separate protocol message. In the export surface that is the bid/ask tick (TseTickBidAsk: bid, bidVolume, ask, askVolume, last), pushed through an adapter of type tse_md_bidask, mirroring the IEX TOPS/DEEP split: the top-of-book feed and the depth feed are two feeds.
- Nasdaq TotalView-ITCH 5.0 specification
- IEX DEEP (depth of book) introduction alert
- IEX TOPS / SNAP specification
- CME MDP 3.0 — Market by Price, Multiple Depth Book
- CME MDP 3.0 — Central Limit Order Book
Price discipline
Every book — L1, L2 and L3 alike — runs the same tick pipeline on every price it receives: check conformance, reject what is far from the grid, snap what is near, and only then touch the book.
Prices ride in book messages as TsePrice pairs — a significand and a decimal scale (tse_types.h) — converted exactly into the engine's fix-point integer in units of one millionth of a price unit (the FinValue representation; tse_finvalue_scale returns the exponent), and the contract's tick size is expressed in those raw units. A price is conformant when its distance to the nearest grid point is at most one raw millionth-unit; a pair written on the grid, such as {205, 2} for 2.05 against a tick of 0.01, lands on its grid point exactly. A conformant price is never stored raw — it is snapped to the nearest tick on accept, and price levels are keyed by the snapped price, so two inputs near the same grid point always land on the same level.
A price farther than one raw unit from the grid is rejected outright: the message is refused, a log entry records the rejection, and the book is left unchanged. The check runs on the new and replace paths — a modify carries no price, only quantity.
Two ordering guarantees complete the discipline. First, a replace is validated before the resting order is pulled: a non-conformant replace is rejected as a whole, the old order stays resting, and the side valuation does not move. Second, an emptied price level is removed entirely — when a cancel, executed or replace takes the last quantity off a level, the level disappears from the book: it no longer appears in level reads and contributes nothing to statistics. L2 and L3 behave identically in both respects.
Messages
Books consume one flat structure, TseBookMessage — a tagged union in spirit: the kind field selects which of the remaining fields are read, and the unused fields are ignored.
The numeric values of kind are the engine's message codes, and the gap is deliberate: the value 5 is the engine-protocol "execution" message, which books do not accept — hence the jump from tse_book_message_replace (4) to tse_book_message_executed (6).
structSize must equal sizeof(TseBookMessage). A raw C caller sets it explicitly; both wrappers fill it for you — the C++ tse::BookMessage has no such field at all, and in Python make_book_message, Book.apply and the push_book_* methods stamp it before every call. A wrong structSize is a validation error and the message never reaches the book.
Reads come back through two structures. TseBookSideStats carries the aggregate of one side: notional, orderCount and contracts. TseBookLevel is one price-level row, and its index field deserves attention: it is the tick distance from the best price of the side, not an ordinal row number. In skip mode the indexes arrive sparse — only occupied ticks produce rows; in include mode they are dense, empty ticks are materialized as rows with present equal to zero, and a depth argument measures a fixed price distance rather than a row count.
| Field | Type |
|---|---|
| structSize | size_t |
| kind | TseBookMessageKind |
| tsNanoseconds | int64_t |
| messageId | uint64_t |
| orderId | uint64_t |
| prevId | int64_t |
| price | TsePrice |
| quantity | double |
| txnSide | TseSide |
| Kind | Fields read |
|---|---|
tse_book_message_new | messageId, price, quantity, txnSide |
tse_book_message_modify | messageId, quantity |
tse_book_message_cancel | messageId only |
tse_book_message_replace | messageId, prevId, price, quantity, txnSide |
tse_book_message_executed | messageId, price, quantity, txnSide |
The book keys every order it holds by messageId — the identifier of the message that placed it. orderId rides along in the payload and the book never looks an order up by it: a modify, a cancel and the prevId of a replace all name a resting order by the messageId of the message that placed it. A kind that reads quantity refuses a quantity that is not greater than zero, because an order of zero quantity would destroy the level other orders rest on.
TseBookMessageKind enumerates those kinds: the value column is the engine code, the three name columns the spelling in each language.
| Value | C | C++ | Python |
|---|---|---|---|
| 1 | tse_book_message_new | new_ | New |
| 2 | tse_book_message_modify | modify | Modify |
| 3 | tse_book_message_cancel | cancel | Cancel |
| 4 | tse_book_message_replace | replace | Replace |
| 6 | tse_book_message_executed | executed | Executed |
| Field | Type |
|---|---|
| notional | double |
| orderCount | int64_t |
| contracts | double |
| Field | Type |
|---|---|
| index | uint64_t |
| price | TsePrice |
| notional | double |
| orderCount | int64_t |
| contracts | double |
| present | int32_t |
TseBookMissingLevel selects between the two modes above, and is spelled in each language as follows.
| Value | C | C++ | Python |
|---|---|---|---|
| 0 | tse_book_missing_level_skip | skip | Skip |
| 1 | tse_book_missing_level_include | include | Include |
The C surface
All book functions live in tse_book.h. They fall into eight groups.
Lifecycle. A book is created for a contract already declared with tse_add_contract, named by the handle that call returned. TseBookLevelKind is tse_book_l1, tse_book_l2 or tse_book_l3 (values 1, 2, 3). tse_book_create returns NULL on failure with the reason in tse_last_error(account); every later failure on the created book is reported through the book's own tse_book_last_error. tse_book_kind names the depth the book was created at and tse_book_contract the contract it keeps.
tse_book_destroy takes the book off the account and destroys it there and then. The account keeps no trace of a book it has released, so the handle is dead the moment the call returns: reading it, applying a message to it, clearing it or destroying it a second time is not allowed, and the library cannot tell a dead handle from a live one. A null handle is still a refusal, because that the library can see. A book the account still owns is destroyed with the account, so a book wired into an input must outlive that input: release it after the account, or not at all.
TSE_API TseBookHandle tse_book_create(TseAccountHandle account, TseContractHandle contract, TseBookLevelKind kind);
TSE_API void tse_book_destroy(TseBookHandle book);
TSE_API char const* tse_book_last_error(TseBookHandle book);
TSE_API TseStatus tse_book_kind(TseBookHandle book, TseBookLevelKind* outKind);
TSE_API TseContractHandle tse_book_contract(TseBookHandle book);
Emptying a book. tse_book_clear returns a book to the state it was built in: both sides lose every level and every order, the aggregates fall to zero, the arrival counter of an L3 book falls to zero, and the memory the levels and the orders held is given back to the pools the book owns. The contract is untouched, so the book takes new messages immediately and answers exactly as a book created a moment ago on the same contract would. Clearing a book twice is allowed and costs nothing the second time. The one refusal is the mirror a book Simulator keeps: it is cleared through the execution, as the environment chapter describes, because the Simulator must forget its queue in the same action.
TSE_API TseStatus tse_book_clear(TseBookHandle book);
Every pointer and every row a reader handed out before the clear speaks of levels and orders that no longer exist. Read again through the book after clearing; a row kept across the call is stale.
Applying messages. tse_book_apply validates before it mutates: an unknown kind, a wrong structSize or a price off the tick grid is an error and the book stays unchanged.
TSE_API TseStatus tse_book_apply(TseBookHandle book, TseBookMessage const* message);
The imbalance family. Whole-book imbalance is defined over total contracts as (bid − ask) / (bid + ask). The bounded form restricts each side to a price band — [bidBound, best bid] on the bid side and [best ask, askBound] on the ask side; the depth form takes the top rows of each side under a missing-level mode. Both restricted forms require L2 or L3.
TSE_API TseStatus tse_book_imbalance(TseBookHandle book, double* outValue);
TSE_API TseStatus tse_book_imbalance_to_bound(TseBookHandle book, TsePrice bidBound, TsePrice askBound, double* outValue);
TSE_API TseStatus tse_book_imbalance_to_depth(TseBookHandle book, size_t depth, TseBookMissingLevel mode, double* outValue);
Side statistics. The side argument is tse_side_long for the bid and tse_side_short for the ask. The to-bound form requires L2 or L3.
TSE_API TseStatus tse_book_side_stats(TseBookHandle book, TseSide side, TseBookSideStats* outStats);
TSE_API TseStatus tse_book_side_stats_to_bound(TseBookHandle book, TseSide side, TsePrice bound, TseBookSideStats* outStats);
Level access. tse_book_levels_top returns the top rows of one side, best price first, using the capacity-in / count-out convention: pass the capacity of outLevels in *inoutCount, and on return it holds the number of rows written. Pass a null outLevels to query the row count first. Requires L2 or L3 — on L1 this is the refusal described above.
TSE_API TseStatus tse_book_levels_top(TseBookHandle book, TseSide side, size_t depth, TseBookMissingLevel mode, TseBookLevel* outLevels, size_t* inoutCount);
tse_book_levels_to_bound is the same reading bounded by a price instead of by a depth: every level of the side not worse than bound comes back, best price first, with no limit on how many that is. tse_book_level_orders goes one step deeper and lists the live orders of the level resting at one price, in queue order, where tse_book_level_first_order returns only the head of that queue; it needs L3, because L1 and L2 keep no orders one by one. Both follow the capacity-in / count-out convention of tse_book_levels_top, and a price that carries no orders yields a count of zero rather than an error.
TSE_API TseStatus tse_book_levels_to_bound(TseBookHandle book, TseSide side, TsePrice bound, TseBookMissingLevel mode, TseBookLevel* outLevels, size_t* inoutCount);
TSE_API TseStatus tse_book_level_orders(TseBookHandle book, TseSide side, TsePrice price, TseBookOrderInfo* outOrders, size_t* inoutCount);
Point reads. Ten functions answer about one side, one level or one order without building a side first. tse_book_side_snapshot reads a whole side at once: its aggregate, the best and the worst price that carry orders, and how many levels it holds. tse_book_level_at finds the level resting at one exact price, rounded to the tick grid first; tse_book_level_at_distance counts ticks from the best price of the side, so a distance of zero is the best level itself; tse_book_level_neighbour steps from one occupied level to the next occupied one, either towards the best price of the side or away from it. tse_book_order_find reads one order by the messageId the book keyed it with, searching both sides. tse_book_top reads the top of the book in one call. The last two walk the queue of one level and say so in their cost: tse_book_level_first_order returns the order at the head of a level's queue, and tse_book_order_ahead returns how many live orders stand in front of a given order and what they carry. tse_book_contains asks one named side whether it carries an order, where tse_book_order_find searches both sides in turn and returns the whole sheet; it works at every depth. tse_book_arrivals reads the arrival counter of one side — how many orders have ever reached it — which only an L3 book keeps and which only tse_book_clear returns to zero.
TSE_API TseStatus tse_book_side_snapshot(TseBookHandle book, TseSide side, TseBookSideSnapshot* outSnapshot);
TSE_API TseStatus tse_book_level_at(TseBookHandle book, TseSide side, TsePrice price, TseBookLevel* outLevel);
TSE_API TseStatus tse_book_level_at_distance(TseBookHandle book, TseSide side, size_t distance, TseBookLevel* outLevel);
TSE_API TseStatus tse_book_level_neighbour(TseBookHandle book, TseSide side, TsePrice price, TseBookDirection direction, TseBookLevel* outLevel);
TSE_API TseStatus tse_book_order_find(TseBookHandle book, uint64_t messageId, TseBookOrderInfo* outInfo);
TSE_API TseStatus tse_book_top(TseBookHandle book, TseBookTop* outTop);
TSE_API TseStatus tse_book_level_first_order(TseBookHandle book, TseSide side, TsePrice price, TseBookOrderInfo* outOrder);
TSE_API TseStatus tse_book_order_ahead(TseBookHandle book, uint64_t messageId, TseBookQueueAhead* outAhead);
TSE_API TseStatus tse_book_contains(TseBookHandle book, TseSide side, uint64_t messageId, int32_t* outPresent);
TSE_API TseStatus tse_book_arrivals(TseBookHandle book, TseSide side, uint32_t* outArrivals);
A read that finds nothing is not an error: the level row comes back with present equal to zero, the order sheet with present equal to zero and its messageId echoed, and the queue sheet with zeros. An error is reserved for a null output, a side that is neither long nor short, an unknown direction, a price pair the engine cannot represent, and a book of the wrong depth.
TseBookDirection names the two ways to walk a side. For a bid, towards the best price means a higher price; for an ask, a lower one.
| Value | C | C++ | Python |
|---|---|---|---|
| 1 | tse_book_direction_to_best | toBest | ToBest |
| 2 | tse_book_direction_from_best | fromBest | FromBest |
| Field | Type |
|---|---|
| stats | TseBookSideStats |
| bestPrice | TsePrice |
| worstPrice | TsePrice |
| levelCount | uint64_t |
| Field | Type |
|---|---|
| present | int32_t |
| messageId | uint64_t |
| price | TsePrice |
| quantity | double |
| status | int32_t |
| level | TseBookSideStats |
| Field | Type |
|---|---|
| bidPrice | TsePrice |
| askPrice | TsePrice |
| bidContracts | double |
| askContracts | double |
| spread | TsePrice |
| mid | TsePrice |
| microprice | TsePrice |
| imbalance | double |
| crossed | int32_t |
| Field | Type |
|---|---|
| ordersAhead | int64_t |
| contractsAhead | double |
Three readings need a word of their own. An order's status is the engine's code — 0 undefined, 1 active, 2 removed — and only L3 keeps the state of an order one by one; L1 and L2 answer "active", because they hold an order only while it lives, and an L1 book, which keeps no levels, answers zeros in the order's level summary. The top is reported only when both sides carry orders: when either side is empty every field of TseBookTop is zero, including crossed. The microprice weighs each best price by the contracts resting on the opposite side, so a thin ask pulls it towards the ask.
What each read costs. The table names the cost in the size of the book, not of the answer.
| Function | Cost | Why |
|---|---|---|
tse_book_imbalance | O(1) | both side aggregates are maintained on every message |
tse_book_side_stats | O(1) | the same aggregate |
tse_book_side_snapshot | O(1) | aggregate plus the two maintained end levels and the level count |
tse_book_top | O(1) | the best level of each side is maintained |
tse_book_level_at | O(1) | one lookup by the snapped price |
tse_book_level_at_distance | O(1) | the best price plus the distance, then one lookup |
tse_book_level_neighbour | O(1) on L3, O(log L) on L2 | L3 links its levels, L2 keeps them in an ordered tree of L levels |
tse_book_order_find | O(1) | one lookup by messageId in each side's ledger |
tse_book_side_stats_to_bound | O(k) | the k levels inside the bound are summed |
tse_book_imbalance_to_bound | O(k) | two bounded sums |
tse_book_levels_top | O(L) in skip mode, O(span) in include mode | the side is built, then truncated to the depth |
tse_book_imbalance_to_depth | O(L) in skip mode, O(span) in include mode | both sides are built, then truncated |
tse_book_level_first_order | at most 41 cells per block | the level's order cells are walked until a live one is found |
tse_book_order_ahead | the order cells of one level | every live cell in front of the order is counted |
tse_book_kind | O(1) | the depth is the alternative the handle holds |
tse_book_contract | O(1) | the contract is a pointer the book was built with |
tse_book_contains | O(1) | one lookup by messageId in the named side's ledger |
tse_book_arrivals | O(1) | the counter is raised on every arrival |
tse_book_levels_to_bound | O(k) in skip mode, O(span) in include mode | the levels inside the bound are built |
tse_book_level_orders | the order cells of one level | every cell of the level is walked and the live ones are written |
tse_book_clear | O(L + B) | every level is returned to its store and every order block to the one it came from |
In that table L is the number of occupied levels of the side, B the number of order blocks those levels hold, k the number of levels inside the bound, and the span of include mode is the tick distance between the best and the worst level of the side, because every empty tick between them becomes a row.
Feeding a book from an adapter. Book messages can be pushed through a market-data adapter of type tse_md_book (created with tse_market_create); the message then reaches every input bound to that adapter-and-contract pair, in every account the adapter feeds.
TSE_API TseStatus tse_market_push_book(TseMarketHandle market, TseContractHandle contract, TseBookMessage const* message);
Book inputs. Two input builders wire book data into the signal chain. tse_add_input_book takes a user processor of type TseBookInputProcessor — it receives each book message and decides what to store into the input's storage; to maintain a book inside the processor, create one with tse_book_create and apply the messages with tse_book_apply. tse_add_input_book_imbalance is the compiled-in alternative: it feeds every message into the given book and stores the whole-book imbalance per message, with zero callback crossings — the built-in mirror of an imbalance strategy.
typedef int (*TseBookInputProcessor)(TseStorageHandle storage, TseContractHandle contract, TseBookMessage const* message, void* userData);
TSE_API TseStatus tse_add_input_book(TseAccountHandle account, char const* label, int32_t dataLength, TseDuration duration, TseBookInputProcessor processor, void* userData, TseMarketHandle market, int coreId, TseContractHandle const* contracts, size_t contractCount);
TSE_API TseStatus tse_add_input_book_imbalance(TseAccountHandle account, char const* label, int32_t dataLength, TseDuration duration, TseBookHandle book, TseMarketHandle market, int coreId, TseContractHandle const* contracts, size_t contractCount);
The book an execution keeps. The book Simulator of the environment chapter mirrors a book feed for every traded contract, and tse_exec_book hands out that mirror as an ordinary book handle: every statistic, level and order function above applies to it unchanged. The handle belongs to the account and must not be destroyed by the caller, and tse_book_apply and tse_book_clear on it are refused, because the mirror takes its messages from the feed alone and is emptied through the execution that owns it.
C++ and Python
The C++ wrapper exposes the book as tse::Book, a non-owning handle: the Account owns the book, and the handle becomes invalid when the account is destroyed. The enumerations are tse::BookLevelKind (l1, l2, l3), tse::BookMessageKind (new_, modify, cancel, replace, executed — same engine codes, same gap at 5), tse::BookMissingLevel (skip, include) and tse::BookDirection (toBest, fromBest). The point reads return BookSideSnapshot, BookLevel, BookOrderInfo, BookTop and BookQueueAhead, each a mirror of its C structure with present and crossed spelled as bool. Errors surface as exceptions carrying the tse_book_last_error text.
namespace tse {
class Book final {
public:
void apply(BookMessage const& message) const &;
double imbalance() const &;
double imbalanceToBound(Price bidBound, Price askBound) const &;
double imbalanceToDepth(std::size_t depth, BookMissingLevel mode) const &;
BookSideStats sideStats(Side side) const &;
BookSideStats sideStatsToBound(Side side, Price bound) const &;
std::vector<BookLevel> levelsTop(Side side, std::size_t depth, BookMissingLevel mode) const &;
BookSideSnapshot sideSnapshot(Side side) const &;
BookLevel levelAt(Side side, Price price) const &;
BookLevel levelAtDistance(Side side, std::size_t distance) const &;
BookLevel levelNeighbour(Side side, Price price, BookDirection direction) const &;
BookOrderInfo orderFind(std::uint64_t messageId) const &;
BookTop top() const &;
BookOrderInfo levelFirstOrder(Side side, Price price) const &;
BookQueueAhead orderAhead(std::uint64_t messageId) const &;
void clear() const &;
BookLevelKind kind() const &;
TseContractHandle contract() const & noexcept;
bool contains(Side side, std::uint64_t messageId) const &;
std::uint32_t arrivals(Side side) const &;
std::vector<BookLevel> levelsToBound(Side side, Price bound, BookMissingLevel mode) const &;
std::vector<BookOrderInfo> levelOrders(Side side, Price price) const &;
TseBookHandle handle() const noexcept;
};
}
On the account, Account::createBook(contract, kind) builds the book, Account::addInputBook takes a tse::BookInputProcessor — an std::function<bool(Storage const&, TseContractHandle, BookMessage const&)> — and Account::addInputBookImbalance takes a Book const&. Adapter feeding is Market::pushBook, which takes the contract.
Book createBook(Contract const& contract, BookLevelKind kind) &;
void addInputBook(std::string label, std::int32_t dataLength, Duration duration, BookInputProcessor processor, Market const& market, std::vector<Contract> contracts, int coreId = -1) &;
void addInputBookImbalance(std::string label, std::int32_t dataLength, Duration duration, Book const& book, Market const& market, std::vector<Contract> contracts, int coreId = -1) &;
void pushBook(Contract const& contract, BookMessage const& message) const &;
The Python module mirrors the same surface. The enumerations are BookLevelKind (L1, L2, L3), BookMessageKind (New, Modify, Cancel, Replace, Executed), BookMissingLevel (Skip, Include) and BookDirection (ToBest, FromBest); the point reads answer with TseBookSideSnapshot, TseBookLevel, TseBookOrderInfo, TseBookTop and TseBookQueueAhead. make_book_message builds a TseBookMessage with structSize pre-filled; Book methods raise TseError with the tse_book_last_error text on failure, and levels_top allocates the depth it is given, calls the boundary once and returns the rows that came back as a list of TseBookLevel.
book = account.create_book(aapl_contract, tse.BookLevelKind.L3)
message = tse.make_book_message(tse.BookMessageKind.New, ts_ns, message_id, order_id, 0, price, quantity, tse.Side.Long)
book.apply(message)
whole = book.imbalance()
banded = book.imbalance_to_bound(bid_bound, ask_bound)
deep = book.imbalance_to_depth(depth, tse.BookMissingLevel.Include)
stats = book.side_stats(tse.Side.Long)
bounded = book.side_stats_to_bound(tse.Side.Short, bound)
rows = book.levels_top(tse.Side.Long, depth, tse.BookMissingLevel.Skip)
snapshot = book.side_snapshot(tse.Side.Long)
level = book.level_at(tse.Side.Long, price)
nearest = book.level_at_distance(tse.Side.Long, 0)
deeper = book.level_neighbour(tse.Side.Long, price, tse.BookDirection.FromBest)
order = book.order_find(message_id)
top = book.top()
first = book.level_first_order(tse.Side.Long, price)
ahead = book.order_ahead(first.messageId)
held = book.contains(tse.Side.Long, message_id)
seen = book.arrivals(tse.Side.Long)
depth_kind = book.kind()
banded_rows = book.levels_to_bound(tse.Side.Long, bound, tse.BookMissingLevel.Skip)
queue = book.level_orders(tse.Side.Long, price)
book.clear()
market.push_book(aapl_contract, message)
account.add_input_book(label, data_length, duration, processor, market, [aapl_contract])
account.add_input_book_imbalance(label, data_length, duration, book, market, [aapl_contract])
Finally, the fix-point converters translate between the boundary forms and the engine's scaled-integer price representation — useful whenever raw tick sizes or scaled prices cross the boundary. The scaled integer carries units of ten to the minus scale of one price unit. tse_price_to_finvalue converts a TsePrice pair exactly and refuses a scale outside 0..6 or a product that does not fit int64_t; tse_finvalue_to_price always answers with scale 6; the two double translators round half to even at the sixth decimal. The C++ wrapper names the pair tse::Price and reaches the two pair converters through the C declarations it includes; Python adds fin_value_from_price / fin_value_to_price over the library and three pure-Python helpers, make_price, price_to_float and price_from_text, the last of which parses a decimal text through decimal.Decimal so that "256.27" becomes TsePrice(25627, 2).
TSE_API int32_t tse_finvalue_scale(void);
TSE_API int64_t tse_finvalue_from_double(double value);
TSE_API double tse_finvalue_to_double(int64_t scaled);
TSE_API TseStatus tse_price_to_finvalue(TsePrice price, int64_t* scaled);
TSE_API TsePrice tse_finvalue_to_price(int64_t scaled);
using Price = TsePrice;
std::int32_t finValueScale() noexcept;
std::int64_t finValueFromDouble(double value) noexcept;
double finValueToDouble(std::int64_t scaled) noexcept;
scale = tse.fin_value_scale()
scaled = tse.fin_value_from_double(2.05)
value = tse.fin_value_to_double(scaled)
price = tse.make_price(25627, 2)
scaled = tse.fin_value_from_price(price)
price = tse.fin_value_to_price(scaled)
price = tse.price_from_text("256.27")
value = tse.price_to_float(price)
Version 6.1.0.0. Also as Markdown: this chapter, the whole reference in one file, and the llms.txt map.