Skip to main content

bybit_api/api/
broker.rs

1//! Broker API endpoints.
2
3use crate::client::BybitClient;
4use crate::error::Result;
5use crate::models::broker::*;
6
7impl BybitClient {
8    /// Get Broker Account Info.
9    pub async fn query_broker_account_info(&self) -> Result<QueryBrokerAccountInfoResponse> {
10        self.get("/v5/broker/account-info", &[]).await
11    }
12
13    /// Query Broker All UID Rate Limits.
14    pub async fn query_broker_all_uid_details(
15        &self,
16        uids: Option<&str>,
17        limit: Option<i64>,
18        cursor: Option<&str>,
19    ) -> Result<QueryBrokerAllUidDetailsResponse> {
20        let limit_str = limit.map(|v| v.to_string());
21        let mut params: Vec<(&str, &str)> = vec![];
22        if let Some(u) = uids {
23            params.push(("uids", u));
24        }
25        if let Some(ref l) = limit_str {
26            params.push(("limit", l.as_str()));
27        }
28        if let Some(c) = cursor {
29            params.push(("cursor", c));
30        }
31        self.get("/v5/broker/apilimit/query-all", &params).await
32    }
33
34    /// Query Broker Rate Limit Cap.
35    pub async fn query_broker_cap(&self) -> Result<QueryBrokerCapResponse> {
36        self.get("/v5/broker/apilimit/query-cap", &[]).await
37    }
38
39    /// Get Broker Earnings Info.
40    pub async fn query_broker_earning(
41        &self,
42        biz_type: Option<&str>,
43        begin: Option<&str>,
44        end: Option<&str>,
45        uid: Option<&str>,
46        limit: Option<i64>,
47        cursor: Option<&str>,
48    ) -> Result<QueryBrokerEarningResponse> {
49        let limit_str = limit.map(|v| v.to_string());
50        let mut params: Vec<(&str, &str)> = vec![];
51        if let Some(b) = biz_type {
52            params.push(("bizType", b));
53        }
54        if let Some(b) = begin {
55            params.push(("begin", b));
56        }
57        if let Some(e) = end {
58            params.push(("end", e));
59        }
60        if let Some(u) = uid {
61            params.push(("uid", u));
62        }
63        if let Some(ref l) = limit_str {
64            params.push(("limit", l.as_str()));
65        }
66        if let Some(c) = cursor {
67            params.push(("cursor", c));
68        }
69        self.get("/v5/broker/earnings-info", &params).await
70    }
71
72    /// Set Broker API Rate Limit.
73    pub async fn set_broker_api_limit(
74        &self,
75        params: SetBrokerApiLimitParams,
76    ) -> Result<SetBrokerApiLimitResponse> {
77        self.post("/v5/broker/apilimit/set", &params).await
78    }
79
80    /// Distribute voucher.
81    // FIXME(typed-signature): falls back to `serde_json::Value` because the
82    // OpenAPI spec referenced a response/request type that gen-sdk-rust could
83    // not auto-resolve. Replace with a typed struct in a follow-up PR.
84    pub async fn distribute_award(
85        &self,
86        params: DistributeAwardParams,
87    ) -> Result<serde_json::Value> {
88        self.post("/v5/broker/award/distribute-award", &params)
89            .await
90    }
91
92    /// Get voucher details.
93    pub async fn get_award_info(&self, params: GetAwardInfoParams) -> Result<GetAwardInfoResponse> {
94        self.post("/v5/broker/award/info", &params).await
95    }
96
97    /// Query voucher distribution record.
98    pub async fn get_distribution_record(
99        &self,
100        params: GetDistributionRecordParams,
101    ) -> Result<GetDistributionRecordResponse> {
102        self.post("/v5/broker/award/distribution-record", &params)
103            .await
104    }
105}