Executors

Executors.LIQUIDATION_BUFFERConstant

Some exchanges add funding rates and trading fees to the liquidation price, we use a default buffer of -0.02.

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.
Executors.ContextMethod

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

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

The Context function takes the following parameters:

  • s: a Strategy object of subtype ExecMode.
Executors.OptRunType

Action run before a single simulation during optimization.

Executors.OptScoreType

Action to get the score of a single simulation (after it has finished).

Base.collectMethod

Collects all elements of the OrderIterator into a Vector.

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

Counts the number of elements in the OrderIterator.

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

Removes a single order from the order queue.

delete!(
    s::Strategies.Strategy,
    ai,
    o::OrderTypes.IncreaseOrder
) -> Union{Nothing, Set{Instances.AssetInstance{T, E} where T<:AbstractAsset} where E<:ExchangeID}
Base.delete!Method

Removes a single short buy order from the order queue.

delete!(
    s::Strategies.Strategy,
    ai,
    o::OrderTypes.Order{<:OrderTypes.OrderType{OrderTypes.Buy}, A, E, Misc.Short} where {A, E}
) -> Union{Nothing, Set{Instances.AssetInstance{T, E} where T<:AbstractAsset} where E<:ExchangeID}
Base.delete!Method

Removes a single sell order from the order queue.

delete!(
    s::Strategies.Strategy,
    ai,
    o::OrderTypes.Order{<:OrderTypes.OrderType{OrderTypes.Sell}, A, E, Misc.Long} where {A, E}
) -> Union{Nothing, Set{Instances.AssetInstance{T, E} where T<:AbstractAsset} where E<:ExchangeID}
Base.delete!Method

Removes all buy/sell orders for an asset instance.

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

Removes all buy and sell orders for an asset instance.

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

Removes all orders for an asset instance.

delete!(s::Strategies.Strategy, ai) -> Any
Base.eltypeMethod

Returns the element type of the OrderIterator.

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

Fills a short buy order.

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

Fills a sell order.

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

Fills a buy order for a no-margin strategy.

fill!(
    _::Strategies.Strategy{<:Union{Misc.Paper, Misc.Sim}},
    ai::Instances.AssetInstance{<:AbstractAsset, <:ExchangeID, NoMargin},
    o::OrderTypes.Order{<:OrderTypes.OrderType{OrderTypes.Buy}, A, E, Misc.Long} where {A, E},
    t::OrderTypes.BuyTrade
)
Base.fill!Method

Fills an increase order for a margin strategy.

fill!(
    _::Strategies.Strategy{var"#s238", N, <:ExchangeID, <:Misc.WithMargin, C} where {var"#s238"<:Union{Misc.Paper, Misc.Sim}, N, C},
    ai::Instances.AssetInstance{<:AbstractAsset, <:ExchangeID, M} where M<:Misc.WithMargin,
    o::OrderTypes.IncreaseOrder,
    t::OrderTypes.IncreaseTrade
)
Base.firstMethod

Returns the first order for an asset in a strategy.

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

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

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

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

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

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

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

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

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

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

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

Checks if the OrderIterator is empty.

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

Checks if an order is open.

isopen(
    ai::Instances.AssetInstance,
    o::OrderTypes.Order
) -> Any
Base.iszeroMethod

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

iszero(
    ai::Instances.AssetInstance,
    o::OrderTypes.Order
) -> Any
Base.iterateMethod

Returns the next element in the OrderIterator.

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

Returns all keys for orders in a strategy.

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

Returns the last element in the OrderIterator.

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

Returns the last order for an asset in a strategy.

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

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

lastindex(s::Strategies.Strategy{M, S, E}, ai) -> Any
lastindex(
    s::Strategies.Strategy{M, S, E},
    ai,
    bs::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::Strategies.Strategy,
    ai,
    o::OrderTypes.Order{<:OrderTypes.OrderType{S<:OrderTypes.OrderSide}}
) -> OrderTypes.Order{<:OrderTypes.OrderType{S}} where S<:OrderTypes.OrderSide
Base.valuesMethod

Returns all values for orders in a strategy.

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

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

_check_cash(ai::Instances.AssetInstance, _::Misc.Long)
Executors._check_cashMethod

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

_check_cash(ai::Instances.AssetInstance, _::Misc.Short)
Executors._check_unfillmentMethod

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

