Misc
Misc.ATOL
— ConstantThe margin of error to use [2eps
].
Misc.Iterable
— TypeAn union of iterable types.
Misc.ONE
— ConstantStatic one(DFT)
Misc.WithMargin
— TypeAny margin mode.
Misc.ZERO
— ConstantStatic zero(DFT)
Misc.config
— ConstantGlobal configuration instance.
Misc.fetch_limits
— ConstantExchange ohlcv candles limits.
Misc.futures_exchange
— ConstantSome exchanges are split into different classes in ccxt.
Misc.results
— ConstantHolds recently evaluated statements.
Misc.Config
— TypeCreates a Config object from a profile and path.
Config(profile::Union{Module, String, Symbol}; ...) -> Any
Config(
profile::Union{Module, String, Symbol},
path::String;
hasentry,
kwargs...
) -> Any
This function creates a Config
object using the provided profile
and path
. The profile
can be a Symbol
, Module
, or String
representing a specific configuration setup or a user/project profile. If hasentry
is true
, it also checks for an entry point.
Misc.Config
— TypeStrategy config.
path
: File path that loaded this config.mode
: Execution mode (Sim
,Paper
,Live
)exchange
: A symbol to instantiate an exchange (a raw ExchangeID symbol)account
: Different accounts have different api keysparams
: Parameters for exchange constructorsandbox
: Exchange sandbox mode flagqc
: The quote currency for the strategy cash.margin
: Configures the margin mode of the strategy (NoMargin
,Isolated
orCross
)leverage
: The default leverage that should be used when opening position with margin mode.min_vol
: A minimum acceptable volume, e.g. for filtering markets.initial_cash
: Starting cash, used when instantiating a strategy.min_size
: Default order size.min_timeframe
: The default (shortest) timeframe of the candles.timeframes
: Vector of sorted timeframes that the strategy uses (for loading data).window
: The default number of candles (OHLCV).sources
: Mapping of modules symbols name to (.jl) file pathsattrs
: Generic metadata container.toml
: Raw toml that instantiated this config.defaults
Misc.ContiguityException
— TypeAn exception that is thrown when the data stored ends before the new data starts (or vice versa).
Misc.Cross
— TypeNotHedged CrossMargin mode.
Misc.CrossHedged
— TypeHedged CrossMargin mode.
Misc.CrossMargin
— TypeCross margin mode handles margin across all assets (NOT IMPLEMENTED).
Misc.DFT
— TypeThe floating point number type to use.
Misc.ExecAction
— TypeAn ExecAction
is any holy trait singleton used to dispatch call!
and call!
functions.
Misc.ExecMode
— TypeExecMode is one of Sim
, Paper
, Live
.
Misc.Hedged
— TypeHedged
implies both short and long positions can be held.
Misc.HedgedMode
— TypeHedgedMode
is one of Hedged
, NotHedged
.
Misc.Isolated
— TypeNotHedged IsolatedMargin mode.
Misc.IsolatedHedged
— TypeHedged IsolatedMargin mode.
Misc.IsolatedMargin
— TypeIsolated margin mode handles margin for each asset separately.
Misc.LeftContiguityException
— TypeAn exception that is thrown when the data stored starts before the new data ends.
Misc.Live
— TypeLive execution.
Misc.Long
— TypeLong position side.
Misc.MM
— TypeMin, max named tuple
Misc.MarginMode
— TypeMargin mode is one of Isolated
, Cross
, NoMargin
.
Misc.NoMargin
— TypeNo margin mode, margin handling is disabled (usually in simple spot markets).
Misc.NotHedged
— TypeNotHedged
implies only one position side can be held.
Misc.Paper
— TypePaper execution.
Misc.PositionSide
— TypePosition side is one of Long
, Short
.
Misc.RightContiguityException
— TypeAn exception that is thrown when the data stored ends before the new data starts.
Misc.Short
— TypeShort position side.
Misc.Sim
— TypeSimulated execution.
Misc.TaskFlag
— TypeUsed to indicate that a task is still running.
f
: The function that indicates that the task is still running (returns aBool
).
Misc.TaskFlag
— MethodThe default task flag
Uses the task local storage to communicate if the task is still running.
Misc.UniqueIterator
— TypeReturns an iterator that yields unique elements from an iterable.
Base.copy
— MethodCreates a (shallow) copy of the Config object.
copy(c::Misc.Config) -> Any
This function returns a new Config
object that is a copy of the given Config
object c
.
Misc._find_module
— MethodFinds the module corresponding to a given symbol.
_find_module(sym) -> Any
This function takes a symbol sym
and attempts to find the corresponding module in the loaded modules.
Misc._instantiate_workers
— MethodInstantiates worker processes for a given module.
_instantiate_workers(
mod;
force,
num
) -> Union{Nothing, Int64}
This function takes a module mod
and optionally a boolean force
and an integer num
. It spawns num
worker processes for mod
. If force
is true, it first kills any existing worker processes for mod
.
Misc._options!
— MethodSets the options in cfg based on provided name.
_options!(cfg, name) -> Any
This function iterates over the options defined in the cfg
object's TOML and sets each option according to the values provided under the given name
.
Misc._path!
— MethodSets the path in cfg if the file exists.
_path!(cfg, path) -> Any
This function sets the path
field of the cfg
object to the provided path
if a file exists at that location.
Misc._sources!
— MethodSets the sources in cfg based on provided name.
_sources!(cfg, name)
This function iterates over the sources defined in the cfg
object's TOML and sets each source according to the values provided under the given name
.
Misc._toml!
— MethodSets the TOML config in cfg if the file exists.
_toml!(cfg, name; check)
This function sets the toml
field of the cfg
object to the parsed contents of a TOML file with the provided name
, if the file exists.
Misc.after
— MethodReturns a view of the vector after a specified value.
after(v::AbstractVector, d; kwargs...) -> Any
This function returns a view of the vector v
starting from the position after the first occurrence of d
. The behavior can be adjusted using keyword arguments passed to rangeafter
.
Misc.approxzero
— MethodChecks if a value is approximately zero.
approxzero(v; atol) -> Any
This function takes a value v
and a tolerance atol
. It returns true
if the absolute difference between v
and zero is less than or equal to atol
, and false
otherwise.
Misc.attr!
— MethodGet k
from the attrs
field of the input object, or v
if k
is not present, setting k
to v
.
attr!(d, k, v) -> Any
Misc.attr
— MethodGet k
from the attrs
field of the input object, or v
if k
is not present.
attr(d, k, v) -> Any
Misc.attr
— MethodGet k
from the attrs
field of the input object.
attr(d, k) -> Any
Misc.attrs
— MethodGet all keys...
from the attrs
field of the input object.
attrs(d, keys...) -> Dict{Any, Any}
Misc.attrs
— MethodGet the attrs
field of the input object.
Misc.before
— MethodComplement of after
.
Misc.between
— MethodReturns a view of the sorted vector v
, indexed using rangebetween
.
between(v::AbstractVector, left, right; kwargs...) -> Any
julia> between([1, 2, 3, 3, 3], 3, 3; strict=true)
0-element view(::Vector{Int64}, 6:5) with eltype Int64
julia> between([1, 2, 3, 3, 3], 1, 3; strict=true)
1-element view(::Vector{Int64}, 2:2) with eltype Int64:
2
julia> between([1, 2, 3, 3, 3], 2, 3; strict=false)
2-element view(::Vector{Int64}, 3:4) with eltype Int64:
3
3
Misc.config!
— MethodParses the toml file and populates the config cfg
.
config!(
name::String;
cfg,
path,
check
) -> Misc.Config{Float64}
This function updates the configuration object cfg
by parsing the TOML file specified by name
and path
. If check
is true, the function validates the config.
Misc.config_path
— MethodDetermines the config file path.
This function attempts to find the configuration file using find_config()
. If it doesn't exist in the default directory, it falls back to the active project directory.
Misc.dec!
— MethodDecrement an integer reference by one
Misc.default_dir
— MethodReturns the default directory path for the project.
default_dir() -> String
This function returns the directory of the active project if it exists. Otherwise, it uses the JULIA_PROJECT
from the environment variables. If neither exist, it defaults to the current directory.
Misc.default_local_dir
— MethodReturns the default local directory.
Misc.drop
— MethodReturns a NamedTuple without the given keys.
Misc.exchange_keys
— MethodRetrieves the API keys for a specific exchange.
exchange_keys(name; sandbox, account)
This function tries to open and parse a JSON file named after the exchange name
, which should contain the API keys.
Misc.execmode
— MethodReturns the execution mode of the arguments.
Misc.find_config
— FunctionFinds the configuration file in the given path.
find_config(; ...) -> Union{Nothing, String}
find_config(cur_path; name, dir) -> Any
This function recursively searches for a file with the specified name
starting from cur_path
. It stops once the file is found or when it reaches the root directory.
Misc.gtxzero
— MethodChecks if a value is greater than or approximately equal to zero.
gtxzero(v; atol) -> Any
This function takes a value v
and a tolerance atol
. It returns true
if v
is greater than zero or if the absolute difference between v
and zero is less than or equal to atol
, and false
otherwise.
Misc.hasattr
— MethodCheck if k
is present in the attrs
field of the input object.
Misc.hasattr
— MethodCheck if any of keys...
is present in the attrs
field of the input object.
Misc.inc!
— MethodIncrement an integer reference by one
Misc.init_task
— MethodInitializes a task with a given state.
init_task(t::Task, state) -> Task
This function initializes a task t
with a given state
. It sets up the task's storage dictionary which includes running flag, state, and a condition variable for notification.
Misc.isdirempty
— MethodChecks if a directory is empty.
isdirempty(path::AbstractString) -> Bool
This function takes a path
and returns true
if the directory at the given path is empty, and false
otherwise.
Misc.isstrictlysorted
— MethodChecks if an iterable is strictly sorted.
isstrictlysorted(itr...) -> Bool
This function takes an iterable itr
and returns true
if the elements in itr
are strictly increasing, and false
otherwise.
Misc.istaskrunning
— MethodCheck if a task is running.
istaskrunning(t::Task) -> Bool
This function checks if a task (t
) is running. A task is considered running if it has started and is not yet done.
Misc.istaskrunning
— MethodMisc.keys_path
— MethodGenerates the path for the JSON keys file.
keys_path(exc_name::AbstractString) -> String
This function constructs a filename from the given exc_name
, replacing any existing .json
extension, and joins it with the user directory path.
Misc.marginmode
— MethodReturns the margin mode of the arguments.
Misc.modifyattr!
— MethodSet k
in the attrs
field of the input object to v
.
modifyattr!(d, v, op, keys...)
Misc.negative
— Methodnegate(abs(v))
Misc.opposite
— MethodThe opposite position side (Long -> Short, Short -> Long)
Misc.positive
— MethodAlias to abs
Misc.queryfromstruct
— FunctionCreates a query from a struct type.
queryfromstruct(T::Type; ...) -> Dict{Any, Any}
queryfromstruct(T::Type, sep; kwargs...) -> Dict{Any, Any}
This function takes a struct type T
and a separator sep
, and creates a query string using the fields and their values in T
.
Misc.rangeafter
— MethodFinds the range after a specified value in a vector.
rangeafter(v::AbstractVector, d; strict, kwargs...) -> Any
This function takes a vector v
and a value d
, and returns a range that starts after the first occurrence of d
in v
. If strict
is true, the range starts after d
, otherwise it starts at d
.
Misc.rangebefore
— MethodComplement of rangeafter
.
Misc.rangebetween
— MethodFinds the range between two specified values in a vector.
rangebetween(
v::AbstractVector,
left,
right;
kwargs...
) -> Any
This function takes a vector v
and two values left
and right
, and returns a range that starts from the position of left
and ends at the position of right
in v
.
Misc.reset!
— MethodResets the Config object to its default values.
reset!(c::Misc.Config)
This function iterates over the fields of the Config
object c
and resets each field to its default value. (stored in the defaults
field)
Misc.rewritekeys!
— MethodRewrites keys in a dictionary based on a function.
rewritekeys!(dict::AbstractDict, f) -> AbstractDict
This function takes a dictionary dict
and a function f
, and rewrites each key in the dictionary by applying the function f
to it.
Misc.setattr!
— MethodSet k
in the attrs
field of the input object to v
.
Misc.setoffline!
— MethodSets the offline mode.
setoffline!() -> Bool
This function sets the offline mode based on the PLANAR_OFFLINE
environment variable. If the environment variable is set, it parses its value as a boolean to set the offline mode. It is used to skip some errors during precompilation, if precompiling offline.
Misc.shift!
— FunctionShifts elements in a vector.
shift!(
arr::Vector{<:AbstractFloat}
) -> Vector{<:AbstractFloat}
shift!(
arr::Vector{<:AbstractFloat},
n
) -> Vector{<:AbstractFloat}
shift!(
arr::Vector{<:AbstractFloat},
n,
def
) -> Vector{<:AbstractFloat}
This function shifts the elements in arr
by n
positions to the left. The new elements added to the end of the array are set to the value of def
.
Misc.start_task
— MethodInitializes and starts a task with a given state.
start_task(t::Task, state) -> Task
This function initializes a task t
with a given state
, schedules the task, and then returns the task.
Misc.stop_task
— MethodStops a task if it's running.
stop_task(t::Task) -> Bool
This function attempts to stop a running task t
. It sets the task's running flag to false
and notifies any waiting threads if applicable.
Misc.swapkeys
— MethodSwaps keys in a dictionary based on a function and new key type.
swapkeys(
dict::AbstractDict{K, V},
k_type::Type,
f;
dict_type
) -> Any
This function takes a dictionary dict
, a function f
, and a new key type k_type
. It returns a new dictionary of type dict_type
where each key is transformed by the function f
and cast to k_type
.
Misc.task_sem
— MethodRetrieves or initializes a semaphore for a task.
task_sem(task) -> Any
This function retrieves or initializes a semaphore for a task task
. If the semaphore doesn't exist, it initializes a new one with an empty queue and a condition variable.
Misc.toprecision
— MethodWhen precision is a Integer it represents the number of decimals.
toprecision(n::AbstractFloat, prec::Int64) -> Any
Misc.toprecision
— MethodRound a float to a given precision (SIGNIFICANT_DIGITS
).
toprecision(n::AbstractFloat, prec::UInt64) -> Any
SIGNIFICANT_DIGITS
precision mode is similar to DECIMAL_PLACES
except that the last digit is the one that is rounded
Misc.toprecision
— MethodWhen precision is a float it represents the pip.
toprecision(
n::Union{AbstractFloat, Integer},
prec::AbstractFloat
) -> Any
Misc.truncate_file
— MethodTruncate a file to contain only the last nlines
lines.
truncate_file(filename, nlines) -> Any
Opens the file for reading, keeps only the last nlines
lines, then opens the file again for writing and overwrites it with those last lines. Throws an error if nlines
is not a positive integer.
Misc.waitforcond
— MethodWaits for a certain condition for a specified time.
waitforcond(cond, time) -> Int64
This function waits for a certain condition cond
to be met within a specified time
. The condition cond
is a function that returns a boolean value. The function continuously checks the condition until it's true or until the specified time
has passed.
Misc.waitforcond
— MethodWaits for a condition function to return true for a specified time.
waitforcond(cond::Function, time) -> Int64
This function waits for a condition function cond
to return true. It keeps checking the condition for a specified time
.
Misc.@as_dfdict
— MacroBinds a mrkts
variable to a Dict{String, DataFrame} where the keys are the pairs names and the data is the OHLCV data of the pair.
Misc.@istaskrunning
— MacroChecks if the current task is running (Macro).
Equivalent to istaskrunning()
but should be used within other macros.
Misc.@lev!
— MacroToggle config leverage flag
Misc.@margin!
— MacroToggle config margin flag.
Misc.@skipoffline
— MacroSame as the Lang.@ignoremacro, but only if
PLANAR_OFFLINE` is set.
Misc.@start_task
— MacroStarts a task with a given state and code block.
This macro initializes and starts a task with a given state
and code
block. It creates a task with the provided code
, initializes it with the state
, and schedules the task for running.