Executors
Executors.AnyFOKOrder
— TypeType alias for any FOK order
Executors.AnyGTCOrder
— TypeType alias for any GTC order
Executors.AnyIOCOrder
— TypeType alias for any IOC order
Executors.IncreaseLimitOrder
— TypeUnion type representing limit order increase operations. Includes Buy and Sell Short orders.
Executors.IncreaseLimitTrade
— TypeUnion type representing limit trade increase operations. Includes Buy and Sell Short trades.
Executors.LIQUIDATION_BUFFER
— ConstantSome exchanges add funding rates and trading fees to the liquidation price, we use a default buffer of -0.02.
Executors.ReduceLimitOrder
— TypeUnion type representing limit order reduction operations. Includes Sell and Buy Short orders.
Executors.ReduceLimitTrade
— TypeUnion type representing limit trade reduction operations. Includes Sell and Buy Short trades.
Executors.AnyLimitOrder
— TypeType alias for any limit order
Executors.AnyMarketOrder
— TypeType alias for any market order
Executors.AnyPostOnlyOrder
— TypeType alias for any post only order
Executors.CancelOrders
— TypeAction to cancel open orders.
Executors.Context
— TypeThe 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.
Executors.Context
— MethodCreate 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 subtypeExecMode
.
Executors.InitData
— TypeAction to initialize OHLCV data.
Executors.LimitBuyTrade
— TypeType representing a limit buy trade, specific to long position buy limit orders.
Executors.LimitSellTrade
— TypeType representing a limit sell trade, specific to long position sell limit orders.
Executors.LimitTrade
— TypeType representing a limit trade, includes long position limit orders.
Executors.LongMarketBuyTrade
— TypeDefines a long market buy trade type.
Executors.LongMarketSellTrade
— TypeRepresents a long market sell trade on a certain exchange for a specific asset.
Executors.NewTrade
— TypeAction executed after a new trade occurs.
Executors.OptRun
— TypeAction run before a single simulation during optimization.
Executors.OptScore
— TypeAction to get the score of a single simulation (after it has finished).
Executors.OptSetup
— TypeAction to setup an optimizer (context and params).
Executors.OrderIterator
— TypeA data structure for maintaining a collection of iterators.
iters
Executors.ShortLimitBuyTrade
— TypeType representing a short limit buy trade, specific to short position buy limit orders.
Executors.ShortLimitSellTrade
— TypeType representing a short limit sell trade, specific to short position sell limit orders.
Executors.ShortLimitTrade
— TypeType representing a short limit trade, includes short position limit orders.
Executors.UpdateData
— TypeAction to update OHLCV data (from watchers).
Executors.UpdateLeverage
— TypeAction to update leverage.
Executors.UpdateMargin
— TypeAction to update margin mode.
Executors.UpdateOrders
— Type(DEPRECATED) order updates are done internally now.
Executors.UpdateOrdersShuffled
— Type(DEPRECATED) The shuffled version of UpdateOrders
.
Executors.UpdatePositions
— TypeAction to update positions size.
Executors.WatchOHLCV
— TypeAction to setup an OHLCV watcher.
Base.collect
— MethodCollects all elements of the OrderIterator into a Vector.
collect(
oi::Executors.OrderIterator
) -> Vector{Pair{@NamedTuple{price::Float64, time::Dates.DateTime}, <:OrderTypes.Order}}
Base.count
— MethodCounts the number of elements in the OrderIterator.
count(oi::Executors.OrderIterator) -> Int64
Base.delete!
— MethodRemoves 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!
— MethodRemoves 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!
— MethodRemoves 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!
— MethodRemoves all buy/sell orders for an asset instance.
delete!(
s::Strategies.Strategy,
ai,
t::Type{<:Union{OrderTypes.Buy, OrderTypes.Sell}}
) -> Any
Base.delete!
— MethodRemoves all buy and sell orders for an asset instance.
delete!(
s::Strategies.Strategy,
ai,
_::Type{OrderTypes.BuyOrSell}
) -> Any
Base.delete!
— MethodRemoves all orders for an asset instance.
delete!(s::Strategies.Strategy, ai) -> Any
Base.eltype
— MethodReturns the element type of the OrderIterator.
eltype(
_::Executors.OrderIterator
) -> Type{Pair{@NamedTuple{price::Float64, time::Dates.DateTime}, <:OrderTypes.Order}}
Base.fill!
— MethodFills 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!
— MethodFills 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!
— MethodFills 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!
— MethodFills 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.first
— MethodReturns 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.firstindex
— MethodReturns 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.haskey
— MethodChecks 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.haskey
— MethodChecks 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.haskey
— MethodChecks 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.haskey
— MethodChecks if a strategy has a specific order for an asset.
haskey(
s::Strategies.Strategy,
ai,
o::OrderTypes.Order
) -> Bool
Base.isdone
— MethodChecks if the OrderIterator is empty.
isdone(oi::Executors.OrderIterator) -> Bool
Base.isopen
— MethodChecks if an order is open.
isopen(
ai::Instances.AssetInstance,
o::OrderTypes.Order
) -> Any
Base.iszero
— MethodChecks if the order amount left to fill is below minimum qty.
iszero(
ai::Instances.AssetInstance,
o::OrderTypes.Order
) -> Any
Base.iterate
— MethodReturns the next element in the OrderIterator.
iterate(
oi::Executors.OrderIterator,
_
) -> Union{Nothing, Tuple{Any, Nothing}}
Base.keys
— MethodReturns 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.last
— MethodReturns the last element in the OrderIterator.
last(oi::Executors.OrderIterator) -> Any
Base.last
— MethodReturns 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.lastindex
— MethodReturns 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!
— MethodInserts 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.values
— MethodReturns 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.Checks.cost
— MethodReturns the cost of an order.
cost(o::OrderTypes.Order) -> Float64
Executors._check_cash
— MethodChecks the cash for an asset instance in a strategy for long.
_check_cash(ai::Instances.AssetInstance, _::Misc.Long)
Executors._check_cash
— MethodChecks the cash for an asset instance in a strategy for short.
_check_cash(ai::Instances.AssetInstance, _::Misc.Short)
Executors._check_committment
— MethodChecks order committment to be within expected values.
_check_committment(o)
Executors._check_trade
— MethodChecks a buy trade.
_check_trade(t::OrderTypes.BuyTrade, ai)
Executors._check_trade
— MethodChecks a sell trade.
_check_trade(t::OrderTypes.SellTrade, ai)
Executors._check_trade
— MethodChecks a short buy trade.
_check_trade(t::OrderTypes.ShortBuyTrade, ai)
Executors._check_trade
— MethodChecks a short sell trade.
_check_trade(t::OrderTypes.ShortSellTrade, ai)
Executors._check_unfillment
— MethodChecks 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_unfillment
— MethodChecks 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_unfillment
— MethodChecks 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_unfillment
— MethodChecks 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_unfillment
— MethodChecks if the unfilled amount for a long order is positive.
_check_unfillment(o::OrderTypes.LongOrder) -> Any
Executors._check_unfillment
— MethodChecks if the unfilled amount for a short order is negative.
_check_unfillment(o::OrderTypes.ShortOrder) -> Any
Executors._do_orders_iter
— MethodFilters out empty iterators and returns the smallest value.
_do_orders_iter(oi) -> Union{Nothing, Tuple{Any, Nothing}}
Executors._doclamp
— MethodClamps the given values within the correct boundaries.
_doclamp(clamper, ai, whats...) -> Expr
Executors._findmin
— MethodFinds and returns the iterator with the smallest value.
_findmin(non_empty_iters) -> Tuple{Any, Any}
Executors.aftertrade!
— FunctionUnconditionally 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!
— FunctionRemoves 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!
— FunctionPerforms cleanups after a trade (attempt).
aftertrade!(s, ai, o) -> Any
aftertrade!(s, ai, o, t) -> Any
Executors.amount
— MethodReturns the amount of an order.
amount(o::OrderTypes.Order) -> Float64
Executors.basic_order_state
— MethodConstructs 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.basicorder
— MethodConstructs 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.buyorders
— MethodReturns 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!
— MethodCancels an order with given error.
cancel!(
s::Strategies.Strategy,
o::OrderTypes.Order,
ai;
err
)
Executors.committment
— MethodCalculates the commitment for an order.
committment(
ai::Instances.AssetInstance,
o::OrderTypes.Order;
kwargs...
) -> Any
Executors.committment
— MethodCalculates the partial commitment of a trade.
committment(
ai::Instances.AssetInstance,
t::OrderTypes.Trade
) -> Any
Executors.committment
— MethodCalculates 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.committment
— MethodCalculates the commitment for an increase order without margin.
committment(
::Type{<:OrderTypes.IncreaseOrder},
ai::Instances.AssetInstance{<:AbstractAsset, <:ExchangeID, NoMargin},
price,
amount;
kwargs...
) -> Any
Executors.committment
— MethodCalculates 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.committment
— MethodCalculates 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!
— FunctionDecommits 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!
— MethodDecommits 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!
— MethodDecommits 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.feespaid
— MethodThe sum of all the trades fees that have heppened for the order.
feespaid(o::OrderTypes.Order) -> Any
Executors.filled_amount
— MethodReturns the filled amount of an order.
filled_amount(o) -> Any
Executors.hascash
— MethodChecks if any of the holdings has non dust cash.
hascash(s::Strategies.Strategy) -> Bool
Executors.hasorders
— MethodChecks if an asset instance has pending orders in a strategy.
hasorders(
s::Strategies.Strategy,
ai::Instances.AssetInstance
) -> Bool
Executors.hasorders
— MethodChecks 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.hasorders
— MethodChecks if a strategy has orders.
hasorders(s::Strategies.Strategy) -> Any
Executors.hasorders
— MethodChecks 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.hasorders
— MethodChecks 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.hasorders
— MethodChecks 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.hastrade
— MethodMore precise version of hastrade
.
Executors.hastrade
— MethodCheck if the given trade is in the order.
hastrade(o::OrderTypes.Order, t::OrderTypes.Trade) -> Bool
Executors.hold!
— MethodWhen 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!
— MethodReduce orders can never switch an asset from not held to held.
hold!(_::Strategies.Strategy, _, _::OrderTypes.ReduceOrder)
Executors.iscommittable
— MethodChecks if an increase order can be committed to a strategy.
iscommittable(
s::Strategies.Strategy,
o::OrderTypes.IncreaseOrder,
ai
) -> Any
Executors.iscommittable
— MethodChecks 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.iscommittable
— MethodChecks 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.iscommittable
— MethodChecks if a strategy can commit to an increase order.
iscommittable(
s::Strategies.Strategy,
_::Type{<:OrderTypes.IncreaseOrder},
commit,
ai
) -> Any
Executors.iscommittable
— MethodChecks 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.iscommittable
— MethodChecks 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.isfilled
— MethodChecks if an order is filled.
isfilled(
ai::Instances.AssetInstance,
o::OrderTypes.Order
) -> Any
Executors.isfirstfill
— MethodChecks if the provided trade is the first fill for the given asset instance.
isfirstfill(
_::Instances.AssetInstance,
t::OrderTypes.Trade{<:OrderTypes.LimitOrderType}
) -> Any
Executors.islastfill
— MethodChecks if the provided trade is the last fill for the given asset instance.
islastfill(
ai::Instances.AssetInstance,
t::OrderTypes.Trade{<:OrderTypes.LimitOrderType}
) -> Any
Executors.isliquidatable
— MethodTests 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.isliquidatable
— MethodChecks 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.isoutof_orders
— MethodChecks if a strategy is out of orders.
isoutof_orders(s::Strategies.Strategy) -> Any
Executors.isqueued
— MethodChecks if an order is already added to the queue.
isqueued(
o::OrderTypes.Order{<:OrderTypes.OrderType{S<:OrderTypes.OrderSide}},
s::Strategies.Strategy,
ai
) -> Any
Executors.limitorder
— MethodPlaces 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.liquidations
— MethodThe 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.longorders
— MethodReturns 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.marketorder
— MethodExecutes 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_byid
— MethodReturns the order that matches the given id (if any).
order_byid(
s::Strategies.Strategy,
ai::Instances.AssetInstance,
id::String
) -> Any
Executors.orders
— MethodReturns all orders for an asset instance in a strategy.
orders(s, ai, _::Type{OrderTypes.BuyOrSell}) -> Any
Executors.orders
— MethodReturns 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.orders
— MethodReturns 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.orders
— MethodIterates 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.orders
— MethodIterates 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.orders
— MethodReturns 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.orders
— MethodReturns 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.orders
— MethodIterates 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.orders
— MethodIterates 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.orders
— MethodIterates over all the orders in a strategy (all the assets in the universe).
orders(
s::Strategies.Strategy,
_::Val{:universe}
) -> Executors.OrderIterator
Executors.orders
— MethodIterates over all the orders in a strategy.
orders(s::Strategies.Strategy) -> Executors.OrderIterator
Executors.orders
— MethodReturns 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.orders
— MethodReturns 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.orderscount
— MethodReturns the count of orders for an asset in a strategy.
orderscount(
s::Strategies.Strategy,
ai::Instances.AssetInstance,
_::Type{OrderTypes.BuyOrSell}
) -> Any
Executors.orderscount
— MethodReturns the count of buy orders for an asset in a strategy.
orderscount(
s::Strategies.Strategy,
ai::Instances.AssetInstance,
_::Type{OrderTypes.Buy}
) -> Int64
Executors.orderscount
— MethodReturns the count of sell orders for an asset in a strategy.
orderscount(
s::Strategies.Strategy,
ai::Instances.AssetInstance,
_::Type{OrderTypes.Sell}
) -> Int64
Executors.orderscount
— MethodReturns the count of orders for an asset in a strategy.
orderscount(
s::Strategies.Strategy,
ai::Instances.AssetInstance
) -> Any
Executors.orderscount
— MethodReturns the count of pending entry orders in a strategy.
orderscount(
s::Strategies.Strategy,
_::Val{:increase}
) -> Any
Executors.orderscount
— MethodReturns the count of pending exit orders in a strategy.
orderscount(s::Strategies.Strategy, _::Val{:reduce}) -> Any
Executors.orderscount
— MethodReturns the total count of pending orders in a strategy.
orderscount(s::Strategies.Strategy) -> Any
Executors.orderscount
— MethodReturns 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.ordershistory
— MethodReturns a unique list of orders from the trade history of a given asset instance.
ordershistory(ai::Instances.AssetInstance) -> Any
Executors.position!
— MethodUpdates 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.position!
— MethodNon margin strategies don't have positions.
Executors.priceat
— MethodThe price for an order at a particular date.
priceat(
_::Strategies.Strategy,
_::Type{<:OrderTypes.Order},
ai,
date
) -> Any
Executors.queue!
— MethodAdds 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!
— MethodAn 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.sellorders
— MethodReturns 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.shortorders
— MethodReturns 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.sideorders
— MethodReturns 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.sideorders
— MethodReturns 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.sideorders
— MethodReturns 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!
— MethodUpdates the strategy's cash after an increase trade.
strategycash!(
s::Strategies.IsolatedStrategy,
ai,
t::OrderTypes.IncreaseTrade
)
Executors.strategycash!
— MethodUpdates the strategy's cash after a reduce trade.
strategycash!(
s::Strategies.IsolatedStrategy,
ai,
t::OrderTypes.ReduceTrade
)
Executors.strategycash!
— MethodUpdates 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!
— MethodUpdates 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!
— MethodExecutes 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.unfilled
— MethodReturns the absolute value of the unfilled amount of an order.
unfilled(o::OrderTypes.Order) -> Any
Executors.unfillment
— MethodCalculates the unfulfilled amount for an order.
unfillment(o::OrderTypes.Order) -> Float64
Executors.unfillment
— MethodCalculates the unfulfilled amount for a buy order.
unfillment(t::Type{<:OrderTypes.AnyBuyOrder}, amount) -> Any
Executors.unfillment
— MethodCalculates the unfulfilled amount for a sell order.
unfillment(
t::Type{<:OrderTypes.AnySellOrder},
amount
) -> Any
Executors.update_leverage!
— MethodUpdates leverage based on position state.
Executors.update_maintenance!
— MethodUpdates 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!
— MethodUpdates 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!
— MethodUpdate 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!
— MethodUpdate 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.committed
— MethodReturns 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.committed
— MethodReturns the committed amount of an order.
committed(o::OrderTypes.Order) -> Any
Instances.committed
— MethodCalculates 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.isdust
— MethodChecks if the order committed value is below minimum quantity.
isdust(
ai::Instances.AssetInstance,
o::OrderTypes.Order
) -> Bool
Instances.liqprice
— MethodCalculates 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!
— MethodUpdates the strategy's and asset instance's cash after a trade.
cash!(s::Strategies.Strategy, ai, t::OrderTypes.Trade)
Misc.attr
— MethodReturns the attribute of an order.
attr(o::OrderTypes.Order, sym) -> Any
Misc.reset!
— MethodResets an order committment and unfilled amount.
reset!(o::OrderTypes.Order, ai) -> Float64
OrderTypes.commit!
— MethodCommits an increase order to a strategy.
commit!(
s::Strategies.Strategy,
o::OrderTypes.IncreaseOrder,
_
)
OrderTypes.commit!
— MethodCommits a reduce order to an asset instance.
commit!(
_::Strategies.Strategy,
o::OrderTypes.ReduceOrder,
ai
) -> Any
OrderTypes.trades
— MethodReturns the trades of an order.
trades(o::OrderTypes.Order) -> Any
Executors.@amount!
— MacroEnsures the amount is within correct boundaries.
Executors.@price!
— MacroEnsures the price is within correct boundaries.