Reference
Scripting Reference
Global objects and functions
Name | Description |
---|---|
spx | SPX market data object. |
vix | VIX market data object. |
vix9d | VIX9D market data object. |
vix1d | VIX1D market data object. |
es | ES (Futures) market data object. |
bots | Trademade bots configuration. |
bot | The bot that is currently in scope. This value is only set for bot scripts and entry filter scripts, otherwise it is undefined. |
externals | Trademade externals. |
kv | Key-value store object. |
accountValues | Account values for the default Interactive Brokers account. |
info(msg) | Sends an info message via Telegram. The msg parameter must be a string. |
warn(msg) | Sends a warning message via Telegram. The msg parameter must be a string. |
error(msg) | Sends an error message via Telegram. The msg parameter must be a string. |
log(msg) | Emits a message to the Trademade log file. The msg parameter must be a string. |
telegramCommand(cmd) | Executes the cmd Telegram command. The preceding slash (/ ) is not required. For example, telegramCommand("status") would run the /status command with the output being returned to the user via Telegram. |
Types
MarketData
Properties
Name | Type | Description |
---|---|---|
last | Number | Last price |
open | Number | Current session open price |
close | Number | The closing price from the previous day |
high | Number | High price for the day |
low | Number | Low price for the day |
isTradingHours | Boolean | A boolean that indicates if the instrument is currently trading |
Bots
An ECMAScript Array object with a few additional methods and properties.
Properties
Name | Type | Description |
---|---|---|
current | Bot | The current bot in context for the script. |
length | Number | The total number of bots. |
Methods
Name | Return type | Description |
---|---|---|
get(name) | Bot | Get the bot with the specified name. |
find(regexp) | Bot | Finds the first bot that matches the given regular expression or string. |
findAll(regxp) | Iterator | Returns an iterator with all bots that match the given regular expression. |
Bot
Properties
Name | Type | Description |
---|---|---|
name | String | The bot name |
open | Boolean | A boolean value that indicates if the bot has any open positions |
type | String | The position type of the bot |
openCount | Number | The number of open trades |
isTradingHours | Boolean | A boolean value that indicates if the market is currently open and trading |
dailyClosedProfit | Number | The daily P/L for the bot's closed positions |
dailyEntryCount | Number | The number of entries the bot has made for the current day |
dailyExitCount | Number | The number of closed trades for the current day |
tags | Array of String | The array of tags that are applied to this bot. |
delta | Number | The delta value for the currently open position. An error will be raised if there is no open position. |
currentPrice | Number | The current price of the currently open position. An error will be raised if there is no open position. |
entryPrice | Number | The entry price of the currently open position. An error will be raised if there is no open position. |
expiry | String | The expiry date-time of the currently open position. This value can be parsed by Date.parse() . An error will be raised if there is no open position. |
dte | Number | The number of days to expiration for the currently open position. An error will be raised if there is no open position. |
position | Number | The quantity for the currently open position. This value will be negative for credit and positive for debit positions. An error will be raised if there is no open position. |
Methods
Name | Return type | Description |
---|---|---|
close() | None | Immediately closes the position. |
isStopEnabled(type) | boolean | Returns a boolean that indicates if type stop monitor is enabled. The type parameter is a string and must be one of: delta , percent , itm , value , or auto-close . |
enableStop(type) | None | Enables the stop monitor for the specified stop type. The type parameter is a string and must be one of: delta , percent , itm , value , or auto-close . |
disableStop(type) | None | Disables the stop monitor for the specified stop type. The type parameter is a string and must be one of: delta , percent , itm , value , or auto-close . |
Externals
Properties
Name | Type | Description |
---|---|---|
id | External | The external object identified by id . This is the id attribute defined on the external's configuration. |
External
Properties
Name | Type | Description |
---|---|---|
data | Object | The data returned by the API endpoint. This value will be null if the endpoint has not yet been fetched, or if there was an error accessing the endpoint. |
updateTime | Date | The last time the data was updated. This value is null if the endpoint has not yet been fetched. |
isError | boolean | Returns a boolean that indicates if there was an error accessing the API endpoint. |
errorText | String | The text when an error is returned from the API endpoint. |
errorCode | Number | The response code when an error is returned from the API endpoint. |
KVStore
Methods
Name | Return type | Description |
---|---|---|
get(key) | Object | Get an object from the key-value store. This will return null if no mapping exists for the given key. The key parameter must be a string. |
set(key, value) | None | Sets an object in the key-value store. The key parameter must be a string and value must be a primitive type (string, number or boolean). |
Account Values
The Account Values object exposes the current account values that are available to TWS. Values are accessible as though they are keys in a hash map, for example:
log(accountValues['ExcessLiquidity'])
A null value will be returned if the value does not exist.
See the TWS API documentation for a full listing of available values.