Executors API

The Executors module handles order execution and trade management in Planar. It provides the interface between strategy logic and actual order placement, managing the execution lifecycle across different trading modes.

Overview

The Executors module is responsible for:

  • Order creation and validation
  • Trade execution across different modes (sim, paper, live)
  • Order lifecycle management
  • Position tracking and updates
  • Risk management and validation

Complete API Reference

PlanarCore.Executors.ContextType

The configuration against which a strategy is tested.

The Context struct has the following type parameter:

  • M: a subtype of ExecMode.

The struct has the following fields:

  • range: The date range to backtest around.
source
PlanarCore.Executors.ContextMethod

Create an instance of Context for a given strategy using the shortest timeframe.

Context(
    s::PlanarCore.Strategies.Strategy
) -> PlanarCore.Executors.Context

The Context function takes the following parameters:

  • s: a Strategy object of subtype ExecMode.
source
Base.collectMethod

Collects all elements of the OrderIterator into a Vector.

collect(
    oi::PlanarCore.Executors.OrderIterator
) -> Vector{Pair{@NamedTuple{price::Float64, time::Dates.DateTime}, <:PlanarCore.OrderTypes.Order}}
source
Base.countMethod

Counts the number of elements in the OrderIterator.

count(oi::PlanarCore.Executors.OrderIterator) -> Int64
source
Base.delete!Method

Removes a single order from the order queue.

delete!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::PlanarCore.OrderTypes.IncreaseOrder
) -> Union{Nothing, Set{PlanarCore.Instances.InstrumentInstance{T, E} where T<:PlanarCore.Instruments.AbstractInstrument} where E<:ExchangeID}
source
Base.delete!Method

Removes a single short buy order from the order queue.

delete!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, A, E, PlanarCore.Misc.Short} where {A, E}
) -> Union{Nothing, Set{PlanarCore.Instances.InstrumentInstance{T, E} where T<:PlanarCore.Instruments.AbstractInstrument} where E<:ExchangeID}
source
Base.delete!Method

Removes a single sell order from the order queue.

delete!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}, A, E, PlanarCore.Misc.Long} where {A, E}
) -> Union{Nothing, Set{PlanarCore.Instances.InstrumentInstance{T, E} where T<:PlanarCore.Instruments.AbstractInstrument} where E<:ExchangeID}
source
Base.delete!Method

Removes all buy/sell orders for an asset instance.

delete!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    t::Type{<:Union{PlanarCore.OrderTypes.Buy, PlanarCore.OrderTypes.Sell}}
) -> Any
source
Base.delete!Method

Removes all buy and sell orders for an asset instance.

delete!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    _::Type{PlanarCore.OrderTypes.BuyOrSell}
) -> Any
source
Base.delete!Method

Removes all orders for an asset instance.

delete!(s::PlanarCore.Strategies.Strategy, ii) -> Any
source
Base.eltypeMethod

Returns the element type of the OrderIterator.

eltype(
    _::PlanarCore.Executors.OrderIterator
) -> Type{Pair{@NamedTuple{price::Float64, time::Dates.DateTime}, <:PlanarCore.OrderTypes.Order}}
source
Base.fill!Method

Fills a short buy order.

fill!(
    _::PlanarCore.Strategies.Strategy{<:Union{PlanarCore.Misc.Paper, PlanarCore.Misc.Sim}},
    ii::PlanarCore.Instances.InstrumentInstance,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, A, E, PlanarCore.Misc.Short} where {A, E},
    t::PlanarCore.OrderTypes.ShortBuyTrade
)
source
Base.fill!Method

Fills a sell order.

fill!(
    _::PlanarCore.Strategies.Strategy{<:Union{PlanarCore.Misc.Paper, PlanarCore.Misc.Sim}},
    ii::PlanarCore.Instances.InstrumentInstance,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}, A, E, PlanarCore.Misc.Long} where {A, E},
    t::PlanarCore.OrderTypes.SellTrade
)
source
Base.fill!Method

Fills a buy order for a no-margin strategy.

fill!(
    _::PlanarCore.Strategies.Strategy{<:Union{PlanarCore.Misc.Paper, PlanarCore.Misc.Sim}},
    ii::PlanarCore.Instances.InstrumentInstance{<:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, NoMargin},
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, A, E, PlanarCore.Misc.Long} where {A, E},
    t::PlanarCore.OrderTypes.BuyTrade
)
source
Base.fill!Method

Fills an increase order for a margin strategy.

fill!(
    _::PlanarCore.Strategies.Strategy{var"#s3529", N, <:ExchangeID, <:PlanarCore.Misc.WithMargin, C} where {var"#s3529"<:Union{PlanarCore.Misc.Paper, PlanarCore.Misc.Sim}, N, C},
    ii::PlanarCore.Instances.InstrumentInstance{<:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, M} where M<:PlanarCore.Misc.WithMargin,
    o::PlanarCore.OrderTypes.IncreaseOrder,
    t::PlanarCore.OrderTypes.IncreaseTrade
)
source
Base.firstMethod

Returns the first order for an asset in a strategy.

first(s::PlanarCore.Strategies.Strategy{M, S, E}, ii) -> Any
first(
    s::PlanarCore.Strategies.Strategy{M, S, E},
    ii,
    bs::PlanarCore.OrderTypes.BySide
) -> Any
source
Base.firstindexMethod

Returns the first index for an order for an asset in a strategy.

firstindex(
    s::PlanarCore.Strategies.Strategy{M, S, E},
    ii
) -> Any
firstindex(
    s::PlanarCore.Strategies.Strategy{M, S, E},
    ii,
    bs::PlanarCore.OrderTypes.BySide
) -> Any
source
Base.haskeyMethod

Checks if a strategy has a specific order for an asset by price and time.

