Misc

Misc.ATOLConstant

The margin of error to use [2eps].

Misc.resultsConstant

Holds recently evaluated statements.

Misc.ConfigType

Creates 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.ConfigType

Strategy 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 keys

  • params: Parameters for exchange constructor

  • sandbox: Exchange sandbox mode flag

  • qc: The quote currency for the strategy cash.

  • margin: Configures the margin mode of the strategy (NoMargin, Isolated or Cross)

  • 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 paths

  • attrs: Generic metadata container.

  • toml: Raw toml that instantiated this config.

  • defaults

Misc.ContiguityExceptionType

An exception that is thrown when the data stored ends before the new data starts (or vice versa).

Misc.CrossMarginType

Cross margin mode handles margin across all assets (NOT IMPLEMENTED).

Misc.DFTType

The floating point number type to use.

Misc.ExecActionType

An ExecAction is any holy trait singleton used to dispatch call! and call! functions.

Misc.HedgedType

Hedged implies both short and long positions can be held.

Misc.MMType

Min, max named tuple

Misc.NoMarginType

No margin mode, margin handling is disabled (usually in simple spot markets).

Misc.NotHedgedType

NotHedged implies only one position side can be held.

Misc.TaskFlagType

Used to indicate that a task is still running.

  • f: The function that indicates that the task is still running (returns a Bool).
Misc.TaskFlagMethod

The default task flag

Uses the task local storage to communicate if the task is still running.

Base.copyMethod

Creates 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_moduleMethod

Finds 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_workersMethod

Instantiates 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!Method

Sets 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!Method

Sets 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!Method

Sets 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!Method

Sets 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.afterMethod

Returns 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.approxzeroMethod

Checks 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!Method

Get 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.attrMethod

Get k from the attrs field of the input object, or v if k is not present.

attr(d, k, v) -> Any
Misc.attrMethod

Get k from the attrs field of the input object.

attr(d, k) -> Any
Misc.attrsMethod

Get all keys... from the attrs field of the input object.

attrs(d, keys...) -> Dict{Any, Any}
Misc.attrsMethod

Get the attrs field of the input object.

Misc.betweenMethod

Returns 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!Method

Parses 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_pathMethod

Determines 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!Method

Decrement an integer reference by one

Misc.default_dirMethod

Returns 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.dropMethod

Returns a NamedTuple without the given keys.

Misc.exchange_keysMethod

Retrieves 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.execmodeMethod

Returns the execution mode of the arguments.

Misc.find_configFunction

Finds 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.gtxzeroMethod

Checks 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.hasattrMethod

Check if k is present in the attrs field of the input object.

Misc.hasattrMethod

Check if any of keys... is present in the attrs field of the input object.

Misc.inc!Method

Increment an integer reference by one

Misc.init_taskMethod

Initializes 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.isdiremptyMethod

Checks 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.isstrictlysortedMethod

Checks 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.istaskrunningMethod

Check 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.istaskrunningMethod

Checks if the current task is running.

This function checks if the current task is running by accessing the task's local storage.

Don't use within macros

Use the homonymous macro @istaskrunning() instead.

Misc.keys_pathMethod

Generates 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.modifyattr!Method

Set k in the attrs field of the input object to v.

modifyattr!(d, v, op, keys...)
Misc.oppositeMethod

The opposite position side (Long -> Short, Short -> Long)

Misc.queryfromstructFunction

Creates 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.rangeafterMethod

Finds 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.rangebetweenMethod

Finds 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!Method

Resets 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!Method

Rewrites 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!Method

Set k in the attrs field of the input object to v.

Misc.setoffline!Method

Sets 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!Function

Shifts 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_taskMethod

Initializes 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_taskMethod

Stops 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.swapkeysMethod

Swaps 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_semMethod

Retrieves 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.toprecisionMethod

When precision is a Integer it represents the number of decimals.

toprecision(n::AbstractFloat, prec::Int64) -> Any
Misc.toprecisionMethod

Round 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.toprecisionMethod

When precision is a float it represents the pip.

toprecision(
    n::Union{AbstractFloat, Integer},
    prec::AbstractFloat
) -> Any
Misc.truncate_fileMethod

Truncate 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.waitforcondMethod

Waits 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.waitforcondMethod

Waits 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_dfdictMacro

Binds 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.@istaskrunningMacro

Checks if the current task is running (Macro).

Equivalent to istaskrunning() but should be used within other macros.

Misc.@skipofflineMacro

Same as the Lang.@ignoremacro, but only ifPLANAR_OFFLINE` is set.

Misc.@start_taskMacro

Starts 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.