pub struct KuCoin { /* private fields */ }Expand description
A KuCoin client over injected transports.
Implementations§
Source§impl KuCoin
impl KuCoin
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/v1/timestamp.
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,
) -> KuCoin
pub fn with_http( http: Box<dyn HttpTransport>, options: &ExchangeOptions, ) -> KuCoin
Build a public KuCoin client.
Sourcepub fn with_credentials(
http: Box<dyn HttpTransport>,
options: &ExchangeOptions,
credentials: Credentials,
) -> KuCoin
pub fn with_credentials( http: Box<dyn HttpTransport>, options: &ExchangeOptions, credentials: Credentials, ) -> KuCoin
Build an authenticated KuCoin client (credentials must carry a passphrase).
Sourcepub fn with_clock(self, now_ms: Box<dyn Fn() -> i64 + Send + Sync>) -> KuCoin
pub fn with_clock(self, now_ms: Box<dyn Fn() -> i64 + Send + Sync>) -> KuCoin
Override the timestamp source (deterministic signing in tests).
Sourcepub fn with_ws(self, ws: Box<dyn WsTransport>) -> KuCoin
pub fn with_ws(self, ws: Box<dyn WsTransport>) -> KuCoin
Attach a WebSocket transport.
Sourcepub fn wire_symbol(symbol: &Symbol) -> String
pub fn wire_symbol(symbol: &Symbol) -> String
The KuCoin 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.
KuCoin publishes both on /contract/instrument, under two subjects:
funding.rate and mark.index.price. The funding subject carries no
price, so a funding print reports a mark of zero rather than one taken
from the other subject at another moment.
Liquidations is refused: KuCoin publishes no public stream of forced
orders.
§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 /api/v1/contracts/<contract>).
Polled, not pushed. KuCoin reports it in contracts and publishes the
contract’s multiplier in the same reply, so the base-currency figure
is exact arithmetic on one reading rather than two.
§Errors
Returns an Error on a spot client, if the request fails, or if the
reply carries neither figure.
Sourcepub fn long_short_ratio(
&self,
_symbol: &Symbol,
) -> Result<LongShortRatio, Error>
pub fn long_short_ratio( &self, _symbol: &Symbol, ) -> Result<LongShortRatio, Error>
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. Negotiates a bullet-private token over
REST (POST /api/v1/bullet-private, signed), connects the returned
instance endpoint (<endpoint>?token=<token>&connectId=<id>), then
subscribes to the account’s own order and balance channels – on spot
/spotMarket/tradeOrders and /account/balance, on futures
/contractMarket/tradeOrders and /contractAccount/wallet. A futures
client negotiates its token against the futures host, which serves the
same /api/v1/bullet-private path. Afterwards poll_events also surfaces the
account’s own Event::OrderUpdate and Event::BalanceUpdate.
The bullet token expires;
keepalive_user_data sends KuCoin’s ping to
keep it alive, and a dropped stream is re-subscribed automatically on the
next poll_events, which re-negotiates a fresh token.
§Errors
Returns Error::InvalidCredentials without credentials or a passphrase,
Error::NotConnected without a WebSocket transport, or another
Error if the token negotiation or subscription fails.
Sourcepub fn keepalive_user_data(&mut self) -> Result<(), Error>
pub fn keepalive_user_data(&mut self) -> Result<(), Error>
Send KuCoin’s application-level heartbeat ({"id":..,"type":"ping"}) on the
private stream so the bullet token 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 KuCoin
impl KuCoin
Sourcepub fn set_leverage(
&mut self,
_symbol: &Symbol,
leverage: u32,
) -> Result<(), Error>
pub fn set_leverage( &mut self, _symbol: &Symbol, leverage: u32, ) -> Result<(), Error>
Record the leverage applied to subsequent futures orders. KuCoin has no standalone set-leverage endpoint — leverage is a per-order field — so this stores it locally rather than issuing a request.
§Errors
Never errors; the signature matches the Derivatives trait.
Sourcepub fn set_margin_mode(
&self,
symbol: &Symbol,
mode: MarginMode,
) -> Result<(), Error>
pub fn set_margin_mode( &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
(size in contracts).
§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>
Trait Implementations§
Source§impl AdvancedOrders for KuCoin
impl AdvancedOrders for KuCoin
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>
KuCoin has no in-place amend (orders are cancelled and re-placed), 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 KuCoin
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 KuCoin
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 KuCoin
impl Derivatives for KuCoin
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 KuCoin
impl DerivativesStream for KuCoin
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 KuCoin
impl Execution for KuCoin
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 KuCoin
impl MarketData for KuCoin
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 KuCoin
impl WsExecution for KuCoin
Source§fn place_order_ws(&mut self, _request: &OrderRequest) -> Result<Order, Error>
fn place_order_ws(&mut self, _request: &OrderRequest) -> Result<Order, Error>
KuCoin exposes no WebSocket order-entry API — its WebSocket surface is
subscription-only (market data plus the private tradeOrders/balance
push channels). Orders are placed over REST, so this returns a documented
Error::Exchange.
Source§impl WsUserData for KuCoin
impl WsUserData for KuCoin
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 KuCoin
impl !RefUnwindSafe for KuCoin
impl !Sync for KuCoin
impl !UnwindSafe for KuCoin
impl Send for KuCoin
impl Unpin for KuCoin
impl UnsafeUnpin for KuCoin
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