haskey(
    s::PlanarCore.Strategies.Strategy,
    ii,
    pt::@NamedTuple{price::Float64, time::Dates.DateTime},
    _::Union{Type{PlanarCore.OrderTypes.BuyOrSell}, PlanarCore.OrderTypes.BuyOrSell, Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.BuyOrSell}}}, PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.BuyOrSell}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.BuyOrSell}}}
) -> Bool
source
Base.haskeyMethod

Checks if a strategy has a specific order for an asset by price and time.

haskey(
    s::PlanarCore.Strategies.Strategy,
    ii,
    pt::@NamedTuple{price::Float64, time::Dates.DateTime},
    side::Union{Type{var"#s3529"}, Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{var"#s3529"}}}, PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{var"#s3529"}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{var"#s3529"}}, var"#s3529"} where var"#s3529"<:Union{PlanarCore.OrderTypes.Buy, PlanarCore.OrderTypes.Sell}
) -> Bool
source
Base.haskeyMethod

Checks if a strategy has a specific order for an asset by price and time.

haskey(
    s::PlanarCore.Strategies.Strategy,
    ii,
    pt::@NamedTuple{price::Float64, time::Dates.DateTime}
) -> Bool
source
Base.haskeyMethod

Checks if a strategy has a specific order for an asset.

haskey(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::PlanarCore.OrderTypes.Order
) -> Bool
source
Base.isdoneMethod

Checks if the OrderIterator is empty.

isdone(oi::PlanarCore.Executors.OrderIterator) -> Bool
source
Base.isopenMethod

Checks if an order is open.

isopen(
    ii::PlanarCore.Instances.InstrumentInstance,
    o::PlanarCore.OrderTypes.Order
) -> Any
source
Base.iszeroMethod

Checks if the order amount left to fill is below minimum qty.

iszero(
    ii::PlanarCore.Instances.InstrumentInstance,
    o::PlanarCore.OrderTypes.Order
) -> Any
source
Base.iterateMethod

Returns the next element in the OrderIterator.

iterate(
    oi::PlanarCore.Executors.OrderIterator,
    _
) -> Union{Nothing, Tuple{Any, Nothing}}
source
Base.keysMethod

Returns all keys for orders in a strategy.

keys(
    s::PlanarCore.Strategies.Strategy,
    args...;
    kwargs...
) -> Union{Base.Generator{_A, PlanarCore.Executors.var"#47#48"} where _A, DiskArrays.DiskGenerator{I, PlanarCore.Executors.var"#47#48"} where I<:DiskArrays.AbstractDiskArray}
source
Base.lastMethod

Returns the last element in the OrderIterator.

last(oi::PlanarCore.Executors.OrderIterator) -> Any
source
Base.lastMethod

Returns the last order for an asset in a strategy.

last(s::PlanarCore.Strategies.Strategy{M, S, E}, ii) -> Any
last(
    s::PlanarCore.Strategies.Strategy{M, S, E},
    ii,
    bs::PlanarCore.OrderTypes.BySide
) -> Any
source
Base.lastindexMethod

Returns the last index for an order for an asset in a strategy.

lastindex(
    s::PlanarCore.Strategies.Strategy{M, S, E},
    ii
) -> Any
lastindex(
    s::PlanarCore.Strategies.Strategy{M, S, E},
    ii,
    bs::PlanarCore.OrderTypes.BySide
) -> Any
source
Base.push!Method

Inserts an order into the order dict of the asset instance. Orders should be identifiable by a unique (price, date) tuple.

push!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{S<:PlanarCore.OrderTypes.OrderSide}}
) -> PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{S}} where S<:PlanarCore.OrderTypes.OrderSide
source
Base.valuesMethod

Returns all values for orders in a strategy.

values(
    s::PlanarCore.Strategies.Strategy,
    args...;
    kwargs...
) -> Union{Base.Generator{_A, PlanarCore.Executors.var"#51#52"} where _A, DiskArrays.DiskGenerator{I, PlanarCore.Executors.var"#51#52"} where I<:DiskArrays.AbstractDiskArray}
source
PlanarCore.Executors._check_cashMethod

Checks the cash for an asset instance in a strategy for long.

_check_cash(
    ii::PlanarCore.Instances.InstrumentInstance,
    _::PlanarCore.Misc.Long
)
source
PlanarCore.Executors._check_cashMethod

Checks the cash for an asset instance in a strategy for short.

_check_cash(
    ii::PlanarCore.Instances.InstrumentInstance,
    _::PlanarCore.Misc.Short
)
source
PlanarCore.Executors._check_unfillmentMethod

Checks if the unfilled amount for a limit buy order is negative.

_check_unfillment(
    o::PlanarCore.OrderTypes.AnyBuyOrder{P, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, var"#s3530"} where {P<:PlanarCore.Misc.PositionSide, var"#s3530"<:PlanarCore.OrderTypes.LimitOrderType{PlanarCore.OrderTypes.Buy}}
) -> Any
source
PlanarCore.Executors._check_unfillmentMethod

Checks if the unfilled amount for a market buy order is negative.

_check_unfillment(
    o::PlanarCore.OrderTypes.AnyBuyOrder{P, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, var"#s3530"} where {P<:PlanarCore.Misc.PositionSide, var"#s3530"<:PlanarCore.OrderTypes.MarketOrderType{PlanarCore.OrderTypes.Buy}}
) -> Any
source
PlanarCore.Executors._check_unfillmentMethod

Checks if the unfilled amount for a limit sell order is positive.

_check_unfillment(
    o::PlanarCore.OrderTypes.AnySellOrder{P, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, var"#s3530"} where {P<:PlanarCore.Misc.PositionSide, var"#s3530"<:PlanarCore.OrderTypes.LimitOrderType{PlanarCore.OrderTypes.Sell}}
) -> Any
source
PlanarCore.Executors._check_unfillmentMethod

