Skip to main content

Positions

Represents a collection of positions in the grid. It is used to manage a collection of stocks (or cryptocurrencies) that we're interested in tracking. Tickers can be retrieved, added, and removed tickers from the grid using either the UI or programmatically (as shown below).

Positions.all#

Retrieve a list containing all instances of Position objects currently in the grid. Useful when there is a need to iterate through all items currently in the grid.

var tickers = Positions.all();

Return value#

ResultResult value
on successan array of Position objects
on erroran empty array

Sample code#

The code snippet below retrieves all Position instances currently in the grid and dumps it current price to the log.

//get a reference to a list of all symbol we're tracking
var all = Positions.all();
//'all' is now an array of Position instances, iterate the list
for (n = 0; n < all.length; n++) {
//item is now a Position object
var item = all[n];
//just logging it for now
Log.info(item.symbol + ": " + item.currentPrice);
//or even display on screen
Alert.info(item.symbol + ": " + item.currentPrice);
}

The code below iterates and processes all tickers in the grid except for SPCE. Notice the use of 'return' rather than 'continue', which is due to the fact that this code fragment is within an anonymous function.

//get a reference to a list of all symbol we're tracking
Positions.all().forEach(
// iterate the list and only process symbols of interest at this time
function(item) {
if (item.symbol === 'SPCE')
return;
//
// do something with position:
// ... calculate something, check signals, clear signals, etc
//
}
);

Positions.get#

Positions.add#

Positions.remove#