Skip to content

Position Information

Every bit of information about the bot's positions is available through the commands in this category. Most commands accept an optional positionId parameter — leave it empty for managed trading, or pass a specific ID when working with multiple positions in unmanaged mode. See the Position Handling page for more on that.

Reading The Current Position

These commands query the bot's current open position state.

GetAllOpenPositions

Returns an array of PositionContainer objects for every open position. Useful when you need to inspect or iterate over multiple positions at once.

PositionContainer

Returns an object with all details about a specific position: direction, amount, enter price, profit, market, and more.

local pos = PositionContainer([positionId])
-- pos.direction, pos.amount, pos.enterPrice, pos.profit, ...

GetPositionDirection

Returns the position's direction: PositionLong, PositionShort, or NoPosition. Use this when execution flow depends on which side the bot is on.

GetPositionAmount

Returns the total amount open in the position. Note that this is not reduced by open orders.

GetPositionMarket

Returns the account and market associated with the position as a single string. The return value can be passed to commands that expect an account or a market.

LongAmount / ShortAmount

Returns the total amount open in a long or short position for a given market - which is optional, and if empty, will use bot's main market.

local longs = LongAmount([market])
local shorts = ShortAmount([market])

IsPositionClosed

Returns true if the position has been closed, false otherwise.

Profit & ROI

GetPositionProfit

Returns the total realized plus unrealized profit of a position. On spot and margin markets the result is in the quote currency. On leveraged markets it's in the underlying currency.

local profit = GetPositionProfit([positionId, targetPrice])

GetPositionROI

Returns the ROI as a percentage, calculated from the position's total (realized + unrealized) profit divided by the margin used. On cross margin, the calculation uses the maximum allowed leverage when the exchange doesnt allow leverage to be locked. For example, on BitMEX (100x max leverage), a $1 position is treated as if only $0.01 in margin was used — so a $0.01 profit returns 100%, not 1%.

local roi = GetPositionROI([positionId, targetPrice])

LastLongProfit / LastShortProfit

Returns the profit from the last completed long or short position.

LastLongROI / LastShortROI

Returns the ROI percentage from the last completed long or short position.

Position Prices

AverageEnterPrice

Returns the average price at which the current position was entered.

AverageExitPrice

Returns the average exit price of the position.

LastLongPrice / LastShortPrice

Returns the price of the most recent long or short entry.

LastExitLongPrice / LastExitShortPrice / LastExitPositionPrice

Returns the price of the most recent exit — specific to direction (LastExitLongPrice, LastExitShortPrice) or the last exit regardless of direction (LastExitPositionPrice).

Virtual Positions

Virtual positions let you simulate trades without sending real orders to the exchange. This is useful for testing strategies, tracking hypothetical positions, or backtesting logic inside a live script.

CreatePosition

Creates a simulated position with a given direction, price, and amount. The position is tracked internally so its profit/loss and details can be queried with the same commands above. Returns a position ID.

local posId = CreatePosition(PositionLong, 50000, 0.1, market, 10)

AdjustVPosition

Adjusts an existing virtual position by processing a simulated order at the given price and amount (negative to reduce, positive to increase). This modifies the virtual position without creating any real order.

AdjustVPosition(51000, -0.05, posId)  -- sell half

CloseVPosition

Closes a virtual position entirely by processing a simulated exit at the given price. Use this to clean up virtual positions when needed.

CloseVPosition(51000, posId)