You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To install CcyConv, simply use the Julia package manager:
12
+
13
+
```julia
14
+
] add CcyConv
15
+
```
16
+
17
+
## Usage
6
18
7
19
Here's how you can find a conversion path from `ADA` to `BNB`:
8
20
@@ -35,15 +47,20 @@ using CcyConv
35
47
36
48
crypto =FXGraph()
37
49
38
-
push!(crypto, Price("ADA", "USDT", 0.5911))
39
-
push!(crypto, Price("ADA", "BTC", 0.00000892))
40
-
push!(crypto, Price("BTC", "ETH", 19.9089))
41
-
push!(crypto, Price("USDT", "ETH", 0.0003))
42
-
push!(crypto, Price("ETH", "BNB", 5.9404))
43
-
push!(crypto, Price("USDT", "XRP", 1.6929))
44
-
push!(crypto, Price("XRP", "BNB", NaN))
45
-
push!(crypto, Price("USDC", "XRP", 1.6920))
46
-
push!(crypto, Price("ADA", "USDC", 0.5909))
50
+
append!(
51
+
crypto,
52
+
[
53
+
Price("ADA", "USDT", 0.5911),
54
+
Price("ADA", "BTC", 0.00000892),
55
+
Price("BTC", "ETH", 19.9089),
56
+
Price("USDT", "ETH", 0.0003),
57
+
Price("ETH", "BNB", 5.9404),
58
+
Price("USDT", "XRP", 1.6929),
59
+
Price("XRP", "BNB", NaN),
60
+
Price("USDC", "XRP", 1.6920),
61
+
Price("ADA", "USDC", 0.5909),
62
+
],
63
+
)
47
64
48
65
conv =conv_a_star(crypto, "ADA", "BNB")
49
66
@@ -56,3 +73,63 @@ julia> conv_chain(conv)
56
73
Price("USDT", "ETH", 0.0003)
57
74
Price("ETH", "BNB", 5.9404)
58
75
```
76
+
77
+
The package lets you to set up a directed graph containing currencies as vertices and convert rates as edges. The graph can fill the missing data from anywhere and directly during the running conversion path calculation.
78
+
79
+
```julia
80
+
using CcyConv
81
+
using CryptoAPIs
82
+
83
+
struct MyCtx <:CcyConv.AbstractCtx
84
+
prices::Dict{String,Float64}
85
+
86
+
MyCtx() =new(Dict{String,Float64}())
87
+
end
88
+
89
+
struct ExSymbol <:CcyConv.AbstractPrice
90
+
base_asset::String
91
+
quote_asset::String
92
+
symbol::String
93
+
end
94
+
95
+
function CcyConv.from_asset(x::ExSymbol)::String
96
+
return x.base_asset
97
+
end
98
+
99
+
function CcyConv.to_asset(x::ExSymbol)::String
100
+
return x.quote_asset
101
+
end
102
+
103
+
function CcyConv.price(ctx::MyCtx, x::ExSymbol)::Float64
104
+
returnget!(ctx.prices, x.symbol) do
105
+
try
106
+
CryptoAPIs.Binance.Spot.avg_price(; symbol = x.symbol).result.price
107
+
catch
108
+
NaN
109
+
end
110
+
end
111
+
end
112
+
113
+
my_graph =FXGraph()
114
+
my_ctx =MyCtx()
115
+
116
+
append!(
117
+
my_graph,
118
+
[
119
+
ExSymbol("ADA", "BTC", "ADABTC"),
120
+
ExSymbol("BTC", "USDT", "BTCUSDT"),
121
+
ExSymbol("PEPE", "USDT", "PEPEUSDT"),
122
+
ExSymbol("EOS", "USDT", "EOSUSDT"),
123
+
],
124
+
)
125
+
126
+
my_conv = (to, from) ->conv_value(my_graph(my_ctx, CcyConv.a_star_alg, to, from))
127
+
128
+
julia>@timemy_conv("ADA", "EOS")
129
+
4.740000 seconds (1.80 M allocations:120.606 MiB, 0.52% gc time, 14.55% compilation time)
0 commit comments