deribit_http_private/http_private.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Example demonstrating Deribit private API usage.
17//!
18//! # Prerequisites
19//!
20//! Set environment variables with your Deribit API credentials:
21//! - For mainnet: `DERIBIT_API_KEY` and `DERIBIT_API_SECRET`
22//! - For testnet: `DERIBIT_TESTNET_API_KEY` and `DERIBIT_TESTNET_API_SECRET`
23
24use nautilus_deribit::http::client::DeribitHttpClient;
25use nautilus_model::identifiers::AccountId;
26
27#[tokio::main]
28async fn main() -> Result<(), Box<dyn std::error::Error>> {
29 tracing_subscriber::fmt()
30 .with_max_level(tracing::Level::INFO)
31 .init();
32
33 let is_testnet = !std::env::args().any(|x| x == "--mainnet");
34 let client =
35 DeribitHttpClient::new_with_env(None, None, is_testnet, Some(30), None, None, None, None)?;
36
37 let account_id = AccountId::from("DERIBIT-001");
38
39 // Fetch account state for all currencies
40 println!("Fetching account state...");
41 match client.request_account_state(account_id).await {
42 Ok(account_state) => println!("{account_state:?}"),
43 Err(e) => {
44 eprintln!("✗ Failed to fetch account state: {e}");
45 return Err(e.into());
46 }
47 }
48
49 Ok(())
50}