_check_unfillment(
    o::OrderTypes.AnyBuyOrder{P, <:AbstractAsset, <:ExchangeID, var"#s1940"} where {P<:Misc.PositionSide, var"#s1940"<:OrderTypes.LimitOrderType{OrderTypes.Buy}}
) -> Any
Executors._check_unfillmentMethod

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

_check_unfillment(
    o::OrderTypes.AnyBuyOrder{P, <:AbstractAsset, <:ExchangeID, var"#s1940"} where {P<:Misc.PositionSide, var"#s1940"<:OrderTypes.MarketOrderType{OrderTypes.Buy}}
) -> Any
Executors._check_unfillmentMethod

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

_check_unfillment(
    o::OrderTypes.AnySellOrder{P, <:AbstractAsset, <:ExchangeID, var"#s1940"} where {P<:Misc.PositionSide, var"#s1940"<:OrderTypes.LimitOrderType{OrderTypes.Sell}}
) -> Any
Executors._check_unfillmentMethod

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

_check_unfillment(
    o::OrderTypes.AnySellOrder{P, <:AbstractAsset, <:ExchangeID, var"#s1940"} where {P<:Misc.PositionSide, var"#s1940"<:OrderTypes.MarketOrderType{OrderTypes.Sell}}
) -> Any
Executors._check_unfillmentMethod

Checks if the unfilled amount for a long order is positive.

_check_unfillment(o::OrderTypes.LongOrder) -> Any
Executors._check_unfillmentMethod

Checks if the unfilled amount for a short order is negative.

_check_unfillment(o::OrderTypes.ShortOrder) -> Any
Executors._do_orders_iterMethod

Filters out empty iterators and returns the smallest value.

_do_orders_iter(oi) -> Union{Nothing, Tuple{Any, Nothing}}
Executors._doclampMethod

Clamps the given values within the correct boundaries.

_doclamp(clamper, ai, whats...) -> Expr
Executors._findminMethod

Finds and returns the iterator with the smallest value.

_findmin(non_empty_iters) -> Tuple{Any, Any}
Executors.aftertrade!Function

Unconditionally dequeues immediate orders.

aftertrade!(
    s::Strategies.Strategy,
    ai,
    o::Union{OrderTypes.Order{<:OrderTypes.MarketOrderType{S}, <:AbstractAsset, <:ExchangeID, P} where {S<:OrderTypes.OrderSide, P<:Misc.PositionSide}, OrderTypes.FOKOrder, OrderTypes.IOCOrder, OrderTypes.ShortFOKOrder, OrderTypes.ShortIOCOrder}
) -> Any
aftertrade!(
    s::Strategies.Strategy,
    ai,
    o::Union{OrderTypes.Order{<:OrderTypes.MarketOrderType{S}, <:AbstractAsset, <:ExchangeID, P} where {S<:OrderTypes.OrderSide, P<:Misc.PositionSide}, OrderTypes.FOKOrder, OrderTypes.IOCOrder, OrderTypes.ShortFOKOrder, 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.

Executors.aftertrade!Function

Removes a filled limit order from the queue

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

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

Executors.aftertrade!Function

Performs cleanups after a trade (attempt).

aftertrade!(s, ai, o) -> Any
aftertrade!(s, ai, o, t) -> Any
Executors.amountMethod

Returns the amount of an order.

amount(o::OrderTypes.Order) -> Float64
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{OrderTypes.Trade}}, Tuple{Nothing, Real, Ref{T}, Ref{T}, Vector{OrderTypes.Trade}}, Tuple{Real, Nothing, Ref{T}, Ref{T}, Vector{OrderTypes.Trade}}, Tuple{Real, Real, Ref{T}, Ref{T}, Vector{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{OrderTypes.Trade}}, Tuple{Nothing, Real, Ref{T}, Ref{T}, Vector{OrderTypes.Trade}}, Tuple{Real, Nothing, Ref{T}, Ref{T}, Vector{OrderTypes.Trade}}, Tuple{Real, Real, Ref{T}, Ref{T}, Vector{OrderTypes.Trade}}}}
Executors.basicorderMethod

Constructs an Order for a given OrderType type and inputs.

basicorder(
    ai::Instances.AssetInstance,
    price,
    amount,
    committed,
    ::Executors.Checks.SanitizeOff;
    type,
    date,
    loss,
    profit,
    id,
    tag
)
Executors.buyordersMethod

Returns buy orders for an asset in a strategy.

