Overview Intro Log In
  

Collections

A collection represents a group of objects. Objects in the collection can be accessed by identifier, tags or with array-like indexes.

API Reference

Properties

Functions

call(fname, ...args)

Calls function named fname on each item in the collection passing args.

Arguments
  • String

    The name of the function to call.

  • Any

    Each argument after fname is treated as argument to the function call.

Usage
// calls close() function on each opportunity,
// passing 1 string argument (a message).
$a5.opps.call('close', 'Liquidating before earnings');

first(type)

Returns the first item in the collection. If type is specified, the first item with a type property equal to type is returned.

Arguments
  • String

    (optional) The type property value for the item.

Usage
// The first opportunity
var opp = $bot.opps.first();

// The first 'shortcall' opportunity
var call = $bot.opps.first('shortcall');

forEach(fn)

Calls the supplied function, fn, with each item in the collection.

Arguments
  • Function

    A function to call. Passed (item, index).

Usage
$a5.bots.forEach(function(bot, index){
    if(!bot.opp){
        bot.pause();
    }
});

get(id) Object

Returns the item in the collection with the specified id.

Arguments
  • String

    The id of the item.

Usage
var bot = $a5.bots.get('BOT123456789');

has(id) Boolean

Returns true if there is an item in the collection with the specified id.

Arguments
  • String

    The id of the item.

max(prop, precision = 2) Number

Returns the maximum value of prop for all items in the collection.

Arguments
  • String

    The property to compare.

  • Number

    The precision of the result. (defaults to 2)

Usage
var maxDraw = $a5.opps.max('draw');

mean(prop, precision = 2) Number

Returns the mean average of prop for all items in the collection.

Arguments
  • String

    The property to average.

  • Number

    The precision of the result. (defaults to 2)

Usage
var avgDraw = $a5.opps.mean('draw');

min(prop, precision = 2) Number

Returns the minimum value of prop for all items in the collection.

Arguments
  • String

    The property to compare.

  • Number

    The precision of the result. (defaults to 2)

Usage
var minDraw = $a5.opps.min('draw');

sum(prop, precision = 2) Number

Returns the sum of prop for all items in the collection.

Arguments
  • String

    The property to sum.

  • Number

    The precision of the result. (defaults to 2)

Usage
var totalDraw = $a5.opps.sum('draw');

tag(tag) Array

Returns an array with the items in the collection that have the specified tag.

Arguments
  • String

    The tag, e.g. 'bullish'

Usage
var items = $a5.bots.tag('bearish');

toArray() Array

Returns an array with the items in the collection.