pub struct BitgetSignedRequestBuilder<'a> { /* private fields */ }Expand description
Builder for creating authenticated Bitget API requests.
This builder encapsulates the common signing workflow:
- Credential validation
- Millisecond timestamp generation
- Parameter signing with HMAC-SHA256
- Authentication header injection
- HTTP request execution
§Example
let bitget = Bitget::new(ExchangeConfig::default())?;
let data = bitget.signed_request("/api/v2/spot/account/assets")
.param("symbol", "BTCUSDT")
.optional_param("limit", Some(100))
.execute()
.await?;Implementations§
Source§impl<'a> BitgetSignedRequestBuilder<'a>
impl<'a> BitgetSignedRequestBuilder<'a>
Sourcepub fn new(bitget: &'a Bitget, endpoint: impl Into<String>) -> Self
pub fn new(bitget: &'a Bitget, endpoint: impl Into<String>) -> Self
Creates a new signed request builder.
§Arguments
bitget- Reference to the Bitget exchange instanceendpoint- API endpoint path (e.g., “/api/v2/spot/account/assets”)
§Example
let bitget = Bitget::new(ExchangeConfig::default()).unwrap();
let builder = BitgetSignedRequestBuilder::new(&bitget, "/api/v2/spot/account/assets");Sourcepub fn method(self, method: HttpMethod) -> Self
pub fn method(self, method: HttpMethod) -> Self
Sets the HTTP method for the request.
Default is GET.
§Arguments
method- The HTTP method to use
§Example
let bitget = Bitget::new(ExchangeConfig::default())?;
let data = bitget.signed_request("/api/v2/spot/trade/place-order")
.method(HttpMethod::Post)
.param("symbol", "BTCUSDT")
.execute()
.await?;Sourcepub fn param(self, key: impl Into<String>, value: impl ToString) -> Self
pub fn param(self, key: impl Into<String>, value: impl ToString) -> Self
Adds a required parameter.
§Arguments
key- Parameter namevalue- Parameter value (will be converted to string)
§Example
let bitget = Bitget::new(ExchangeConfig::default())?;
let data = bitget.signed_request("/api/v2/spot/trade/orders-history")
.param("symbol", "BTCUSDT")
.param("limit", 100)
.execute()
.await?;Sourcepub fn optional_param<T: ToString>(
self,
key: impl Into<String>,
value: Option<T>,
) -> Self
pub fn optional_param<T: ToString>( self, key: impl Into<String>, value: Option<T>, ) -> Self
Adds an optional parameter (only if value is Some).
§Arguments
key- Parameter namevalue- Optional parameter value
§Example
let bitget = Bitget::new(ExchangeConfig::default())?;
let since: Option<i64> = Some(1234567890000);
let limit: Option<u32> = None;
let data = bitget.signed_request("/api/v2/spot/trade/orders-history")
.param("symbol", "BTCUSDT")
.optional_param("after", since)
.optional_param("limit", limit) // Won't be added since it's None
.execute()
.await?;Sourcepub fn params(self, params: BTreeMap<String, String>) -> Self
pub fn params(self, params: BTreeMap<String, String>) -> Self
Adds multiple parameters from a BTreeMap.
§Arguments
params- Map of parameter key-value pairs
§Example
let bitget = Bitget::new(ExchangeConfig::default())?;
let mut params = BTreeMap::new();
params.insert("symbol".to_string(), "BTCUSDT".to_string());
params.insert("side".to_string(), "buy".to_string());
let data = bitget.signed_request("/api/v2/spot/trade/place-order")
.params(params)
.execute()
.await?;Sourcepub fn body(self, body: Value) -> Self
pub fn body(self, body: Value) -> Self
Sets the request body for POST/DELETE requests.
§Arguments
body- JSON value to use as request body
§Example
let bitget = Bitget::new(ExchangeConfig::default())?;
let body = json!({
"symbol": "BTCUSDT",
"side": "buy",
"orderType": "limit"
});
let data = bitget.signed_request("/api/v2/spot/trade/place-order")
.method(ccxt_exchanges::bitget::signed_request::HttpMethod::Post)
.body(body)
.execute()
.await?;Sourcepub async fn execute(self) -> Result<Value>
pub async fn execute(self) -> Result<Value>
Executes the signed request and returns the response.
This method:
- Validates that credentials are configured
- Gets the current millisecond timestamp
- Signs the request with HMAC-SHA256
- Adds authentication headers
- Executes the HTTP request
§Returns
Returns the raw serde_json::Value response for further parsing.
§Errors
- Returns authentication error if credentials are missing
- Returns network error if the request fails
- Returns parse error if response parsing fails
§Example
let bitget = Bitget::new(ExchangeConfig::default())?;
let data = bitget.signed_request("/api/v2/spot/account/assets")
.execute()
.await?;
println!("Response: {:?}", data);Auto Trait Implementations§
impl<'a> Freeze for BitgetSignedRequestBuilder<'a>
impl<'a> !RefUnwindSafe for BitgetSignedRequestBuilder<'a>
impl<'a> Send for BitgetSignedRequestBuilder<'a>
impl<'a> Sync for BitgetSignedRequestBuilder<'a>
impl<'a> Unpin for BitgetSignedRequestBuilder<'a>
impl<'a> !UnwindSafe for BitgetSignedRequestBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more