Exchanges API

The Exchanges module provides unified interfaces for connecting to cryptocurrency exchanges through the CCXT library. It handles exchange connectivity, market data access, and order management across multiple exchanges.

Overview

The Exchanges module includes:

  • Exchange connection and authentication management
  • Unified market data interfaces
  • Order placement and management
  • Account and balance information
  • Market information and trading rules
  • Sandbox and live trading modes

Complete API Reference

PlanarCore.Exchanges.LEVERAGED_PAIR_OPTIONS — Constant

A leveraged pair is a pair like BTC3L/USD.

  • :yes : Leveraged pairs will not be filtered.
  • :only : ONLY leveraged will be kept.
  • :from : Selects non leveraged pairs, that also have at least one leveraged sibling.
source
PlanarCore.Exchanges.CcxtTrade — Type

A named tuple representing a trade in the CCXT (CryptoCurrency eXchange Trading) library.

  • timestamp

  • symbol

  • order

  • type

  • side

  • takerOrMaker

  • price

  • amount

  • cost

  • fee

  • fees

source
PlanarCore.Exchanges.CurrencyCash — Method

Create a CurrencyCash object.

CurrencyCash(
    id::Type{<:ExchangeID},
    cash_type::Type{<:PlanarCore.Instruments.Cash},
    v;
    sandbox,
    account
) -> PlanarCore.Exchanges.CurrencyCash
source
PlanarCore.Data.load_ohlcv — Method

Loads all pairs for a given timeframe, matching the global exc (Exchange object) and config.

load_ohlcv(timeframe::AbstractString; kwargs...) -> Any
source
PlanarCore.Data.load_ohlcv — Method

Loads all pairs for a given exchange and timeframe, matching the global config and zi (Zarr Instance).

load_ohlcv(
    exc::PlanarCore.ExchangeTypes.Exchange,
    timeframe::AbstractString;
    kwargs...
)
source
PlanarCore.Data.load_ohlcv — Method

Load given pairs from the global exc (Exchange object) and zi (Zarr Instance).

load_ohlcv(
    pairs::Union{AbstractDict, AbstractArray},
    timeframe::AbstractString;
    kwargs...
) -> Union{Dict{String, Zarr.ZArray}, Dict{String, PlanarCore.Data.PairData}}
source
PlanarCore.Data.save_ohlcv — Method

Updates pair data of the globally set Exchange instance.

save_ohlcv(
    pair,
    timeframe,
    data;
    kwargs...
) -> Union{Nothing, Zarr.ZArray}
source
PlanarCore.Exchanges._elconvert — Method

Converts a nested structure (Dict/Vector) recursively into a standard Julia Dict.

_elconvert(v) -> Any

Handles JSON3.Object and JSON3.Array types from gateway responses.

source
PlanarCore.Exchanges._margin_str_norm — Method

Normalize a margin-mode string to its canonical form.

_margin_str_norm(mode) -> Tuple{String, Bool}

Lowercases the input, replaces - and spaces with _, and returns the canonical (mode_str, hedged) tuple. Used by both the generic and Binance string marginmode! overloads so normalization stays in sync.

source
PlanarCore.Exchanges.check — Method

Checks if the exchange instance supports all the calls required by Planar.

check(exc::PlanarCore.ExchangeTypes.Exchange; type)
  • exc: an Exchange object to perform the check on.
  • type (optional, default is :basic): a symbol representing the type of check to perform.
source
PlanarCore.Exchanges.check_margin_support! — Method

Checks that the exchange supports the margin mode requested by a strategy.

check_margin_support!(
    exc::PlanarCore.ExchangeTypes.Exchange,
    margin::MarginMode
) -> Bool

Mirrors the existing isolated-margin support check: at strategy instantiation we verify against ccxt (via has) that the exchange the strategy instance is using actually supports the chosen margin mode.

  • Any WithMargin mode (isolated or cross) requires setMarginMode.
  • Hedged variants (IsolatedHedged, CrossHedged) additionally require setPositionMode (hedge / position-mode support).

A missing capability emits a clear @error (and false is returned) so the strategy fails fast instead of corrupting state later. This matches the lenient style of marginmode! (which warns on setMarginMode failure) but makes the missing hedged/cross support explicit.

source
PlanarCore.Exchanges.dosetpositionmode — Method

Set position (hedge) mode for exchange.

dosetpositionmode(exc, symbol; hedged, kwargs...) -> Any

