use super::Kalshi;
use crate::kalshi_error::*;
use serde::{Deserialize, Serialize};
impl Kalshi {
pub async fn get_api_keys(&self) -> Result<Vec<ApiKey>, KalshiError> {
let path = "/api_keys";
let res: ApiKeysResponse = self.signed_get(path).await?;
Ok(res.keys)
}
pub async fn create_api_key(&self, label: &str) -> Result<ApiKeyCreated, KalshiError> {
let path = "/api_keys";
let body = CreateApiKeyRequest {
label: label.to_string(),
};
self.signed_post(path, &body).await
}
pub async fn generate_api_key(&self, key_id: &str) -> Result<ApiKeySecret, KalshiError> {
let path = format!("/api_keys/{}/generate", key_id);
self.signed_post(&path, &()).await
}
pub async fn delete_api_key(&self, key_id: &str) -> Result<(), KalshiError> {
let path = format!("/api_keys/{}", key_id);
let _res: DeleteApiKeyResponse = self.signed_delete(&path).await?;
Ok(())
}
}
#[derive(Debug, Serialize)]
struct CreateApiKeyRequest {
label: String,
}
#[derive(Debug, Deserialize)]
struct ApiKeysResponse {
keys: Vec<ApiKey>,
}
#[derive(Debug, Deserialize)]
struct DeleteApiKeyResponse {
}
#[derive(Debug, Deserialize, Serialize)]
pub struct ApiKey {
pub key_id: String,
pub label: String,
pub created_time: String,
pub is_active: bool,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct ApiKeyCreated {
pub key_id: String,
pub label: String,
pub secret: String,
pub created_time: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct ApiKeySecret {
pub secret: String,
}