Checks if the unfilled amount for a market sell order is positive.

_check_unfillment(
    o::PlanarCore.OrderTypes.AnySellOrder{P, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, var"#s3530"} where {P<:PlanarCore.Misc.PositionSide, var"#s3530"<:PlanarCore.OrderTypes.MarketOrderType{PlanarCore.OrderTypes.Sell}}
) -> Any
source
PlanarCore.Executors.aftertrade!Function

Removes a filled limit order from the queue

aftertrade!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::PlanarCore.OrderTypes.Order
) -> Any
aftertrade!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::PlanarCore.OrderTypes.Order,
    t
) -> Any

The function is used post-trade to clean up the strategy's order queue.

source
PlanarCore.Executors.aftertrade!Function

Unconditionally dequeues immediate orders.

aftertrade!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::Union{PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.MarketOrderType{S}, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, P} where {S<:PlanarCore.OrderTypes.OrderSide, P<:PlanarCore.Misc.PositionSide}, PlanarCore.OrderTypes.FOKOrder, PlanarCore.OrderTypes.IOCOrder, PlanarCore.OrderTypes.ShortFOKOrder, PlanarCore.OrderTypes.ShortIOCOrder}
) -> Any
aftertrade!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::Union{PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.MarketOrderType{S}, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, P} where {S<:PlanarCore.OrderTypes.OrderSide, P<:PlanarCore.Misc.PositionSide}, PlanarCore.OrderTypes.FOKOrder, PlanarCore.OrderTypes.IOCOrder, PlanarCore.OrderTypes.ShortFOKOrder, PlanarCore.OrderTypes.ShortIOCOrder},
    t
) -> Any

This function is called after a trade to remove filled 'Fill Or Kill' (FOK) or 'Immediate Or Cancel' (IOC) orders from the strategy's order queue.

source
PlanarCore.Executors.basic_order_stateMethod

Constructs a basic order state with given parameters.

basic_order_state(
    take,
    stop,
    committed::Ref{T<:Real},
    unfilled::Ref{T<:Real}
) -> NamedTuple{(:take, :stop, :committed, :unfilled, :trades), T1} where {T<:Real, T1<:Union{Tuple{Nothing, Nothing, Ref{T}, Ref{T}, Vector{PlanarCore.OrderTypes.Trade}}, Tuple{Nothing, Real, Ref{T}, Ref{T}, Vector{PlanarCore.OrderTypes.Trade}}, Tuple{Real, Nothing, Ref{T}, Ref{T}, Vector{PlanarCore.OrderTypes.Trade}}, Tuple{Real, Real, Ref{T}, Ref{T}, Vector{PlanarCore.OrderTypes.Trade}}}}
basic_order_state(
    take,
    stop,
    committed::Ref{T<:Real},
    unfilled::Ref{T<:Real},
    trades
) -> NamedTuple{(:take, :stop, :committed, :unfilled, :trades), T1} where {T<:Real, T1<:Union{Tuple{Nothing, Nothing, Ref{T}, Ref{T}, Vector{PlanarCore.OrderTypes.Trade}}, Tuple{Nothing, Real, Ref{T}, Ref{T}, Vector{PlanarCore.OrderTypes.Trade}}, Tuple{Real, Nothing, Ref{T}, Ref{T}, Vector{PlanarCore.OrderTypes.Trade}}, Tuple{Real, Real, Ref{T}, Ref{T}, Vector{PlanarCore.OrderTypes.Trade}}}}
source
PlanarCore.Executors.basicorderMethod

Constructs an Order for a given OrderType type and inputs.

basicorder(
    ii::PlanarCore.Instances.InstrumentInstance,
    price,
    amount,
    committed,
    ::PlanarCore.Executors.Checks.SanitizeOff;
    type,
    date,
    loss,
    profit,
    id,
    tag
)
source
PlanarCore.Executors.buyordersMethod

Returns buy orders for an asset in a strategy.

buyorders(
    s::PlanarCore.Strategies.Strategy,
    ii
) -> SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, PlanarCore.Strategies.BuyPriceTimeOrdering} where D<:(PlanarCore.OrderTypes.AnyBuyOrder{P, T, E} where {E<:ExchangeID, P<:PlanarCore.Misc.PositionSide, T<:PlanarCore.Instruments.AbstractInstrument})
source
PlanarCore.Executors.committmentMethod

Calculates the commitment for an order.

committment(
    ii::PlanarCore.Instances.InstrumentInstance,
    o::PlanarCore.OrderTypes.Order;
    kwargs...
) -> Any
source
PlanarCore.Executors.committmentMethod

Calculates the partial commitment of a trade.

committment(
    ii::PlanarCore.Instances.InstrumentInstance,
    t::PlanarCore.OrderTypes.Trade
) -> Any
source
PlanarCore.Executors.committmentMethod

Calculates the commitment for a leveraged position.

committment(
    o::Type{<:PlanarCore.OrderTypes.IncreaseOrder},
    ii::PlanarCore.Instances.InstrumentInstance{<:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, M} where M<:PlanarCore.Misc.WithMargin,
    price,
    amount;
    ntl,
    fees,
    lev,
    kwargs...
) -> Any
source
PlanarCore.Executors.committmentMethod

Calculates the commitment for an increase order without margin.

committment(
    ::Type{<:PlanarCore.OrderTypes.IncreaseOrder},
    ii::PlanarCore.Instances.InstrumentInstance{<:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, NoMargin},
    price,
    amount;
    kwargs...
) -> Any
source
PlanarCore.Executors.committmentMethod

Calculates the commitment when exiting a position for shorts.

committment(
    ::Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, A, E, PlanarCore.Misc.Short} where {A, E}},
    ii,
    price,
    amount;
    fees_base,
    kwargs...
) -> Any
source
PlanarCore.Executors.committmentMethod

