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.AnyFOKOrder — Type
Type alias for any FOK order
PlanarCore.Executors.AnyGTCOrder — Type
Type alias for any GTC order
PlanarCore.Executors.AnyIOCOrder — Type
Type alias for any IOC order
PlanarCore.Executors.IncreaseLimitOrder — Type
Union type representing limit order increase operations. Includes Buy and Sell Short orders.
PlanarCore.Executors.IncreaseLimitTrade — Type
Union type representing limit trade increase operations. Includes Buy and Sell Short trades.
PlanarCore.Executors.LIQUIDATION_BUFFER — Constant
Some exchanges add funding rates and trading fees to the liquidation price, we use a default buffer of -0.02.
PlanarCore.Executors.ReduceLimitOrder — Type
Union type representing limit order reduction operations. Includes Sell and Buy Short orders.
PlanarCore.Executors.ReduceLimitTrade — Type
Union type representing limit trade reduction operations. Includes Sell and Buy Short trades.
PlanarCore.Executors.AnyLimitOrder — Type
Type alias for any limit order
PlanarCore.Executors.AnyMarketOrder — Type
Type alias for any market order
PlanarCore.Executors.AnyPostOnlyOrder — Type
Type alias for any post only order
PlanarCore.Executors.CancelOrders — Type
Action to cancel open orders.
PlanarCore.Executors.Context — Type
The configuration against which a strategy is tested.
The Context struct has the following type parameter:
M: a subtype ofExecMode.
The struct has the following fields:
range: The date range to backtest around.
PlanarCore.Executors.Context — Method
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 subtypeExecMode.
PlanarCore.Executors.InitData — Type
Action to initialize OHLCV data.
PlanarCore.Executors.LimitBuyTrade — Type
Type representing a limit buy trade, specific to long position buy limit orders.
PlanarCore.Executors.LimitSellTrade — Type
Type representing a limit sell trade, specific to long position sell limit orders.
PlanarCore.Executors.LimitTrade — Type
Type representing a limit trade, includes long position limit orders.
PlanarCore.Executors.LongMarketBuyTrade — Type
Defines a long market buy trade type.
PlanarCore.Executors.LongMarketSellTrade — Type
Represents a long market sell trade on a certain exchange for a specific asset.
PlanarCore.Executors.NewTrade — Type
Action executed after a new trade occurs.
PlanarCore.Executors.OptMinimize — Type
Action to indicate if the optimization is a minimization problem.
PlanarCore.Executors.OptRun — Type
Action run before a single simulation during optimization.
PlanarCore.Executors.OptScore — Type
Action to get the score of a single simulation (after it has finished).
PlanarCore.Executors.OptSetup — Type
Action to setup an optimizer (context and params).
PlanarCore.Executors.OrderIterator — Type
A data structure for maintaining a collection of iterators.
iters
PlanarCore.Executors.ShortLimitBuyTrade — Type
Type representing a short limit buy trade, specific to short position buy limit orders.
PlanarCore.Executors.ShortLimitSellTrade — Type
Type representing a short limit sell trade, specific to short position sell limit orders.
PlanarCore.Executors.ShortLimitTrade — Type
Type representing a short limit trade, includes short position limit orders.
PlanarCore.Executors.UpdateData — Type
Action to update OHLCV data (from watchers).
PlanarCore.Executors.UpdateLeverage — Type
Action to update leverage.
PlanarCore.Executors.UpdateMargin — Type
Action to update margin mode.
PlanarCore.Executors.UpdateOrders — Type
(DEPRECATED) order updates are done internally now.
PlanarCore.Executors.UpdateOrdersShuffled — Type
(DEPRECATED) The shuffled version of UpdateOrders.
PlanarCore.Executors.UpdatePositions — Type
Action to update positions size.
PlanarCore.Executors.WatchOHLCV — Type
Action to setup an OHLCV watcher.
Base.collect — Method
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}}
Base.count — Method
Counts the number of elements in the OrderIterator.
count(oi::PlanarCore.Executors.OrderIterator) -> Int64
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}
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}
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}
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
Base.delete! — Method
Removes all buy and sell orders for an asset instance.
delete!(
s::PlanarCore.Strategies.Strategy,
ii,
_::Type{PlanarCore.OrderTypes.BuyOrSell}
) -> Any
Base.delete! — Method
Removes all orders for an asset instance.
delete!(s::PlanarCore.Strategies.Strategy, ii) -> Any
Base.eltype — Method
Returns the element type of the OrderIterator.
eltype(
_::PlanarCore.Executors.OrderIterator
) -> Type{Pair{@NamedTuple{price::Float64, time::Dates.DateTime}, <:PlanarCore.OrderTypes.Order}}
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
)
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
)
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
)
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
)
Base.first — Method
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
Base.firstindex — Method
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
Base.haskey — Method
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
Base.haskey — Method
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
Base.haskey — Method
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
Base.haskey — Method
Checks if a strategy has a specific order for an asset.
haskey(
s::PlanarCore.Strategies.Strategy,
ii,
o::PlanarCore.OrderTypes.Order
) -> Bool
Base.isdone — Method
Checks if the OrderIterator is empty.
isdone(oi::PlanarCore.Executors.OrderIterator) -> Bool
Base.isopen — Method
Checks if an order is open.
isopen(
ii::PlanarCore.Instances.InstrumentInstance,
o::PlanarCore.OrderTypes.Order
) -> Any
Base.iszero — Method
Checks if the order amount left to fill is below minimum qty.
iszero(
ii::PlanarCore.Instances.InstrumentInstance,
o::PlanarCore.OrderTypes.Order
) -> Any
Base.iterate — Method
Returns the next element in the OrderIterator.
iterate(
oi::PlanarCore.Executors.OrderIterator,
_
) -> Union{Nothing, Tuple{Any, Nothing}}
Base.keys — Method
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}
Base.lastindex — Method
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
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
Base.values — Method
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}
PlanarCore.Executors.Checks.cost — Method
Returns the cost of an order.
cost(o::PlanarCore.OrderTypes.Order) -> Float64
PlanarCore.Executors._check_cash — Method
Checks the cash for an asset instance in a strategy for long.
_check_cash(
ii::PlanarCore.Instances.InstrumentInstance,
_::PlanarCore.Misc.Long
)
PlanarCore.Executors._check_cash — Method
Checks the cash for an asset instance in a strategy for short.
_check_cash(
ii::PlanarCore.Instances.InstrumentInstance,
_::PlanarCore.Misc.Short
)
PlanarCore.Executors._check_committment — Method
Checks order committment to be within expected values.
_check_committment(o)
PlanarCore.Executors._check_trade — Method
Checks a buy trade.
_check_trade(t::PlanarCore.OrderTypes.BuyTrade, ii)
PlanarCore.Executors._check_trade — Method
Checks a sell trade.
_check_trade(t::PlanarCore.OrderTypes.SellTrade, ii)
PlanarCore.Executors._check_trade — Method
Checks a short buy trade.
_check_trade(t::PlanarCore.OrderTypes.ShortBuyTrade, ii)
PlanarCore.Executors._check_trade — Method
Checks a short sell trade.
_check_trade(t::PlanarCore.OrderTypes.ShortSellTrade, ii)
PlanarCore.Executors._check_unfillment — Method
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
PlanarCore.Executors._check_unfillment — Method
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
PlanarCore.Executors._check_unfillment — Method
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
PlanarCore.Executors._check_unfillment — Method
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
PlanarCore.Executors._check_unfillment — Method
Checks if the unfilled amount for a long order is positive.
_check_unfillment(o::PlanarCore.OrderTypes.LongOrder) -> Any
PlanarCore.Executors._check_unfillment — Method
Checks if the unfilled amount for a short order is negative.
_check_unfillment(
o::PlanarCore.OrderTypes.ShortOrder
) -> Any
PlanarCore.Executors._do_orders_iter — Method
Filters out empty iterators and returns the smallest value.
_do_orders_iter(oi) -> Union{Nothing, Tuple{Any, Nothing}}
PlanarCore.Executors._doclamp — Method
Clamps the given values within the correct boundaries.
_doclamp(clamper, ii, whats...) -> Expr
PlanarCore.Executors._findmin — Method
Finds and returns the iterator with the smallest value.
_findmin(non_empty_iters) -> Tuple{Any, Any}
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.
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.
PlanarCore.Executors.aftertrade! — Function
Performs cleanups after a trade (attempt).
aftertrade!(s, ii, o) -> Any
aftertrade!(s, ii, o, t) -> Any
PlanarCore.Executors.amount — Method
Returns the amount of an order.
amount(o::PlanarCore.OrderTypes.Order) -> Float64
PlanarCore.Executors.basic_order_state — Method
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}}}}
PlanarCore.Executors.basicorder — Method
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
)
PlanarCore.Executors.buyorders — Method
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})
PlanarCore.Executors.cancel! — Method
Cancels an order with given error.
cancel!(
s::PlanarCore.Strategies.Strategy,
o::PlanarCore.OrderTypes.Order,
ii;
err
)
PlanarCore.Executors.committment — Method
Calculates the commitment for an order.
committment(
ii::PlanarCore.Instances.InstrumentInstance,
o::PlanarCore.OrderTypes.Order;
kwargs...
) -> Any
PlanarCore.Executors.committment — Method
Calculates the partial commitment of a trade.
committment(
ii::PlanarCore.Instances.InstrumentInstance,
t::PlanarCore.OrderTypes.Trade
) -> Any
PlanarCore.Executors.committment — Method
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
PlanarCore.Executors.committment — Method
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
PlanarCore.Executors.committment — Method
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
PlanarCore.Executors.committment — Method
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
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
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
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
PlanarCore.Executors.feespaid — Method
The sum of all the trades fees that have heppened for the order.
feespaid(o::PlanarCore.OrderTypes.Order) -> Any
PlanarCore.Executors.filled_amount — Method
Returns the filled amount of an order.
filled_amount(o) -> Any
PlanarCore.Executors.hascash — Method
Checks if any of the holdings has non dust cash.
hascash(s::PlanarCore.Strategies.Strategy) -> Bool
PlanarCore.Executors.hasorders — Method
Checks if an asset instance has pending orders in a strategy.
hasorders(
s::PlanarCore.Strategies.Strategy,
ii::PlanarCore.Instances.InstrumentInstance
) -> Bool
PlanarCore.Executors.hasorders — Method
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.
PlanarCore.Executors.hasorders — Method
Checks if a strategy has orders.
hasorders(s::PlanarCore.Strategies.Strategy) -> Any
PlanarCore.Executors.hasorders — Method
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
PlanarCore.Executors.hasorders — Method
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
PlanarCore.Executors.hasorders — Method
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
PlanarCore.Executors.hastrade — Method
More precise version of hastrade.
PlanarCore.Executors.hastrade — Method
Check if the given trade is in the order.
hastrade(
o::PlanarCore.OrderTypes.Order,
t::PlanarCore.OrderTypes.Trade
) -> Bool
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
PlanarCore.Executors.hold! — Method
Reduce orders can never switch an asset from not held to held.
hold!(
_::PlanarCore.Strategies.Strategy,
_,
_::PlanarCore.OrderTypes.ReduceOrder
)
PlanarCore.Executors.iscommittable — Method
Checks if an increase order can be committed to a strategy.
iscommittable(
s::PlanarCore.Strategies.Strategy,
o::PlanarCore.OrderTypes.IncreaseOrder,
ii
) -> Any
PlanarCore.Executors.iscommittable — Method
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
PlanarCore.Executors.iscommittable — Method
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
PlanarCore.Executors.iscommittable — Method
Checks if a strategy can commit to an increase order.
iscommittable(
s::PlanarCore.Strategies.Strategy,
_::Type{<:PlanarCore.OrderTypes.IncreaseOrder},
commit,
ii
) -> Any
PlanarCore.Executors.iscommittable — Method
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
PlanarCore.Executors.iscommittable — Method
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
PlanarCore.Executors.isfilled — Method
Checks if an order is filled.
isfilled(
ii::PlanarCore.Instances.InstrumentInstance,
o::PlanarCore.OrderTypes.Order
) -> Any
PlanarCore.Executors.isfirstfill — Method
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
PlanarCore.Executors.islastfill — Method
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
PlanarCore.Executors.isliquidatable — Method
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.
PlanarCore.Executors.isliquidatable — Method
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.
PlanarCore.Executors.isoutof_orders — Method
Checks if a strategy is out of orders.
isoutof_orders(s::PlanarCore.Strategies.Strategy) -> Any
PlanarCore.Executors.isqueued — Method
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
PlanarCore.Executors.limitorder — Method
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.
PlanarCore.Executors.liquidations — Method
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.
PlanarCore.Executors.longorders — Method
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.
PlanarCore.Executors.marketorder — Method
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.
PlanarCore.Executors.order_byid — Method
Returns the order that matches the given id (if any).
order_byid(
s::PlanarCore.Strategies.Strategy,
ii::PlanarCore.Instances.InstrumentInstance,
id::String
) -> Any
PlanarCore.Executors.orders — Method
Returns all orders for an asset instance in a strategy.
orders(
s,
ii,
_::Type{PlanarCore.OrderTypes.BuyOrSell}
) -> Any
PlanarCore.Executors.orders — Method
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.
PlanarCore.Executors.orders — Method
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.
PlanarCore.Executors.orders — Method
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}))
PlanarCore.Executors.orders — Method
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})}
PlanarCore.Executors.orders — Method
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
PlanarCore.Executors.orders — Method
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
PlanarCore.Executors.orders — Method
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
PlanarCore.Executors.orders — Method
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}))
PlanarCore.Executors.orders — Method
Iterates over all the orders in a strategy (all the assets in the universe).
orders(
s::PlanarCore.Strategies.Strategy,
_::Val{:universe}
) -> PlanarCore.Executors.OrderIterator
PlanarCore.Executors.orders — Method
Iterates over all the orders in a strategy.
orders(
s::PlanarCore.Strategies.Strategy
) -> PlanarCore.Executors.OrderIterator
PlanarCore.Executors.orders — Method
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})
PlanarCore.Executors.orders — Method
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})
PlanarCore.Executors.orderscount — Method
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
PlanarCore.Executors.orderscount — Method
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
PlanarCore.Executors.orderscount — Method
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
PlanarCore.Executors.orderscount — Method
Returns the count of orders for an asset in a strategy.
orderscount(
s::PlanarCore.Strategies.Strategy,
ii::PlanarCore.Instances.InstrumentInstance
) -> Any
PlanarCore.Executors.orderscount — Method
Returns the count of pending entry orders in a strategy.
orderscount(
s::PlanarCore.Strategies.Strategy,
_::Val{:increase}
) -> Any
PlanarCore.Executors.orderscount — Method
Returns the count of pending exit orders in a strategy.
orderscount(
s::PlanarCore.Strategies.Strategy,
_::Val{:reduce}
) -> Any
PlanarCore.Executors.orderscount — Method
Returns the total count of pending orders in a strategy.
orderscount(s::PlanarCore.Strategies.Strategy) -> Any
PlanarCore.Executors.orderscount — Method
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
PlanarCore.Executors.ordershistory — Method
Returns a unique list of orders from the trade history of a given asset instance.
ordershistory(
ii::PlanarCore.Instances.InstrumentInstance
) -> Any
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.
PlanarCore.Executors.position! — Method
Non margin strategies don't have positions.
PlanarCore.Executors.priceat — Method
The price for an order at a particular date.
priceat(
_::PlanarCore.Strategies.Strategy,
_::Type{<:PlanarCore.OrderTypes.Order},
ii,
date
) -> Any
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.
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}
PlanarCore.Executors.sellorders — Method
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})
PlanarCore.Executors.shortorders — Method
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.
PlanarCore.Executors.sideorders — Method
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})
PlanarCore.Executors.sideorders — Method
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})
PlanarCore.Executors.sideorders — Method
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})
PlanarCore.Executors.strategycash! — Method
Updates the strategy's cash after an increase trade.
strategycash!(
s::PlanarCore.Strategies.IsolatedStrategy,
ii,
t::PlanarCore.OrderTypes.IncreaseTrade
)
PlanarCore.Executors.strategycash! — Method
Updates the strategy's cash after a reduce trade.
strategycash!(
s::PlanarCore.Strategies.IsolatedStrategy,
ii,
t::PlanarCore.OrderTypes.ReduceTrade
)
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
)
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
)
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.
PlanarCore.Executors.unfilled — Method
Returns the absolute value of the unfilled amount of an order.
unfilled(o::PlanarCore.OrderTypes.Order) -> Any
PlanarCore.Executors.unfillment — Method
Calculates the unfulfilled amount for an order.
unfillment(o::PlanarCore.OrderTypes.Order) -> Float64
PlanarCore.Executors.unfillment — Method
Calculates the unfulfilled amount for a buy order.
unfillment(
t::Type{<:PlanarCore.OrderTypes.AnyBuyOrder},
amount
) -> Any
PlanarCore.Executors.unfillment — Method
Calculates the unfulfilled amount for a sell order.
unfillment(
t::Type{<:PlanarCore.OrderTypes.AnySellOrder},
amount
) -> Any
PlanarCore.Executors.update_leverage! — Method
Updates leverage based on position state.
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.
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.
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.
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.
PlanarCore.Instances.committed — Method
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
PlanarCore.Instances.committed — Method
Returns the committed amount of an order.
committed(o::PlanarCore.OrderTypes.Order) -> Any
PlanarCore.Instances.committed — Method
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.
PlanarCore.Instances.isdust — Method
Checks if the order committed value is below minimum quantity.
isdust(
ii::PlanarCore.Instances.InstrumentInstance,
o::PlanarCore.OrderTypes.Order
) -> Bool
PlanarCore.Instances.liqprice — Method
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.
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
)
PlanarCore.Misc.attr — Method
Returns the attribute of an order.
attr(o::PlanarCore.OrderTypes.Order, sym) -> Any
PlanarCore.Misc.reset! — Method
Resets an order committment and unfilled amount.
reset!(o::PlanarCore.OrderTypes.Order, ii) -> Float64
PlanarCore.OrderTypes.commit! — Method
Commits an increase order to a strategy.
commit!(
s::PlanarCore.Strategies.Strategy,
o::PlanarCore.OrderTypes.IncreaseOrder,
_
)
PlanarCore.OrderTypes.commit! — Method
Commits a reduce order to an asset instance.
commit!(
_::PlanarCore.Strategies.Strategy,
o::PlanarCore.OrderTypes.ReduceOrder,
ii
) -> Any
PlanarCore.OrderTypes.trades — Method
Returns the trades of an order.
trades(o::PlanarCore.OrderTypes.Order) -> Any
PlanarCore.Executors.@amount! — Macro
Ensures the amount is within correct boundaries.
PlanarCore.Executors.@price! — Macro
Ensures the price is within correct boundaries.
See Also
- Strategies API - Strategy base classes and interfaces
- OrderTypes API - Order types and structures
- Engine API - Core execution engine functions
- Instances API - Asset instance management
- Strategy Development Guide - Building trading strategies
- Execution Modes Guide - Understanding different execution modes