Instruments API

The Instruments module provides definitions and management for financial instruments in Planar. It handles different asset types, currency management, and derivative instruments for advanced trading strategies.

Overview

The Instruments module includes:

  • Base asset types and currency definitions
  • Cash and currency management
  • Derivative instruments (futures, options, etc.)
  • Asset validation and conversion utilities
  • Compact number formatting for financial data

Complete API Reference

PlanarCore.Instruments.InstrumentType

An Instrument 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)
Instrument{:BTC, :USDT}
end
source
PlanarCore.Instruments.addzero!Method

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

addzero!(
    c::PlanarCore.Instruments.Cash,
    v,
    args...;
    kwargs...
) -> PlanarCore.Instruments.Cash
source
PlanarCore.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
source
PlanarCore.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"
source
PlanarCore.Instruments.div!Method

Inplace division for Cash objects.

div!(
    c::PlanarCore.Instruments.Cash,
    v,
    args...;
    kwargs...
) -> PlanarCore.Instruments.Cash
source
PlanarCore.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
source
PlanarCore.Instruments.mod!Method

Inplace modulo for Cash objects.

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

Inplace multiplication for Cash objects.

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

Convert an AbstractInstrument object a to its raw representation.

raw(a::PlanarCore.Instruments.AbstractInstrument) -> Any

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

Example:

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

Inplace remaineder division for Cash objects.

rdiv!(
    c::PlanarCore.Instruments.Cash,
    v,
    args...;
    kwargs...
) -> PlanarCore.Instruments.Cash
source
PlanarCore.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")

source
PlanarCore.Instruments.subzero!Method

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

subzero!(
    c::PlanarCore.Instruments.AbstractCash,
    v,
    args...;
    kwargs...
) -> Union{PlanarCore.Exchanges.CurrencyCash, PlanarCore.Instruments.Cash}
source
PlanarCore.Instruments.@c_strMacro

Macro to instantiate Cash statically with zero value.

> ca = c"USDT"
USDT: 0.0

Use add!(ca, 1000.0) or cash!(ca, 1000.0) to set the value.

source

See Also