Trade Smarter with Automation

Bot

Hooks

Bots have hooks that are triggered daily and other hooks that are triggered by activity. When you build your bot, you add routines (scripts) that are executed when a bot hook is triggered. Below is a list of the available hooks for your routines and when they are triggered:

Hook When... Notes
 setup the bot starts (daily) Used to setup buttons and other controls.
 wake the market opens (weekdays) Generally used to load data and/or calculate signals.
 tick,  scan and/or  monitor are triggered once per second the market is open, the wake event is done and all requested data is loaded tick is triggered right before scan or monitor.

scan is triggered if the number of open opportunities is less than the strategy's opportunity limit.

monitor is triggered if the bot has an open opportunity.
Triggered by activity
 open the bot opens a new opportunity Can be used to leg into opportunities, reload data, etc.
 close the bot closes an opportunity "
 cancel the bot cancels an opportunity Can be used to retry and/or adjust prices when an opportunity times out.
 load $bot.reload() is called Used to reload data and/or recalculate signals.
 error the bot has an error $bot.message has the error message.
 pause the bot is paused $bot.message has the pause message.

Bot API

Properties

  • Boolean

    true if the bot's status is 'active'.

  • Object

    Contains properties with real-time capital, P/L and statistical values the bot. More about bot.book.

  • Boolean

    true if the bot's status is stopped because of an error. See message for details about the error.

  • String

    A description for the bot.

  • Object

    Set informative data for display in the web client.

    Values are sorted alphabetically by name and should be appropriate for display in a small space (e.g. numbers, dates).

    Usage
    $bot.displayData.Expires = $now.nextFriday;

    Setting multiple values:

    $bot.displayData.set({
        'Expiration': fri,
        'Bull Open': bd.bull.open,
        'Bull Close': bd.bull.close,
        'Bull Legs': bd.bull.legs.join(', '),
        'Bear Open': bd.bear.open,
        'Bear Close': bd.bear.close,
        'Bear Legs': bd.bear.legs.join(', ')
    });

    Displays the data on the bot dashboard:

  • Boolean

    When set to true, it allows you to open new opportunities after hours using the Alta5 console.

    This feature was added to help with testing code when the market is closed. Since the bid / ask spread afterhours can be very wide, fill prices after hours are inconsistent. Live trading is not recommended after hours.

    Usage
    $bot.enableAfterhours = true;
    $bot.open({
        ...
    });
  • String

    The text displayed about the bots current status.

  • String

    The name of the bot.

  • Opportunity

    The current open opportunity or the opportunity with the last trade activity if multiple opportunities are open.

  • Collection

    Collection containing all open opportunities for a bot.

  • Boolean

    true if the bot has an active trade in progress.

  • Object

    Stores data and variables for a bot indefinitely.

    Each property set on $bot.state is also defined as a variable, available indefinitely across bot restarts. For example, if you set a state property named "phase":

    $bot.state.phase = 2;

    Then a new variable, $phase, is available globally for that bot:

    if($phase === 2){
        ...
    }

    State variables are stored and can only be set to storable values.

  • String

    The bots current status. starting, sleep, loading, active, paused or error

  • String

    A list of comma separated tags.

Functions

die(message)

Stop the bot and throw an error.

Arguments
  • String

    (optional) Informative message displayed while the bot is stopped.

Usage
$bot.die('Your error message');

log(message, data)

Add an entry to the bot's log.

Implementation notes:
Limited to 100 log entries per day. The new entry is saved to the database immediately if it has been more than 5 seconds than since the last call to $bot.log(); otherwise new entries are queued and saved in 5 second intervals.

Arguments
  • String

    (optional) A text message to log

  • Object

    (optional) Any data you want to attach to the log entry.

Usage
// just a message
$bot.log('This is a log message');

// just data
$bot.log({
    signal: 1234,
    price: $stock.last
});

// Snapshot a run-time object
$bot.log($bot.opp);

// both
$bot.log('Bot crossed entry signal', {
    signal: 1234,
    price: $stock.last
});

notify(message)

Send a notification.

Arguments
  • String

    The message for the notification.

Usage
$bot.notify('Underlying crossed signal to ' + $under.last);

open(opts)

Open a new opportunity.

Options

See the Opportunity guide for more details about the options for opening a specific type of opportunity.

The options below are available when opening all types of opportunities:

  • String

    The opportunity type, e.g. 'bullput'

  • String

    The underlying symbol (e.g. 'JPM' or 'AAPL')

  • String

    A comma separated list of tags.

  • Object

    Any storable data you want to attach to the opportunity.

Options for the opening trade:

  • Mixed

    A fixed limit price, array of prices or price settings object. If you don't provide a price, Smart Pricing will automatically try limit orders between the bid/ask spread.

  • Number

    The quantity for the order. If you don't provide a quantity, Alta5 will automatically calculate the quantity based on the bot's opportunity draw limit. More info...

  • Number/String

    The number of seconds to keep the order open, 'day' for the rest of the day or 'gtc' for good-til-canceled. More info...

  • String

    A memo message displayed in the app when viewing the opportunity.

Usage
$bot.open({
    type: 'equity',
    symbol: 'AAPL'
});
$bot.open({
    type: 'bullput',
    symbol: 'AAPL',
    expiration: 'next friday',
    legs: [122, 123],
    memo: 'Underlying crossed signal.'
});

pause(opts)

Pause the bot. Prevents the bot from scanning, monitoring opportunities or making any trades.

Options
  • String/Date

    (optional) Pause bot until a specific time/date. Date formats...

  • String

    (optional) Informative message displayed while the bot is paused.

Usage
$bot.pause({
    alarm: 'next monday',
    message: 'Skipping earnings week.'
});

reset()

Reset bot statistics to original empty state. All data and trade history is deleted.

Usage
$bot.reset();

restart()

Restart the bot.

Usage
$bot.restart();

resume()

Resume a bot that was paused or stopped because of an error.

Usage
$bot.resume();

bot.book

Every bot has a Book object with calculated properties accessible from your scripts:

  • Number

    The draw currently available for opening a new opportunity.

    Calculation:

    $$.range(0, oppDrawLimit, drawLimit - totalDraw)
  • Number

    P/L today.

  • Number

    The total cash used to close opportunities.

  • Number

    Total P/L in the bot's lifetime.

  • Number

    Total commission paid in the bot's lifetime.

  • Number

    The total cash used to open opportunities.

  • Number

    The combined delta greek value for the bot's open opportunities.

  • Number

    Alias for openDraw.

  • Number

    Highest draw at any time.

  • Number

    Highest draw today.

  • Number

    Limits the total capital draw for a bot in its lifetime. See the risk controls guide for more details.

  • Number

    Total % gain for the bot, including open opportunities.

  • Number

    The combined gamma greek value for the bot's open opportunities.

  • Number

    The current margin/maintenance requirements.

  • Number

    The number of open opportunities.

  • Number

    The total draw for all open opportunities and active trades.

  • Number

    Limits the total capital draw for an individual opportunity. See the risk controls guide for more details.

  • Number

    Total P/L in the bot's lifetime.

  • Number

    The combined rho greek value for the bot's open opportunities.

  • Number

    The combined theta greek value for the bot's open opportunities.

  • Number

    The total current draw including any closed losing P/L.

    Calculation:

    closedPnl < 0 ? $$.max(0, openDraw - closedPnl) : openDraw
  • Number

    Total draw for active trades.

  • Number

    The combined vega greek value for the bot's open opportunities.