Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nkaz001/hftbacktest/llms.txt
Use this file to discover all available pages before exploring further.
BacktestAsset
Configures a single asset for backtesting.Methods
Sets the feed data for the asset.Parameters:
data(str | List[str] | NDArray | List[NDArray]): File paths to.npzfiles or NumPy arrays containing feed data
BacktestAsset (for method chaining)Configures the asset as a linear asset (standard futures/spot).Parameters:
contract_size(float): The contract size or multiplier
BacktestAssetConfigures the asset as an inverse asset (inverse perpetuals).Parameters:
contract_size(float): The contract size or multiplier
BacktestAssetUses interpolated order latency model based on historical latency data.Parameters:
data(str | NDArray | List[str]): Historical order latency data in.npzformat or NumPy arraylatency_offset(int, optional): Latency offset in nanoseconds. Default: 0
BacktestAssetSets the initial order book snapshot.Parameters:
data(str | NDArray): File path or NumPy array of the initial snapshot
BacktestAssetHashMapMarketDepthBacktest
Backtester using hashmap-based market depth. Suitable for most use cases.assets(List[BacktestAsset]): List of configured backtest assets
@njit functions
Properties
Current timestamp in the backtest (nanoseconds by default).
Total number of assets in the backtest.
Methods
Retrieves the market depth for a specific asset.Parameters:
asset_no(uint64): Asset number (0-indexed)
HashMapMarketDepth instanceReturns the current position for an asset.Parameters:
asset_no(uint64): Asset number
float64 - Position quantity (positive for long, negative for short)Retrieves state values including balance, fees, and trading statistics.Parameters:
asset_no(uint64): Asset number
StateValues instanceReturns the order dictionary for an asset.Parameters:
asset_no(uint64): Asset number
OrderDict - Dictionary of active ordersSubmits a buy order.Parameters:
asset_no(uint64): Asset numberorder_id(uint64): Unique order IDprice(float64): Order priceqty(float64): Quantity to buytime_in_force(uint8):GTC,GTX,FOK, orIOCorder_type(uint8):LIMITorMARKETwait(bool): If True, wait for order response
int64 - 0 on success, 1 if end of data reached, negative on errorSubmits a sell order.Parameters:
asset_no(uint64): Asset numberorder_id(uint64): Unique order IDprice(float64): Order priceqty(float64): Quantity to selltime_in_force(uint8):GTC,GTX,FOK, orIOCorder_type(uint8):LIMITorMARKETwait(bool): If True, wait for order response
int64 - 0 on success, 1 if end of data reached, negative on errorCancels an order.Parameters:
asset_no(uint64): Asset numberorder_id(uint64): Order ID to cancelwait(bool): If True, wait for cancel response
int64 - 0 on success, 1 if end of data reached, negative on errorModifies an existing order.Parameters:
asset_no(uint64): Asset numberorder_id(uint64): Order ID to modifyprice(float64): New order priceqty(float64): New order quantitywait(bool): If True, wait for modify response
int64 - 0 on success, 1 if end of data reached, negative on errorClears inactive orders from the order dictionary.Parameters:
asset_no(uint64): Asset number, orALL_ASSETSto clear all assets
Elapses time by the specified duration.Parameters:
duration(uint64): Duration to elapse (nanoseconds by default)
int64 - 0 on success, 1 if end of data reached, negative on errorWaits for an order response with timeout.Parameters:
asset_no(uint64): Asset numberorder_id(uint64): Order ID to wait fortimeout(int64): Timeout in nanoseconds
int64 - 0 on response or timeout, 1 if end of data reached, negative on errorWaits for the next market feed.Parameters:
include_order_resp(bool): If True, also return on order responsestimeout(int64): Timeout in nanoseconds
int64 - 0 on timeout, 1 on end of data, 2 on feed, 3 on order responseRetrieves recent market trades.Parameters:
asset_no(uint64): Asset number
Clears the last trades buffer.Parameters:
asset_no(uint64): Asset number, orALL_ASSETSto clear all
Closes the backtester.Returns:
int64 - 0 on success, negative on errorROIVectorMarketDepthBacktest
Backtester using vector-based market depth with a defined range of interest (ROI). More efficient for strategies focusing on specific price ranges.assets(List[BacktestAsset]): List of configured backtest assets
HashMapMarketDepthBacktest, but returns ROIVectorMarketDepth instead of HashMapMarketDepth.
HashMapMarketDepth
Market depth interface using hashmap storage.Properties
Best bid price.
Best ask price.
Best bid price in ticks.
Best ask price in ticks.
Quantity at the best bid.
Quantity at the best ask.
Minimum price increment.
Minimum quantity increment.
Methods
Returns the bid quantity at a specific price level.Parameters:
price_tick(int64): Price in ticks
float64 - Quantity at the specified priceReturns the ask quantity at a specific price level.Parameters:
price_tick(int64): Price in ticks
float64 - Quantity at the specified priceROIVectorMarketDepth
Market depth interface using vector storage within a range of interest. Provides the same properties and methods asHashMapMarketDepth, plus:
Additional Properties
Array of bid quantities indexed by price tick within the ROI.
Array of ask quantities indexed by price tick within the ROI.
Lower bound of the range of interest in ticks.
Upper bound of the range of interest in ticks.
Order
Represents an order in the system.Properties
Unique order identifier.
Order price.
Order price in ticks.
Order quantity.
Remaining unfilled quantity.
Order side:
BUY (1) or SELL (-1).Order status:
NONE, NEW, FILLED, CANCELED, EXPIRED, PARTIALLY_FILLED.Order type:
LIMIT or MARKET.Time-in-force:
GTC, GTX, FOK, or IOC.Execution price (valid when status is
FILLED or PARTIALLY_FILLED).Executed quantity.
Whether the order can be cancelled.
Exchange timestamp when order was processed.
Local timestamp when order was submitted.
StateValues
Contains state information for an asset.Properties
Current open position.
Cash balance.
Accumulated trading fees.
Total number of trades executed.
Total trading volume (quantity).
Total trading value (notional).
OrderDict
Dictionary of active orders.Methods
Retrieves an order by ID.Parameters:
order_id(uint64): Order ID
Order instance or NoneReturns an iterator over order values.Returns:
Values iteratorChecks if an order exists.Parameters:
order_id(uint64): Order ID
boolReturns the number of active orders.Returns:
uint64