Skip to main content

bybit/
url.rs

1use std::fmt;
2
3// Mainnet.
4pub const BASE_URL_API_MAINNET_1: &str = "https://api.bybit.com";
5pub const BASE_URL_API_MAINNET_2: &str = "https://api.bytick.com";
6/// For Netherland users.
7pub const BASE_URL_API_MAINNET_3: &str = "https://api.bybit.nl";
8/// For Hong Kong users.
9pub const BASE_URL_API_MAINNET_4: &str = "https://api.byhkbit.com";
10/// For Turkey users.
11pub const BASE_URL_API_MAINNET_5: &str = "https://api.bybit-tr.com";
12/// For Kazakhstan users.
13pub const BASE_URL_API_MAINNET_6: &str = "https://api.bybit.kz";
14
15pub const BASE_URL_STREAM_MAINNET_1: &str = "wss://stream.bybit.com";
16/// For Turkey users.
17pub const BASE_URL_STREAM_MAINNET_2: &str = "wss://stream.bybit-tr.com";
18/// For Kazakhstan users.
19pub const BASE_URL_STREAM_MAINNET_3: &str = "wss://stream.bybit.kz";
20
21// Testnet.
22pub const BASE_URL_API_TESTNET: &str = "https://api-testnet.bybit.com";
23pub const BASE_URL_STREAM_TESTNET: &str = "wss://stream-testnet.bybit.com";
24
25// Demo trading.
26pub const BASE_URL_API_DEMO: &str = "https://api-demo.bybit.com";
27pub const BASE_URL_STREAM_DEMO: &str = "wss://stream-demo.bybit.com";
28
29// The following HTTP header keys must be used for authentication:
30/// API key.
31pub const HEADER_X_BAPI_API_KEY: &str = "X-BAPI-API-KEY";
32/// UTC timestamp in milliseconds.
33pub const HEADER_X_BAPI_TIMESTAMP: &str = "X-BAPI-TIMESTAMP";
34/// A signature derived from the request's parameters.
35pub const HEADER_X_BAPI_SIGN: &str = "X-BAPI-SIGN";
36/// The header for broker users only.
37pub const HEADER_X_REFERER: &str = "X-Referer";
38/// 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..
39pub const HEADER_X_BAPI_RECV_WINDOW: &str = "X-BAPI-RECV-WINDOW";
40/// Your remaining requests for current endpoint.
41pub const HEADER_X_BAPI_LIMIT: &str = "X-Bapi-Limit";
42/// Your current limit for current endpoint.
43pub const HEADER_X_BAPI_LIMIT_STATUS: &str = "X-Bapi-Limit-Status";
44/// 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).
45pub const HEADER_X_BAPI_LIMIT_RESET_TIMESTAMP: &str = "X-Bapi-Limit-Reset-Timestamp";
46///  To assist in diagnosing advanced network problems. Its value should be unique for each request.
47// TODO: use this constant.
48#[allow(dead_code)]
49pub const HEADER_CDN_REQUEST_ID: &str = "cdn-request-id";
50
51pub const HEADER_RET_CODE: &str = "ret_code";
52pub const HEADER_TRACE_ID: &str = "traceid";
53pub const HEADER_TIME_NOW: &str = "timenow";
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
56pub enum Path {
57    // Candlestick, orderbook, ticker, platform transaction data, underlying financial rules, risk control rules
58    MarketServerTime,
59    MarketKline,
60    MarketMarkPriceKline,
61    MarketIndexPriceKline,
62    MarketPremiumIndexPriceKline,
63    MarketOrderbook,
64    MarketTickers,
65    MarketFundingHistory,
66    MarketRecentTrade,
67    MarketOpenInterest,
68    MarketHistoricalVolatility,
69    MarketInsurance,
70    MarketInstrumentsInfo,
71    MarketRiskLimit,
72    MarketDeliveryPrice,
73
74    // Order management
75    TradeOrderCreate,
76    TradeOrderAmend,
77    TradeOrderCancel,
78    TradeOrderRealtime,
79    TradeOrderCancelAll,
80    TradeOrderHistory,
81    TradeOrderCreateBatch,
82    TradeOrderAmendBatch,
83    TradeOrderCancelBatch,
84    TradeOrderSpotBorrowCheck,
85
86    // Position management
87    PositionList,
88    PositionSetLeverage,
89    PositionSetRiskLimit,
90    PositionTradingStop,
91    PositionSwitchIsolated,
92    PositionSwitchMode,
93    PositionSetAutoAddMargin,
94    PositionClosedPnl,
95    ExecutionList,
96
97    // Single account operations only - unified funding account, rates, etc.
98    AccountWalletBalance,
99    AccountUpgradeToUta,
100    AccountBorrowHistory,
101    AccountCollateralInfo,
102    AssetCoinGreeks,
103    AccountInfo,
104    AccountTransactionLog,
105    AccountSetMarginMode,
106    AccountSetMarginModeDemoApplyMoney,
107    AccountFeeRate,
108
109    // Operations across multiple accounts - asset management, fund management, etc.
110    AssetDeliveryRecord,
111    AssetSettlementRecord,
112    AssetTransferInterTransfer,
113    AssetTransferQueryInterTransferList,
114    AssetTransferSaveTransferSubMember,
115    AssetTransferUniversalTransfer,
116    AssetTransferQueryUniversalTransferList,
117    AssetTransferQueryTransferCoinList,
118    AssetTransferQuerySubMemberList,
119    AssetTransferQueryAccountCoinBalance,
120    AssetTransferQueryAssetInfo,
121    AssetDepositQueryAllowedList,
122    AssetDepositQueryRecord,
123    AssetDepositQuerySubMemberRecord,
124    AssetWithdrawQueryRecord,
125    AssetWithdrawWithdrawableAmount,
126    AssetCoinQueryInfo,
127    AssetWithdrawCreate,
128    AssetWithdrawCancel,
129    AssetDepositQueryAddress,
130    AssetDepositQuerySubMemberAddress,
131    AssetExchangeOrderRecord,
132
133    UserQueryApi,
134
135    // Obtain quotes from Leveraged Tokens on Spot, and to exercise purchase and redeem functions
136    SpotLeverTokenInfo,
137    SpotLeverTokenReference,
138    SpotLeverTokenPurchase,
139    SpotLeverTokenRedeem,
140    SpotLeverTokenOrderRecord,
141
142    // Manage Margin Trading on Spot
143    SpotMarginTradeSwitchMode,
144    SpotMarginTradeSetLeverage,
145
146    // Stream paths.
147    PublicSpot,
148    PublicLinear,
149    PublicInverse,
150    PublicOption,
151    Private,
152    Trade,
153}
154
155impl fmt::Display for Path {
156    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
157        let s = match self {
158            Self::MarketServerTime => "/v5/market/time",
159            Self::MarketKline => "/v5/market/kline",
160            Self::MarketMarkPriceKline => "/v5/market/mark-price-kline",
161            Self::MarketIndexPriceKline => "/v5/market/index-price-kline",
162            Self::MarketPremiumIndexPriceKline => "/v5/market/premium-index-price-kline",
163            Self::MarketOrderbook => "/v5/market/orderbook",
164            Self::MarketTickers => "/v5/market/tickers",
165            Self::MarketFundingHistory => "/v5/market/funding/history",
166            Self::MarketRecentTrade => "/v5/market/recent-trade",
167            Self::MarketOpenInterest => "/v5/market/open-interest",
168            Self::MarketHistoricalVolatility => "/v5/market/historical-volatility",
169            Self::MarketInsurance => "/v5/market/insurance",
170            Self::MarketInstrumentsInfo => "/v5/market/instruments-info",
171            Self::MarketRiskLimit => "/v5/market/risk-limit",
172            Self::MarketDeliveryPrice => "/v5/market/delivery-price",
173
174            Self::TradeOrderCreate => "/v5/order/create",
175            Self::TradeOrderAmend => "/v5/order/amend",
176            Self::TradeOrderCancel => "/v5/order/cancel",
177            Self::TradeOrderRealtime => "/v5/order/realtime",
178            Self::TradeOrderCancelAll => "/v5/order/cancel-all",
179            Self::TradeOrderHistory => "/v5/order/history",
180            Self::TradeOrderCreateBatch => "/v5/order/create-batch",
181            Self::TradeOrderAmendBatch => "/v5/order/amend-batch",
182            Self::TradeOrderCancelBatch => "/v5/order/cancel-batch",
183            Self::TradeOrderSpotBorrowCheck => "/v5/order/spot-borrow-check",
184
185            Self::PositionList => "/v5/position/list",
186            Self::PositionSetLeverage => "/v5/position/set-leverage",
187            Self::PositionSetRiskLimit => "/v5/position/set-risk-limit",
188            Self::PositionTradingStop => "/v5/position/trading-stop",
189            Self::PositionSwitchIsolated => "/v5/position/switch-isolated",
190            Self::PositionSwitchMode => "/v5/position/switch-mode",
191            Self::PositionSetAutoAddMargin => "/v5/position/set-auto-add-margin",
192            Self::PositionClosedPnl => "/v5/position/closed-pnl",
193
194            Self::ExecutionList => "/v5/execution/list",
195
196            Self::AccountWalletBalance => "/v5/account/wallet-balance",
197            Self::AccountUpgradeToUta => "/v5/account/upgrade-to-uta",
198            Self::AccountBorrowHistory => "/v5/account/borrow-history",
199            Self::AccountCollateralInfo => "/v5/account/collateral-info",
200            Self::AssetCoinGreeks => "/v5/asset/coin-greeks",
201            Self::AccountInfo => "/v5/account/info",
202            Self::AccountTransactionLog => "/v5/account/transaction-log",
203            Self::AccountSetMarginMode => "/v5/account/set-margin-mode",
204            Self::AccountSetMarginModeDemoApplyMoney => "/v5/account/demo-apply-money",
205            Self::AccountFeeRate => "/v5/account/fee-rate",
206
207            Self::AssetDeliveryRecord => "/v5/asset/delivery-record",
208            Self::AssetSettlementRecord => "/v5/asset/settlement-record",
209            Self::AssetTransferInterTransfer => "/v5/asset/transfer/inter-transfer",
210            Self::AssetTransferQueryInterTransferList => {
211                "/v5/asset/transfer/query-inter-transfer-list"
212            }
213            Self::AssetTransferSaveTransferSubMember => {
214                "/v5/asset/transfer/save-transfer-sub-member"
215            }
216            Self::AssetTransferUniversalTransfer => "/v5/asset/transfer/universal-transfer",
217            Self::AssetTransferQueryUniversalTransferList => {
218                "/v5/asset/transfer/query-universal-transfer-list"
219            }
220            Self::AssetTransferQueryTransferCoinList => {
221                "/v5/asset/transfer/query-transfer-coin-list"
222            }
223            Self::AssetTransferQuerySubMemberList => "/v5/asset/transfer/query-sub-member-list",
224            Self::AssetTransferQueryAccountCoinBalance => {
225                "/v5/asset/transfer/query-account-coin-balance"
226            }
227            Self::AssetTransferQueryAssetInfo => "/v5/asset/transfer/query-asset-info",
228            Self::AssetDepositQueryAllowedList => "/v5/asset/deposit/query-allowed-list",
229            Self::AssetDepositQueryRecord => "/v5/asset/deposit/query-record",
230            Self::AssetDepositQuerySubMemberRecord => "/v5/asset/deposit/query-sub-member-record",
231            Self::AssetWithdrawQueryRecord => "/v5/asset/withdraw/query-record",
232            Self::AssetWithdrawWithdrawableAmount => "/v5/asset/withdraw/withdrawable-amount",
233            Self::AssetCoinQueryInfo => "/v5/asset/coin/query-info",
234            Self::AssetWithdrawCreate => "/v5/asset/withdraw/create",
235            Self::AssetWithdrawCancel => "/v5/asset/withdraw/cancel",
236            Self::AssetDepositQueryAddress => "/v5/asset/deposit/query-address",
237            Self::AssetDepositQuerySubMemberAddress => "/v5/asset/deposit/query-sub-member-address",
238            Self::AssetExchangeOrderRecord => "/v5/asset/exchange/order-record",
239
240            Self::UserQueryApi => "/v5/user/query-api",
241
242            Self::SpotLeverTokenInfo => "/v5/spot-lever-token/info",
243            Self::SpotLeverTokenReference => "/v5/spot-lever-token/reference",
244            Self::SpotLeverTokenPurchase => "/v5/spot-lever-token/purchase",
245            Self::SpotLeverTokenRedeem => "/v5/spot-lever-token/redeem",
246            Self::SpotLeverTokenOrderRecord => "/v5/spot-lever-token/order-record",
247            Self::SpotMarginTradeSwitchMode => "/v5/spot-margin-trade/switch-mode",
248            Self::SpotMarginTradeSetLeverage => "/v5/spot-margin-trade/set-leverage",
249
250            Self::PublicSpot => "/v5/public/spot",
251            Self::PublicLinear => "/v5/public/linear",
252            Self::PublicInverse => "/v5/public/inverse",
253            Self::PublicOption => "/v5/public/option",
254            Self::Private => "/v5/private",
255            Self::Trade => "/v5/trade",
256        };
257
258        write!(f, "{s}")
259    }
260}