Skip to content

Commit 5cb3039

Browse files
authored
Move readme to index (#5)
1 parent 9008199 commit 5cb3039

File tree

3 files changed

+102
-20
lines changed

3 files changed

+102
-20
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "CcyConv"
22
uuid = "6414a262-d954-4101-8ae8-e45873c55136"
3-
version = "1.0.0"
3+
version = "1.0.1"
44

55
[deps]
66
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,20 @@ using CcyConv
5353

5454
crypto = FXGraph()
5555

56-
push!(crypto, Price("ADA", "USDT", 0.5911))
57-
push!(crypto, Price("ADA", "BTC", 0.00000892))
58-
push!(crypto, Price("BTC", "ETH", 19.9089))
59-
push!(crypto, Price("USDT", "ETH", 0.0003))
60-
push!(crypto, Price("ETH", "BNB", 5.9404))
61-
push!(crypto, Price("USDT", "XRP", 1.6929))
62-
push!(crypto, Price("XRP", "BNB", NaN))
63-
push!(crypto, Price("USDC", "XRP", 1.6920))
64-
push!(crypto, Price("ADA", "USDC", 0.5909))
56+
append!(
57+
crypto,
58+
[
59+
Price("ADA", "USDT", 0.5911),
60+
Price("ADA", "BTC", 0.00000892),
61+
Price("BTC", "ETH", 19.9089),
62+
Price("USDT", "ETH", 0.0003),
63+
Price("ETH", "BNB", 5.9404),
64+
Price("USDT", "XRP", 1.6929),
65+
Price("XRP", "BNB", NaN),
66+
Price("USDC", "XRP", 1.6920),
67+
Price("ADA", "USDC", 0.5909),
68+
],
69+
)
6570

6671
conv = conv_a_star(crypto, "ADA", "BNB")
6772

docs/src/index.md

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22

33
CcyConv is a Julia package for performing currency conversions. It allows for direct and multi-step conversions using the latest exchange 💱 rates.
44

5-
## Quickstart
5+
## Installation
6+
If you haven't installed our [local registry](https://github.com/bhftbootcamp/Green) yet, do that first:
7+
```
8+
] registry add https://github.com/bhftbootcamp/Green.git
9+
```
10+
11+
To install CcyConv, simply use the Julia package manager:
12+
13+
```julia
14+
] add CcyConv
15+
```
16+
17+
## Usage
618

719
Here's how you can find a conversion path from `ADA` to `BNB`:
820

@@ -35,15 +47,20 @@ using CcyConv
3547

3648
crypto = FXGraph()
3749

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+
)
4764

4865
conv = conv_a_star(crypto, "ADA", "BNB")
4966

@@ -56,3 +73,63 @@ julia> conv_chain(conv)
5673
Price("USDT", "ETH", 0.0003)
5774
Price("ETH", "BNB", 5.9404)
5875
```
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+
return get!(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> @time my_conv("ADA", "EOS")
129+
4.740000 seconds (1.80 M allocations: 120.606 MiB, 0.52% gc time, 14.55% compilation time)
130+
0.6004274502578457
131+
132+
julia> @time my_conv("ADA", "EOS")
133+
0.000130 seconds (46 allocations: 2.312 KiB)
134+
0.6004274502578457
135+
```

0 commit comments

Comments
 (0)