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 = "wss://api.bybit-tr.com";
12/// For Kazakhstan users.
13pub const BASE_URL_API_MAINNET_6: &str = "wss://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
55pub enum Path {
56    // Candlestick, orderbook, ticker, platform transaction data, underlying financial rules, risk control rules
57    MarketServerTime,
58    MarketKline,
59    MarketMarkPriceKline,
60    MarketIndexPriceKline,
61    MarketPremiumIndexPriceKline,
62    MarketOrderbook,
63    MarketTickers,
64    MarketFundingHistory,
65    MarketRecentTrade,
66    MarketOpenInterest,
67    MarketHistoricalVolatility,
68    MarketInsurance,
69    MarketInstrumentsInfo,
70    MarketRiskLimit,
71    MarketDeliveryPrice,
72
73    // Order management
74    TradeOrderCreate,
75    TradeOrderAmend,
76    TradeOrderCancel,
77    TradeOrderRealtime,
78    TradeOrderCancelAll,
79    TradeOrderHistory,
80    TradeOrderCreateBatch,
81    TradeOrderAmendBatch,
82    TradeOrderCancelBatch,
83    TradeOrderSpotBorrowCheck,
84
85    // Position management
86    PositionList,
87    PositionSetLeverage,
88    PositionSetRiskLimit,
89    PositionTradingStop,
90    PositionSwitchIsolated,
91    PositionSwitchMode,
92    PositionSetAutoAddMargin,
93    PositionClosedPnl,
94    ExecutionList,
95
96    // Single account operations only – unified funding account, rates, etc.
97    AccountWalletBalance,
98    AccountUpgradeToUta,
99    AccountBorrowHistory,
100    AccountCollateralInfo,
101    AssetCoinGreeks,
102    AccountInfo,
103    AccountTransactionLog,
104    AccountSetMarginMode,
105    AccountSetMarginModeDemoApplyMoney,
106    AccountFeeRate,
107
108    // Operations across multiple accounts – asset management, fund management, etc.
109    AssetDeliveryRecord,
110    AssetSettlementRecord,
111    AssetTransferInterTransfer,
112    AssetTransferQueryInterTransferList,
113    AssetTransferSaveTransferSubMember,
114    AssetTransferUniversalTransfer,
115    AssetTransferQueryUniversalTransferList,
116    AssetTransferQueryTransferCoinList,
117    AssetTransferQuerySubMemberList,
118    AssetTransferQueryAccountCoinBalance,
119    AssetTransferQueryAssetInfo,
120    AssetDepositQueryAllowedList,
121    AssetDepositQueryRecord,
122    AssetDepositQuerySubMemberRecord,
123    AssetWithdrawQueryRecord,
124    AssetCoinQueryInfo,
125    AssetWithdrawCreate,
126    AssetWithdrawCancel,
127    AssetDepositQueryAddress,
128    AssetDepositQuerySubMemberAddress,
129    AssetExchangeOrderRecord,
130
131    UserQueryApi,
132
133    // Obtain quotes from Leveraged Tokens on Spot, and to exercise purchase and redeem functions
134    SpotLeverTokenInfo,
135    SpotLeverTokenReference,
136    SpotLeverTokenPurchase,
137    SpotLeverTokenRedeem,
138    SpotLeverTokenOrderRecord,
139
140    // Manage Margin Trading on Spot
141    SpotMarginTradeSwitchMode,
142    SpotMarginTradeSetLeverage,
143    SpotMarginTradeSetPledgeToken,
144
145    // Stream paths.
146    PublicSpot,
147    PublicLinear,
148    PublicInverse,
149    PublicOption,
150    Private,
151    Trade,
152}
153
154impl fmt::Display for Path {
155    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
156        let s = match self {
157            Self::MarketServerTime => "/v5/market/time",
158            Self::MarketKline => "/v5/market/kline",
159            Self::MarketMarkPriceKline => "/v5/market/mark-price-kline",
160            Self::MarketIndexPriceKline => "/v5/market/index-price-kline",
161            Self::MarketPremiumIndexPriceKline => "/v5/market/premium-index-price-kline",
162            Self::MarketOrderbook => "/v5/market/orderbook",
163            Self::MarketTickers => "/v5/market/tickers",
164            Self::MarketFundingHistory => "/v5/market/funding/history",
165            Self::MarketRecentTrade => "/v5/market/recent-trade",
166            Self::MarketOpenInterest => "/v5/market/open-interest",
167            Self::MarketHistoricalVolatility => "/v5/market/historical-volatility",
168            Self::MarketInsurance => "/v5/market/insurance",
169            Self::MarketInstrumentsInfo => "/v5/market/instruments-info",
170            Self::MarketRiskLimit => "/v5/market/risk-limit",
171            Self::MarketDeliveryPrice => "/v5/market/delivery-price",
172
173            Self::TradeOrderCreate => "/v5/order/create",
174            Self::TradeOrderAmend => "/v5/order/amend",
175            Self::TradeOrderCancel => "/v5/order/cancel",
176            Self::TradeOrderRealtime => "/v5/order/realtime",
177            Self::TradeOrderCancelAll => "/v5/order/cancel-all",
178            Self::TradeOrderHistory => "/v5/order/history",
179            Self::TradeOrderCreateBatch => "/v5/order/create-batch",
180            Self::TradeOrderAmendBatch => "/v5/order/amend-batch",
181            Self::TradeOrderCancelBatch => "/v5/order/cancel-batch",
182            Self::TradeOrderSpotBorrowCheck => "/v5/order/spot-borrow-check",
183
184            Self::PositionList => "/v5/position/list",
185            Self::PositionSetLeverage => "/v5/position/set-leverage",
186            Self::PositionSetRiskLimit => "/v5/position/set-risk-limit",
187            Self::PositionTradingStop => "/v5/position/trading-stop",
188            Self::PositionSwitchIsolated => "/v5/position/switch-isolated",
189            Self::PositionSwitchMode => "/v5/position/switch-mode",
190            Self::PositionSetAutoAddMargin => "/v5/position/set-auto-add-margin",
191            Self::PositionClosedPnl => "/v5/position/closed-pnl",
192
193            Self::ExecutionList => "/v5/execution/list",
194
195            Self::AccountWalletBalance => "/v5/account/wallet-balance",
196            Self::AccountUpgradeToUta => "/v5/account/upgrade-to-uta",
197            Self::AccountBorrowHistory => "/v5/account/borrow-history",
198            Self::AccountCollateralInfo => "/v5/account/collateral-info",
199            Self::AssetCoinGreeks => "/v5/asset/coin-greeks",
200            Self::AccountInfo => "/v5/account/info",
201            Self::AccountTransactionLog => "/v5/account/transaction-log",
202            Self::AccountSetMarginMode => "/v5/account/set-margin-mode",
203            Self::AccountSetMarginModeDemoApplyMoney => "/v5/account/demo-apply-money",
204            Self::AccountFeeRate => "/v5/account/fee-rate",
205
206            Self::AssetDeliveryRecord => "/v5/asset/delivery-record",
207            Self::AssetSettlementRecord => "/v5/asset/settlement-record",
208            Self::AssetTransferInterTransfer => "/v5/asset/transfer/inter-transfer",
209            Self::AssetTransferQueryInterTransferList => {
210                "/v5/asset/transfer/query-inter-transfer-list"
211            }
212            Self::AssetTransferSaveTransferSubMember => {
213                "/v5/asset/transfer/save-transfer-sub-member"
214            }
215            Self::AssetTransferUniversalTransfer => "/v5/asset/transfer/universal-transfer",
216            Self::AssetTransferQueryUniversalTransferList => {
217                "/v5/asset/transfer/query-universal-transfer-list"
218            }
219            Self::AssetTransferQueryTransferCoinList => {
220                "/v5/asset/transfer/query-transfer-coin-list"
221            }
222            Self::AssetTransferQuerySubMemberList => "/v5/asset/transfer/query-sub-member-list",
223            Self::AssetTransferQueryAccountCoinBalance => {
224                "/v5/asset/transfer/query-account-coin-balance"
225            }
226            Self::AssetTransferQueryAssetInfo => "/v5/asset/transfer/query-asset-info",
227            Self::AssetDepositQueryAllowedList => "/v5/asset/deposit/query-allowed-list",
228            Self::AssetDepositQueryRecord => "/v5/asset/deposit/query-record",
229            Self::AssetDepositQuerySubMemberRecord => "/v5/asset/deposit/query-sub-member-record",
230            Self::AssetWithdrawQueryRecord => "/v5/asset/withdraw/query-record",
231            Self::AssetCoinQueryInfo => "/v5/asset/coin/query-info",
232            Self::AssetWithdrawCreate => "/v5/asset/withdraw/create",
233            Self::AssetWithdrawCancel => "/v5/asset/withdraw/cancel",
234            Self::AssetDepositQueryAddress => "/v5/asset/deposit/query-address",
235            Self::AssetDepositQuerySubMemberAddress => "/v5/asset/deposit/query-sub-member-address",
236            Self::AssetExchangeOrderRecord => "/v5/asset/exchange/order-record",
237
238            Self::UserQueryApi => "/v5/user/query-api",
239
240            Self::SpotLeverTokenInfo => "/v5/spot-lever-token/info",
241            Self::SpotLeverTokenReference => "/v5/spot-lever-token/reference",
242            Self::SpotLeverTokenPurchase => "/v5/spot-lever-token/purchase",
243            Self::SpotLeverTokenRedeem => "/v5/spot-lever-token/redeem",
244            Self::SpotLeverTokenOrderRecord => "/v5/spot-lever-token/order-record",
245            Self::SpotMarginTradeSwitchMode => "/v5/spot-margin-trade/switch-mode",
246            Self::SpotMarginTradeSetLeverage => "/v5/spot-margin-trade/set-leverage",
247            Self::SpotMarginTradeSetPledgeToken => "/v5/spot-margin-trade/set-pledge-token",
248
249            Self::PublicSpot => "/v5/public/spot",
250            Self::PublicLinear => "/v5/public/linear",
251            Self::PublicInverse => "/v5/public/inverse",
252            Self::PublicOption => "/v5/public/option",
253            Self::Private => "/v5/private",
254            Self::Trade => "/v5/trade",
255        };
256
257        write!(f, "{s}")
258    }
259}