Reference

Scripting Reference

Global objects and functions

NameDescription
spxSPX market data object.
vixVIX market data object.
vix9dVIX9D market data object.
vix1dVIX1D market data object.
esES (Futures) market data object.
botsTrademade bots configuration.
botThe bot that is currently in scope. This value is only set for bot scripts and entry filter scripts, otherwise it is undefined.
externalsTrademade externals.
kvKey-value store object.
accountValuesAccount 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

NameTypeDescription
lastNumberLast price
openNumberCurrent session open price
closeNumberThe closing price from the previous day
highNumberHigh price for the day
lowNumberLow price for the day
isTradingHoursBooleanA boolean that indicates if the instrument is currently trading

Bots

An ECMAScript Array object with a few additional methods and properties.

Properties

NameTypeDescription
currentBotThe current bot in context for the script.
lengthNumberThe total number of bots.

Methods

NameReturn typeDescription
get(name)BotGet the bot with the specified name.
find(regexp)BotFinds the first bot that matches the given regular expression or string.
findAll(regxp)IteratorReturns an iterator with all bots that match the given regular expression.

Bot

Properties

NameTypeDescription
nameStringThe bot name
openBooleanA boolean value that indicates if the bot has any open positions
typeStringThe position type of the bot
openCountNumberThe number of open trades
isTradingHoursBooleanA boolean value that indicates if the market is currently open and trading
dailyClosedProfitNumberThe daily P/L for the bot's closed positions
dailyEntryCountNumberThe number of entries the bot has made for the current day
dailyExitCountNumberThe number of closed trades for the current day
tagsArray of StringThe array of tags that are applied to this bot.
deltaNumberThe delta value for the currently open position. An error will be raised if there is no open position.
currentPriceNumberThe current price of the currently open position. An error will be raised if there is no open position.
entryPriceNumberThe entry price of the currently open position. An error will be raised if there is no open position.
expiryStringThe 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.
dteNumberThe number of days to expiration for the currently open position. An error will be raised if there is no open position.
positionNumberThe 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

NameReturn typeDescription
close()NoneImmediately closes the position.
isStopEnabled(type)booleanReturns 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)NoneEnables 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)NoneDisables 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

NameTypeDescription
idExternalThe external object identified by id. This is the id attribute defined on the external's configuration.

External

Properties

NameTypeDescription
dataObjectThe 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.
updateTimeDateThe last time the data was updated. This value is null if the endpoint has not yet been fetched.
isErrorbooleanReturns a boolean that indicates if there was an error accessing the API endpoint.
errorTextStringThe text when an error is returned from the API endpoint.
errorCodeNumberThe response code when an error is returned from the API endpoint.

KVStore

Methods

NameReturn typeDescription
get(key)ObjectGet 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)NoneSets 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.

Previous
config.yaml