Calculates the commitment when exiting a position for longs.

committment(
    ::Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}, A, E, PlanarCore.Misc.Long} where {A, E}},
    ii,
    price,
    amount;
    fees_base,
    kwargs...
) -> Any
source
PlanarCore.Executors.decommit!Function

Decommits an increase order from a strategy.

decommit!(
    s::PlanarCore.Strategies.Strategy,
    o::PlanarCore.OrderTypes.IncreaseOrder,
    ii
) -> Float64
decommit!(
    s::PlanarCore.Strategies.Strategy,
    o::PlanarCore.OrderTypes.IncreaseOrder,
    ii,
    canceled
) -> Float64
source
PlanarCore.Executors.decommit!Method

Decommits a short buy order from an asset instance.

decommit!(
    s::PlanarCore.Strategies.Strategy,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, A, E, PlanarCore.Misc.Short} where {A, E},
    ii,
    args...
) -> Float64
source
PlanarCore.Executors.decommit!Method

Decommits a sell order from an asset instance.

decommit!(
    s::PlanarCore.Strategies.Strategy,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}, A, E, PlanarCore.Misc.Long} where {A, E},
    ii,
    args...
) -> Float64
source
PlanarCore.Executors.hasordersMethod

Checks if an asset instance has pending orders in a strategy.

hasorders(
    s::PlanarCore.Strategies.Strategy,
    ii::PlanarCore.Instances.InstrumentInstance
) -> Bool
source
PlanarCore.Executors.hasordersMethod

Checks if there are any orders for a given position side

hasorders(
    s::PlanarCore.Strategies.Strategy{X, N, <:ExchangeID, <:PlanarCore.Misc.WithMargin, C} where {X<:PlanarCore.Misc.ExecMode, N, C},
    ii,
    ps::PlanarCore.Misc.PositionSide
) -> Bool

This function checks both Buy and Sell sides for any orders that match the provided position side in the Margin Strategy.

source
PlanarCore.Executors.hasordersMethod

Checks if an asset instance has a specific order in a strategy by side.

hasorders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    id::String
) -> Bool
hasorders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    id::String,
    ::Union{Type{S<:PlanarCore.OrderTypes.OrderSide}, Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{S<:PlanarCore.OrderTypes.OrderSide}}}, PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{S<:PlanarCore.OrderTypes.OrderSide}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{S<:PlanarCore.OrderTypes.OrderSide}}, S<:PlanarCore.OrderTypes.OrderSide}
) -> Bool
source
PlanarCore.Executors.hasordersMethod

Checks if an asset instance has pending buy orders in a strategy.

hasorders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    _::Type{S<:Union{PlanarCore.OrderTypes.Buy, PlanarCore.OrderTypes.Sell}}
) -> Bool
source
PlanarCore.Executors.hasordersMethod

Checks if a strategy has sell orders.

hasorders(
    s::PlanarCore.Strategies.Strategy,
    _::Union{Type{S<:PlanarCore.OrderTypes.OrderSide}, Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{S<:PlanarCore.OrderTypes.OrderSide}}}, PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{S<:PlanarCore.OrderTypes.OrderSide}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{S<:PlanarCore.OrderTypes.OrderSide}}, S<:PlanarCore.OrderTypes.OrderSide}
) -> Bool
source
PlanarCore.Executors.hold!Method

When an increase order is added to a strategy, the asset is added to the holdings.

hold!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    o::PlanarCore.OrderTypes.IncreaseOrder
) -> Set{PlanarCore.Instances.InstrumentInstance{T, E} where T<:PlanarCore.Instruments.AbstractInstrument} where E<:ExchangeID
source
PlanarCore.Executors.hold!Method

Reduce orders can never switch an asset from not held to held.

hold!(
    _::PlanarCore.Strategies.Strategy,
    _,
    _::PlanarCore.OrderTypes.ReduceOrder
)
source
PlanarCore.Executors.iscommittableMethod

Checks if an increase order can be committed to a strategy.

iscommittable(
    s::PlanarCore.Strategies.Strategy,
    o::PlanarCore.OrderTypes.IncreaseOrder,
    ii
) -> Any
source
PlanarCore.Executors.iscommittableMethod

Checks if a short buy order can be committed to an asset instance.

iscommittable(
    _::PlanarCore.Strategies.Strategy,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, A, E, PlanarCore.Misc.Short} where {A, E},
    ii
) -> Any
source
PlanarCore.Executors.iscommittableMethod

Checks if a sell order can be committed to an asset instance.

iscommittable(
    _::PlanarCore.Strategies.Strategy,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}, A, E, PlanarCore.Misc.Long} where {A, E},
    ii
) -> Any
source
PlanarCore.Executors.iscommittableMethod

Checks if a strategy can commit to an increase order.

iscommittable(
    s::PlanarCore.Strategies.Strategy,
    _::Type{<:PlanarCore.OrderTypes.IncreaseOrder},
    commit,
    ii
) -> Any
source
PlanarCore.Executors.iscommittableMethod

Checks if a strategy can commit to a short buy order.

iscommittable(
    _::PlanarCore.Strategies.Strategy,
    _::Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, A, E, PlanarCore.Misc.Short} where {A, E}},
    commit,
    ii
) -> Any
source
PlanarCore.Executors.iscommittableMethod

Checks if a strategy can commit to a sell order.

iscommittable(
    s::PlanarCore.Strategies.Strategy,
    _::Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}, A, E, PlanarCore.Misc.Long} where {A, E}},
    commit,
    ii
) -> Any
source
PlanarCore.Executors.isfirstfillMethod

Checks if the provided trade is the first fill for the given asset instance.

isfirstfill(
    _::PlanarCore.Instances.InstrumentInstance,
    t::PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.LimitOrderType}
) -> Any
source
PlanarCore.Executors.islastfillMethod

