|
| 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