pub struct Gate { /* private fields */ }Expand description
A Gate.io client over injected transports.
Implementations§
Source§impl Gate
impl Gate
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/v4/spot/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,
) -> Gate
pub fn with_http( http: Box<dyn HttpTransport>, options: &ExchangeOptions, ) -> Gate
Build a public Gate.io client.
Sourcepub fn with_credentials(
http: Box<dyn HttpTransport>,
options: &ExchangeOptions,
credentials: Credentials,
) -> Gate
pub fn with_credentials( http: Box<dyn HttpTransport>, options: &ExchangeOptions, credentials: Credentials, ) -> Gate
Build an authenticated Gate.io client.
Sourcepub fn with_clock(self, now_ms: Box<dyn Fn() -> i64 + Send + Sync>) -> Gate
pub fn with_clock(self, now_ms: Box<dyn Fn() -> i64 + Send + Sync>) -> Gate
Override the timestamp source (deterministic signing in tests).
Sourcepub fn with_ws(self, ws: Box<dyn WsTransport>) -> Gate
pub fn with_ws(self, ws: Box<dyn WsTransport>) -> Gate
Attach a WebSocket transport.
Sourcepub fn wire_symbol(symbol: &Symbol) -> String
pub fn wire_symbol(symbol: &Symbol) -> String
The Gate wire symbol for a canonical Symbol (BTC/USDT -> BTC_USDT).
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.
Gate publishes the funding rate, the mark price and the index price
inside the futures.tickers frame – one reading at one moment – so
Funding and MarkIndex are the same subscription seen two ways.
Liquidations is refused. Gate has a futures.liquidates channel, but
it answers an anonymous subscribe with “authentication required for
Channel futures.liquidates”: it reports the caller’s own liquidations,
not the venue’s forced flow, so it is not the public feed this channel
means.
§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>
The current open interest
(GET /futures/usdt/contract_stats), most recent point.
Polled, not pushed. The figure is in contracts, the unit this client’s
futures order path takes. The row’s time is in seconds, where every
other stamp in this crate is milliseconds.
§Errors
Returns an Error on a spot client, if the request fails, or if the
venue returns no data point.
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 /futures/usdt/contract_stats), most recent point.
Polled, not pushed. Gate publishes lsr_account, the ratio of long
accounts to short ones, where Binance publishes the two proportions.
With two categories the conversion is exact and sums to one.
§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://api.gateio.ws/ws/v4/). Sends
signed subscribe frames for the spot.orders and spot.balances
channels (each carries an auth object whose SIGN is HMAC-SHA512 over
channel=<channel>&event=subscribe&time=<time>). 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,
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) 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.
Sourcepub fn place_order_ws(&mut self, request: &OrderRequest) -> Result<Order, Error>
pub fn place_order_ws(&mut self, request: &OrderRequest) -> Result<Order, Error>
Place a spot order over the Gate WebSocket order API (spot.order_place).
Logs into a dedicated connection on first use (spot.login, signature =
HMAC-SHA512 over api\nspot.login\n\n<timestamp>), then exchanges the same
order args as the REST path.
§Errors
Returns Error::Exchange on the futures client (this binding’s WS
order API covers spot), Error::NotConnected without a WebSocket
transport, or another Error if the order is invalid or rejected.
Sourcepub fn cancel_order_ws(
&mut self,
symbol: &Symbol,
order_id: &str,
) -> Result<(), Error>
pub fn cancel_order_ws( &mut self, symbol: &Symbol, order_id: &str, ) -> Result<(), Error>
Cancel a spot order over the Gate WebSocket order API (spot.order_cancel).
§Errors
Returns Error::Exchange on the futures client, Error::NotConnected
without a WebSocket transport, or another Error if the request fails.
pub fn place_order(&self, request: &OrderRequest) -> Result<Order, Error>
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.
Trait Implementations§
Source§impl AdvancedOrders for Gate
impl AdvancedOrders for Gate
Source§fn place_oco(&mut self, _request: &OcoRequest) -> Result<Vec<Order>, Error>
fn place_oco(&mut self, _request: &OcoRequest) -> Result<Vec<Order>, Error>
Gate has no OCO order-list (it uses standalone price-triggered orders), so
this returns an Error::Exchange.
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>
None leaves that field
unchanged. Venues without a native amend emulate it as cancel-replace. Read moreSource§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 Gate
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 Gate
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 Gate
impl Derivatives for Gate
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 Gate
impl DerivativesStream for Gate
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 Gate
impl Execution for Gate
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 Gate
impl MarketData for Gate
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 Gate
impl WsExecution for Gate
Source§fn place_order_ws(&mut self, request: &OrderRequest) -> Result<Order, Error>
fn place_order_ws(&mut self, request: &OrderRequest) -> Result<Order, Error>
Source§impl WsUserData for Gate
impl WsUserData for Gate
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 Gate
impl !RefUnwindSafe for Gate
impl !Sync for Gate
impl !UnwindSafe for Gate
impl Send for Gate
impl Unpin for Gate
impl UnsafeUnpin for Gate
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