Checks if the provided trade is the last fill for the given asset instance.

islastfill(
    ii::PlanarCore.Instances.InstrumentInstance,
    t::PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.LimitOrderType}
) -> Any
source
PlanarCore.Executors.isliquidatableMethod

Tests if a position should be liquidated at a particular price.

isliquidatable(
    _::PlanarCore.Strategies.RTStrategy,
    ii::PlanarCore.Instances.InstrumentInstance{<:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, M} where M<:PlanarCore.Misc.WithMargin,
    p::PlanarCore.Misc.PositionSide,
    date::Dates.DateTime
) -> Any

This function checks whether a position in a Paper or Live strategy should be liquidated at the current price at the specified date.

source
PlanarCore.Executors.isliquidatableMethod

Checks if a position is liquidatable at a given date

isliquidatable(
    _::PlanarCore.Strategies.SimStrategy,
    ii::PlanarCore.Instances.InstrumentInstance{<:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, M} where M<:PlanarCore.Misc.WithMargin,
    p::PlanarCore.Misc.PositionSide,
    date::Dates.DateTime
) -> Any

This function determines whether a position in a margin strategy is eligible for liquidation at the specified date.

source
PlanarCore.Executors.isqueuedMethod

Checks if an order is already added to the queue.

isqueued(
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{S<:PlanarCore.OrderTypes.OrderSide}},
    s::PlanarCore.Strategies.Strategy,
    ii
) -> Any
source
PlanarCore.Executors.limitorderMethod

Places a limit order in the strategy

limitorder(
    s::PlanarCore.Strategies.Strategy,
    ii,
    amount;
    date,
    type,
    price,
    take,
    stop,
    skipcommit,
    kwargs...
)

This function places a limit order with specified parameters in the strategy s. The type argument specifies the type of the order. The price defaults to the current price at the given date if not provided. The take and stop arguments are optional and default to nothing. If skipcommit is true, the function will not commit the order. Additional arguments can be passed via kwargs.

source
PlanarCore.Executors.liquidationsMethod

The number of liquidations that have happened for an asset instance.

liquidations(
    ii::PlanarCore.Instances.InstrumentInstance{<:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, M} where M<:PlanarCore.Misc.WithMargin
) -> @NamedTuple{long::Vector{PlanarCore.OrderTypes.Trade}, long_loss::Float64, short::Vector{PlanarCore.OrderTypes.Trade}, short_loss::Float64}

This function counts the number of liquidations that have occurred in the history of a margin asset instance.

source
PlanarCore.Executors.longordersMethod

Returns a generator for long orders matching a given order side

longorders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    os::Type{<:PlanarCore.OrderTypes.OrderSide}
) -> Base.Generator{I, typeof(identity)} where I<:(Base.Iterators.Filter{PlanarCore.Executors.var"#orders##24#orders##25"{PlanarCore.Misc.Long}})

This function utilizes the orders function to generate orders for the Long position side that match the provided order side.

source
PlanarCore.Executors.marketorderMethod

Executes a market order.

marketorder(
    s::PlanarCore.Strategies.Strategy,
    ii,
    amount;
    date,
    type,
    take,
    stop,
    price,
    skipcommit,
    kwargs...
)

This function takes a strategy, an ii, an amount, and other optional arguments such as date, type, take, stop, price, and kwargs. It executes a market order with the given parameters. If skipcommit is set to false (default), the order is committed. Returns nothing.

source
PlanarCore.Executors.order_byidMethod

Returns the order that matches the given id (if any).

order_byid(
    s::PlanarCore.Strategies.Strategy,
    ii::PlanarCore.Instances.InstrumentInstance,
    id::String
) -> Any
source
PlanarCore.Executors.ordersMethod

Returns a generator for orders matching a given position side and order side

orders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    pos::PlanarCore.Misc.PositionSide,
    os::Type{<:PlanarCore.OrderTypes.OrderSide}
) -> Base.Generator{I, typeof(identity)} where I<:(Base.Iterators.Filter{F} where F<:(PlanarCore.Executors.var"#orders##24#orders##25"{<:PlanarCore.Misc.PositionSide}))

This function iterates over the orders of a strategy, returning only those that match the provided position side and order side.

source
PlanarCore.Executors.ordersMethod

Returns a generator for orders matching a given position side

orders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    pos::PlanarCore.Misc.PositionSide
) -> Base.Iterators.Flatten{I} where I<:(Base.Generator{Tuple{DataType, DataType}, F} where F<:(PlanarCore.Executors.var"#orders##26#orders##27"{PlanarCore.Strategies.Strategy{X, N, E, M, C}, _A, <:PlanarCore.Misc.PositionSide} where {X<:PlanarCore.Misc.ExecMode, N, E<:ExchangeID, M<:MarginMode, C, _A}))

This function iterates over the orders of a strategy for both Buy and Sell sides, returning those that match the provided position side.

source
PlanarCore.Executors.ordersMethod

Iterates over all the orderless orders for an asset instance in a strategy.

orders(
    s::PlanarCore.Strategies.Strategy,
    ii::PlanarCore.Instances.InstrumentInstance,
    _::Val{:orderless}
) -> Base.Iterators.Flatten{I} where I<:(Base.Generator{Tuple{DataType, DataType}, F} where F<:(PlanarCore.Executors.var"#orders##18#orders##19"{PlanarCore.Strategies.Strategy{X, N, E, M, C}, PlanarCore.Instances.InstrumentInstance{T, E1, M1}} where {X<:PlanarCore.Misc.ExecMode, N, E<:ExchangeID, M<:MarginMode, C, T<:PlanarCore.Instruments.AbstractInstrument, E1<:ExchangeID, M1<:MarginMode}))
source
PlanarCore.Executors.ordersMethod

