pub struct Bitget { /* private fields */ }Expand description
A Bitget client over injected transports.
Implementations§
Source§impl Bitget
impl Bitget
Sourcepub fn sync_time(&mut self) -> Result<i64, Error>
pub fn sync_time(&mut self) -> Result<i64, Error>
Learn the offset between this machine’s clock and the venue’s, from
GET /api/v2/public/time.
Explicit rather than automatic: it costs a request, and a client should not make one the caller did not ask for. Call it once after connecting, and again if the process runs long enough for drift to matter.
Returns the new offset in milliseconds (server - local).
§Errors
Returns an Error if the request fails or the response cannot be parsed.
Sourcepub fn with_http(
http: Box<dyn HttpTransport>,
options: &ExchangeOptions,
) -> Bitget
pub fn with_http( http: Box<dyn HttpTransport>, options: &ExchangeOptions, ) -> Bitget
Build a public Bitget client.
Sourcepub fn with_credentials(
http: Box<dyn HttpTransport>,
options: &ExchangeOptions,
credentials: Credentials,
) -> Bitget
pub fn with_credentials( http: Box<dyn HttpTransport>, options: &ExchangeOptions, credentials: Credentials, ) -> Bitget
Build an authenticated Bitget client (credentials must carry a passphrase).
Sourcepub fn with_clock(self, now_ms: Box<dyn Fn() -> i64 + Send + Sync>) -> Bitget
pub fn with_clock(self, now_ms: Box<dyn Fn() -> i64 + Send + Sync>) -> Bitget
Override the timestamp source (deterministic signing in tests).
Sourcepub fn with_ws(self, ws: Box<dyn WsTransport>) -> Bitget
pub fn with_ws(self, ws: Box<dyn WsTransport>) -> Bitget
Attach a WebSocket transport.
Sourcepub fn wire_symbol(symbol: &Symbol) -> String
pub fn wire_symbol(symbol: &Symbol) -> String
The Bitget wire symbol for a canonical Symbol (BTC/USDT -> BTCUSDT).
Sourcepub fn klines(
&self,
symbol: &Symbol,
interval: &str,
limit: u32,
) -> Result<Vec<Candle>, Error>
pub fn klines( &self, symbol: &Symbol, interval: &str, limit: u32, ) -> Result<Vec<Candle>, Error>
Sourcepub fn order_book(
&self,
symbol: &Symbol,
depth: u32,
) -> Result<OrderBookSnapshot, Error>
pub fn order_book( &self, symbol: &Symbol, depth: u32, ) -> Result<OrderBookSnapshot, Error>
Sourcepub fn subscribe_derivatives(
&mut self,
symbol: &Symbol,
channel: DerivativesChannel,
) -> Result<(), Error>
pub fn subscribe_derivatives( &mut self, symbol: &Symbol, channel: DerivativesChannel, ) -> Result<(), Error>
Subscribe to a pushed derivatives channel.
Bitget publishes the funding rate, the mark price and the index price
inside the mix ticker frame – all three in one reading, taken at one
moment – so Funding and MarkIndex are the same subscription seen
two ways.
Liquidations is refused: Bitget publishes no public stream of forced
orders. Subscribing to nothing and waiting would be the worse answer.
§Errors
Returns an Error on a spot client, for Liquidations, or if the
subscription fails.
Sourcepub fn open_interest(&self, symbol: &Symbol) -> Result<OpenInterest, Error>
pub fn open_interest(&self, symbol: &Symbol) -> Result<OpenInterest, Error>
Sourcepub fn long_short_ratio(&self, symbol: &Symbol) -> Result<LongShortRatio, Error>
pub fn long_short_ratio(&self, symbol: &Symbol) -> Result<LongShortRatio, Error>
The current long/short account ratio
(GET /api/v2/mix/market/account-long-short), most recent point.
Polled, not pushed. Bitget publishes the two proportions directly, as Binance does, so nothing is derived here.
§Errors
Returns an Error on a spot client, if the request fails, or if the
venue returns no data point.
Sourcepub fn subscribe_trades(&mut self, symbol: &Symbol) -> Result<(), Error>
pub fn subscribe_trades(&mut self, symbol: &Symbol) -> Result<(), Error>
Subscribe to the public trade stream for symbol.
§Errors
Returns Error::NotConnected if no WebSocket transport is configured.
Sourcepub fn poll_events(&mut self) -> Vec<Event>
pub fn poll_events(&mut self) -> Vec<Event>
Drain all stream events available since the last call. Non-blocking.
Sourcepub fn subscribe_user_data(&mut self) -> Result<(), Error>
pub fn subscribe_user_data(&mut self) -> Result<(), Error>
Open the private user-data stream (wss://ws.bitget.com/v2/ws/private).
Logs in with an op:login frame (sign = base64(HMAC-SHA256) over
<epochSeconds>GET/user/verify), then subscribes to the orders and
account channels. Afterwards poll_events also
surfaces the account’s own Event::OrderUpdate and Event::BalanceUpdate.
A dropped private stream is re-subscribed automatically on the next
poll_events; call
keepalive_user_data periodically to keep it
from being dropped for inactivity.
§Errors
Returns Error::InvalidCredentials without credentials or a passphrase,
Error::NotConnected without a WebSocket transport, or another
Error if the request fails.
Sourcepub fn keepalive_user_data(&mut self) -> Result<(), Error>
pub fn keepalive_user_data(&mut self) -> Result<(), Error>
Send an application-level heartbeat (the ping text frame Bitget expects)
on the private stream so it is not dropped for inactivity. A no-op before
subscribe_user_data.
§Errors
Returns an Error if the ping cannot be sent.
pub fn place_order(&self, request: &OrderRequest) -> Result<Order, Error>
Source§impl Bitget
impl Bitget
Sourcepub fn set_margin_mode(
&mut self,
symbol: &Symbol,
mode: MarginMode,
) -> Result<(), Error>
pub fn set_margin_mode( &mut self, symbol: &Symbol, mode: MarginMode, ) -> Result<(), Error>
Sourcepub fn close_position(&self, symbol: &Symbol) -> Result<Order, Error>
pub fn close_position(&self, symbol: &Symbol) -> Result<Order, Error>
Flatten the open position in symbol with a reduce-only market order.
§Errors
Returns Error::NotFound if there is no open position, or another
Error if the request fails.
Sourcepub fn place_batch(
&self,
requests: &[OrderRequest],
) -> Result<Vec<Result<Order, Error>>, Error>
pub fn place_batch( &self, requests: &[OrderRequest], ) -> Result<Vec<Result<Order, Error>>, Error>
Place several orders on one symbol in one request
(/api/v2/spot/trade/batch-orders). Bitget returns separate success and
failure lists, so a synthetic clientOid per index re-aligns them to each
request’s own Result. Batch requires a single symbol (that of the
first request).
§Errors
Returns an Error if the batch request itself fails, or if called on a
futures client (mix batch is a documented follow-up).
Trait Implementations§
Source§impl AdvancedOrders for Bitget
impl AdvancedOrders for Bitget
Source§fn amend_order(
&mut self,
_symbol: &Symbol,
_order_id: &str,
_new_price: Option<Decimal>,
_new_quantity: Option<Decimal>,
) -> Result<Order, Error>
fn amend_order( &mut self, _symbol: &Symbol, _order_id: &str, _new_price: Option<Decimal>, _new_quantity: Option<Decimal>, ) -> Result<Order, Error>
Bitget spot has no in-place amend (orders are cancelled and re-placed),
so this returns an Error::Exchange.
Source§fn place_oco(&mut self, _request: &OcoRequest) -> Result<Vec<Order>, Error>
fn place_oco(&mut self, _request: &OcoRequest) -> Result<Vec<Order>, Error>
Bitget has no OCO order-list (it uses standalone plan/trigger orders), so
this returns an Error::Exchange.
Source§fn place_batch(
&mut self,
requests: &[OrderRequest],
) -> Result<Vec<Result<Order, Error>>, Error>
fn place_batch( &mut self, requests: &[OrderRequest], ) -> Result<Vec<Result<Order, Error>>, Error>
Source§impl Debug for Bitget
Hand-written: the client holds Box<dyn HttpTransport>, Box<dyn WsTransport>
and a Box<dyn Fn() -> i64> clock, none of which a derive can reach. The
transports are shown by whether a connection is open rather than by value, and
the credentials only by whether they are set – printing them would put secret
material into every log line that formats a client.
impl Debug for Bitget
Hand-written: the client holds Box<dyn HttpTransport>, Box<dyn WsTransport>
and a Box<dyn Fn() -> i64> clock, none of which a derive can reach. The
transports are shown by whether a connection is open rather than by value, and
the credentials only by whether they are set – printing them would put secret
material into every log line that formats a client.
Source§impl Derivatives for Bitget
impl Derivatives for Bitget
Source§fn positions(&mut self, symbol: Option<&Symbol>) -> Result<Vec<Position>, Error>
fn positions(&mut self, symbol: Option<&Symbol>) -> Result<Vec<Position>, Error>
symbol; flat positions are omitted. Read moreSource§fn set_leverage(&mut self, symbol: &Symbol, leverage: u32) -> Result<(), Error>
fn set_leverage(&mut self, symbol: &Symbol, leverage: u32) -> Result<(), Error>
symbol. Read moreSource§fn set_margin_mode(
&mut self,
symbol: &Symbol,
mode: MarginMode,
) -> Result<(), Error>
fn set_margin_mode( &mut self, symbol: &Symbol, mode: MarginMode, ) -> Result<(), Error>
symbol. Read moreSource§impl DerivativesStream for Bitget
impl DerivativesStream for Bitget
Source§fn subscribe_derivatives(
&mut self,
symbol: &Symbol,
channel: DerivativesChannel,
) -> Result<(), Error>
fn subscribe_derivatives( &mut self, symbol: &Symbol, channel: DerivativesChannel, ) -> Result<(), Error>
poll_events as
Event::Derivatives. Read moreSource§fn open_interest(&mut self, symbol: &Symbol) -> Result<OpenInterest, Error>
fn open_interest(&mut self, symbol: &Symbol) -> Result<OpenInterest, Error>
Source§fn long_short_ratio(&mut self, symbol: &Symbol) -> Result<LongShortRatio, Error>
fn long_short_ratio(&mut self, symbol: &Symbol) -> Result<LongShortRatio, Error>
Source§impl Execution for Bitget
impl Execution for Bitget
Source§fn place_order(&mut self, request: &OrderRequest) -> Result<Order, Error>
fn place_order(&mut self, request: &OrderRequest) -> Result<Order, Error>
Source§fn cancel_order(&mut self, symbol: &Symbol, order_id: &str) -> Result<(), Error>
fn cancel_order(&mut self, symbol: &Symbol, order_id: &str) -> Result<(), Error>
Source§fn query_order(
&mut self,
symbol: &Symbol,
order_id: &str,
) -> Result<Order, Error>
fn query_order( &mut self, symbol: &Symbol, order_id: &str, ) -> Result<Order, Error>
Source§impl MarketData for Bitget
impl MarketData for Bitget
Source§fn ticker(&mut self, symbol: &Symbol) -> Result<Ticker, Error>
fn ticker(&mut self, symbol: &Symbol) -> Result<Ticker, Error>
symbol. Read moreSource§fn klines(
&mut self,
symbol: &Symbol,
interval: &str,
limit: u32,
) -> Result<Vec<Candle>, Error>
fn klines( &mut self, symbol: &Symbol, interval: &str, limit: u32, ) -> Result<Vec<Candle>, Error>
limit historical candles for symbol at the given interval
(e.g. "1m", "1h"). Returns wickra_core::Candles so the result
feeds the indicator core directly. Read moreSource§fn order_book(
&mut self,
symbol: &Symbol,
depth: u32,
) -> Result<OrderBookSnapshot, Error>
fn order_book( &mut self, symbol: &Symbol, depth: u32, ) -> Result<OrderBookSnapshot, Error>
Source§fn subscribe_trades(&mut self, symbol: &Symbol) -> Result<(), Error>
fn subscribe_trades(&mut self, symbol: &Symbol) -> Result<(), Error>
symbol. Read moreSource§fn subscribe_book(&mut self, symbol: &Symbol) -> Result<(), Error>
fn subscribe_book(&mut self, symbol: &Symbol) -> Result<(), Error>
symbol. Read moreSource§fn subscribe_ticker(&mut self, symbol: &Symbol) -> Result<(), Error>
fn subscribe_ticker(&mut self, symbol: &Symbol) -> Result<(), Error>
symbol. Read moreSource§fn poll_events(&mut self) -> Vec<Event>
fn poll_events(&mut self) -> Vec<Event>
Source§impl WsExecution for Bitget
impl WsExecution for Bitget
Source§fn place_order_ws(&mut self, _request: &OrderRequest) -> Result<Order, Error>
fn place_order_ws(&mut self, _request: &OrderRequest) -> Result<Order, Error>
Bitget exposes no public WebSocket order-entry API — its WebSocket surface
is subscription-only (market data plus the private order/account push
channels). Orders are placed over REST, so this returns a documented
Error::Exchange.
Source§impl WsUserData for Bitget
impl WsUserData for Bitget
Source§fn subscribe_user_data(&mut self) -> Result<(), Error>
fn subscribe_user_data(&mut self) -> Result<(), Error>
poll_events on the same client also drains the
user’s order and balance events alongside the public market-data stream. Read moreSource§fn keepalive_user_data(&mut self) -> Result<(), Error>
fn keepalive_user_data(&mut self) -> Result<(), Error>
Auto Trait Implementations§
impl !Freeze for Bitget
impl !RefUnwindSafe for Bitget
impl !Sync for Bitget
impl !UnwindSafe for Bitget
impl Send for Bitget
impl Unpin for Bitget
impl UnsafeUnpin for Bitget
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more