-
Notifications
You must be signed in to change notification settings - Fork 2
/
live_public_endpoint_request.rs
41 lines (36 loc) · 1.76 KB
/
live_public_endpoint_request.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use kraken_async_rs::clients::core_kraken_client::CoreKrakenClient;
use kraken_async_rs::clients::http_response_types::ResultErrorResponse;
use kraken_async_rs::clients::kraken_client::KrakenClient;
use kraken_async_rs::crypto::nonce_provider::{IncreasingNonceProvider, NonceProvider};
use kraken_async_rs::request_types::TradableAssetPairsRequest;
use kraken_async_rs::secrets::secrets_provider::{SecretsProvider, StaticSecretsProvider};
use kraken_async_rs::test_support::set_up_logging;
use std::sync::Arc;
use tokio::sync::Mutex;
/// This retrieves the asset pair details for BTC-USD, showing a simple public endpoint request.
#[tokio::main]
async fn main() {
set_up_logging("live_public_endpoint.log");
// credentials aren't needed for public endpoints
let secrets_provider: Box<Arc<Mutex<dyn SecretsProvider>>> =
Box::new(Arc::new(Mutex::new(StaticSecretsProvider::new("", ""))));
let nonce_provider: Box<Arc<Mutex<dyn NonceProvider>>> =
Box::new(Arc::new(Mutex::new(IncreasingNonceProvider::new())));
let mut client = CoreKrakenClient::new_with_tracing(secrets_provider, nonce_provider, true);
let request = TradableAssetPairsRequest::builder()
.pair("BTCUSD".into())
.build();
let response = client.get_tradable_asset_pairs(&request).await;
// Note that Kraken will return assets in their own naming scheme, e.g. a request for
// "BTCUSD" will return as "XXBTZUSD"
// For a reasonable understanding of their mappings, see: https://gist.github.com/brendano257/975a395d73a6d7bb53e53d292534d6af
if let Ok(ResultErrorResponse {
result: Some(tradable_assets),
..
}) = response
{
for (asset, details) in tradable_assets {
println!("{asset}: {details:?}")
}
}
}