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. |
argv | An array of arguments passed to the current command script. This value is only set for command scripts, otherwise it is undefined. |
kv | Key-value store object. |
accountValues | Account values for the default Interactive Brokers account. |
info(msg, markdown = false) | Sends an info message via Telegram. The msg parameter must be a string. If markdown is true, the message will be sent with markdown formatting. The default is false. |
warn(msg, markdown = false) | Sends a warning message via Telegram. The msg parameter must be a string. If markdown is true, the message will be sent with markdown formatting. The default is false. |
error(msg, markdown = false) | Sends an error message via Telegram. The msg parameter must be a string. If markdown is true, the message will be sent with markdown formatting. The default is false. |
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 |
isCredit | Boolean | A boolean value that indicates if the bot is a credit position |
isDebit | Boolean | A boolean value that indicates if the bot is a debit position |
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. |
tradeId | Number | The unique trade ID for the currently open position. An error will be raised if there is no open position. |
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 . |
delta(legIndex) | Number | The delta value for the specified leg. The legIndex parameter is a number and must be between 0 and the total number of legs in the position. For spread positions 0 is the primary leg and 1 is the spread leg. For a strangle 0 is the put side and 1 is the call side. For an iron condor 0 is the short put, 1 is the long put, 2 is the short call, and 3 is the long call. An error will be raised if there is no open position. |
Externals
External objects can be accessed through the [id]
property of the externals
object. For example: externals['fomc']
would return the external object defined with an id
of fomc
in the config. It is also possible to enumerate over the externals
object to access each external using a for...in
statement, for example:
for (const id in externals) {
log(externals[id].data)
}
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 object 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. |
id | String | The identifier for the external. This is the id attribute defined on the external's configuration. |
KVStore
The KVStore object is a key-value store that can be used to store data between script runs. It is able to store primitive types (string, number, boolean) only.
KVStore data is persisted between restarts but will be automatically cleared daily.
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.