kalshi_rust/structured_targets/
mod.rs

1use super::Kalshi;
2use crate::kalshi_error::*;
3use serde::{Deserialize, Serialize};
4
5impl Kalshi {
6    /// Retrieves all structured targets.
7    ///
8    /// This method lists all available structured target markets.
9    ///
10    /// # Returns
11    ///
12    /// - `Ok(Vec<StructuredTarget>)`: A vector of structured targets on successful retrieval.
13    /// - `Err(KalshiError)`: An error if there is an issue with the request.
14    ///
15    /// # Example
16    ///
17    /// ```
18    /// // Assuming `kalshi_instance` is an instance of `Kalshi`
19    /// let targets = kalshi_instance.get_structured_targets().await.unwrap();
20    /// ```
21    ///
22    pub async fn get_structured_targets(&self) -> Result<Vec<StructuredTarget>, KalshiError> {
23        let path = "/structured_targets";
24        let res: StructuredTargetsResponse = self.signed_get(path).await?;
25        Ok(res.targets)
26    }
27
28    /// Retrieves a specific structured target by ID.
29    ///
30    /// This method fetches detailed information about a specific structured target market.
31    ///
32    /// # Arguments
33    ///
34    /// * `target_id` - The ID of the structured target to retrieve.
35    ///
36    /// # Returns
37    ///
38    /// - `Ok(StructuredTarget)`: The structured target details on successful retrieval.
39    /// - `Err(KalshiError)`: An error if there is an issue with the request.
40    ///
41    /// # Example
42    ///
43    /// ```
44    /// // Assuming `kalshi_instance` is an instance of `Kalshi`
45    /// let target = kalshi_instance.get_structured_target("target-123").await.unwrap();
46    /// ```
47    ///
48    pub async fn get_structured_target(
49        &self,
50        target_id: &str,
51    ) -> Result<StructuredTarget, KalshiError> {
52        let path = format!("/structured_targets/{}", target_id);
53        let res: StructuredTargetResponse = self.signed_get(&path).await?;
54        Ok(res.target)
55    }
56}
57
58// -------- Response wrappers --------
59
60#[derive(Debug, Deserialize)]
61struct StructuredTargetsResponse {
62    targets: Vec<StructuredTarget>,
63}
64
65#[derive(Debug, Deserialize)]
66struct StructuredTargetResponse {
67    target: StructuredTarget,
68}
69
70// -------- Public models --------
71
72/// Represents a structured target market.
73#[derive(Debug, Deserialize, Serialize)]
74pub struct StructuredTarget {
75    /// The unique identifier for the structured target.
76    pub id: String,
77    /// The title or description of the target.
78    pub title: String,
79    /// Additional target details.
80    #[serde(flatten)]
81    pub details: std::collections::HashMap<String, serde_json::Value>,
82}