The language used to query data from IQ RestAPI uses natural words. It is similar to the well known database language called SQL. Data available from IQ RestAPI is represented in tables. IQL statements to retrieve data issue SELECT statements, and posting data issue INSERT, UPDATE, or DELETE statements. Results are also represented as tables and are named in the requesting statments.
A SELECT statment retrieves data according to the search criteria provided. A SELECT statement follows the pattern:
SELECT {column names | *} FROM {table name} [WHERE {key field name} {operator} {key value}]
For example, the following statement would collect the last traded price for the stock with the code “BHP”:
SELECT SymbolCode, Name, LastPrice FROM Security WHERE Code = ‘BHP’
The result table will look something like this:
SymbolCode | Name | LastPrice |
---|---|---|
BHP | BHP Limited | 37.48 |
Please note: String and character literals are enclosed in single quotes, as in ‘BHP’.
The WHERE portion of the statement filters the data source to return only the values you are interested in. The way this is achieved can be with any of the following methods.
Operator | Meaning | Example |
---|---|---|
= | Value is equal to | SymbolCode = “BHP” |
IS | Value is equal to | SymbolCode IS “BHP” |
> | Value is greater than | LastPrice > 20 |
>= | Value is greater than or equal to | LastPrice >= 20 |
< | Value is less than | LastPrice < 20 |
<= | Value is less than or equal to | LastPrice <= 20 |
BEGINS | Text value start with the characters | Name BEGINS “AUS” |
CONTAINS | Text value contains the characters | Name CONTAINS “MONEY” |
IN | Value is contained in the set | SymbolCode IN [“BHP”, “ANZ”, “WOW”] |
LIKE | Text value conforms to wildcard expression | SymbolCode LIKE ‘AT*’ |
BETWEEN a AND b | Value lies between a and b | LastPrice BETWEEN 10 AND 20 |
AND | conjoining WHERE statments | LastPrice > 20 AND SymbolCode BEGINS “T” |
OR | conjoing WHERE statements | LastPrice > 20 OR SymbolCode BEGINS “A” |
There exists 2 tables which describe what data is available in the system. These are meta data tables
An INSERT statement is a mechanism of posting data to the IQ system. They are used in the Order Pad functions to Place, Amend, and Cancel orders. An INSERT statment follows the pattern:
INSERT INTO {table name} ({field name}[,…]) VALUES ({field value}[,…])
For example, the following would issue a cancel order request:
INSERT INTO CancelOrderRequest (AccountCode, OrderId) VALUES (‘TST0001’, ‘abcdef0123456789’)