Iterates over all the orders for an asset instance in a strategy.

orders(
    s::PlanarCore.Strategies.Strategy,
    ii::PlanarCore.Instances.InstrumentInstance
) -> Union{PlanarCore.Executors.OrderIterator, SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, PlanarCore.Strategies.BuyPriceTimeOrdering} where D<:(PlanarCore.OrderTypes.AnyBuyOrder{P, T, E} where {E<:ExchangeID, P<:PlanarCore.Misc.PositionSide, T<:PlanarCore.Instruments.AbstractInstrument}), SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, PlanarCore.Strategies.SellPriceTimeOrdering} where D<:(PlanarCore.OrderTypes.AnySellOrder{P, T, E} where {E<:ExchangeID, P<:PlanarCore.Misc.PositionSide, T<:PlanarCore.Instruments.AbstractInstrument})}
source
PlanarCore.Executors.ordersMethod

Returns all buy orders for a strategy.

orders(
    s::PlanarCore.Strategies.Strategy,
    _::Union{Type{PlanarCore.OrderTypes.Buy}, PlanarCore.OrderTypes.Buy, Type{<:PlanarCore.OrderTypes.AnyBuyOrder{P, A, E, var"#s1779"} where {var"#s1779"<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, A<:PlanarCore.Instruments.AbstractInstrument, E<:ExchangeID, P<:PlanarCore.Misc.PositionSide}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}}, PlanarCore.OrderTypes.AnyBuyOrder{P, A, E} where {P<:PlanarCore.Misc.PositionSide, A<:PlanarCore.Instruments.AbstractInstrument, E<:ExchangeID}}
) -> PlanarCore.Executors.OrderIterator
source
PlanarCore.Executors.ordersMethod

Returns all sell orders for a strategy.

orders(
    s::PlanarCore.Strategies.Strategy,
    _::Union{Type{PlanarCore.OrderTypes.Sell}, PlanarCore.OrderTypes.Sell, Type{<:PlanarCore.OrderTypes.AnySellOrder{P, A, E, var"#s1779"} where {var"#s1779"<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}, A<:PlanarCore.Instruments.AbstractInstrument, E<:ExchangeID, P<:PlanarCore.Misc.PositionSide}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}}, PlanarCore.OrderTypes.AnySellOrder{P, A, E} where {P<:PlanarCore.Misc.PositionSide, A<:PlanarCore.Instruments.AbstractInstrument, E<:ExchangeID}}
) -> PlanarCore.Executors.OrderIterator
source
PlanarCore.Executors.ordersMethod

Iterates orderlessly over all the orders in a strategy (all the assets in the universe).

orders(
    s::PlanarCore.Strategies.Strategy,
    _::Val{:orderless},
    _::Val{:universe}
) -> PlanarCore.Executors.OrderIterator
source
PlanarCore.Executors.ordersMethod

Iterates over all the orderless orders in a strategy.

orders(
    s::PlanarCore.Strategies.Strategy,
    _::Val{:orderless}
) -> Base.Iterators.Flatten{I} where I<:(Base.Generator{Tuple{DataType, DataType}, F} where F<:(PlanarCore.Executors.var"#orders##4#orders##5"{PlanarCore.Strategies.Strategy{X, N, E, M, C}} where {X<:PlanarCore.Misc.ExecMode, N, E<:ExchangeID, M<:MarginMode, C}))
source
PlanarCore.Executors.ordersMethod

Iterates over all the orders in a strategy (all the assets in the universe).

orders(
    s::PlanarCore.Strategies.Strategy,
    _::Val{:universe}
) -> PlanarCore.Executors.OrderIterator
source
PlanarCore.Executors.ordersMethod

Iterates over all the orders in a strategy.

orders(
    s::PlanarCore.Strategies.Strategy
) -> PlanarCore.Executors.OrderIterator
source
PlanarCore.Executors.ordersMethod

Returns all buy orders for an asset in a strategy.

orders(
    s::PlanarCore.Strategies.Strategy{M, S, E},
    ii,
    _::Union{Type{PlanarCore.OrderTypes.Buy}, PlanarCore.OrderTypes.Buy, Type{<:PlanarCore.OrderTypes.AnyBuyOrder{P, A, E, var"#s1779"} where {var"#s1779"<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, A<:PlanarCore.Instruments.AbstractInstrument, E<:ExchangeID, P<:PlanarCore.Misc.PositionSide}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}}, PlanarCore.OrderTypes.AnyBuyOrder{P, A, E} where {P<:PlanarCore.Misc.PositionSide, A<:PlanarCore.Instruments.AbstractInstrument, E<:ExchangeID}}
) -> SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, PlanarCore.Strategies.BuyPriceTimeOrdering} where D<:(PlanarCore.OrderTypes.AnyBuyOrder{P, T, _A} where {_A, P<:PlanarCore.Misc.PositionSide, T<:PlanarCore.Instruments.AbstractInstrument})
source
PlanarCore.Executors.ordersMethod

Returns all sell orders for an asset in a strategy.

orders(
    s::PlanarCore.Strategies.Strategy{M, S, E},
    ii,
    _::Union{Type{PlanarCore.OrderTypes.Sell}, PlanarCore.OrderTypes.Sell, Type{<:PlanarCore.OrderTypes.AnySellOrder{P, A, E, var"#s1779"} where {var"#s1779"<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}, A<:PlanarCore.Instruments.AbstractInstrument, E<:ExchangeID, P<:PlanarCore.Misc.PositionSide}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Sell}}, PlanarCore.OrderTypes.AnySellOrder{P, A, E} where {P<:PlanarCore.Misc.PositionSide, A<:PlanarCore.Instruments.AbstractInstrument, E<:ExchangeID}}
) -> SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, PlanarCore.Strategies.SellPriceTimeOrdering} where D<:(PlanarCore.OrderTypes.AnySellOrder{P, T, _A} where {_A, P<:PlanarCore.Misc.PositionSide, T<:PlanarCore.Instruments.AbstractInstrument})
source
PlanarCore.Executors.orderscountMethod

