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

Core Asset Types

Base Asset Types

Asset Creation and Management

Currency Operations

Advanced Cash Operations

Derivative Instruments

Derivative Types

Working with Derivatives

Derivative Portfolio Management

Number Formatting

Compact Number Display

Asset Validation and Utilities

Asset Validation

Asset Comparison and Sorting

Integration with Strategy Framework

Asset Instance Integration

Performance Considerations

Efficient Asset Operations

Complete API Reference

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.

source
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
source
Instruments.CashType

A variable quantity of some currency.

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

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

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

Inplace division for Cash objects.

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

Inplace modulo for Cash objects.

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

Inplace multiplication for Cash objects.

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

Inplace remaineder division for Cash objects.

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

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

sc(d::Instruments.Derivatives.Derivative8; orqc) -> Symbol
source
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
source
Instruments.@importcash!Macro

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

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

source

See Also