#[repr(C)]pub struct HostVTable {Show 33 fields
pub abi_version: u32,
pub clock_now_ns: unsafe extern "C" fn() -> u64,
pub log: unsafe extern "C" fn(level: HostLogLevel, target: BorrowedStr<'_>, message: BorrowedStr<'_>),
pub cache_instrument: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>,
pub cache_account: unsafe extern "C" fn(ctx: *const HostContext, account_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>,
pub cache_order: unsafe extern "C" fn(ctx: *const HostContext, client_order_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>,
pub cache_position: unsafe extern "C" fn(ctx: *const HostContext, position_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>,
pub cache_orders_for_strategy: unsafe extern "C" fn(ctx: *const HostContext, strategy_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>,
pub cache_positions_for_strategy: unsafe extern "C" fn(ctx: *const HostContext, strategy_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>,
pub subscribe_quotes: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub unsubscribe_quotes: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub subscribe_trades: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub unsubscribe_trades: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub subscribe_bars: unsafe extern "C" fn(ctx: *const HostContext, bar_type: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub unsubscribe_bars: unsafe extern "C" fn(ctx: *const HostContext, bar_type: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub subscribe_book_deltas: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, book_type: u8, depth: usize, client_id: BorrowedStr<'_>, managed: u8, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub unsubscribe_book_deltas: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub subscribe_book_at_interval: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, book_type: u8, depth: usize, interval_ms: usize, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub unsubscribe_book_at_interval: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, interval_ms: usize, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>,
pub msgbus_publish: unsafe extern "C" fn(ctx: *const HostContext, topic: BorrowedStr<'_>, payload: Slice<'_, u8>) -> PluginResult<()>,
pub set_time_alert: unsafe extern "C" fn(ctx: *const HostContext, name: BorrowedStr<'_>, alert_time_ns: u64, allow_past: u8) -> PluginResult<()>,
pub set_timer: unsafe extern "C" fn(ctx: *const HostContext, name: BorrowedStr<'_>, interval_ns: u64, start_time_ns: u64, stop_time_ns: u64, allow_past: u8, fire_immediately: u8) -> PluginResult<()>,
pub cancel_timer: unsafe extern "C" fn(ctx: *const HostContext, name: BorrowedStr<'_>) -> PluginResult<()>,
pub submit_order: unsafe extern "C" fn(ctx: *const HostContext, command: *const SubmitOrderHandle) -> PluginResult<()>,
pub cancel_order: unsafe extern "C" fn(ctx: *const HostContext, command: *const CancelOrderHandle) -> PluginResult<()>,
pub modify_order: unsafe extern "C" fn(ctx: *const HostContext, command: *const ModifyOrderHandle) -> PluginResult<()>,
pub submit_order_list: unsafe extern "C" fn(ctx: *const HostContext, command: *const SubmitOrderListHandle) -> PluginResult<()>,
pub cancel_orders: unsafe extern "C" fn(ctx: *const HostContext, command: *const CancelOrdersHandle) -> PluginResult<()>,
pub cancel_all_orders: unsafe extern "C" fn(ctx: *const HostContext, command: *const CancelAllOrdersHandle) -> PluginResult<()>,
pub close_position: unsafe extern "C" fn(ctx: *const HostContext, command: *const ClosePositionHandle) -> PluginResult<()>,
pub close_all_positions: unsafe extern "C" fn(ctx: *const HostContext, command: *const CloseAllPositionsHandle) -> PluginResult<()>,
pub query_account: unsafe extern "C" fn(ctx: *const HostContext, command: *const QueryAccountHandle) -> PluginResult<()>,
pub query_order: unsafe extern "C" fn(ctx: *const HostContext, command: *const QueryOrderHandle) -> PluginResult<()>,
}Expand description
Function table the host passes to every plug-in at load time.
All function pointers are non-null and stable for the process lifetime. Plug-ins stash the pointer and call back through it whenever they need host services. Adding a method is a breaking ABI change and requires rebuilding plug-ins to match the host during alpha.
Fields§
§abi_version: u32ABI version of this vtable. Must equal NAUTILUS_PLUGIN_ABI_VERSION.
clock_now_ns: unsafe extern "C" fn() -> u64Returns the host’s monotonic clock reading in UNIX nanoseconds.
log: unsafe extern "C" fn(level: HostLogLevel, target: BorrowedStr<'_>, message: BorrowedStr<'_>)Emits a log line to the host’s logger.
target is the log target (e.g. plug-in name), message is the body.
cache_instrument: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>Returns the JSON-encoded instrument snapshot for instrument_id.
Empty bytes mean the cache had no matching instrument.
cache_account: unsafe extern "C" fn(ctx: *const HostContext, account_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>Returns the JSON-encoded account snapshot for account_id.
Empty bytes mean the cache had no matching account.
cache_order: unsafe extern "C" fn(ctx: *const HostContext, client_order_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>Returns the JSON-encoded order snapshot for client_order_id.
Empty bytes mean the cache had no matching order.
cache_position: unsafe extern "C" fn(ctx: *const HostContext, position_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>Returns the JSON-encoded position snapshot for position_id.
Empty bytes mean the cache had no matching position.
cache_orders_for_strategy: unsafe extern "C" fn(ctx: *const HostContext, strategy_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>Returns JSON-encoded order snapshots for the requested strategy.
Passing an empty strategy_id uses the calling strategy’s own ID.
cache_positions_for_strategy: unsafe extern "C" fn(ctx: *const HostContext, strategy_id: BorrowedStr<'_>) -> PluginResult<OwnedBytes>Returns JSON-encoded position snapshots for the requested strategy.
Passing an empty strategy_id uses the calling strategy’s own ID.
subscribe_quotes: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>Subscribes the calling actor or strategy to quote ticks.
unsubscribe_quotes: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>Unsubscribes the calling actor or strategy from quote ticks.
subscribe_trades: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>Subscribes the calling actor or strategy to trade ticks.
unsubscribe_trades: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>Unsubscribes the calling actor or strategy from trade ticks.
subscribe_bars: unsafe extern "C" fn(ctx: *const HostContext, bar_type: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>Subscribes the calling actor or strategy to bars.
unsubscribe_bars: unsafe extern "C" fn(ctx: *const HostContext, bar_type: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>Unsubscribes the calling actor or strategy from bars.
subscribe_book_deltas: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, book_type: u8, depth: usize, client_id: BorrowedStr<'_>, managed: u8, params_json: BorrowedStr<'_>) -> PluginResult<()>Subscribes the calling actor or strategy to order book deltas.
book_type uses the BookType discriminant. depth == 0 means no
depth limit. managed != 0 requests a managed book subscription.
unsubscribe_book_deltas: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>Unsubscribes the calling actor or strategy from order book deltas.
subscribe_book_at_interval: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, book_type: u8, depth: usize, interval_ms: usize, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>Subscribes the calling actor or strategy to periodic order book snapshots.
book_type uses the BookType discriminant. depth == 0 means no
depth limit. interval_ms must be greater than zero.
unsubscribe_book_at_interval: unsafe extern "C" fn(ctx: *const HostContext, instrument_id: BorrowedStr<'_>, interval_ms: usize, client_id: BorrowedStr<'_>, params_json: BorrowedStr<'_>) -> PluginResult<()>Unsubscribes the calling actor or strategy from periodic order book snapshots.
interval_ms must be greater than zero.
msgbus_publish: unsafe extern "C" fn(ctx: *const HostContext, topic: BorrowedStr<'_>, payload: Slice<'_, u8>) -> PluginResult<()>Publishes an arbitrary byte payload on the host message bus.
The payload is delivered as a Vec<u8> to subscribers of topic.
set_time_alert: unsafe extern "C" fn(ctx: *const HostContext, name: BorrowedStr<'_>, alert_time_ns: u64, allow_past: u8) -> PluginResult<()>Registers a one-shot time alert on the calling actor or strategy clock.
set_timer: unsafe extern "C" fn(ctx: *const HostContext, name: BorrowedStr<'_>, interval_ns: u64, start_time_ns: u64, stop_time_ns: u64, allow_past: u8, fire_immediately: u8) -> PluginResult<()>Registers an interval timer on the calling actor or strategy clock.
start_time_ns == 0 and stop_time_ns == 0 mean no explicit bound.
cancel_timer: unsafe extern "C" fn(ctx: *const HostContext, name: BorrowedStr<'_>) -> PluginResult<()>Cancels a timer on the calling actor or strategy clock.
submit_order: unsafe extern "C" fn(ctx: *const HostContext, command: *const SubmitOrderHandle) -> PluginResult<()>Submits an order on behalf of the calling strategy.
ctx is the HostContext the host passed into the strategy’s
create. command is a boundary-owned SubmitOrderHandle the
plug-in constructs around the order and its routing/position
metadata. The plug-in owns the box and frees it when this call
returns; the host only borrows the handle for the duration of the
call.
cancel_order: unsafe extern "C" fn(ctx: *const HostContext, command: *const CancelOrderHandle) -> PluginResult<()>Cancels an in-flight order on behalf of the calling strategy.
command is a boundary-owned CancelOrderHandle the plug-in
constructs around the cancel parameters (typically client_order_id,
optional client_id, optional venue params). The plug-in owns the
box and frees it when this call returns; the host only borrows the
handle for the duration of the call.
modify_order: unsafe extern "C" fn(ctx: *const HostContext, command: *const ModifyOrderHandle) -> PluginResult<()>Modifies an in-flight order on behalf of the calling strategy.
command is a boundary-owned ModifyOrderHandle the plug-in
constructs around the modify parameters (new quantity, price,
trigger price, etc.). The plug-in owns the box and frees it when
this call returns; the host only borrows the handle for the
duration of the call.
submit_order_list: unsafe extern "C" fn(ctx: *const HostContext, command: *const SubmitOrderListHandle) -> PluginResult<()>Submits a list of orders as a single batch on behalf of the calling strategy.
command is a boundary-owned SubmitOrderListHandle the plug-in
constructs around the order list and optional position id, client
id, and routing params. The host dispatches the batch atomically
through the execution engine.
cancel_orders: unsafe extern "C" fn(ctx: *const HostContext, command: *const CancelOrdersHandle) -> PluginResult<()>Cancels every order named in the supplied list on behalf of the calling strategy.
command is a boundary-owned CancelOrdersHandle carrying the
client_order_id list plus optional client id and routing params.
cancel_all_orders: unsafe extern "C" fn(ctx: *const HostContext, command: *const CancelAllOrdersHandle) -> PluginResult<()>Cancels every open order matching the supplied filter on behalf of the calling strategy.
command is a boundary-owned CancelAllOrdersHandle carrying the
instrument_id and optional order_side, client_id, and routing
params. The host scans its cache for matching open orders and
issues the cancels.
close_position: unsafe extern "C" fn(ctx: *const HostContext, command: *const ClosePositionHandle) -> PluginResult<()>Closes the position identified by the command on behalf of the calling strategy.
command is a boundary-owned ClosePositionHandle carrying the
position_id plus optional client_id, tags, time_in_force,
reduce_only, and quote_quantity. The host reads the position
from its cache and submits a closing market order through the
strategy’s order factory.
close_all_positions: unsafe extern "C" fn(ctx: *const HostContext, command: *const CloseAllPositionsHandle) -> PluginResult<()>Closes every open position matching the supplied filter on behalf of the calling strategy.
command is a boundary-owned CloseAllPositionsHandle carrying
the instrument_id plus optional position_side, client_id,
tags, time_in_force, reduce_only, and quote_quantity. The
host scans its cache for matching open positions and submits
closing market orders.
query_account: unsafe extern "C" fn(ctx: *const HostContext, command: *const QueryAccountHandle) -> PluginResult<()>Queries the venue for the latest snapshot of account_id on
behalf of the calling strategy.
command is a boundary-owned QueryAccountHandle carrying the
account_id plus optional client_id and routing params. The
result is delivered asynchronously through the host’s normal
account-state event flow; this call only fires the query, it does
not return the snapshot inline.
query_order: unsafe extern "C" fn(ctx: *const HostContext, command: *const QueryOrderHandle) -> PluginResult<()>Queries the venue for the latest snapshot of client_order_id on
behalf of the calling strategy.
command is a boundary-owned QueryOrderHandle carrying the
client_order_id plus optional client_id and routing params.
The result is delivered asynchronously through the host’s normal
order-status event flow; this call only fires the query, it does
not return the snapshot inline.
Implementations§
Source§impl HostVTable
impl HostVTable
Sourcepub fn matches_compiled_abi(&self) -> bool
pub fn matches_compiled_abi(&self) -> bool
Asserts that the embedded ABI version matches the compiled-in constant.
Plug-ins should call this in their nautilus_plugin_init body before
trusting any function pointer from the table.
Sourcepub unsafe fn now_ns(&self) -> u64
pub unsafe fn now_ns(&self) -> u64
Reads the clock through the vtable.
§Safety
The vtable pointer must originate from the host’s nautilus_plugin_init
call and the host’s library must still be live.
Sourcepub unsafe fn log_message(
&self,
level: HostLogLevel,
target: &str,
message: &str,
)
pub unsafe fn log_message( &self, level: HostLogLevel, target: &str, message: &str, )
Trait Implementations§
impl Send for HostVTable
SAFETY: function pointers are thread-safe by construction; the host
guarantees the underlying implementations are Sync.
impl Sync for HostVTable
SAFETY: see above.