call.jl
1 import Executors: call! 2 using Executors 3 using Executors: iscommittable, priceat, marketorder, hold!, AnyLimitOrder 4 using .OrderTypes: LimitOrderType, MarketOrderType 5 using .Lang: @lget!, Option 6 7 @doc """ Creates a simulated limit order. 8 9 $(TYPEDSIGNATURES) 10 11 The function `call!` is responsible for creating a simulated limit order. 12 It creates the order using `create_sim_limit_order`, checks if the order is not `nothing`, and then calls `limitorder_ifprice!`. 13 The parameters include a strategy `s`, an asset `ai`, and a type `t`. The function also accepts an `amount` and additional arguments `kwargs...`. 14 """ 15 function call!(s::NoMarginStrategy{Sim}, ai, t::Type{<:AnyLimitOrder}; amount, kwargs...) 16 fees_kwarg, order_kwargs = splitkws(:fees; kwargs) 17 o = create_sim_limit_order(s, t, ai; amount, order_kwargs...) 18 isnothing(o) && return nothing 19 limitorder_ifprice!(s, o, o.date, ai; fees_kwarg...) 20 end 21 22 @doc """ Creates a simulated market order. 23 24 $(TYPEDSIGNATURES) 25 26 The function `call!` creates a simulated market order using `create_sim_market_order`. 27 It checks if the order is not `nothing`, and then calls `marketorder!`. 28 Parameters include a strategy `s`, an asset `ai`, a type `t`, an `amount` and a `date`. 29 Additional arguments can be passed through `kwargs...`. 30 """ 31 function call!( 32 s::NoMarginStrategy{Sim}, ai, t::Type{<:AnyMarketOrder}; amount, date, kwargs... 33 ) 34 fees_kwarg, order_kwargs = splitkws(:fees; kwargs) 35 o = create_sim_market_order(s, t, ai; amount, date, order_kwargs...) 36 isnothing(o) && return nothing 37 marketorder!(s, o, ai, amount; date, fees_kwarg...) 38 end 39 40 @doc """ Cancel orders for a specific asset instance. 41 42 $(TYPEDSIGNATURES) 43 44 The function `call!` cancels all orders for a specific asset instance `ai`. 45 It iterates over the orders of the asset and cancels each one using `cancel!`. 46 Parameters include a strategy `s`, an asset instance `ai`, and a type `t` which defaults to `BuyOrSell`. 47 Additional arguments can be passed through `kwargs...`. 48 """ 49 function call!( 50 s::Strategy{<:Union{Paper,Sim}}, 51 ai::AssetInstance, 52 ::CancelOrders; 53 t::Type{<:OrderSide}=BuyOrSell, 54 kwargs..., 55 )::Bool 56 all(cancel!(s, o, ai; err=OrderCanceled(o)) for o in values(s, ai, t)) 57 end