MatchingEngineSimulator#
- class swordfish._swordfishcpp.MatchingEngineSimulator#
- engine_type: EngineType#
The type of the streaming engine.
- stat: MatchingEngineSimulatorStat#
Descriptive statistics related to the streaming engine.
- classmethod create(name, exchange, data_type, order_detail_output, quote_schema=None, user_order_schema=None, *, config=None)#
Create and configure a matching engine simulator instance.
- Parameters:
name (str) – Unique engine name.
exchange (Union[plugin_simulator.Exchange, str]) – Market type.
data_type (Union[plugin_simulator.MarketDataType, int]) – Market data type.
order_detail_output (Table) – Unique engine name.
quote_schema (Union[Table, TypeDict], optional) – Unique engine name.
user_order_schema (Union[Table, TypeDict], optional) – Unique engine name.
config (plugin_simulator.MatchingEngineSimulatorConfig, optional) – Unique engine name.
- Returns:
An instance of
MatchingEngineSimulatorBuilderinstant.- Return type:
plugin_simulator.MatchingEngineSimulatorBuilder
- reset(cancel_order=False)#
Clear cached orders and market data.
- Parameters:
cancel_order (bool, optional) –
Whether to cancel all unfilled user orders.
If True, all unfilled user orders will be canceled, and the corresponding cancellation information will be written to the trade detail table (specified via the order_detail_output parameter in create).
Default is False, meaning no cancellation is performed.
- drop()#
Drop the matching engine.
- get_open_orders(symbol=None)#
Get all unfilled user orders as a table.
- Parameters:
symbol (str, optional) – A STRING scalar used to specify a stock for retrieving all unfilled orders.
- Returns:
Returns a table containing the following columns:
Name
Type
Description
orderId
LONG
Order ID
timestamp
TIMESTAMP
Timestamp
symbol
STRING
Stock symbol
price
DOUBLE
Order price
totalQty
LONG
User order quantity
openQty
LONG
Remaining quantity of user order
direction
INT
1 = Buy, 2 = Sell
isMatching
INT
Whether the order has reached matching time
openVolumeWithBetterPrice
LONG
Total unfilled order volume at prices better than the order price
openVolumeWithWorsePrice
LONG
Total unfilled order volume at prices worse than the order price
openVolumeAtOrderPrice
LONG
Total unfilled order volume at the order price
priorOpenVolumeAtOrderPrice
LONG
Total unfilled order volume at the order price with earlier timestamp than this order
depthWithBetterPrice
INT
Number of price levels better than the order price
updateTime
TIMESTAMP
Latest update time
Note
The columns openVolumeWithBetterPrice, openVolumeWithWorsePrice, openVolumeAtOrderPrice, priorOpenVolumeAtOrderPrice, depthWithBetterPrice, and updateTime are included only when output_queue_position=1. (See the config parameter description in the create interface for details.)
- Return type:
- property symbol_list: Vector#
Retrieve the list of stock symbols in the engine.
- Returns:
A string vector indicating the list of stock symbols.
- Return type:
- insert_market(msg_body)#
Insert market data (table or tuple).
- Parameters:
msg_body (Constant) – It can be either a table object or a tuple, representing market data or user order data. Its format must conform to the target table structure specified when creating the engine, such as quote_schema or user_order_schema. In particular, when msg_body is a tuple, if a column in the target table is an array vector, the corresponding element in the tuple must be either an array vector (e.g., arrayVector([2], 23.42 23.43)) or a tuple containing only a regular vector (e.g., [23.42 23.43]).
- Return type:
None
- insert_order(msg_body)#
Insert user order data. Returns order ID.
- Parameters:
msg_body (Constant) – It can be either a table object or a tuple, representing market data or user order data. Its format must conform to the target table structure specified when creating the engine, such as quote_schema or user_order_schema. In particular, when msg_body is a tuple, if a column in the target table is an array vector, the corresponding element in the tuple must be either an array vector (e.g., arrayVector([2], 23.42 23.43)) or a tuple containing only a regular vector (e.g., [23.42 23.43]).
- Returns:
A LONG vector indicating the order ID.
- Return type:
- set_limit_price(data)#
Set limit up/down prices.
- Parameters:
data (Table) – A table containing three columns: symbol (STRING), upLimitPrice (DOUBLE), and downLimitPrice (DOUBLE).
- Returns:
Returns True if the settings are applied successfully.
- Return type:
bool
- set_prev_close(prev_close)#
Set the previous closing prices for the matching engine simulator.
- Parameters:
prev_close (Union[Dict[str, float], Dictionary]) – A dictionary where keys are stock symbols (strings) and values are the corresponding previous closing prices (floats).
- Returns:
Returns True if the settings are applied successfully.
- Return type:
bool
- get_snapshot(symbol=None)#
Get market snapshot from the engine.
- Parameters:
symbol (str, optional) – A STRING scalar specifying a stock. If not provided, snapshots for all stocks are retrieved.
- Returns:
A table with the following schema:
Name
Type
Description
symbol
STRING
Stock symbol
timestamp
TIMESTAMP
Time
avgTradePriceAtBid
DOUBLE
Average trade price at bid
avgTradePriceAtOffer
DOUBLE
Average trade price at offer
totalTradeQtyAtBid
LONG
Total traded quantity at bid
totalTradeQtyAtOffer
LONG
Total traded quantity at offer
bidPrice
DOUBLE[]
List of bid prices
bidQty
LONG[]
List of bid quantities
offerPrice
DOUBLE[]
List of offer prices
offerQty
LONG[]
List of offer quantities
lastPrice
DOUBLE
Last price
highPrice
DOUBLE
Highest price
lowPrice
DOUBLE
Lowest price
- Return type: