genOutputColumnsForOBSnapshotEngine
Syntax
genOutputColumnsForOBSnapshotEngine([basic=true], [time=true], [depth],
[tradeDetail=true], [orderDetail=true], [withdrawDetail=true],
[orderBookDetailDepth=0], [prevDetail=true], [seqDetail=false],
[residualDetail=false])
Details
This function works with the order book engine and simplifies the process of creating an order book engine.
Parameters
The following parameters specify which columns the order book should include. Each
parameter name represents a column category, and each category contains multiple
columns. See the Appendix in createOrderBookSnapshotEngine for the
column categories and the columns included in each category.
basic: A Boolean value that specifies whether to output the columns in the basic category. The default value is true.
time: A Boolean value that specifies whether to output the fields in the time category. The default value is true.
depth: A tuple. Its length is 2, and the default value is (10, true).
- The first element is an integer scalar in the range [0, 100], specifying the number of bid and ask levels for price and quantity. If it is 0, no columns in depth are output.
- The second element is a Boolean value that determines how the price and quantity for multiple bid/ask levels are output. If it is false, the data is output in multiple columns; if it is true, the data is output as array vectors.
tradeDetail: A Boolean value that specifies whether to output the columns in tradeDetail, excluding tradeBuyOrderTypeList and tradeSellOrderTypeList. The default value is true.
orderDetail: A Boolean value that specifies whether to output the columns in orderDetail. The default value is true.
withdrawDetail: A Boolean value that specifies whether to output the columns in withdrawDetail, excluding withdrawBuyOrderNoList and withdrawSellOrderNoList. The default value is true.
orderbookDetailDepth: An integer scalar that specifies the depth level of
order book details to output. The default value is 0, indicating that nothing
is output. This parameter must have the same value as the
orderbookDetailDepth parameter of
createOrderBookSnapshotEngine.
prevDetail: A Boolean value that specifies whether to output the columns in prevDetail. The default value is true.
seqDetail: A Boolean value that specifies whether to output the columns in seqDetail. The default value is false.
residualDetail: A Boolean value that specifies whether to output the columns in the remaining order details (residualDetail), excluding ResidualBidOrderNoList and ResidualAskOrderNoList. The default value is false.
Returns
A tuple containing two elements.
- The first element is a string vector that lists the columns to include in the
order book and can be used as the outputColMap parameter of
createOrderBookSnapshotEngine. - The second element is an empty in-memory table that indicates the table schema
required by the order book and can be used as the outputTable parameter
of
createOrderBookSnapshotEngine.
Examples
When you create an order book engine, use the outputColMap parameter to specify the columns to output and the outputTable parameter to specify the output table.
genOutputColumnsForOBSnapshotEngine simplifies the
process of defining these two parameters. Before you create the order book engine,
perform the following steps:
First, use
genOutputColumnsForOBSnapshotEngine to specify the columns to
output.
Then, set outputColMap to the first element returned by
genOutputColumnsForOBSnapshotEngine, and set outputTable
to the second element.
Before you run the code, download the file orderbookDemoInput.zip.
try { dropStreamEngine("demo") } catch(ex) { print(ex) }
filePath = "./orderbookDemoInput.csv"
// Create a dummy table to define the schema of the input table, which will be passed to the dummyTable parameter
colNames = `SecurityID`Date`Time`SecurityIDSource`SecurityType`Index`SourceType`Type`Price`Qty`BSFlag`BuyNo`SellNo`ApplSeqNum`ChannelNo
colTypes = [SYMBOL, DATE, TIME, SYMBOL, SYMBOL, LONG, INT, INT, LONG, LONG, INT, LONG, LONG, LONG, INT]
dummyOrderStream = table(1:0, colNames, colTypes)
// Create a dictionary to define the meaning of each column in the input table, which will be passed to the inputColMap parameter
inputColMap = dict(`codeColumn`timeColumn`typeColumn`priceColumn`qtyColumn`buyOrderColumn`sellOrderColumn`sideColumn`msgTypeColumn`seqColumn, `SecurityID`Time`Type`Price`Qty`BuyNo`SellNo`BSFlag`SourceType`ApplSeqNum)
// Create a dictionary to define the previous day's closing prices, which will be passed to the prevClose parameter. prevClose does not affect any output columns other than the previous day's closing prices.
prevClose = dict(`000587.SZ`002694.SZ`002822.SZ`000683.SZ`301063.SZ`300459.SZ`300057.SZ`300593.SZ`301035.SZ`300765.SZ, [1.66, 6.56, 6.10, 8.47, 38.10, 5.34, 9.14, 48.81, 60.04, 16.52])
//Create outputColMap and outputTableSch to receive the return values of genOutputColumnsForOBSnapshotEngine. They are used to define outputColMap and the schema of outputTable, respectively.
outputColMap, outputTableSch = genOutputColumnsForOBSnapshotEngine(basic=true, time=false, depth=(10, true), tradeDetail=true, orderDetail=false, withdrawDetail=false, orderBookDetailDepth=0, prevDetail=false)
share(outputTableSch, `sharedOutputTable)
go
engine = createOrderBookSnapshotEngine(name="demo", exchange="XSHE", orderbookDepth=10, intervalInMilli = 1000, date=2022.01.10, startTime=09:15:00.000, prevClose=prevClose, dummyTable=dummyOrderStream, outputTable=outputTableSch, inputColMap=inputColMap, outputColMap=outputColMap, orderBookAsArray=true)
// Batch-insert tick-by-tick data of 10 stocks into the order book engine
engine.append!(select * from loadText(filePath) order by Time)
select top 10 * from sharedOutputTable where code="300593.SZ", timestamp between 2022.01.10T13:15:01.000 and 2022.01.10T13:15:10.000Some results are shown below:

