Crates.io | kraapi |
lib.rs | kraapi |
version | 0.2.1 |
source | src |
created_at | 2021-03-16 05:09:26.12663 |
updated_at | 2021-03-16 05:47:01.053964 |
description | Asynchronous HTTP client for the Kraken Cryptocurrency Exchange |
homepage | |
repository | https://github.com/Fuzzy-Math/Kraapi |
max_upload_size | |
id | 369533 |
size | 154,939 |
Asynchronous HTTP client for the Kraken cryptocurrency exchange
Via Crates.io - Add the following to your Cargo.toml:
kraapi = "0.2"
Via local clone - Add the following to your Cargo.toml
kraapi = { path = "path/to_local_checkout" }
use kraapi::api::AssetPairInfo;
use kraapi::public::KIAssetPairs;
let some_application_logic = true;
// mut to allow reassignment based on application logic
let mut input = KIAssetPairs::build();
if some_application_logic {
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();
with_asset(...)
or with_asset_list(...)
always
append to the list. Chained calls to with_asset(...)
is functionally equivalent to one call
to with_asset_list(...)
with the same list of assetsupdate_transaction_list(...)
will always overwrite the current data with
the new dataclear_asset_list()
exist to remove the previous asset list from the request builderclone()
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(
"<Your-API-Key>",
"<Your-API-Secret>"
);
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 library is pronounced "crappy"