Skip to main content

bybit/
url.rs

1use std::fmt;
2
3// Mainnet.
4/// Mainnet REST.
5#[deprecated(since = "0.3.0", note = "use `Environment`")]
6pub const BASE_URL_API_MAINNET_1: &str = "https://api.bybit.com";
7/// Alternative mainnet REST domain.
8#[deprecated(since = "0.3.0", note = "use `Environment`")]
9pub const BASE_URL_API_MAINNET_2: &str = "https://api.bytick.com";
10/// For Netherland users.
11#[deprecated(since = "0.3.0", note = "use `Environment`")]
12pub const BASE_URL_API_MAINNET_3: &str = "https://api.bybit.nl";
13/// For Hong Kong users.
14#[deprecated(since = "0.3.0", note = "use `Environment`")]
15pub const BASE_URL_API_MAINNET_4: &str = "https://api.byhkbit.com";
16/// For Turkey users.
17#[deprecated(since = "0.3.0", note = "use `Environment`")]
18pub const BASE_URL_API_MAINNET_5: &str = "https://api.bybit-tr.com";
19/// For Kazakhstan users.
20#[deprecated(since = "0.3.0", note = "use `Environment`")]
21pub const BASE_URL_API_MAINNET_6: &str = "https://api.bybit.kz";
22
23/// Mainnet WebSocket.
24#[deprecated(since = "0.3.0", note = "use `Environment`")]
25pub const BASE_URL_STREAM_MAINNET_1: &str = "wss://stream.bybit.com";
26/// For Turkey users.
27#[deprecated(since = "0.3.0", note = "use `Environment`")]
28pub const BASE_URL_STREAM_MAINNET_2: &str = "wss://stream.bybit-tr.com";
29/// For Kazakhstan users.
30#[deprecated(since = "0.3.0", note = "use `Environment`")]
31pub const BASE_URL_STREAM_MAINNET_3: &str = "wss://stream.bybit.kz";
32
33// Testnet.
34/// Testnet REST.
35#[deprecated(since = "0.3.0", note = "use `Environment`")]
36pub const BASE_URL_API_TESTNET: &str = "https://api-testnet.bybit.com";
37/// Testnet WebSocket.
38#[deprecated(since = "0.3.0", note = "use `Environment`")]
39pub const BASE_URL_STREAM_TESTNET: &str = "wss://stream-testnet.bybit.com";
40
41// Demo trading.
42/// Demo trading REST.
43#[deprecated(since = "0.3.0", note = "use `Environment`")]
44pub const BASE_URL_API_DEMO: &str = "https://api-demo.bybit.com";
45/// Demo trading WebSocket (private streams only).
46#[deprecated(since = "0.3.0", note = "use `Environment`")]
47pub const BASE_URL_STREAM_DEMO: &str = "wss://stream-demo.bybit.com";
48
49// The following HTTP header keys must be used for authentication:
50/// API key.
51pub const HEADER_X_BAPI_API_KEY: &str = "X-BAPI-API-KEY";
52/// UTC timestamp in milliseconds.
53pub const HEADER_X_BAPI_TIMESTAMP: &str = "X-BAPI-TIMESTAMP";
54/// A signature derived from the request's parameters.
55pub const HEADER_X_BAPI_SIGN: &str = "X-BAPI-SIGN";
56/// The header for broker users only.
57pub const HEADER_X_REFERER: &str = "X-Referer";
58/// The header for specify how long an HTTP request is valid (unit in millisecond and default value is 5,000). It is also used to prevent replay attacks..
59pub const HEADER_X_BAPI_RECV_WINDOW: &str = "X-BAPI-RECV-WINDOW";
60/// Your current limit for current endpoint.
61pub const HEADER_X_BAPI_LIMIT: &str = "X-Bapi-Limit";
62/// Your remaining requests for current endpoint.
63pub const HEADER_X_BAPI_LIMIT_STATUS: &str = "X-Bapi-Limit-Status";
64/// The timestamp indicating when your request limit resets if you have exceeded your rate_limit. Otherwise, this is just the current timestamp (it may not exactly match timeNow).
65pub const HEADER_X_BAPI_LIMIT_RESET_TIMESTAMP: &str = "X-Bapi-Limit-Reset-Timestamp";
66pub const HEADER_RET_CODE: &str = "ret_code";
67pub const HEADER_TRACE_ID: &str = "traceid";
68pub const HEADER_TIME_NOW: &str = "timenow";
69
70/// Path of a Bybit REST endpoint or WebSocket stream, appended to the
71/// base URL of an [`Environment`](crate::Environment).
72#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
73pub enum Path {
74    // Candlestick, orderbook, ticker, platform transaction data, underlying financial rules, risk control rules
75    /// `/v5/market/time`
76    MarketServerTime,
77    /// `/v5/market/kline`
78    MarketKline,
79    /// `/v5/market/mark-price-kline`
80    MarketMarkPriceKline,
81    /// `/v5/market/index-price-kline`
82    MarketIndexPriceKline,
83    /// `/v5/market/premium-index-price-kline`
84    MarketPremiumIndexPriceKline,
85    /// `/v5/market/orderbook`
86    MarketOrderbook,
87    /// `/v5/market/tickers`
88    MarketTickers,
89    /// `/v5/market/funding/history`
90    MarketFundingHistory,
91    /// `/v5/market/recent-trade`
92    MarketRecentTrade,
93    /// `/v5/market/open-interest`
94    MarketOpenInterest,
95    /// `/v5/market/historical-volatility`
96    MarketHistoricalVolatility,
97    /// `/v5/market/insurance`
98    MarketInsurance,
99    /// `/v5/market/instruments-info`
100    MarketInstrumentsInfo,
101    /// `/v5/market/risk-limit`
102    MarketRiskLimit,
103    /// `/v5/market/delivery-price`
104    MarketDeliveryPrice,
105
106    // Order management
107    /// `/v5/order/create`
108    TradeOrderCreate,
109    /// `/v5/order/amend`
110    TradeOrderAmend,
111    /// `/v5/order/cancel`
112    TradeOrderCancel,
113    /// `/v5/order/realtime`
114    TradeOrderRealtime,
115    /// `/v5/order/cancel-all`
116    TradeOrderCancelAll,
117    /// `/v5/order/history`
118    TradeOrderHistory,
119    /// `/v5/order/create-batch`
120    TradeOrderCreateBatch,
121    /// `/v5/order/amend-batch`
122    TradeOrderAmendBatch,
123    /// `/v5/order/cancel-batch`
124    TradeOrderCancelBatch,
125    /// `/v5/order/spot-borrow-check`
126    TradeOrderSpotBorrowCheck,
127
128    // Position management
129    /// `/v5/position/list`
130    PositionList,
131    /// `/v5/position/set-leverage`
132    PositionSetLeverage,
133    /// `/v5/position/set-risk-limit`
134    PositionSetRiskLimit,
135    /// `/v5/position/trading-stop`
136    PositionTradingStop,
137    /// `/v5/position/switch-isolated`
138    PositionSwitchIsolated,
139    /// `/v5/position/switch-mode`
140    PositionSwitchMode,
141    /// `/v5/position/set-auto-add-margin`
142    PositionSetAutoAddMargin,
143    /// `/v5/position/closed-pnl`
144    PositionClosedPnl,
145    /// `/v5/execution/list`
146    ExecutionList,
147
148    // Single account operations only - unified funding account, rates, etc.
149    /// `/v5/account/wallet-balance`
150    AccountWalletBalance,
151    /// `/v5/account/upgrade-to-uta`
152    AccountUpgradeToUta,
153    /// `/v5/account/borrow-history`
154    AccountBorrowHistory,
155    /// `/v5/account/collateral-info`
156    AccountCollateralInfo,
157    /// `/v5/asset/coin-greeks`
158    AssetCoinGreeks,
159    /// `/v5/account/info`
160    AccountInfo,
161    /// `/v5/account/transaction-log`
162    AccountTransactionLog,
163    /// `/v5/account/set-margin-mode`
164    AccountSetMarginMode,
165    /// `/v5/account/demo-apply-money`
166    AccountSetMarginModeDemoApplyMoney,
167    /// `/v5/account/fee-rate`
168    AccountFeeRate,
169
170    // Operations across multiple accounts - asset management, fund management, etc.
171    /// `/v5/asset/delivery-record`
172    AssetDeliveryRecord,
173    /// `/v5/asset/settlement-record`
174    AssetSettlementRecord,
175    /// `/v5/asset/transfer/inter-transfer`
176    AssetTransferInterTransfer,
177    /// `/v5/asset/transfer/query-inter-transfer-list`
178    AssetTransferQueryInterTransferList,
179    /// `/v5/asset/transfer/save-transfer-sub-member`
180    AssetTransferSaveTransferSubMember,
181    /// `/v5/asset/transfer/universal-transfer`
182    AssetTransferUniversalTransfer,
183    /// `/v5/asset/transfer/query-universal-transfer-list`
184    AssetTransferQueryUniversalTransferList,
185    /// `/v5/asset/transfer/query-transfer-coin-list`
186    AssetTransferQueryTransferCoinList,
187    /// `/v5/asset/transfer/query-sub-member-list`
188    AssetTransferQuerySubMemberList,
189    /// `/v5/asset/transfer/query-account-coin-balance`
190    AssetTransferQueryAccountCoinBalance,
191    /// `/v5/asset/transfer/query-asset-info`
192    AssetTransferQueryAssetInfo,
193    /// `/v5/asset/deposit/query-allowed-list`
194    AssetDepositQueryAllowedList,
195    /// `/v5/asset/deposit/query-record`
196    AssetDepositQueryRecord,
197    /// `/v5/asset/deposit/query-sub-member-record`
198    AssetDepositQuerySubMemberRecord,
199    /// `/v5/asset/withdraw/query-record`
200    AssetWithdrawQueryRecord,
201    /// `/v5/asset/withdraw/withdrawable-amount`
202    AssetWithdrawWithdrawableAmount,
203    /// `/v5/asset/coin/query-info`
204    AssetCoinQueryInfo,
205    /// `/v5/asset/withdraw/create`
206    AssetWithdrawCreate,
207    /// `/v5/asset/withdraw/cancel`
208    AssetWithdrawCancel,
209    /// `/v5/asset/deposit/query-address`
210    AssetDepositQueryAddress,
211    /// `/v5/asset/deposit/query-sub-member-address`
212    AssetDepositQuerySubMemberAddress,
213    /// `/v5/asset/exchange/order-record`
214    AssetExchangeOrderRecord,
215
216    /// `/v5/user/query-api`
217    UserQueryApi,
218
219    // Obtain quotes from Leveraged Tokens on Spot, and to exercise purchase and redeem functions
220    /// `/v5/spot-lever-token/info`
221    SpotLeverTokenInfo,
222    /// `/v5/spot-lever-token/reference`
223    SpotLeverTokenReference,
224    /// `/v5/spot-lever-token/purchase`
225    SpotLeverTokenPurchase,
226    /// `/v5/spot-lever-token/redeem`
227    SpotLeverTokenRedeem,
228    /// `/v5/spot-lever-token/order-record`
229    SpotLeverTokenOrderRecord,
230
231    // Manage Margin Trading on Spot
232    /// `/v5/spot-margin-trade/switch-mode`
233    SpotMarginTradeSwitchMode,
234    /// `/v5/spot-margin-trade/set-leverage`
235    SpotMarginTradeSetLeverage,
236
237    // Stream paths.
238    /// `/v5/public/spot`
239    PublicSpot,
240    /// `/v5/public/linear`
241    PublicLinear,
242    /// `/v5/public/inverse`
243    PublicInverse,
244    /// `/v5/public/option`
245    PublicOption,
246    /// `/v5/private`
247    Private,
248    /// `/v5/trade`
249    Trade,
250}
251
252impl fmt::Display for Path {
253    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
254        let s = match self {
255            Self::MarketServerTime => "/v5/market/time",
256            Self::MarketKline => "/v5/market/kline",
257            Self::MarketMarkPriceKline => "/v5/market/mark-price-kline",
258            Self::MarketIndexPriceKline => "/v5/market/index-price-kline",
259            Self::MarketPremiumIndexPriceKline => "/v5/market/premium-index-price-kline",
260            Self::MarketOrderbook => "/v5/market/orderbook",
261            Self::MarketTickers => "/v5/market/tickers",
262            Self::MarketFundingHistory => "/v5/market/funding/history",
263            Self::MarketRecentTrade => "/v5/market/recent-trade",
264            Self::MarketOpenInterest => "/v5/market/open-interest",
265            Self::MarketHistoricalVolatility => "/v5/market/historical-volatility",
266            Self::MarketInsurance => "/v5/market/insurance",
267            Self::MarketInstrumentsInfo => "/v5/market/instruments-info",
268            Self::MarketRiskLimit => "/v5/market/risk-limit",
269            Self::MarketDeliveryPrice => "/v5/market/delivery-price",
270
271            Self::TradeOrderCreate => "/v5/order/create",
272            Self::TradeOrderAmend => "/v5/order/amend",
273            Self::TradeOrderCancel => "/v5/order/cancel",
274            Self::TradeOrderRealtime => "/v5/order/realtime",
275            Self::TradeOrderCancelAll => "/v5/order/cancel-all",
276            Self::TradeOrderHistory => "/v5/order/history",
277            Self::TradeOrderCreateBatch => "/v5/order/create-batch",
278            Self::TradeOrderAmendBatch => "/v5/order/amend-batch",
279            Self::TradeOrderCancelBatch => "/v5/order/cancel-batch",
280            Self::TradeOrderSpotBorrowCheck => "/v5/order/spot-borrow-check",
281
282            Self::PositionList => "/v5/position/list",
283            Self::PositionSetLeverage => "/v5/position/set-leverage",
284            Self::PositionSetRiskLimit => "/v5/position/set-risk-limit",
285            Self::PositionTradingStop => "/v5/position/trading-stop",
286            Self::PositionSwitchIsolated => "/v5/position/switch-isolated",
287            Self::PositionSwitchMode => "/v5/position/switch-mode",
288            Self::PositionSetAutoAddMargin => "/v5/position/set-auto-add-margin",
289            Self::PositionClosedPnl => "/v5/position/closed-pnl",
290
291            Self::ExecutionList => "/v5/execution/list",
292
293            Self::AccountWalletBalance => "/v5/account/wallet-balance",
294            Self::AccountUpgradeToUta => "/v5/account/upgrade-to-uta",
295            Self::AccountBorrowHistory => "/v5/account/borrow-history",
296            Self::AccountCollateralInfo => "/v5/account/collateral-info",
297            Self::AssetCoinGreeks => "/v5/asset/coin-greeks",
298            Self::AccountInfo => "/v5/account/info",
299            Self::AccountTransactionLog => "/v5/account/transaction-log",
300            Self::AccountSetMarginMode => "/v5/account/set-margin-mode",
301            Self::AccountSetMarginModeDemoApplyMoney => "/v5/account/demo-apply-money",
302            Self::AccountFeeRate => "/v5/account/fee-rate",
303
304            Self::AssetDeliveryRecord => "/v5/asset/delivery-record",
305            Self::AssetSettlementRecord => "/v5/asset/settlement-record",
306            Self::AssetTransferInterTransfer => "/v5/asset/transfer/inter-transfer",
307            Self::AssetTransferQueryInterTransferList => {
308                "/v5/asset/transfer/query-inter-transfer-list"
309            }
310            Self::AssetTransferSaveTransferSubMember => {
311                "/v5/asset/transfer/save-transfer-sub-member"
312            }
313            Self::AssetTransferUniversalTransfer => "/v5/asset/transfer/universal-transfer",
314            Self::AssetTransferQueryUniversalTransferList => {
315                "/v5/asset/transfer/query-universal-transfer-list"
316            }
317            Self::AssetTransferQueryTransferCoinList => {
318                "/v5/asset/transfer/query-transfer-coin-list"
319            }
320            Self::AssetTransferQuerySubMemberList => "/v5/asset/transfer/query-sub-member-list",
321            Self::AssetTransferQueryAccountCoinBalance => {
322                "/v5/asset/transfer/query-account-coin-balance"
323            }
324            Self::AssetTransferQueryAssetInfo => "/v5/asset/transfer/query-asset-info",
325            Self::AssetDepositQueryAllowedList => "/v5/asset/deposit/query-allowed-list",
326            Self::AssetDepositQueryRecord => "/v5/asset/deposit/query-record",
327            Self::AssetDepositQuerySubMemberRecord => "/v5/asset/deposit/query-sub-member-record",
328            Self::AssetWithdrawQueryRecord => "/v5/asset/withdraw/query-record",
329            Self::AssetWithdrawWithdrawableAmount => "/v5/asset/withdraw/withdrawable-amount",
330            Self::AssetCoinQueryInfo => "/v5/asset/coin/query-info",
331            Self::AssetWithdrawCreate => "/v5/asset/withdraw/create",
332            Self::AssetWithdrawCancel => "/v5/asset/withdraw/cancel",
333            Self::AssetDepositQueryAddress => "/v5/asset/deposit/query-address",
334            Self::AssetDepositQuerySubMemberAddress => "/v5/asset/deposit/query-sub-member-address",
335            Self::AssetExchangeOrderRecord => "/v5/asset/exchange/order-record",
336
337            Self::UserQueryApi => "/v5/user/query-api",
338
339            Self::SpotLeverTokenInfo => "/v5/spot-lever-token/info",
340            Self::SpotLeverTokenReference => "/v5/spot-lever-token/reference",
341            Self::SpotLeverTokenPurchase => "/v5/spot-lever-token/purchase",
342            Self::SpotLeverTokenRedeem => "/v5/spot-lever-token/redeem",
343            Self::SpotLeverTokenOrderRecord => "/v5/spot-lever-token/order-record",
344            Self::SpotMarginTradeSwitchMode => "/v5/spot-margin-trade/switch-mode",
345            Self::SpotMarginTradeSetLeverage => "/v5/spot-margin-trade/set-leverage",
346
347            Self::PublicSpot => "/v5/public/spot",
348            Self::PublicLinear => "/v5/public/linear",
349            Self::PublicInverse => "/v5/public/inverse",
350            Self::PublicOption => "/v5/public/option",
351            Self::Private => "/v5/private",
352            Self::Trade => "/v5/trade",
353        };
354
355        write!(f, "{s}")
356    }
357}