Enables or disables hedge / position mode (setPositionMode). This is an account-wide setting (the symbol argument is optional). hedged MUST be a real boolean: it is passed via the request body (POST) so the JSON bool type is preserved — a query= string would send "true"/"false" which Python treats as truthy (Gotcha #8) and would silently force hedge mode.

source
PlanarCore.Exchanges.getexchange! — Function

getexchange!: Get ccxt exchange by symbol, either from cache or create anew via CcxtGateway.

getexchange!(
    x::Symbol;
    ...
) -> PlanarCore.ExchangeTypes.Exchange
getexchange!(
    x::Symbol,
    params;
    account,
    sandbox,
    markets,
    kwargs...
) -> PlanarCore.ExchangeTypes.Exchange
source
PlanarCore.Exchanges.isfileyounger — Method

Checks if a file is younger than a specified period.

isfileyounger(f::AbstractString, p::Dates.Period) -> Any
  • f: a string that represents the path to the file.
  • p: a Period object that represents the time period.
source
PlanarCore.Exchanges.lastprice — Method

Fetch the latest price for a specific pair from an exchange.

lastprice(
    pair::AbstractString,
    exc::PlanarCore.ExchangeTypes.Exchange;
    kwargs...
) -> Any
source
PlanarCore.Exchanges.loadmarkets! — Method

Load exchange markets from gateway or cache.

loadmarkets!(exc; cache, agemax)
  • exc: an Exchange object that represents the exchange to load markets from.
  • cache (optional, default is true): a boolean that indicates whether to rely on storage cache.
  • agemax (optional, default is Day(1)): a Period object that represents the maximum cache valid period.
source
PlanarCore.Exchanges.marginmode! — Function

Set margin mode for exchange.

marginmode!(
    exc::PlanarCore.ExchangeTypes.Exchange,
    mode::MarginMode;
    ...
) -> Any
marginmode!(
    exc::PlanarCore.ExchangeTypes.Exchange,
    mode::MarginMode,
    symbol;
    kwargs...
) -> Any
source
PlanarCore.Exchanges.market_fees — Method

Get the maker and taker fee for a given pair from an exchange.

market_fees(
    pair,
    exc;
    only_taker
) -> NamedTuple{(:taker, :maker, :min, :max), <:NTuple{4, Any}}
source
PlanarCore.Exchanges.market_limits — Method

Get the minimum and maximum amount, cost, and price for a given pair from an exchange.

market_limits(
    pair,
    exc;
    precision,
    default_leverage,
    default_amount,
    default_price,
    default_cost
) -> NamedTuple
source
PlanarCore.Exchanges.marketsid — Method

Get vector of market ids from exchange.

  • exclude (optional, default is nothing): a symbol or vector of symbols representing market types to exclude.
source
PlanarCore.Exchanges.sandbox! — Method

Enable sandbox mode for exchange via gateway.

sandbox!(
    exc::PlanarCore.ExchangeTypes.Exchange;
    flag,
    remove_keys
) -> Union{Nothing, Bool}
source
PlanarCore.Exchanges.setexchange! — Method

Initializes a gateway-based exchange struct.

setexchange!(
    exc::PlanarCore.ExchangeTypes.Exchange,
    args...;
    markets,
    kwargs...
) -> PlanarCore.ExchangeTypes.CcxtExchange
  • exc: an Exchange object to be set up.
  • markets (optional, default is :yes): whether to load markets during setup.

Configures the exchange timeframes, loads markets, and sets API keys.

source
PlanarCore.Exchanges.ticker! — Method

Fetch the ticker for a specific pair from an exchange via gateway.

ticker!(
    pair,
    exc::PlanarCore.ExchangeTypes.Exchange;
    timeout,
    func,
    delay
) -> Any
source
PlanarCore.Exchanges.tickers — Function

Fetch and filter tickers from an exchange, or use the global exchange.

tickers(; ...) -> Union{Dict{String, Any}, Vector{String}}
tickers(
    exc::PlanarCore.ExchangeTypes.Exchange;
    ...
) -> Union{Dict{String, Any}, Vector{String}}
tickers(
    exc::PlanarCore.ExchangeTypes.Exchange,
    quot;
    min_vol,
    skip_fiat,
    with_margin,
    with_leverage,
    as_vec,
    verbose,
    type,
    cross_match
) -> Union{Dict{String, Any}, Vector{String}}
source
PlanarCore.ExchangeTypes._supports_ws_method — Method
_supports_ws_method(exc::Exchange, sym::AbstractString, suffix::String) -> Bool

Check whether the WebSocket-based fetch method should be used for the given exchange, symbol, and method suffix.

Some exchanges advertise WS methods in their has dict but restrict them to specific market types (e.g., Binance fetchOrderBookWs only works for swap markets). This function encodes those exchange-specific restrictions.

Returns true by default (respects the has dict).

source

See Also