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_nodes::Dict{NTuple{2,UInt64},Vector{AbstractPrice}}: Dictionary containing information about conversion prices between nodes.
  • edge_encode::Dict{String,UInt64}: 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 curreny.
  • 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

Available pathfinding algorithms:

  • a_star_alg: The most basic algorithm for finding the shortest path between two currencies.
CcyConv.conv_a_starFunction
conv_a_star(fx::FXGraph, from_asset::String, to_asset::String) -> ConvRate

Uses an A* search algorithm to find the shortest path between from_asset and to_asset currencies in graph fx.

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> conv = conv_a_star(crypto, "ADA", "BTC");

julia> conv_value(conv)
0.000009582698067

julia> conv_chain(conv)
2-element Vector{CcyConv.AbstractPrice}:
 Price("ADA",  "USDT", 0.4037234)
 Price("USDT", "BTC",  0.0000237)
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 and is required when using a custom context.

source