Returns the count of orders for an asset in a strategy.

orderscount(
    s::PlanarCore.Strategies.Strategy,
    ii::PlanarCore.Instances.InstrumentInstance,
    _::Type{PlanarCore.OrderTypes.BuyOrSell}
) -> Any
source
PlanarCore.Executors.orderscountMethod

Returns the count of buy orders for an asset in a strategy.

orderscount(
    s::PlanarCore.Strategies.Strategy,
    ii::PlanarCore.Instances.InstrumentInstance,
    _::Type{PlanarCore.OrderTypes.Buy}
) -> Int64
source
PlanarCore.Executors.orderscountMethod

Returns the count of sell orders for an asset in a strategy.

orderscount(
    s::PlanarCore.Strategies.Strategy,
    ii::PlanarCore.Instances.InstrumentInstance,
    _::Type{PlanarCore.OrderTypes.Sell}
) -> Int64
source
PlanarCore.Executors.orderscountMethod

Returns the count of orders for an asset in a strategy.

orderscount(
    s::PlanarCore.Strategies.Strategy,
    ii::PlanarCore.Instances.InstrumentInstance
) -> Any
source
PlanarCore.Executors.orderscountMethod

Returns the count of orders in a strategy.

orderscount(
    s::PlanarCore.Strategies.Strategy,
    _::Union{Type{O}, Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{O}}}, PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{O}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{O}}, O}
) -> Any
source
PlanarCore.Executors.ordershistoryMethod

Returns a unique list of orders from the trade history of a given asset instance.

ordershistory(
    ii::PlanarCore.Instances.InstrumentInstance
) -> Any
source
PlanarCore.Executors.position!Method

Updates the position of the isolated strategy to the given position side at the specified date

position!(
    s::PlanarCore.Strategies.IsolatedStrategy,
    ii,
    date::Dates.DateTime,
    p::PlanarCore.Misc.PositionSide
) -> Any

This function updates the position of the strategy for the asset in question at the given date to the provided position side.

source
PlanarCore.Executors.priceatMethod

The price for an order at a particular date.

priceat(
    _::PlanarCore.Strategies.Strategy,
    _::Type{<:PlanarCore.OrderTypes.Order},
    ii,
    date
) -> Any
source
PlanarCore.Executors.queue!Method

Adds a limit order to the pending orders of the strategy.

queue!(
    s::PlanarCore.Strategies.Strategy,
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.LimitOrderType{S<:PlanarCore.OrderTypes.OrderSide}},
    ii;
    skipcommit
) -> Bool

This function takes a strategy, a limit order of type LimitOrderType{S}, and an asset instance as arguments. It adds the limit order to the pending orders of the strategy. If skipcommit is set to false (default), the order is committed and held. Returns true if the order was successfully added, otherwise false.

source
PlanarCore.Executors.release!Method

An asset is released when there are no orders for it and its balance is zero.

release!(
    s::PlanarCore.Strategies.Strategy,
    ii
) -> Union{Nothing, Set{PlanarCore.Instances.InstrumentInstance{T, E} where T<:PlanarCore.Instruments.AbstractInstrument} where E<:ExchangeID}
source
PlanarCore.Executors.sellordersMethod

Returns sell orders for an asset in a strategy.

sellorders(
    s::PlanarCore.Strategies.Strategy,
    ii
) -> SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, PlanarCore.Strategies.SellPriceTimeOrdering} where D<:(PlanarCore.OrderTypes.AnySellOrder{P, T, E} where {E<:ExchangeID, P<:PlanarCore.Misc.PositionSide, T<:PlanarCore.Instruments.AbstractInstrument})
source
PlanarCore.Executors.shortordersMethod

Returns a generator for short orders matching a given order side

shortorders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    os::Type{<:PlanarCore.OrderTypes.OrderSide}
) -> Base.Generator{I, typeof(identity)} where I<:(Base.Iterators.Filter{PlanarCore.Executors.var"#orders##24#orders##25"{PlanarCore.Misc.Short}})

This function utilizes the orders function to generate orders for the Short position side that match the provided order side.

source
PlanarCore.Executors.sideordersMethod

Returns orders for an asset in a strategy by side.

sideorders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    _::Type{PlanarCore.OrderTypes.Buy}
) -> SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, PlanarCore.Strategies.BuyPriceTimeOrdering} where D<:(PlanarCore.OrderTypes.AnyBuyOrder{P, T, E} where {E<:ExchangeID, P<:PlanarCore.Misc.PositionSide, T<:PlanarCore.Instruments.AbstractInstrument})
source
PlanarCore.Executors.sideordersMethod

Returns orders for an asset in a strategy by side.

sideorders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    _::Type{PlanarCore.OrderTypes.Sell}
) -> SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, PlanarCore.Strategies.SellPriceTimeOrdering} where D<:(PlanarCore.OrderTypes.AnySellOrder{P, T, E} where {E<:ExchangeID, P<:PlanarCore.Misc.PositionSide, T<:PlanarCore.Instruments.AbstractInstrument})
source
PlanarCore.Executors.sideordersMethod

Returns orders for an asset in a strategy by side.

sideorders(
    s::PlanarCore.Strategies.Strategy,
    ii,
    _::Union{Type{S}, Type{<:PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{S}}}, PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{S}}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType{S}}, S}
) -> SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, PlanarCore.Strategies.BuyPriceTimeOrdering} where D<:(PlanarCore.OrderTypes.AnyBuyOrder{P, T, E} where {E<:ExchangeID, P<:PlanarCore.Misc.PositionSide, T<:PlanarCore.Instruments.AbstractInstrument})
source
PlanarCore.Executors.strategycash!Method

