Asynchronous HTTP client for the Kraken cryptocurrency exchange
if someapplicationlogic { input = input.info(AssetPairInfo::Leverage); } else { input = input.info(AssetPairInfo::Margin); }
// Now of type KrakenInput so we have to rebind the variable
let input = input.finish();
``
- Endpoints that allow a list of some items (assets, asset pairs, transaction IDs, etc.) will
have methods with the following characteristics:
- Methods such as
withasset(...)or
withassetlist(...)always
**append** to the list. Chained calls to
withasset(...)is functionally equivalent to one call
to
withassetlist(...)with the same list of assets
- Methods such as
updatetransactionlist(...)will always **overwrite** the current data with
the new data
- For endpoints not requiring their list to be populated, methods such as
clearassetlist()exist to **remove** the previous asset list from the request builder
- The above design allows for templating your requests. You can
clone()` a templated request
and then change only the data you care about before sending the request.
See https://www.kraken.com/features/api#example-api-code-php-lib for more info on these examples
``` use kraapi::client::KrakenClient; use kraapi::public::{KITicker, KOTicker}; use kraapi::api::{KAsset, KAssetPair};
async fn main() -> hyper::Result<()> { let client = KrakenClient::new("", "");
let ticker_input = KITicker::build(KAssetPair(KAsset::XBT, KAsset::USD)).finish();
let ticker_output = client.request::<KOTicker>(&ticker_input).await?;
println!("{:?}", ticker_output);
Ok(())
} ```
``` use kraapi::client::KrakenClient; use kraapi::private::{ KIAddOrder, KOAddOrder}; use kraapi::api::{ KAsset, KAssetPair, TradeType, OrderType};
async fn main() -> hyper::Result<()> {
let client = KrakenClient::new(
"
let add_order_input = KIAddOrder::build(
KAssetPair(KAsset::XBT, KAsset::USD),
TradeType::Buy,
OrderType::Limit("101.9901"),
2.12345678)
.with_leverage((2, 1))
.with_closing_order(OrderType::StopLossLimit("#5%", "#10"))
.validate()
.finish();
let add_order_output = client.request::<KOAddOrder>(&add_order_input).await?;
println!("{:?}", add_order_output);
Ok(())
} ```
This crate is not currently on crates.io but will be soon. Until then, add the following line to the dependencies section of your project's Cargo.toml
kraapi = { git = "https://github.com/Fuzzy-Math/Kraapi" }
That dependency is pinned to the commit it was downloaded from and will have to be update manually if desired
cargo update
This library is pronounced "crappy"