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.AbstractCash — Type
Abstract base type for representing a variable quantity of some currency.
This type defines the interface and common functionality for all cash types.
PlanarCore.Instruments.AbstractInstrument — Type
Abstract base type for representing an asset.
Defines the interface and common functionality for all asset types.
PlanarCore.Instruments.BaseCurrency — Type
A symbol checked to be a valid base currency.
PlanarCore.Instruments.Cash — Type
A variable quantity of some currency.
valuelock
> ca = c"USDT"
> typeof(ca)
# Instruments.Cash{:USDT}PlanarCore.Instruments.Instrument — Type
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 themodremoved, e.g.ETH3L=>ETH
> asset = a"BTC/USDT"
> typeof(asset)
Instrument{:BTC, :USDT}
endPlanarCore.Instruments.QuoteCurrency — Type
A symbol checked to be a valid quote currency.
PlanarCore.Instruments.Derivatives.Derivative8 — Type
Derivative parsed accordingly to regex.
assetscidstrikekind
PlanarCore.Instruments.Derivatives.DerivativeKind — Type
Differentiates between perpetuals and options.
PlanarCore.Instruments.Derivatives.SettlementCurrency — Type
A symbol parsed as settlement currency.
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
PlanarCore.Instruments.bc — Method
Returns the base currency of a.
PlanarCore.Instruments.cash! — Method
Sets the cash object to v.
cash!(
c::PlanarCore.Instruments.Cash,
v,
args...;
kwargs...
) -> PlanarCore.Instruments.Cash
PlanarCore.Instruments.compactnum — Method
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 5PlanarCore.Instruments.deleverage_pair — Method
Remove leveraged pair pre/suffixes from base currency.
PlanarCore.Instruments.deleverage_qc — Method
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"PlanarCore.Instruments.div! — Method
Inplace division for Cash objects.
div!(
c::PlanarCore.Instruments.Cash,
v,
args...;
kwargs...
) -> PlanarCore.Instruments.Cash
PlanarCore.Instruments.has_punct — Method
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 characterPlanarCore.Instruments.isfiatpair — Method
Check if both base and quote are fiat currencies.
PlanarCore.Instruments.isfiatquote — Method
Check if quote currency is a stablecoin.
PlanarCore.Instruments.isleveragedpair — Method
Test if pair has leveraged naming.
PlanarCore.Instruments.mod! — Method
Inplace modulo for Cash objects.
mod!(
c::PlanarCore.Instruments.Cash,
v,
args...;
kwargs...
) -> PlanarCore.Instruments.Cash
PlanarCore.Instruments.mul! — Method
Inplace multiplication for Cash objects.
mul!(
c::PlanarCore.Instruments.Cash,
v,
args...;
kwargs...
) -> PlanarCore.Instruments.Cash
PlanarCore.Instruments.qc — Method
Returns the quote currency of a.
PlanarCore.Instruments.raw — Method
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"PlanarCore.Instruments.rdiv! — Method
Inplace remaineder division for Cash objects.
rdiv!(
c::PlanarCore.Instruments.Cash,
v,
args...;
kwargs...
) -> PlanarCore.Instruments.Cash
PlanarCore.Instruments.splitpair — Method
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")
PlanarCore.Instruments.spotpair — Method
Strips the settlement currency from a symbol.
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}
PlanarCore.Instruments.Derivatives.is_settled — Method
Predicates according to OctoBot
PlanarCore.Instruments.Derivatives.perpetual — Method
Create a Derivative from a raw string representation raw, base currency bc, and quote currency qc.
perpetual(
raw::AbstractString,
bc::AbstractString,
qc::AbstractString
) -> Any
PlanarCore.Instruments.Derivatives.sc — Method
Short-circuit the execution of a derivative calculation if the derivative d is zero.
sc(
d::PlanarCore.Instruments.Derivatives.Derivative8;
orqc
) -> Symbol
PlanarCore.Instruments.@a_str — Macro
Parses pair to an Instrument type. ```julia
typeof(a"BTC/USDT")
Instruments.Instrument
PlanarCore.Instruments.@c_str — Macro
Macro to instantiate Cash statically with zero value.
> ca = c"USDT"
USDT: 0.0Use add!(ca, 1000.0) or cash!(ca, 1000.0) to set the value.
PlanarCore.Instruments.@importcash! — Macro
Cash should not be edited by a strategy, therefore functions that mutate its value should be explicitly imported.
PlanarCore.Instruments.@pusdt_str — Macro
Rewrites sym as a perpetual usdt symbol.
> pusdt"btc"
BTC/USDT:USDTPlanarCore.Instruments.ALL_MARKET_SEPARATORS — Constant
A collection of all possible separators used in market symbols
PlanarCore.Instruments.DEFAULT_MARKET_SEPARATOR — Constant
The default separator used in market symbols
PlanarCore.Instruments.SETTLEMENT_SEPARATOR — Constant
The separator used to separate the settlement currency from the quote currency in a market symbol.
PlanarCore.Instruments.fiatnames — Constant
A list of fiat and fiat-like assets names.
PlanarCore.Instruments.fiatsyms — Constant
A set of symbols representing fiat and fiat-like assets
PlanarCore.Instruments.leverage_pair_rgx — Constant
A regular expression pattern used to match leveraged naming conventions in market symbols. It captures the separator used in leveraged pairs.
PlanarCore.Instruments.Derivatives.@d_str — Macro
Shortand for parsing derivatives:
> drv = d"BTC/USDT:USDT"
> typeof(drv)
# Instruments.Derivatives.Derivative{Instrument{:BTC, :USDT}}See Also
- Instances API - Asset instance management
- Strategies API - Strategy base classes and interfaces
- Data API - Data structures and management
- Strategy Development Guide - Building trading strategies
- Advanced Trading Guide - Margin and derivative trading