Updates the strategy's cash after an increase trade.

strategycash!(
    s::PlanarCore.Strategies.IsolatedStrategy,
    ii,
    t::PlanarCore.OrderTypes.IncreaseTrade
)
source
PlanarCore.Executors.strategycash!Method

Updates the strategy's cash after a reduce trade.

strategycash!(
    s::PlanarCore.Strategies.IsolatedStrategy,
    ii,
    t::PlanarCore.OrderTypes.ReduceTrade
)
source
PlanarCore.Executors.strategycash!Method

Updates the strategy's cash after a buy trade.

strategycash!(
    s::PlanarCore.Strategies.Strategy{X, N, <:ExchangeID, NoMargin, C} where {X<:PlanarCore.Misc.ExecMode, N, C},
    ii,
    t::PlanarCore.OrderTypes.BuyTrade
)
source
PlanarCore.Executors.strategycash!Method

Updates the strategy's cash after a sell trade.

strategycash!(
    s::PlanarCore.Strategies.Strategy{X, N, <:ExchangeID, NoMargin, C} where {X<:PlanarCore.Misc.ExecMode, N, C},
    _,
    t::PlanarCore.OrderTypes.SellTrade
)
source
PlanarCore.Executors.trade!Method

Executes a trade with the given parameters and updates the strategy state.

trade!(
    s::PlanarCore.Strategies.Strategy,
    o,
    ii;
    date,
    price,
    actual_amount,
    fees,
    slippage,
    kwargs...
)

This function executes a trade based on the given order and asset instance. It calculates the actual price, creates a trade using the maketrade function, and updates the strategy and asset instance. If the trade cannot be executed (e.g., not enough cash), the function updates the state as if the order was filled without creating a trade. The function returns the created trade or nothing if the trade could not be executed.

source
PlanarCore.Executors.update_maintenance!Method

Updates leverage based on position state.

update_maintenance!(
    po::PlanarCore.Instances.Position;
    ntl,
    mmr
) -> Float64

This function updates the leverage of a position based on its current state, using the provided leverage, price, and maintenance margin ratio.

source
PlanarCore.Executors.update_notional!Method

Updates notional value.

update_notional!(
    po::PlanarCore.Instances.Position;
    ntl,
    size
)

This function updates the notional value of a position using the provided notional amount and size.

source
PlanarCore.Executors.update_price!Method

Update the entry price from notional, amount diff and cash.

update_price!(
    po::PlanarCore.Instances.Position;
    ntl,
    prev_ntl,
    size
)

This function calculates the new entry price of a position using the notional amount, the difference in amount, and the cash in the position.

source
PlanarCore.Executors.withtrade!Method

Update position price, notional and leverage from a new trade.

withtrade!(
    po::PlanarCore.Instances.Position{P},
    t::PlanarCore.OrderTypes.Trade{O, A, E, P} where {O<:PlanarCore.OrderTypes.OrderType, A<:PlanarCore.Instruments.AbstractInstrument, E<:ExchangeID};
    settle_price
) -> Union{Nothing, Float64}

This function adjusts the price, notional value, and leverage of a position based on a new trade at the given settlement price.

source
PlanarCore.Instances.committedMethod

Returns the committed amount of a short buy order.

committed(
    o::PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType{PlanarCore.OrderTypes.Buy}, var"#s1779", var"#s1778", PlanarCore.Misc.Short} where {var"#s1779"<:PlanarCore.Instruments.AbstractInstrument, var"#s1778"<:ExchangeID}
) -> Any
source
PlanarCore.Instances.committedMethod

Calculates the committed amount for a given position

committed(
    s::PlanarCore.Strategies.Strategy{X, N, <:ExchangeID, <:PlanarCore.Misc.WithMargin, C} where {X<:PlanarCore.Misc.ExecMode, N, C},
    ii::PlanarCore.Instances.InstrumentInstance{<:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, M} where M<:PlanarCore.Misc.WithMargin,
    _::Union{Type{P}, Type{O} where O<:(PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, P}), Type{T} where T<:(PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, P}), PlanarCore.OrderTypes.Order{<:PlanarCore.OrderTypes.OrderType, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, P}, PlanarCore.OrderTypes.Trade{<:PlanarCore.OrderTypes.OrderType, <:PlanarCore.Instruments.AbstractInstrument, <:ExchangeID, P}, P}
) -> Float64

This function sums the amounts of all the orders that match the given position in the Margin Strategy.

source
PlanarCore.Instances.isdustMethod

Checks if the order committed value is below minimum quantity.

isdust(
    ii::PlanarCore.Instances.InstrumentInstance,
    o::PlanarCore.OrderTypes.Order
) -> Bool
source
PlanarCore.Instances.liqpriceMethod

Calculates the liquidation price of a position

liqprice(
    p::PlanarCore.Misc.PositionSide,
    entryprice,
    leverage,
    mmr;
    additional,
    notional
) -> Any

This function calculates the price at which a position would be liquidated, given the entry price, leverage, maintenance margin ratio, additional margin, and notional value.

source
PlanarCore.Instruments.cash!Method

Updates the strategy's and asset instance's cash after a trade.

cash!(
    s::PlanarCore.Strategies.Strategy,
    ii,
    t::PlanarCore.OrderTypes.Trade
)
source
PlanarCore.Misc.reset!Method

Resets an order committment and unfilled amount.

reset!(o::PlanarCore.OrderTypes.Order, ii) -> Float64
source
PlanarCore.OrderTypes.commit!Method

Commits a reduce order to an asset instance.

commit!(
    _::PlanarCore.Strategies.Strategy,
    o::PlanarCore.OrderTypes.ReduceOrder,
    ii
) -> Any
source

See Also