BitgetSignedRequestBuilder

Struct BitgetSignedRequestBuilder 

Source
pub struct BitgetSignedRequestBuilder<'a> { /* private fields */ }
Expand description

Builder for creating authenticated Bitget API requests.

This builder encapsulates the common signing workflow:

  1. Credential validation
  2. Millisecond timestamp generation
  3. Parameter signing with HMAC-SHA256
  4. Authentication header injection
  5. 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>

Source

pub fn new(bitget: &'a Bitget, endpoint: impl Into<String>) -> Self

Creates a new signed request builder.

§Arguments
  • bitget - Reference to the Bitget exchange instance
  • endpoint - 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");
Source

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?;
Source

pub fn param(self, key: impl Into<String>, value: impl ToString) -> Self

Adds a required parameter.

§Arguments
  • key - Parameter name
  • value - 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?;
Source

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 name
  • value - 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?;
Source

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?;
Source

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?;
Source

pub async fn execute(self) -> Result<Value>

Executes the signed request and returns the response.

This method:

  1. Validates that credentials are configured
  2. Gets the current millisecond timestamp
  3. Signs the request with HMAC-SHA256
  4. Adds authentication headers
  5. 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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more