buyorders(
    s::Strategies.Strategy,
    ai
) -> SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, Strategies.BuyPriceTimeOrdering} where D<:(OrderTypes.AnyBuyOrder{P, T, E} where {E<:ExchangeID, P<:Misc.PositionSide, T<:AbstractAsset})
Executors.cancel!Method

Cancels an order with given error.

cancel!(
    s::Strategies.Strategy,
    o::OrderTypes.Order,
    ai;
    err
)
Executors.committmentMethod

Calculates the commitment for an order.

committment(
    ai::Instances.AssetInstance,
    o::OrderTypes.Order;
    kwargs...
) -> Any
Executors.committmentMethod

Calculates the partial commitment of a trade.

committment(
    ai::Instances.AssetInstance,
    t::OrderTypes.Trade
) -> Any
Executors.committmentMethod

Calculates the commitment for a leveraged position.

committment(
    o::Type{<:OrderTypes.IncreaseOrder},
    ai::Instances.AssetInstance{<:AbstractAsset, <:ExchangeID, M} where M<:Misc.WithMargin,
    price,
    amount;
    ntl,
    fees,
    lev,
    kwargs...
) -> Any
Executors.committmentMethod

Calculates the commitment for an increase order without margin.

committment(
    ::Type{<:OrderTypes.IncreaseOrder},
    ai::Instances.AssetInstance{<:AbstractAsset, <:ExchangeID, NoMargin},
    price,
    amount;
    kwargs...
) -> Any
Executors.committmentMethod

Calculates the commitment when exiting a position for shorts.

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

Calculates the commitment when exiting a position for longs.

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

Decommits an increase order from a strategy.

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

Decommits a short buy order from an asset instance.

decommit!(
    s::Strategies.Strategy,
    o::OrderTypes.Order{<:OrderTypes.OrderType{OrderTypes.Buy}, A, E, Misc.Short} where {A, E},
    ai,
    args...
)
Executors.decommit!Method

Decommits a sell order from an asset instance.

decommit!(
    s::Strategies.Strategy,
    o::OrderTypes.Order{<:OrderTypes.OrderType{OrderTypes.Sell}, A, E, Misc.Long} where {A, E},
    ai,
    args...
)
Executors.feespaidMethod

The sum of all the trades fees that have heppened for the order.

feespaid(o::OrderTypes.Order) -> Any
Executors.hascashMethod

Checks if any of the holdings has non dust cash.

hascash(s::Strategies.Strategy) -> Bool
Executors.hasordersMethod

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

hasorders(
    s::Strategies.Strategy,
    ai::Instances.AssetInstance
) -> Bool
Executors.hasordersMethod

Checks if there are any orders for a given position side

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

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

Executors.hasordersMethod

Checks if a strategy has orders.

hasorders(s::Strategies.Strategy) -> Any
Executors.hasordersMethod

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

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

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

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

Checks if a strategy has sell orders.

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

Check if the given trade is in the order.

hastrade(o::OrderTypes.Order, t::OrderTypes.Trade) -> Bool
Executors.hold!Method

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

hold!(
    s::Strategies.Strategy,
    ai,
    o::OrderTypes.IncreaseOrder
) -> Set{Instances.AssetInstance{T, E} where T<:AbstractAsset} where E<:ExchangeID
Executors.hold!Method

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

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

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

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

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

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

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

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

Checks if a strategy can commit to an increase order.

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

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

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

Checks if a strategy can commit to a sell order.

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

Checks if an order is filled.

isfilled(
    ai::Instances.AssetInstance,
    o::OrderTypes.Order
) -> Any
Executors.isfirstfillMethod

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

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

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

islastfill(
    ai::Instances.AssetInstance,
    t::OrderTypes.Trade{<:OrderTypes.LimitOrderType}
) -> Any
Executors.isliquidatableMethod

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

