Expand description
Direct access to any Bybit API method (the “back door”): same key pair, same endpoint, same [BrokerLimiter] as the
connector it came from.
The connectors wrap what the shared traits can express. Everything else (amending an order in place, cancelling all
orders, the batch methods, the take profit and stop loss of a position, leverage and margin mode, the transaction
log, the demo funds, the other topics of the streams) is reachable here. Get a handle with raw() on either
connector.
Rules of a call:
- The quota is taken first, by the operation name (
"CancelAll"), from the route inlimits.toml. A name without a route spends the"*"default route, so a call is never free. A refusal is [Error::RateLimited] and the request is not sent. - The closure gets the connector’s [
BybitHttpClient]: it signs and sends. One closure is one API method. callis for reads.call_commandis for anything that changes the account: a break, a timeout or a 5xx is [Error::Unknown], and it is never retried.connect_wsopens one more session of a stream with the same key.
The raw layer does not know about the connector’s order state: orders placed or amended through it are not tracked
(no events of the connector, no reconcile). Use the shared traits for orders.
§Examples
The amendment of an order in place keeps its queue place and its client id. The shared replace is not offered
(it would have to give the order a new client id), the exchange method is here:
use brokapi_bybit::limits::default_limits;
use brokapi_bybit::{UserDataConfig, UserDataConnector};
use brokapi_bybit_protocol::http::models::CreateOrderRequest;
use brokapi_core::{OrderExecutor, ShutdownMode};
use brokapi_runtime::BrokerLimiter;
let (tx, _events) = tokio::sync::mpsc::channel(256);
let ud = UserDataConnector::start(UserDataConfig::new(cfg, "bybit-ud"), BrokerLimiter::new(&default_limits()), tx).await?;
ud.reconcile(&[]).await?;
let raw = ud.raw();
let order = raw
.call_command("PlaceOrder", |http| async move {
http.create_order(&CreateOrderRequest {
category: "linear".into(),
symbol: "MOCKUSDT".into(),
side: "Buy".into(),
order_type: "Limit".into(),
qty: "10".parse().unwrap(),
price: Some("1".parse().unwrap()),
..Default::default()
})
.await
})
.await?;
assert!(!order.order_id.is_empty());
raw.call_command("CancelAll", |http| async move { http.cancel_all("linear", Some("MOCKUSDT"), "USDT").await })
.await?;
ud.shutdown(ShutdownMode::Immediate).await;Structs§
- Bybit
Raw - A handle to the whole API with the quota of the connector it came from.