API Reference

Price

CcyConv.PriceType
Price <: AbstractPrice

A type representing the price of currency pair.

Fields

  • from_asset::String: Base currency name.
  • to_asset::String: Quote currency name.
  • price::Float64: The currency pair price.
source
CcyConv.to_assetFunction
to_asset(x::AbstractPrice) -> String

Returns the name of the quote currency of x.

source
CcyConv.priceFunction
price(x::AbstractPrice) -> Float64

Returns price of the currency pair x.

source
price(ctx::AbstractCtx, x::AbstractPrice) -> Float64

Advanced function for getting the price of a currency pair x that can take into account the context of the ctx.

Note

This function is called when searching for a currency conversion path and can be overloaded to achieve advanced functionality using context (for example, caching the requested data for subsequent requests). See context guide.

source

FXGraph

CcyConv.FXGraphType
FXGraph

This type describes a weighted directed graph in which:

  • The nodes are currencies.
  • The edges between such nodes represent a currency pair.
  • The direction of the edge determines the base and quote currency.
  • The weight of the edge is determined by the conversion price of the currency pair.

Fields

  • edge_prices::Dict{NTuple{2,Int64},Vector{AbstractPrice}}: Dictionary containing information about conversion prices between nodes.
  • node_ids::Dict{String,Int64}: A dictionary containing the names of currencies as keys and their identification numbers as values.
  • graph::Graphs.SimpleGraph{Int64}: A graph containing basic information about vertices and edges.
source
CcyConv.conv_ccysFunction
conv_ccys(fx::FXGraph) -> Vector{String}

Returns the names of all currencies stored in the graph fx.

source
Base.push!Function
Base.push!(fx::FXGraph, node::AbstractPrice)

Adds a new edge to the graph fx corresponding to the currency pair node.

source
Base.append!Function
Base.append!(fx::FXGraph, nodes::Vector{AbstractPrice})

Does the same as push! but can pass several currency pairs nodes at once.

source

ConvRate

CcyConv.ConvRateType
ConvRate

An object describing the price and conversion path between two currencies.

Fields

  • from_asset::String: The name of an initial currency.
  • to_asset::String: The name of a target currency.
  • conv::Float64: Total currency conversion price.
  • chain::Vector{AbstractPrice}: Chain of currency pairs involved in conversion.
source
CcyConv.conv_safe_valueFunction
conv_safe_value(x::ConvRate) -> Float64

Asserts that the conversion rate of x is not a NaN value and then returns it. Otherwise throws an AssertionError.

source

Pathfinding

CcyConv.DFSType
DFS

Algorithm type for exhaustive depth-first search pathfinding.

source
CcyConv.convFunction
conv(fx::FXGraph, from_asset::String, to_asset::String, [::AStar]; ctx::AbstractCtx = MyCtx()) -> ConvRate

Finds the conversion path with the minimum product rate between from_asset and to_asset in graph fx.

Uses state-space A* over log(rate)-weighted edges: the search runs on a lifted graph whose vertices are (currency, visited_set) pairs, so every walk is a simple path in the original graph by construction. This means the algorithm returns the same answer as the exhaustive DFS on every graph, including those with arbitrage cycles. A min-edge-weight admissible heuristic prunes branches that cannot improve the best path found so far.

The minimum-product simple path is NP-hard in general, so the worst-case state count is O(V * 2^V); in practice the priority-queue ordering and admissible heuristic let it beat the exhaustive DFS on most inputs. For graphs with more than 64 currencies the implementation falls back to DFS (the bitmask representation no longer fits).

Examples

julia> crypto = FXGraph();

julia> append!(
           crypto,
           [
               Price("ADA",  "USDT", 0.4037234),
               Price("USDT", "BTC",  0.0000237),
               Price("BTC",  "ETH",  18.808910),
               Price("ETH",  "ALGO", 14735.460),
           ],
       );

julia> result = conv(crypto, "ADA", "BTC");

julia> conv_value(result)
0.000009582698067

julia> conv_chain(result)
2-element Vector{CcyConv.AbstractPrice}:
 Price("ADA",  "USDT", 0.4037234)
 Price("USDT", "BTC",  0.0000237)
source
conv(fx::FXGraph, from_asset::String, to_asset::String, ::DFS; ctx::AbstractCtx = MyCtx()) -> ConvRate

Finds the conversion path with the minimum product rate between from_asset and to_asset. Uses exhaustive DFS over all simple paths in graph fx.

source
CcyConv.FXGraphMethod
(fx::FXGraph)(ctx::AbstractCtx, path_alg::Function, from_asset::String, to_asset::String) -> ConvRate

Applies algorithm path_alg to find a path on graph fx between base currency from_asset and target currency to_asset using context ctx.

Note

This method is low-level. Prefer using conv with the ctx keyword argument.

source