object tuple
An object tuple stores financial instruments or market data objects of a single type. Its elements must all be INSTRUMENT objects or all be MKTDATA objects.
Create an Object Tuple
You can create an object tuple in three ways.
To create an empty object tuple, call
arraywith dataType set to INSTRUMENT or MKTDATA.To create an object tuple from existing objects, enclose them in square brackets, as in
[priceA, priceB]. The objects must all be INSTRUMENT objects or all be MKTDATA objects.To convert a regular tuple created with parentheses, such as
(priceA, priceB), callsetObjectTuple!.
// Create an empty object tuple
ot = array(INSTRUMENT,0)
isObjectTuple(ot)
// output: true
// Create two MKTDATA objects
priceA = parseMktData(dict={
"mktDataType": "Price",
"referenceDate": 2025.08.18,
"priceType": "Price",
"value": 100.0,
"unit": "CNY"
})
priceB = parseMktData(dict={
"mktDataType": "Price",
"referenceDate": 2025.08.18,
"priceType": "Price",
"value": 101.5,
"unit": "CNY"
})
// Create a regular tuple named prices
prices = (priceA, priceB)
prices.isObjectTuple()
// output: false
// Convert the regular tuple to an object tuple
setObjectTuple!(X=prices)
prices.isObjectTuple()
// output: true
// Create the object tuple objectPrices directly
objectPrices = [priceA, priceB]
objectPrices.isObjectTuple()
// output: true
Note: typestr returns ANY VECTOR for both regular tuples and object tuples. Use isObjectTuple to distinguish them.
Access Elements in an Object Tuple
Object tuples support the following access methods. All indices start at 0.
prices[index] returns the object at the specified index.
prices.row(index) returns the object at the specified index.
prices[start:end] returns an object tuple containing the elements from start (inclusive) to end (exclusive).
Indexing returns an INSTRUMENT or MKTDATA object. To read its fields, use extractInstrument for an INSTRUMENT object or extractMktData for a MKTDATA object.
extractMktData(mktData=prices[0]).value
// output: 100
extractMktData(mktData=prices.row(1)).value
// output: 101.5
selectedPrices = prices[0:1]
selectedPrices.isObjectTuple()
// output: true
Append an Object to an Object Tuple
Use append! to add an object to the end of an object tuple. The new object must have the same type as the existing elements. For example, appending an INSTRUMENT object or a numeric value to a tuple of MKTDATA objects raises an error.
append!(obj=prices, newData=priceA)
extractMktData(mktData=prices[2]).value
// output: 100
Modify Elements in an Object Tuple
Use prices[index] = newValue to replace the element at the specified index with another object of the same type.
prices[0] = priceB
extractMktData(mktData=prices[0]).value
// output: 101.5
To change a field in an object, extract its contents and edit the returned dictionary. The object in the tuple keeps its original value until you parse the updated dictionary and replace the element with the resulting object.
priceInfo = extractMktData(mktData=prices[0])
priceInfo["value"] = 105.0
extractMktData(mktData=prices[0]).value
// output: 101.5
prices[0] = parseMktData(dict=priceInfo)
extractMktData(mktData=prices[0]).value
// output: 105
Remove Elements from an Object Tuple
Use remove! to remove one or more elements by index. Indices start at 0. To remove multiple elements in one call, specify their indices in strictly increasing order. The example removes the objects at indices 0 and 2 from prices. The remaining object is now at index 0.
remove!(obj=prices, index=[0, 2])
size(prices)
// output: 1
extractMktData(mktData=prices[0]).value
// output: 101.5
isObjectTuple(prices)
// output: true
Use pop! to remove and return the last element. At this point, prices contains one object, so removing it leaves the tuple empty.
lastPrice = pop!(prices)
extractMktData(mktData=lastPrice).value
// output: 101.5
size(prices)
// output: 0
Create an In-Memory Table with an Object Tuple Column
An object tuple can serve as a column in an in-memory table. Each object occupies one row, so the tuple must have the same length as the other columns. The example creates a two-row table named quotes whose price column holds MKTDATA objects. The query uses :E to apply extractMktData to each object and display its value field.
prices = (priceA, priceB)
setObjectTuple!(X=prices)
quotes = table(1 2 as id, prices as price)
select id, (extractMktData:E(price)).value as priceValue from quotes
| id | priceValue |
|---|---|
| 1 | 100 |
| 2 | 101.5 |
Each row stores the corresponding object. A regular tuple created with parentheses can also serve as an in-memory table column. A regular tuple column accepts values of other types. An object tuple column requires each new object to have the same type as the existing objects. In this example, inserting the integer 100 into the price column succeeds for ordinaryQuotes and raises an error for quotes.
ordinaryPrices = (priceA, priceB)
ordinaryQuotes = table(1 2 as id, ordinaryPrices as price)
ordinaryQuotes.tableInsert(table(3 as id, 100 as price))
// output:1
quotes.tableInsert(table(3 as id, 100 as price))
// Failed to append data to column 'price'
