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.
PlanarCore.Exchanges.MARKET_TYPES — Constant
Ccxt market types.
PlanarCore.Exchanges.TICKERSLIST_LOCK_DICT — Constant
Lock held when fetching tickers (list).
PlanarCore.Exchanges.TICKERS_CACHE100 — Constant
The cache for tickers which lasts for 100 minutes by exchange pair.
PlanarCore.Exchanges.currenciesCache1Hour — Constant
The cache for currencies which lasts for 1 hour by exchange.
PlanarCore.Exchanges.currency_lock — Constant
This lock is only used during currency construction.
PlanarCore.Exchanges.tickersCache10Sec — Constant
Caches for tickers for 10-second and concurrently.
PlanarCore.Exchanges.CcxtTrade — Type
A named tuple representing a trade in the CCXT (CryptoCurrency eXchange Trading) library.
timestampsymbolordertypesidetakerOrMakerpriceamountcostfeefees
PlanarCore.Exchanges.CurrencyCash — Type
A CurrencyCash contextualizes a Cash instance w.r.t. an exchange. Operations are rounded to the currency precision.
cashlimitsprecisionfeessandbox
PlanarCore.Exchanges.CurrencyCash — Method
Create a CurrencyCash object.
CurrencyCash(
id::Type{<:ExchangeID},
cash_type::Type{<:PlanarCore.Instruments.Cash},
v;
sandbox,
account
) -> PlanarCore.Exchanges.CurrencyCash
PlanarCore.Exchanges.LeverageTier — Type
A leverage tier represents a range of notional values with its max leverage.
PlanarCore.Exchanges.TradeRole — Type
Taker Or Maker
PlanarCore.Exchanges.TradeSide — Type
Buy or Sell
Base.Libc.time — Method
Get exchange time as DateTime via gateway.
PlanarCore.Ccxt.issupported — Method
Check if a timeframe is supported by an exchange.
issupported(tf::TimeFrames.TimeFrame, exc) -> Any
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
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...
)
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}}
PlanarCore.Data.load_ohlcv — Method
Load all pairs from the exchange according to the configured quote currency and timeframe.
load_ohlcv()
PlanarCore.Data.save_ohlcv — Method
Updates pair data of the globally set Exchange instance.
save_ohlcv(
pair,
timeframe,
data;
kwargs...
) -> Union{Nothing, Zarr.ZArray}
PlanarCore.Exchanges._cur — Method
Returns the currency from the exchange if found.
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.
PlanarCore.Exchanges._get_precision — Method
Get the precision of a market, for a given key ('amount' or 'price').
PlanarCore.Exchanges._handle_leverage — Method
Binance-specific handleleverage — checks leverage key in response.
PlanarCore.Exchanges._lev_frompos — Method
Fetch positions to detect current leverage.
PlanarCore.Exchanges._lpf — Method
Returns the limits, precision, and fees for a currency as a named tuple.
PlanarCore.Exchanges._minmax_pair — Method
Get the limits for a market key, and a default.
PlanarCore.Exchanges._negative_lev_if_cross — Method
Negative leverage value for cross margin (Phemex).
PlanarCore.Exchanges._setfees! — Method
Ccxt fees can have different forms. Converts to Julia types.
PlanarCore.Exchanges._settle_from_market — Method
Extract settlement currency from market.
PlanarCore.Exchanges.accounts — Method
The accounts available for the exchange.
PlanarCore.Exchanges.authenticate! — Function
Exchange authentication is handled by the gateway subprocess automatically when keys are set.
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.
PlanarCore.Exchanges.check_timeout — Function
Check that the exchange timeout is not too low wrt the interval.
PlanarCore.Exchanges.current_account — Method
The account currently being used by the exchange.
PlanarCore.Exchanges.default_price_precision — Method
Default price precision for an exchange.
PlanarCore.Exchanges.dosetmargin — Method
Bybit-specific dosetmargin.
PlanarCore.Exchanges.dosetmargin — Method
Phemex-specific dosetmargin.
PlanarCore.Exchanges.emptycaches! — Method
Clears all caches.
PlanarCore.Exchanges.exckeys! — Method
Set exchange API keys directly on the gateway exchange instance.
PlanarCore.Exchanges.exckeys! — Method
Load exchange API keys from config and set on gateway exchange.
PlanarCore.Exchanges.filter_markets — Method
Get the markets of the ccxt instance, according to min_volume and quote currency.
filter_markets(
exc;
min_volume,
quot,
sep,
type
) -> Dict{Any, Any}
PlanarCore.Exchanges.futures — Method
Returns the matching futures exchange instance, if it exists, or the input exchange otherwise.
PlanarCore.Exchanges.gatewayconvert — Method
Convert a gateway response value into a standard Julia Dict.
gatewayconvert(v) -> Any
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
PlanarCore.Exchanges.getexchange — Method
Get the global exchange.
PlanarCore.Exchanges.gettimeout — Method
Get exchange timeout in milliseconds.
PlanarCore.Exchanges.has_leverage — Method
True if pair is a leveraged pair.
PlanarCore.Exchanges.hastickers — Method
Check if exchange has tickers list.
hastickers(
exc::PlanarCore.ExchangeTypes.Exchange
) -> Union{Missing, Bool}
PlanarCore.Exchanges.hasvolume — Method
Checks if sym (or spot) has volume at or below min_vol (true = skip).
PlanarCore.Exchanges.is_pair_active — Method
Check if a given pair is active on an exchange.
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.
PlanarCore.Exchanges.ismargin — Method
True if mkt is a leveraged market.
PlanarCore.Exchanges.ispercentage — Method
Check if market has percentage or absolute fees.
PlanarCore.Exchanges.isquote — Method
True if id is a quote id.
PlanarCore.Exchanges.isratelimited — Method
Check if rate limit is enabled via gateway.
PlanarCore.Exchanges.lastprice — Method
Fetch the latest price for a specific pair from an exchange.
lastprice(
pair::AbstractString,
exc::PlanarCore.ExchangeTypes.Exchange;
kwargs...
)
PlanarCore.Exchanges.leverage! — Method
Set leverage for exchange.
leverage!(
exc::PlanarCore.ExchangeTypes.Exchange,
v,
sym;
side,
timeout
) -> Any
PlanarCore.Exchanges.leverage_func — Function
Constructor that returns a function that checks if a pair is leveraged.
PlanarCore.Exchanges.leverage_value — Method
Binance-specific leverage formatting — integer leverage.
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.
PlanarCore.Exchanges.marginmode! — Method
Set margin mode for exchange.
marginmode!(
exc::PlanarCore.ExchangeTypes.Exchange,
mode,
symbol;
hedged,
kwargs...
) -> Any
PlanarCore.Exchanges.marginmode! — Method
Binance marginmode! override — skip in sandbox.
PlanarCore.Exchanges.market! — Method
Returns the market from the exchange for a given pair.
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}}
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
PlanarCore.Exchanges.market_precision — Method
Get the amount and price precision for a given pair from an exchange.
market_precision(pair, exc) -> Tuple{Any, Any}
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.
PlanarCore.Exchanges.markettype — Function
Any of (:spot, :future, :swap, :option, :margin, :delivery)
PlanarCore.Exchanges.price_ranges — Method
Get price ranges using tickers data from exchange.
price_ranges(pair::AbstractString, args...; exc, kwargs...)
PlanarCore.Exchanges.quoteid — Method
Quote id of the market.
PlanarCore.Exchanges.quotevol — Method
Get quote volume from ticker.
quotevol(tkr::AbstractDict) -> Any
PlanarCore.Exchanges.ratelimit! — Function
Enable or disable rate limit via gateway.
PlanarCore.Exchanges.ratelimit — Method
Get exchange rate limit.
PlanarCore.Exchanges.ratelimit_njobs — Method
Calculate max concurrent requests from rate limits.
PlanarCore.Exchanges.ratelimit_tokens — Method
Get exchange rate limit tokens.
PlanarCore.Exchanges.sandbox! — Method
Enable sandbox mode for exchange via gateway.
sandbox!(
exc::PlanarCore.ExchangeTypes.Exchange;
flag,
remove_keys
) -> Union{Nothing, Bool}
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.
PlanarCore.Exchanges.setflags! — Method
Set the ccxt exchange has flags (already populated by Exchange constructor).
PlanarCore.Exchanges.spotsymbol — Method
Trims the settlement currency in futures. (mkt is a ccxt market.)
spotsymbol(sym, mkt) -> Any
PlanarCore.Exchanges.str_to_float — Method
Convert the string n to Float64.
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
PlanarCore.Exchanges.tickerprice — Method
Get price from ticker.
tickerprice(tkr) -> Any
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}}
PlanarCore.Exchanges.timeout! — Function
Set exchange timeout (milliseconds) via gateway.
PlanarCore.Exchanges.timestamp — Method
The current timestamp from the exchange via gateway.
PlanarCore.Exchanges.to_float — Function
Convert a value to a float number.
PlanarCore.Exchanges.to_num — Method
Convert a value to a number.
PlanarCore.Instruments.value — Method
The currency cash as a number.
Serialization.deserialize — Method
When deserializing an exchange, use the deserialized id to construct the exchange.
Serialization.serialize — Method
When serializing an exchange, serialize only its id.
Serialization.serialize — Method
When serializing an exchange, serialize only its id.
PlanarCore.Exchanges.@exchange! — Macro
Define an exchange variable set to its matching exchange instance.
PlanarCore.Exchanges.@tickers! — Macro
Fetch and cache tickers data via gateway.
PlanarCore.ExchangeTypes.HOOKS — Constant
Functions f(::Exchange) to call when an exchange is loaded
PlanarCore.ExchangeTypes.exchangeIds — Constant
All possible exchanges that can be instantiated by ccxt.
PlanarCore.ExchangeTypes.CcxtExchange — Type
A CcxtExchange wraps a ccxt exchange accessed via CcxtGateway.
Uses HTTP calls to the ccxt-gateway instead of Python ccxt bindings.
PlanarCore.ExchangeTypes.ExcPrecisionMode — Type
Same as ccxt precision mode enums.
PlanarCore.ExchangeTypes.Exchange — Type
Abstract exchange type.
Defines the interface for interacting with crypto exchanges.
PlanarCore.ExchangeTypes.Exchange — Method
Instantiates a new exchange from a symbol using CcxtGateway.
PlanarCore.ExchangeTypes.Exchange — Method
Instantiates a new exchange from a symbol using CcxtGateway. The exchange subprocess is automatically started on the gateway.
PlanarCore.ExchangeTypes.ExchangeID — Type
A structure for handling Exchange IDs in CCXT.
This structure is used to manage Exchange IDs in the CCXT library.
PlanarCore.ExchangeTypes._has — Method
Checks which exchanges support a given feature via the gateway.
PlanarCore.ExchangeTypes._supports_ws_method — Method
_supports_ws_method(exc::Exchange, sym::AbstractString, suffix::String) -> BoolCheck 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).
PlanarCore.ExchangeTypes.close_exc — Method
Closes the given exchange by removing it from caches.
PlanarCore.ExchangeTypes.eids — Method
Union type of many exchange ids (from Symbol arguments)
PlanarCore.ExchangeTypes.exchangeid — Method
Return the given ExchangeID instance.
PlanarCore.ExchangeTypes.exchangeid — Method
Create an ExchangeID instance from a string.
PlanarCore.ExchangeTypes.exchangeid — Method
Create an ExchangeID instance from a symbol.
See Also
- CCXT API - CCXT library integration and utilities
- Engine API - Core execution engine functions
- Strategies API - Strategy base classes and interfaces
- Exchange Configuration Guide - Setting up exchange connections
- Troubleshooting - Common exchange connection issues