Skip to content

Commit d246292

Browse files
artememelingryumov
andauthored
Add Deribit Common exchange (#40)
Co-authored-by: Stas Gryumov <33372067+gryumov@users.noreply.github.com>
1 parent 96003bd commit d246292

File tree

18 files changed

+1331
-1
lines changed

18 files changed

+1331
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "CryptoAPIs"
22
uuid = "5e3d4798-c815-4641-85e1-deed530626d3"
3-
version = "0.22.0"
3+
version = "0.23.0"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ Then, to install CryptoAPIs, simply use the Julia package manager:
8282
<td><a href="src/Cryptocom/Spot">CryptoAPIs.Cryptocom.Spot</a></td>
8383
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Cryptocom/#Spot">Spot</a></td>
8484
</tr>
85+
<tr>
86+
<td><img src="docs/src/assets/deribit.png" alt="Deribit Logo" width="20" height="20"></td>
87+
<td><a href="https://www.deribit.com/">Deribit</a></td>
88+
<td><a href="https://docs.deribit.com/">Common</a></td>
89+
<td><a href="src/Deribit/Common">CryptoAPIs.Deribit.Common</a></td>
90+
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Deribit/#Common">Common</a></td>
91+
</tr>
8592
<tr>
8693
<td><img src="docs/src/assets/gateio.png" alt="Gateio Logo" width="20" height="20"></td>
8794
<td><a href="https://www.gate.io/">Gate.io</a></td>

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ makedocs(;
2121
"pages/Bybit.md",
2222
"pages/Coinbase.md",
2323
"pages/Cryptocom.md",
24+
"pages/Deribit.md",
2425
"pages/Gateio.md",
2526
"pages/Huobi.md",
2627
"pages/Kraken.md",

docs/src/assets/deribit.png

1.97 KB
Loading

docs/src/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ Then, to install CryptoAPIs, simply use the Julia package manager:
7676
<td><a href="src/Cryptocom/Spot">CryptoAPIs.Cryptocom.Spot</a></td>
7777
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Cryptocom/#Spot">Spot</a></td>
7878
</tr>
79+
<tr>
80+
<td><img src="assets/deribit.png" alt="Deribit Logo" width="20" height="20"></td>
81+
<td><a href="https://www.deribit.com/">Deribit</a></td>
82+
<td><a href="https://docs.deribit.com/">Common</a></td>
83+
<td><a href="src/Deribit/Common">CryptoAPIs.Deribit.Common</a></td>
84+
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Deribit/#Common">Common</a></td>
85+
</tr>
7986
<tr>
8087
<td><img src="assets/gateio.png" alt="Gateio Logo" width="20" height="20"></td>
8188
<td><a href="https://www.gate.io/">Gate.io</a></td>

docs/src/pages/Deribit.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Deribit
2+
3+
```@docs
4+
CryptoAPIs.Deribit.DeribitClient
5+
CryptoAPIs.Deribit.DeribitAPIsErrorMsg
6+
CryptoAPIs.Deribit.DeribitAPIError
7+
CryptoAPIs.Deribit.Data
8+
```
9+
10+
## Common
11+
12+
```@docs
13+
CryptoAPIs.Deribit.Common.public_client
14+
```
15+
16+
```@docs
17+
CryptoAPIs.Deribit.Common.book_summary
18+
CryptoAPIs.Deribit.Common.candle
19+
CryptoAPIs.Deribit.Common.funding_rate
20+
CryptoAPIs.Deribit.Common.instrument
21+
CryptoAPIs.Deribit.Common.order_book
22+
CryptoAPIs.Deribit.Common.ticker
23+
```

examples/Deribit/Common.jl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Deribit/Common
2+
# https://docs.deribit.com/
3+
4+
using Dates
5+
using CryptoAPIs
6+
using CryptoAPIs.Deribit
7+
8+
# Common
9+
10+
CryptoAPIs.Deribit.Common.candle(
11+
instrument_name = "BTC-PERPETUAL",
12+
start_timestamp = now(UTC) - Minute(100),
13+
end_timestamp = now(UTC) - Hour(1),
14+
resolution = CryptoAPIs.Deribit.Common.Candle.m1,
15+
)
16+
17+
CryptoAPIs.Deribit.Common.funding_rate(;
18+
instrument_name = "BTC-PERPETUAL",
19+
start_timestamp = Dates.DateTime("2022-11-08"),
20+
end_timestamp = Dates.DateTime("2022-11-08") + Day(2),
21+
)
22+
23+
CryptoAPIs.Deribit.Common.order_book(;
24+
instrument_name = "BTC-PERPETUAL",
25+
depth = CryptoAPIs.Deribit.Common.OrderBook.TEN_THOUSAND,
26+
)
27+
28+
CryptoAPIs.Deribit.Common.ticker(; instrument_name = "BTC-PERPETUAL")
29+
30+
# Spot
31+
32+
CryptoAPIs.Deribit.Common.book_summary(;
33+
currency = CryptoAPIs.Deribit.Common.BookSummary.BTC,
34+
kind = CryptoAPIs.Deribit.Common.BookSummary.spot,
35+
)
36+
37+
CryptoAPIs.Deribit.Common.instrument(;
38+
currency = CryptoAPIs.Deribit.Common.Instrument.BTC,
39+
kind = CryptoAPIs.Deribit.Common.Instrument.spot,
40+
)
41+
42+
# Future
43+
44+
CryptoAPIs.Deribit.Common.book_summary(;
45+
currency = CryptoAPIs.Deribit.Common.BookSummary.BTC,
46+
kind = CryptoAPIs.Deribit.Common.BookSummary.future,
47+
)
48+
49+
CryptoAPIs.Deribit.Common.instrument(;
50+
currency = CryptoAPIs.Deribit.Common.Instrument.BTC,
51+
kind = CryptoAPIs.Deribit.Common.Instrument.future,
52+
)
53+
54+
# Option
55+
56+
CryptoAPIs.Deribit.Common.book_summary(;
57+
currency = CryptoAPIs.Deribit.Common.BookSummary.BTC,
58+
kind = CryptoAPIs.Deribit.Common.BookSummary.option,
59+
)
60+
61+
CryptoAPIs.Deribit.Common.instrument(;
62+
currency = CryptoAPIs.Deribit.Common.Instrument.BTC,
63+
kind = CryptoAPIs.Deribit.Common.Instrument.option,
64+
)

src/CryptoAPIs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ include("Bithumb/Bithumb.jl")
165165
include("Bybit/Bybit.jl")
166166
include("Coinbase/Coinbase.jl")
167167
include("Cryptocom/Cryptocom.jl")
168+
include("Deribit/Deribit.jl")
168169
include("Gateio/Gateio.jl")
169170
include("Huobi/Huobi.jl")
170171
include("Okex/Okex.jl")
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
module BookSummary
2+
3+
export BookSummaryQuery,
4+
BookSummaryData,
5+
book_summary
6+
7+
using Serde
8+
using Dates, NanoDates, TimeZones
9+
10+
using CryptoAPIs.Deribit
11+
using CryptoAPIs.Deribit: Data
12+
using CryptoAPIs: Maybe, APIsRequest
13+
14+
@enum Currency begin
15+
BTC
16+
ETH
17+
USDC
18+
USDT
19+
end
20+
21+
@enum InstrumentKind begin
22+
future
23+
option
24+
future_combo
25+
option_combo
26+
spot
27+
end
28+
29+
Base.@kwdef struct BookSummaryQuery <: DeribitPublicQuery
30+
currency::Currency
31+
kind::Maybe{InstrumentKind} = nothing
32+
end
33+
34+
struct BookSummaryData <: DeribitData
35+
instrument_name::String
36+
base_currency::String
37+
quote_currency::String
38+
ask_price::Maybe{Float64}
39+
bid_price::Maybe{Float64}
40+
mid_price::Maybe{Float64}
41+
mark_price::Maybe{Float64}
42+
estimated_delivery_price::Maybe{Float64}
43+
price_change::Maybe{Float64}
44+
volume::Maybe{Float64}
45+
volume_notional::Maybe{Float64}
46+
volume_usd::Maybe{Float64}
47+
high::Maybe{Float64}
48+
low::Maybe{Float64}
49+
last::Maybe{Float64}
50+
current_funding::Maybe{Float64}
51+
funding_8h::Maybe{Float64}
52+
interest_rate::Maybe{Float64}
53+
open_interest::Maybe{Float64}
54+
underlying_index::Maybe{String}
55+
underlying_price::Maybe{Float64}
56+
creation_timestamp::NanoDate
57+
end
58+
59+
"""
60+
book_summary(client::DeribitClient, query::BookSummaryQuery)
61+
book_summary(client::DeribitClient = Deribit.Common.public_client; kw...)
62+
63+
Retrieves the summary information such as open interest, 24h volume, etc. for all instruments for the currency (optionally filtered by kind).
64+
65+
[`GET api/v2/public/get_book_summary_by_currency`](https://docs.deribit.com/#public-get_book_summary_by_currency)
66+
67+
## Parameters:
68+
69+
| Parameter | Type | Required | Description |
70+
|:----------|:---------------|:---------|:--------------------------|
71+
| currency | Currency | true | `BTC` `ETH` `USDC` `USDT` |
72+
| kind | InstrumentKind | false | `option` `spot` `future` `future_combo` `option_combo` |
73+
74+
## Code samples:
75+
76+
```julia
77+
using Serde
78+
using CryptoAPIs.Deribit
79+
80+
result = Deribit.Common.book_summary(;
81+
currency = CryptoAPIs.Deribit.Common.BookSummary.BTC
82+
)
83+
84+
to_pretty_json(result.result)
85+
```
86+
87+
## Result:
88+
89+
```json
90+
{
91+
"id":null,
92+
"jsonrpc":"2.0",
93+
"testnet":false,
94+
"usDiff":1746,
95+
"usOut":"2024-05-17T11:57:46.222272",
96+
"usIn":"2024-05-17T11:57:46.220526080",
97+
"result":[
98+
{
99+
"instrument_name":"BTC-31MAY24-59000-P",
100+
"base_currency":"BTC",
101+
"quote_currency":"BTC",
102+
"ask_price":0.0065,
103+
"bid_price":0.006,
104+
"mid_price":0.00625,
105+
"mark_price":0.00616094,
106+
"estimated_delivery_price":66227.07,
107+
"price_change":-23.5294,
108+
"volume":196.0,
109+
"volume_notional":null,
110+
"volume_usd":98503.18,
111+
"high":0.0105,
112+
"low":0.006,
113+
"last":0.0065,
114+
"current_funding":null,
115+
"funding_8h":null,
116+
"interest_rate":0.0,
117+
"open_interest":569.7,
118+
"underlying_index":"BTC-31MAY24",
119+
"underlying_price":66481.53,
120+
"creation_timestamp":"2024-05-17T12:00:15.647000064"
121+
},
122+
...
123+
]
124+
}
125+
```
126+
"""
127+
function book_summary(client::DeribitClient, query::BookSummaryQuery)
128+
return APIsRequest{Data{Vector{BookSummaryData}}}("GET", "api/v2/public/get_book_summary_by_currency", query)(client)
129+
end
130+
131+
function book_summary(client::DeribitClient = Deribit.Common.public_client; kw...)
132+
return book_summary(client, BookSummaryQuery(; kw...))
133+
end
134+
135+
end

0 commit comments

Comments
 (0)