Skip to main content

Overview

NanoARB uses fixed-point arithmetic and zero-copy serialization for maximum performance in HFT applications. All core types are optimized for nanosecond-level precision and deterministic behavior.

Price

Fixed-point price representation that avoids floating-point errors.

Definition

Uses i64 internally to represent prices in the smallest tick unit. This ensures deterministic arithmetic and avoids floating-point precision issues.
Price::ZERO
Price
Zero price constant
Price::MAX
Price
Maximum price constant (i64::MAX)
Price::MIN
Price
Minimum price constant (i64::MIN)

Constructors

from_raw
fn(ticks: i64) -> Price
Create a price from raw tick value
from_ticks
fn(value: i64, decimals: u8) -> Price
Create a price from ticks and decimal places
from_f64
fn(value: f64, tick_size: f64) -> Price
Create a price from a floating-point value with specified tick size

Methods

raw
i64
Get the raw tick value
as_f64
f64
Convert to f64 (assumes tick size of 0.01)
as_f64_with_tick
f64
Convert to f64 with specified tick size
is_zero
bool
Check if the price is zero
is_positive
bool
Check if the price is positive
is_negative
bool
Check if the price is negative
abs
Price
Get the absolute value

Arithmetic Operations


Quantity

Represents order and position sizes using unsigned integers.

Definition

Quantity::ZERO
Quantity
Zero quantity constant
Quantity::MAX
Quantity
Maximum quantity constant (u32::MAX)

Constructors

new
fn(value: u32) -> Quantity
Create a new quantity

Methods

value
u32
Get the raw value
is_zero
bool
Check if quantity is zero
as_i64
i64
Convert to i64 for position calculations
as_f64
f64
Convert to f64 for calculations

Example Usage


SignedQuantity

Signed quantity for positions (positive = long, negative = short).

Definition

Methods

new
fn(value: i64) -> SignedQuantity
Create a new signed quantity
value
i64
Get the raw value
abs
Quantity
Get the absolute value as unsigned quantity
is_long
bool
Check if the position is long (positive)
is_short
bool
Check if the position is short (negative)
is_flat
bool
Check if the position is flat (zero)

Example Usage


Side

Order/Trade side enumeration.

Definition

Methods

is_buy
bool
Check if this is a buy side
is_sell
bool
Check if this is a sell side
opposite
Side
Get the opposite side
sign
i64
Convert to a sign multiplier (1 for buy, -1 for sell)
sign_f64
f64
Convert to a sign multiplier as f64

Conversions


Timestamp

Nanosecond-precision timestamp since Unix epoch.

Definition

Optimized for HFT applications where every nanosecond matters.
Timestamp::EPOCH
Timestamp
Zero timestamp (Unix epoch)
Timestamp::MAX
Timestamp
Maximum timestamp
Timestamp::MIN
Timestamp
Minimum timestamp

Constructors

from_nanos
fn(nanos: i64) -> Timestamp
Create a timestamp from nanoseconds since epoch
from_micros
fn(micros: i64) -> Timestamp
Create a timestamp from microseconds since epoch
from_millis
fn(millis: i64) -> Timestamp
Create a timestamp from milliseconds since epoch
from_secs
fn(secs: i64) -> Timestamp
Create a timestamp from seconds since epoch
now
fn() -> Timestamp
Get the current timestamp

Methods

as_nanos
i64
Get nanoseconds since epoch
as_micros
i64
Get microseconds since epoch
as_millis
i64
Get milliseconds since epoch
as_secs
i64
Get seconds since epoch
subsec_nanos
u32
Get the nanosecond component (0-999,999,999)
duration_since
i64
Calculate duration to another timestamp in nanoseconds

Example Usage


OrderId

Unique order identifier.

Definition

Methods

new
fn(id: u64) -> OrderId
Create a new order ID
value
u64
Get the raw value

Conversions


Order

A trading order with full lifecycle tracking.

Definition

Order Types

Time In Force

Order Status

Constructors

new_limit
fn(id: OrderId, instrument_id: u32, side: Side, price: Price, quantity: Quantity, time_in_force: TimeInForce) -> Order
Create a new limit order
new_market
fn(id: OrderId, instrument_id: u32, side: Side, quantity: Quantity) -> Order
Create a new market order

Methods

remaining_quantity
Quantity
Get remaining quantity to be filled
is_filled
bool
Check if the order is completely filled
is_cancellable
bool
Check if the order can be cancelled
fill_ratio
f64
Get fill ratio (0.0 to 1.0)
apply_fill
fn(&mut self, fill_price: Price, fill_qty: Quantity, timestamp: Timestamp)
Update order with a fill

Quote

Best Bid/Offer (BBO) representation.

Definition

Methods

new
fn(instrument_id: u32, bid_price: Price, bid_quantity: Quantity, ask_price: Price, ask_quantity: Quantity, timestamp: Timestamp) -> Quote
Create a new quote
mid_price
Price
Calculate the mid price
spread
Price
Calculate the spread in ticks
is_valid
bool
Check if the quote is valid (bid < ask)

Trade

Trade execution information.

Definition


Fill

Fill information for an executed order.

Definition

Methods

notional
f64
Calculate the notional value of this fill
signed_quantity
i64
Calculate the signed quantity (positive for buy, negative for sell)

Level

A price level in the order book.

Definition

Methods

new
fn(price: Price, quantity: Quantity, order_count: u32) -> Level
Create a new level
empty
fn(price: Price) -> Level
Create an empty level at a given price
is_empty
bool
Check if the level is empty