Instruments

Instruments.AbstractAssetType

Abstract base type for representing an asset.

Defines the interface and common functionality for all asset types.

Instruments.AbstractCashType

Abstract base type for representing a variable quantity of some currency.

This type defines the interface and common functionality for all cash types.

Instruments.AssetType

An Asset represents a parsed raw (usually ccxt) pair of base and quote currency.

  • raw: The raw underlying string e.g. 'BTC/USDT'
  • bc: base currency (Symbol)
  • qc: quote currency (Symbol)
  • fiat: if both the base and quote currencies match a known fiat symbol e.g. 'USDT/USDC'
  • leveraged: if parsing matched a leveraged token e.g. 'ETH3L/USDT' or 'ETH3S/USDT'
  • unleveraged_bc: a leveraged token with the mod removed, e.g. ETH3L => ETH
> asset = a"BTC/USDT"
> typeof(asset)
Asset{:BTC, :USDT}
end
Instruments.CashType

A variable quantity of some currency.

  • value
> ca = c"USDT"
> typeof(ca)
# Instruments.Cash{:USDT}
Instruments.addzero!Method

Add v to cash, approximating to zero if cash is a small value.

addzero!(c::Cash, v, args...; kwargs...) -> Cash
Instruments.cash!Method

Sets the cash object to v.

cash!(c::Cash, v, args...; kwargs...) -> Cash
Instruments.compactnumMethod

Compact a numeric value num to a smaller unit if possible.

compactnum(val::Number) -> Any

The function converts the numeric value to a smaller unit of time if the value is greater than or equal to 1000, and returns the compacted value.

Example:

num = 5000
result = compactnum(num)  # returns 5 since 5000 can be compacted to 5
Instruments.deleverage_qcMethod

Remove the leverage component from a CCXT quote currency quote.

deleverage_qc(pair::Array{T<:AbstractString, 1})

The function returns a new string with the leverage component removed.

Example:

quote = "3BTC/USDT"
deleveraged_quote = deleverage_qc(quote)  # returns "USDT"
Instruments.div!Method

Inplace division for Cash objects.

div!(c::Cash, v, args...; kwargs...) -> Cash
Instruments.has_punctMethod

Check if a string s contains any punctuation characters.

has_punct(s::AbstractString) -> Bool

The function returns true if s contains any punctuation characters, and false otherwise.

Example:

s = "Hello, world!"
result = has_punct(s)  # returns true since the string contains a punctuation character
Instruments.mod!Method

Inplace modulo for Cash objects.

mod!(c::Cash, v, args...; kwargs...) -> Cash
Instruments.mul!Method

Inplace multiplication for Cash objects.

mul!(c::Cash, v, args...; kwargs...) -> Cash
Instruments.rawMethod

Convert an AbstractAsset object a to its raw representation.

raw(a::AbstractAsset) -> Any

The function returns a new AbstractAsset object with special characters escaped using backslashes.

Example:

a = parse("BTC/USDT")
raw(a) # returns "BTC/USDT"
Instruments.rdiv!Method

Inplace remaineder division for Cash objects.

rdiv!(c::Cash, v, args...; kwargs...) -> Cash
Instruments.splitpairMethod

Split a CCXT pair (symbol) pair into its base and quote currencies.

splitpair(
    pair::AbstractString
) -> Array{SubString{_A}, 1} where _A

The function returns a tuple containing the base currency and quote currency.

Example: pair = "BTC/USDT" base, quote = splitpair(pair) # returns ("BTC", "USDT")

Instruments.subzero!Method

Sub v to cash, approximating to zero if cash is a small value.

subzero!(
    c::Instruments.AbstractCash,
    v,
    args...;
    kwargs...
) -> Union{Exchanges.CurrencyCash, Cash}
Instruments.Derivatives.perpetualMethod

Create a Derivative from a raw string representation raw, base currency bc, and quote currency qc.

perpetual(raw::AbstractString, bc, qc) -> Any
Instruments.Derivatives.scMethod

Short-circuit the execution of a derivative calculation if the derivative d is zero.

sc(d::Instruments.Derivatives.Derivative8; orqc) -> Symbol
Instruments.@a_strMacro

Parses pair to an Asset type. ```julia

typeof(a"BTC/USDT")

Instruments.Asset

Instruments.@c_strMacro

Macro to instantiate Cash statically.

Don't put spaces between the id and the value.

> ca = c"USDT"1000
USDT: 1000.0
Instruments.@importcash!Macro

Cash should not be edited by a strategy, therefore functions that mutate its value should be explicitly imported.

Instruments.leverage_pair_rgxConstant

A regular expression pattern used to match leveraged naming conventions in market symbols. It captures the separator used in leveraged pairs.

Instruments.Derivatives.@d_strMacro

Shortand for parsing derivatives:

> drv = d"BTC/USDT:USDT"
> typeof(drv)
# Instruments.Derivatives.Derivative{Asset{:BTC, :USDT}}