Skip to content

Order Handling

Commands for monitoring and managing orders. Some work on all orders at once (no orderId needed), while others target a specific order by its ID.

Checking Order Status

IsAnyOrderOpen

Returns true when the bot has at least one open order. Use this to skip or gate logic that depends on no pending orders.

IsAnyOrderFinished

Returns true if the engine processed a completed order (filled, partially filled, cancelled, or rejected) since the last update cycle. Use this to trigger follow-up logic after an order resolves.

IsOrderOpen

Returns true if a specific order is still active on the exchange.

IsOrderFilled

Returns true only when a specific order is 100% filled.

if not IsOrderOpen(orderId) then
    if IsOrderFilled(orderId) then
        -- Order is fully filled
    elseif GetOrderFilledAmount(orderId) > 0 then
        -- Order is partially filled
    else
        -- Order was cancelled or rejected
    end
end

IsBuyOrder / IsSellOrder

Returns true if the given order is a buy or sell order, respectively.

Cancelling Orders

CancelAllOrders

Cancels all open orders the bot has placed, or specific position's orders when positionId is defined.

CancelOrder

Cancels a single order by its ID.

Order Information

OrderContainer

Returns an object with every detail about a specific order. Fields can be accessed by name or by 1-based index:

local order = OrderContainer(orderId)

-- By name
order.price          -- 1   The price the order was filled or executed at
order.executedAmount -- 2   The executed amount
order.filledAmount   -- 3   The filled amount
order.isOpen         -- 4   True if the order is still open
order.isFilled       -- 5   True if the order is 100% filled
order.isCancelled    -- 6   True if cancelled (may be partially filled)
order.feeCosts       -- 7   Total fee costs
order.feeCurrency    -- 8   Currency of the fee costs
order.openTime       -- 9   Minutes the order has been open
order.positionId     -- 10  The position this order belongs to
order.orderId        -- 11  The unique order identifier
order.isEnterOrder   -- 12  True if this is an enter order
order.isExitOrder    -- 13  True if this is an exit order
order.triggerPrice   -- 14  Trigger price for conditional orders
order.isBuyOrder     -- 15  True if this is a buy order
order.isSellOrder    -- 16  True if this is a sell order

-- By index
local orderPrice = order[1]
local orderAmount = order[2]
-- and so on...

GetAllOpenOrders

Returns a list of OrderContainer objects for all currently open orders.

GetAllFilledOrders

Returns a list of OrderContainer objects for the last 50 (partially) filled orders, sorted newest first. Pass a positionId to filter by position.

Order Details

GetOrderFilledAmount

Returns the amount that was filled for a specific order. Set afterFees to true to subtract fees paid in the base currency.

GetOrderCancelledAmount

Returns the amount that was cancelled if the order resolved as cancelled or partially filled.

GetOrderOpenTime

Returns how long an order has been (or was) open. Default is in minutes; set inSeconds to true for seconds.

GetOrderProfit

Returns the gross realized profit for a specific order.

GetFailedOrderMessage

Returns a string explaining why an order failed. Useful for debugging or logging.