Exchanges
Exchanges.LEVERAGED_PAIR_OPTIONS
— ConstantA 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.
Exchanges.MARKET_TYPES
— ConstantCcxt market types.
Exchanges.TICKERSLIST_LOCK_DICT
— ConstantLock held when fetching tickers (list).
Exchanges.TICKERS_CACHE100
— ConstantThe cache for tickers which lasts for 100 minutes by exchange pair.
Exchanges.activeCache1Min
— ConstantCaches active states (1minute).
Exchanges.currenciesCache1Hour
— ConstantThe cache for currencies which lasts for 1 hour by exchange.
Exchanges.currency_lock
— ConstantThis lock is only used during currency construction.
Exchanges.leverageTiersCache
— ConstantLeverage tiers are cached both in RAM and storage.
Exchanges.marketsCache1Min
— ConstantCaches markets (1minute).
Exchanges.tickersCache10Sec
— ConstantCaches tickers (10seconds).
Exchanges.tickersLockDict
— ConstantLock held when fetching tickers (per ticker).
Exchanges.CcxtTrade
— TypeA named tuple representing a trade in the CCXT (CryptoCurrency eXchange Trading) library.
timestamp
symbol
order
type
side
takerOrMaker
price
amount
cost
fee
fees
Exchanges.CurrencyCash
— TypeA CurrencyCash
contextualizes a Cash
instance w.r.t. an exchange. Operations are rounded to the currency precision.
cash
limits
precision
fees
sandbox
Exchanges.CurrencyCash
— MethodCreate a CurrencyCash object.
CurrencyCash(
id::Type{<:ExchangeID},
cash_type::Type{<:Cash},
v;
sandbox,
account
) -> Exchanges.CurrencyCash
Exchanges.LeverageTier
— TypeA type representing a tier of leverage.
min_notional
max_notional
max_leverage
tier
mmr
bc
This type is used to store and manage information about a specific leverage tier. Each tier is defined by its minimum and maximum notional values, maximum leverage, tier number, and maintenance margin requirement.
Exchanges.LeverageTiersDict
— TypeEvery asset has a list of leverage tiers, that are stored in a SortedDict, if the exchange supports them.
Exchanges.TradeRole
— TypeTaker Or Maker
Exchanges.TradeSide
— TypeBuy or Sell
Ccxt.issupported
— MethodCheck if a timeframe is supported by an exchange.
issupported(tf::TimeFrames.TimeFrame, exc) -> Any
Data.load_ohlcv
— MethodLoads all pairs for a given timeframe, matching the global exc
(Exchange object) and config
.
load_ohlcv(timeframe::AbstractString; kwargs...) -> Any
Data.load_ohlcv
— MethodLoads all pairs for a given exchange and timeframe, matching the global config
and zi
(Zarr Instance).
load_ohlcv(
exc::Exchange,
timeframe::AbstractString;
kwargs...
)
Data.load_ohlcv
— MethodLoad given pairs from the global exc
(Exchange object) and zi
(Zarr Instance).
load_ohlcv(
pairs::Union{AbstractDict, AbstractArray},
timeframe::AbstractString;
kwargs...
) -> Dict{String}
Data.load_ohlcv
— MethodLoad all pairs from the exchange according to the configured quote currency and timeframe.
load_ohlcv() -> Dict{String}
Data.save_ohlcv
— MethodUpdates pair data of the globally set Exchange instance.
save_ohlcv(pair, timeframe, data; kwargs...)
Exchanges._cur
— MethodReturns the currency from the exchange if found.
Exchanges._lpf
— MethodReturns the limits, precision, and fees for a currency as a named tuple.
_lpf(
exc,
cur
) -> NamedTuple{(:limits, :precision, :fees), <:Tuple{@NamedTuple{min::Float64, max::Float64}, Union{Float64, Int64}, Number}}
The tuple fields can be nothing if the currency property is not provided.
Exchanges._setfees!
— MethodCcxt fees can have different forms.
Exchanges.accounts
— MethodThe accounts available for the exchange.
Exchanges.check
— MethodChecks if the python exchange instance supports all the calls required by Planar.
check(exc::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.
Exchanges.check_timeout
— FunctionCheck that the exchange timeout is not too low wrt the interval.
Exchanges.current_account
— MethodThe account currently being used by the exchange.
Exchanges.default_leverage_tier
— MethodReturns a default leverage tier for a specific symbol.
default_leverage_tier(
sym
) -> SortedDict{Int64, Exchanges.LeverageTier{Float64}, Base.Order.ForwardOrdering}
The default leverage tier has generous limits.
Exchanges.emptycaches!
— MethodClears all Python-dependent caches.
Exchanges.exckeys!
— MethodSet exchange api keys.
exckeys!(exc; sandbox, acc)
Exchanges.filter_markets
— MethodGet the markets of the ccxt
instance, according to min_volume
and quote
currency.
filter_markets(
exc;
min_volume,
quot,
sep,
type
) -> Dict{Any, Any}
The filter_markets
function takes the following parameters:
exc
: an Exchange object to get the markets from.min_volume
(optional, default is 10e4): the minimum volume that a market should have.quot
(optional, default is "USDT"): the quote currency to filter the markets by.sep
(optional, default is '/'): the separator used in market strings.
Exchanges.futures
— MethodReturns the matching futures exchange instance, if it exists, or the input exchange otherwise.
Exchanges.getexchange!
— Functiongetexchage!: ccxt exchange by symbol either from cache or anew.
getexchange!(x::Symbol; ...) -> Exchange
getexchange!(
x::Symbol,
params;
account,
sandbox,
markets,
kwargs...
) -> Exchange
It uses a WS instance if available, otherwise an async instance.
Exchanges.getexchange
— MethodGet the global exchange.
Exchanges.has_leverage
— MethodTrue if pair
is a leveraged pair.
Exchanges.hastickers
— MethodCheck if exchange has tickers list.
hastickers(exc::Exchange) -> Union{Missing, Bool}
Exchanges.hasvolume
— MethodTrue if symbol sym
has a quote volume less than min_vol
.
Exchanges.is_pair_active
— MethodCheck if a currency pair is active on an exchange.
is_pair_active(pair::AbstractString, exc::Exchange) -> Any
Exchanges.isfileyounger
— MethodChecks 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.
Exchanges.ismargin
— MethodTrue if mkt
is a leveraged market.
Exchanges.ispercentage
— MethodCheck if market has percentage or absolute fees.
Exchanges.isquote
— MethodTrue if id
is a quote id.
Exchanges.issandbox
— MethodCheck if exchange is in sandbox mode.
Exchanges.jlpyconvert
— MethodConvert a Python object into a Julia object.
jlpyconvert(py) -> Union{Nothing, Dict{Any, Any}}
Exchanges.lastprice
— MethodFetch the latest price for a specific pair from an exchange.
lastprice(
pair::AbstractString,
exc::Exchange;
kwargs...
) -> Any
pair
: a string representing the currency pair to fetch the latest price for.exc
: an Exchange object to fetch the latest price from.kwargs
(optional): any additional keyword arguments are passed on to the underlying fetch operation.
Exchanges.leverage!
— MethodUpdate the leverage for a specific symbol.
leverage!(exc::Exchange, v, sym; side, timeout) -> Any
exc
: an Exchange object to update the leverage on.v
: a Real number representing the new leverage value.sym
: a string representing the symbol to update the leverage for.
Exchanges.leverage_func
— FunctionConstructor that returns a function that checks if a pair is leveraged.
Exchanges.leverage_tiers
— MethodFetch the leverage tiers for a specific symbol from an exchange.
leverage_tiers(exc::Exchange, sym::AbstractString) -> Any
exc
: an Exchange object to fetch the leverage tiers from.sym
: a string representing the symbol to fetch the leverage tiers for.
Exchanges.loadmarkets!
— MethodLoad exchange markets.
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.
Exchanges.marginmode!
— MethodUpdate margin mode for a specific symbol on the exchange.
Also sets if the position is hedged or one sided. For customizations, dispatch to dosetmargin
.
marginmode!(
exc::Exchange,
mode,
symbol;
hedged,
kwargs...
) -> Any
Exchanges.market!
— MethodRetrieves a cached market (1minute) or fetches it from exchange.
market!(pair, exc::Exchange) -> Any
Exchanges.market_fees
— MethodFetch the market fees for a specific pair from an exchange.
market_fees(
pair::AbstractString,
exc::Exchange;
only_taker
) -> NamedTuple{(:taker, :maker, :min, :max), <:NTuple{4, Any}}
pair
: a string representing the currency pair to fetch the market fees for.exc
(optional, default is the current exchange): an Exchange object to fetch the market fees from.only_taker
(optional, default isnothing
): a boolean indicating whether to fetch only the taker fee. Ifnothing
, both maker and taker fees are fetched.
Exchanges.market_limits
— MethodFetch the market limits for a specific pair from an exchange.
market_limits(
pair::AbstractString,
exc::Exchange;
precision,
default_leverage,
default_amount,
default_price,
default_cost
) -> NamedTuple
pair
: a string representing the currency pair to fetch the market limits for.exc
: an Exchange object to fetch the market limits from.precision
(optional, default isprice=nothing, amount=nothing
): a named tuple specifying the precision for price and amount.default_leverage
(optional, default isDEFAULT_LEVERAGE
): the default leverage to use if not specified in the market data.default_amount
(optional, default isDEFAULT_AMOUNT
): the default amount to use if not specified in the market data.default_price
(optional, default isDEFAULT_PRICE
): the default price to use if not specified in the market data.default_cost
(optional, default isDEFAULT_COST
for non-fiat quote pairs andDEFAULT_FIAT_COST
for fiat quote pairs): the default cost to use if not specified in the market data.
Exchanges.market_precision
— MethodPrecision of the (base, quote) currencies of the market.
market_precision(
pair::AbstractString,
exc::Exchange
) -> NamedTuple{(:amount, :price), <:Tuple{Any, Any}}
Exchanges.marketsid
— MethodGet the exchange market ids.
Exchanges.markettype
— FunctionAny of (:spot, :future, :swap, :option, :margin, :delivery)
Exchanges.maxleverage
— MethodGet the maximum leverage for a specific size and symbol from an exchange.
maxleverage(
exc::Exchange,
sym::AbstractString,
size::Real
) -> Real
exc
: an Exchange object to fetch the maximum leverage from.sym
: a string representing the symbol to fetch the maximum leverage for.size
: a Real number representing the size to fetch the maximum leverage for.
Exchanges.price_ranges
— MethodGet price ranges using tickers data from exchange.
price_ranges(pair::AbstractString, args...; exc, kwargs...)
The price_ranges
function takes the following parameters:
pair
: a string representing the currency pair.args...
: a variable number of arguments to pass to the price ranges calculation.exc
(optional, default is globalexc
): an Exchange object to get the tickers data from.kwargs...
: a variable number of keyword arguments to pass to the price ranges calculation.
Exchanges.quoteid
— MethodQuote id of the market.
Exchanges.quotevol
— MethodGet quote volume from ticker.
quotevol(tkr::AbstractDict) -> Any
Exchanges.ratelimit!
— FunctionEnable or disable rate limit.
ratelimit!(exc::Exchange) -> Bool
ratelimit!(exc::Exchange, flag) -> Any
Exchanges.sandbox!
— MethodEnable sandbox mode for exchange. Should only be called on exchange construction.
sandbox!(
exc::Exchange;
flag,
remove_keys
) -> Union{Nothing, Bool}
exc
(optional, default is globalexc
): an Exchange object to set the sandbox mode for.flag
(optional, default is the inverse of the current sandbox mode status): a boolean indicating whether to enable or disable sandbox mode.remove_keys
(optional, default is true): a boolean indicating whether to remove the API keys while enabling sandbox mode.
Exchanges.setexchange!
— MethodInitializes an exchange struct.
setexchange!(
exc::Exchange,
args...;
markets,
kwargs...
) -> Exchange
exc
: an Exchange object to be set.args...
: a variable number of arguments to pass to the exchange setup.markets
(optional, default is:yes
): a symbol that indicates whether to load markets during setup.kwargs...
: a variable number of keyword arguments to pass to the exchange setup.
Configures the matching ccxt class, optionally loads the markets, sets the exchange timeframes, and sets the exchange API keys.
Exchanges.setflags!
— MethodSet the ccxt exchange has
flags.
Exchanges.spotsymbol
— MethodTrims the settlement currency in futures. (mkt
is a ccxt market.)
spotsymbol(sym, mkt) -> Any
Exchanges.ticker!
— MethodFetch the ticker for a specific pair from an exchange.
ticker!(pair, exc::Exchange; timeout, func, delay) -> Any
The ticker!
function takes the following parameters:
pair
: a string representing the currency pair to fetch the ticker for.exc
: an Exchange object to fetch the ticker from.timeout
(optional, default is 3 seconds): the maximum time to wait for the ticker fetch operation.func
(optional, default is the result of_tickerfunc(exc)
): the function to use to fetch the ticker.
Exchanges.tickerprice
— MethodGet price from ticker.
tickerprice(tkr) -> Any
The tickerprice
function takes the following parameters:
tkr
: a Ticker object.
Exchanges.tickers
— MethodGet the exchange tickers.
tickers(
exc::Exchange,
quot;
min_vol,
skip_fiat,
with_margin,
with_leverage,
as_vec,
verbose,
type,
cross_match
)
exc
: an Exchange object to fetch the tickers from.quot
: only choose pairs where the quote currency equalsquot
.min_vol
: the minimum volume of each pair.skip_fiat
(optional, default is true): ignore fiat/fiat pairs.with_margin
(optional, default is the result ofconfig.margin != NoMargin()
): only choose pairs enabled for margin trading.with_leverage
(optional, default is:no
): if:no
, skip all pairs where the base currency matches theleverage_pair_rgx
regex.as_vec
(optional, default is false): return the pair list as a Vector instead of as a Dict.verbose
(optional, default is true): print detailed output about the operation.type
(optional, default is the result ofmarkettype(exc)
): the type of markets to fetch tickers for.cross_match
list of other exchanges where the filter pairs must also be present in
Exchanges.tickers
— MethodGet the tickers matching quote currency quot
.
Exchanges.tier
— MethodGet the leverage tier for a specific size from a sorted dictionary of tiers.
tier(
tiers::SortedDict{Int64, Exchanges.LeverageTier},
size::Real
) -> Tuple{Union{Nothing, Int64}, Exchanges.LeverageTier}
tiers
: a SortedDict where the keys are integers representing the size thresholds and the values are LeverageTier objects.size
: a Real number representing the size to fetch the tier for.
Exchanges.timeout!
— FunctionSet exchange timeout. (milliseconds)
timeout!(exc::Exchange) -> Int64
timeout!(exc::Exchange, v) -> Any
Exchanges.timestamp
— MethodThe current timestamp from the exchange.
Exchanges.to_float
— FunctionConvert a Python object to a float number.
Exchanges.to_num
— MethodConvert a Python object to a number.
Instruments.value
— MethodThe currency cash as a number.
Serialization.deserialize
— MethodWhen deserializing an exchange, use the deserialized id to construct the exchange.
Serialization.serialize
— MethodWhen serializing an exchange, serialize only its id.
Serialization.serialize
— MethodWhen serializing an exchange, serialize only its id.
Exchanges.@exchange!
— MacroDefine an exchange variable set to its matching exchange instance.
Exchanges.@tickers!
— MacroFetch and cache tickers data.
The @tickers!
macro takes the following parameters:
type
(optional, default is nothing): the type of tickers to fetch and cache.force
(optional, default is false): a boolean that indicates whether to force the data fetch, even if the data is already present.
ExchangeTypes.HOOKS
— ConstantFunctions f(::Exchange)
to call when an exchange is loaded
ExchangeTypes.exchangeIds
— ConstantAll possible exchanges that can be instantiated by ccxt.
ExchangeTypes.exchanges
— ConstantGlobal var holding Exchange instances. Used as a cache.
ExchangeTypes.sb_exchanges
— ConstantGlobal var holding Sandbox Exchange instances. Used as a cache.
ExchangeTypes.CcxtExchange
— TypeThe CcxtExchange
type wraps a ccxt exchange instance. Some attributes frequently accessed are copied over to avoid round tripping python. More attributes might be added in the future. To instantiate an exchange call getexchange!
or setexchange!
.
ExchangeTypes.ExcPrecisionMode
— TypeSame as ccxt precision mode enums.
ExchangeTypes.Exchange
— TypeInstantiates a new Exchange
wrapper for the provided x
Python object.
This constructs a CcxtExchange
struct with the provided Python object. It extracts the exchange ID, name, and other metadata. It runs any registered hook functions for that exchange. It sets a finalizer to close the exchange when garbage collected.
Returns the new Exchange
instance, or an empty one if x
is None.
ExchangeTypes.Exchange
— TypeAbstract exchange type.
Defines the interface for interacting with crypto exchanges. Implemented for CCXT in CcxtExchange.
ExchangeTypes.ExchangeID
— TypeA structure for handling Exchange IDs in CCXT.
This structure is used to manage Exchange IDs in the CCXT library. It contains methods for creating an Exchange ID from a symbol, a Python object, or directly from a symbol type. It ensures that the symbol is in the list of valid exchange IDs.
Base.first
— MethodReturn the first available property from a variable number of Symbol arguments in the given Exchange.
first(exc::Exchange, args::Symbol...) -> Any
This function iterates through the provided Symbols and returns the value of the first property that exists in the Exchange object.
Base.getproperty
— MethodAttributes not matching the Exchange
struct fields are forwarded to the wrapped ccxt class instance.
Base.hash
— MethodThe hash of an exchange object is reduced to its symbol (the function used to instantiate the object from ccxt).
ExchangeTypes._has
— MethodChecks if the specified feature feat
is supported by any of the exchanges available through the ccxt library.
Arguments
s::Symbol
: The feature to check for support across exchanges.full::Bool=true
: Iftrue
, checks both static and instantiated properties of the exchange for support.
Returns
Vector{String}
: A list of exchange names that support the specified feature.
ExchangeTypes.close_exc
— MethodCloses the given exchange.
close_exc(
exc::ExchangeTypes.CcxtExchange
) -> Union{Nothing, Task}
This function attempts to close the given exchange if it exists. It checks if the exchange has a 'close' attribute and if so, it schedules the 'close' coroutine for execution.
ExchangeTypes.decimal_to_size
— MethodConverts value v to integer size with precision p.
decimal_to_size(v, p::ExcPrecisionMode; exc) -> Any
Used when converting exchange API responses to integer sizes for orders.
ExchangeTypes.eids
— MethodUnion type of many exchange ids (from Symbol
arguments)
ExchangeTypes.exchangeid
— MethodReturn the given ExchangeID instance.
ExchangeTypes.exchangeid
— MethodCreate an ExchangeID instance from a symbol.