isliquidatable(
    _::Strategies.RTStrategy,
    ai::Instances.AssetInstance{<:AbstractAsset, <:ExchangeID, M} where M<:Misc.WithMargin,
    p::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.

Executors.isliquidatableMethod

Checks if a position is liquidatable at a given date

isliquidatable(
    _::Strategies.SimStrategy,
    ai::Instances.AssetInstance{<:AbstractAsset, <:ExchangeID, M} where M<:Misc.WithMargin,
    p::Misc.PositionSide,
    date::Dates.DateTime
) -> Any

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

Executors.isqueuedMethod

Checks if an order is already added to the queue.

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

Places a limit order in the strategy

limitorder(
    s::Strategies.Strategy,
    ai,
    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.

Executors.liquidationsMethod

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

liquidations(
    ai::Instances.AssetInstance{<:AbstractAsset, <:ExchangeID, M} where M<:Misc.WithMargin
) -> @NamedTuple{long::Vector{OrderTypes.Trade}, long_loss::Float64, short::Vector{OrderTypes.Trade}, short_loss::Float64}

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

Executors.longordersMethod

Returns a generator for long orders matching a given order side

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

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

Executors.marketorderMethod

Executes a market order.

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

This function takes a strategy, an ai, 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.

Executors.order_byidMethod

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

order_byid(
    s::Strategies.Strategy,
    ai::Instances.AssetInstance,
    id::String
) -> Any
Executors.ordersMethod

Returns all orders for an asset instance in a strategy.

orders(s, ai, _::Type{OrderTypes.BuyOrSell}) -> Any
Executors.ordersMethod

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

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

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

Executors.ordersMethod

Returns a generator for orders matching a given position side

orders(
    s::Strategies.Strategy,
    ai,
    pos::Misc.PositionSide
) -> Base.Iterators.Flatten{I} where I<:(Base.Generator{Tuple{DataType, DataType}, F} where F<:(Executors.var"#96#97"{Strategies.Strategy{X, N, E, M, C}, _A, <:Misc.PositionSide} where {X<:Misc.ExecMode, N, E<:ExchangeID, M<:Misc.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.

Executors.ordersMethod

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

orders(
    s::Strategies.Strategy,
    ai::Instances.AssetInstance,
    _::Val{:orderless}
) -> Base.Iterators.Flatten{I} where I<:(Base.Generator{Tuple{DataType, DataType}, F} where F<:(Executors.var"#50#51"{Strategies.Strategy{X, N, E, M, C}, Instances.AssetInstance{T, E1, M1}} where {X<:Misc.ExecMode, N, E<:ExchangeID, M<:Misc.MarginMode, C, T<:AbstractAsset, E1<:ExchangeID, M1<:Misc.MarginMode}))
Executors.ordersMethod

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

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

Returns all buy orders for a strategy.

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

Returns all sell orders for a strategy.

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

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

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

Iterates over all the orderless orders in a strategy.

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

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

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

Iterates over all the orders in a strategy.

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

Returns all buy orders for an asset in a strategy.

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

Returns all sell orders for an asset in a strategy.

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

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

orderscount(
    s::Strategies.Strategy,
    ai::Instances.AssetInstance,
    _::Type{OrderTypes.BuyOrSell}
) -> Any
Executors.orderscountMethod

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

orderscount(
    s::Strategies.Strategy,
    ai::Instances.AssetInstance,
    _::Type{OrderTypes.Buy}
) -> Int64
Executors.orderscountMethod

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

orderscount(
    s::Strategies.Strategy,
    ai::Instances.AssetInstance,
    _::Type{OrderTypes.Sell}
) -> Int64
Executors.orderscountMethod

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

orderscount(
    s::Strategies.Strategy,
    ai::Instances.AssetInstance
) -> Any
Executors.orderscountMethod

Returns the count of pending entry orders in a strategy.

orderscount(
    s::Strategies.Strategy,
    _::Val{:increase}
) -> Any
Executors.orderscountMethod

Returns the count of pending exit orders in a strategy.

orderscount(s::Strategies.Strategy, _::Val{:reduce}) -> Any
Executors.orderscountMethod

Returns the total count of pending orders in a strategy.

orderscount(s::Strategies.Strategy) -> Any
Executors.orderscountMethod

Returns the count of orders in a strategy.

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

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

ordershistory(ai::Instances.AssetInstance) -> Any
Executors.position!Method

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

position!(
    s::Strategies.IsolatedStrategy,
    ai,
    date::Dates.DateTime,
    p::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.

Executors.priceatMethod

The price for an order at a particular date.

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

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

queue!(
    s::Strategies.Strategy,
    o::OrderTypes.Order{<:OrderTypes.LimitOrderType{S<:OrderTypes.OrderSide}},
    ai;
    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.

Executors.release!Method

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

release!(
    s::Strategies.Strategy,
    ai
) -> Union{Nothing, Set{Instances.AssetInstance{T, E} where T<:AbstractAsset} where E<:ExchangeID}
Executors.sellordersMethod

Returns sell orders for an asset in a strategy.

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

Returns a generator for short orders matching a given order side

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

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

Executors.sideordersMethod

Returns orders for an asset in a strategy by side.

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

Returns orders for an asset in a strategy by side.

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

Returns orders for an asset in a strategy by side.

sideorders(
    s::Strategies.Strategy,
    ai,
    _::Union{Type{S}, Type{<:OrderTypes.Order{<:OrderTypes.OrderType{S}}}, OrderTypes.Order{<:OrderTypes.OrderType{S}}, OrderTypes.Trade{<:OrderTypes.OrderType{S}}, S}
) -> SortedDict{@NamedTuple{price::Float64, time::Dates.DateTime}, D, Strategies.SellPriceTimeOrdering} where D<:(OrderTypes.AnySellOrder{P, T, E} where {E<:ExchangeID, P<:Misc.PositionSide, T<:AbstractAsset})
Executors.strategycash!Method

Updates the strategy's cash after an increase trade.

strategycash!(
    s::Strategies.IsolatedStrategy,
    ai,
    t::OrderTypes.IncreaseTrade
)
Executors.strategycash!Method

Updates the strategy's cash after a reduce trade.

strategycash!(
    s::Strategies.IsolatedStrategy,
    ai,
    t::OrderTypes.ReduceTrade
)
Executors.strategycash!Method

Updates the strategy's cash after a buy trade.

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

Updates the strategy's cash after a sell trade.

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

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

trade!(
    s::Strategies.Strategy,
    o,
    ai;
    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.

Executors.unfilledMethod

Returns the absolute value of the unfilled amount of an order.

unfilled(o::OrderTypes.Order) -> Any
Executors.unfillmentMethod

Calculates the unfulfilled amount for an order.

unfillment(o::OrderTypes.Order) -> Float64
Executors.unfillmentMethod

Calculates the unfulfilled amount for a buy order.

unfillment(t::Type{<:OrderTypes.AnyBuyOrder}, amount) -> Any
Executors.unfillmentMethod

Calculates the unfulfilled amount for a sell order.

unfillment(
    t::Type{<:OrderTypes.AnySellOrder},
    amount
) -> Any
Executors.update_maintenance!Method

Updates leverage based on position state.

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

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

Executors.update_notional!Method

Updates notional value.

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

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

Executors.update_price!Method

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

update_price!(po::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.

Executors.withtrade!Method

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

withtrade!(
    po::Instances.Position{P},
    t::OrderTypes.Trade{O, A, E, P} where {O<:OrderTypes.OrderType, A<:AbstractAsset, E<:ExchangeID};
    settle_price
) -> Any

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

Instances.committedMethod

Returns the committed amount of a short buy order.

committed(
    o::OrderTypes.Order{<:OrderTypes.OrderType{OrderTypes.Buy}, var"#s237", var"#s236", Misc.Short} where {var"#s237"<:AbstractAsset, var"#s236"<:ExchangeID}
) -> Any
Instances.committedMethod

Returns the committed amount of an order.

committed(o::OrderTypes.Order) -> Any
Instances.committedMethod

Calculates the committed amount for a given position

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

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

Instances.isdustMethod

Checks if the order committed value is below minimum quantity.

isdust(
    ai::Instances.AssetInstance,
    o::OrderTypes.Order
) -> Bool
Instances.liqpriceMethod

Calculates the liquidation price of a position

liqprice(
    p::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.

Instruments.cash!Method

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

cash!(s::Strategies.Strategy, ai, t::OrderTypes.Trade)
Misc.attrMethod

Returns the attribute of an order.

attr(o::OrderTypes.Order, sym) -> Any
Misc.reset!Method

Resets an order committment and unfilled amount.

reset!(o::OrderTypes.Order, ai) -> Float64
OrderTypes.commit!Method

Commits an increase order to a strategy.

commit!(
    s::Strategies.Strategy,
    o::OrderTypes.IncreaseOrder,
    _
)
OrderTypes.commit!Method

Commits a reduce order to an asset instance.

commit!(
    _::Strategies.Strategy,
    o::OrderTypes.ReduceOrder,
    ai
) -> Any
OrderTypes.tradesMethod

Returns the trades of an order.

trades(o::OrderTypes.Order) -> Any