### Python Client Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/asset/convert-small-balance/small-balanc-coins Shows how to use the pybit library to get small balance coins. Ensure you have the library installed and your API credentials configured. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_small_balance_coins( fromCoin="XRP", accountType="eb_convert_uta", )) ``` -------------------------------- ### Python Example for Server Time Source: https://bybit-exchange.github.io/docs/zh-TW/v5/market/time Demonstrates how to get the Bybit server time using the pybit library. Ensure you have the library installed and a session initialized. ```Python from pybit.unified_trading import HTTP session = HTTP(testnet=True) print(session.get_server_time()) ``` -------------------------------- ### Python SDK Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/asset/sub-uid-list Use the Python SDK to get the list of sub-account UIDs. Ensure you have the 'pybit' library installed and your API key and secret are configured. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_sub_uid()) ``` -------------------------------- ### GET /v5/pre-upgrade/order/history Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/pre-upgrade/order-list This example demonstrates how to make a GET request to retrieve filled orders for the linear category. Ensure you specify the category and any other relevant parameters like limit. ```http GET /v5/pre-upgrade/order/history?category=linear&limit=1&orderStatus=Filled HTTP/1.1 ``` -------------------------------- ### Python SDK Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/position/close-pnl Example using the Python SDK to get closed PnL. Ensure you have the pybit library installed and your API credentials configured. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_closed_pnl( category="linear", limit=1, )) ``` -------------------------------- ### Python SDK Example for Asset Info Source: https://bybit-exchange.github.io/docs/zh-TW/v5/abandon/asset-info Demonstrates how to use the pybit SDK to fetch spot asset information for a given account type and coin. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_spot_asset_info( accountType="FUND", coin="USDC", )) ``` -------------------------------- ### Go Order Creation Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/order/create-order Shows how to place a linear perpetual order using the Bybit Go API client. Remember to replace placeholder API keys and secrets. ```go import ( "context" "fmt" bybit "https://github.com/bybit-exchange/bybit.go.api") client := bybit.NewBybitHttpClient("YOUR_API_KEY", "YOUR_API_SECRET", bybit.WithBaseURL(bybit.TESTNET)) params := map[string]interface{}{ "category": "linear", "symbol": "BTCUSDT", "side": "Buy", "positionIdx": 0, "orderType": "Limit", "qty": "0.001", "price": "10000", "timeInForce": "GTC", } client.NewUtaBybitServiceWithParams(params).PlaceOrder(context.Background()) ``` -------------------------------- ### Python SDK Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/new-crypto-loan/flexible/repay-collateral Example using the pybit unified_trading HTTP client to perform a collateral repayment for a flexible crypto loan. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.collateral_repayment_flexible_crypto_loan( loanCurrency="USDT", amount="500", collateralCoin="BTC", )) ``` -------------------------------- ### Get Transaction Log (Python) Source: https://bybit-exchange.github.io/docs/zh-TW/v5/account/transaction-log Python example using the pybit library to fetch transaction logs. Ensure you have the library installed and your API keys configured. ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_transaction_log( accountType="UNIFIED", category="linear", currency="USDT", )) ``` -------------------------------- ### Python SDK Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/order/spot-borrow-quota Shows how to use the Bybit Python SDK to get the spot borrow quota. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_borrow_quota( category="spot", symbol="BTCUSDT", side="Buy", )) ``` -------------------------------- ### Create Strategy Request Example (HTTP) Source: https://bybit-exchange.github.io/docs/zh-TW/v5/strategy/create-strategy Demonstrates the HTTP request structure for creating a strategy. Ensure all required fields are correctly populated. ```http POST /v5/strategy/create HTTP/1.1 { "side": "Buy", "symbol": "BTCUSDT", "reduceOnly": false, "category": "UTA_USDT", "size": "0.1", "positionIdx": 1, "strategyType": "chaseOrder", "chasePrice": "75967.7", "maxChasePrice": "83564.5", "triggerPrice": "75000.0" } ``` -------------------------------- ### HTTP Request Example for Broker Earning Records Source: https://bybit-exchange.github.io/docs/zh-TW/v5/abandon/earning This snippet shows an example HTTP GET request to retrieve broker earning records. It includes parameters for business type, start and end times, and a limit for the number of results per page. ```http GET /v5/broker/earning-record?bizType=SPOT&startTime=1686240000000&endTime=1686326400000&limit=1 HTTP/1.1 ``` -------------------------------- ### Java SDK Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/order/spot-borrow-quota Illustrates using the Bybit Java SDK to retrieve spot borrow quota information. ```Java import com.bybit.api.client.config.BybitApiConfig; import com.bybit.api.client.domain.trade.request.TradeOrderRequest; import com.bybit.api.client.domain.*; import com.bybit.api.client.domain.trade.*; import com.bybit.api.client.service.BybitApiClientFactory; var client = BybitApiClientFactory.newInstance("YOUR_API_KEY", "YOUR_API_SECRET", BybitApiConfig.TESTNET_DOMAIN).newTradeRestClient(); var getBorrowQuotaRequest = TradeOrderRequest.builder().category(CategoryType.SPOT).symbol("BTCUSDT").side(Side.BUY).build(); System.out.println(client.getBorrowQuota(getBorrowQuotaRequest)); ``` -------------------------------- ### Get Linear Market Instrument Info (Python) Source: https://bybit-exchange.github.io/docs/zh-TW/v5/market/instrument Python example using the pybit library to fetch linear market instrument details. Ensure the library is installed and configured for testnet. ```Python from pybit.unified_trading import HTTP session = HTTP(testnet=True) print(session.get_instruments_info( category="linear", symbol="BTCUSDT", )) ``` -------------------------------- ### Python Order Creation Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/order/create-order Demonstrates creating a spot limit order using the pybit library. Ensure you have the library installed and replace placeholders with your actual API key and secret. ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.place_order( category="spot", symbol="BTCUSDT", side="Buy", orderType="Limit", qty="0.1", price="15600", timeInForce="PostOnly", orderLinkId="spot-test-postonly", isLeverage=0, orderFilter="Order", )) ``` -------------------------------- ### HTTP Request for Index Price Kline Source: https://bybit-exchange.github.io/docs/zh-TW/v5/market/index-kline Example of an HTTP GET request to retrieve index price kline data. Specify parameters like category, symbol, interval, start, end, and limit. ```HTTP GET /v5/market/index-price-kline?category=inverse&symbol=BTCUSDZ22&interval=1&start=1670601600000&end=1670608800000&limit=2 HTTP/1.1 ``` -------------------------------- ### GET /v5/lending/account Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/abandon/account-info Example of an HTTP GET request to retrieve lending account information for a specific coin. ```http GET /v5/lending/account?coin=ETH HTTP/1.1 ``` -------------------------------- ### Python Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/user/apikey-info Shows how to use the pybit library to fetch API key details. Ensure you have the library installed and provide valid API credentials. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_api_key_information()) ``` -------------------------------- ### Request Example for Pre-Upgrade Execution List Source: https://bybit-exchange.github.io/docs/zh-TW/v5/pre-upgrade/execution This snippet shows an example HTTP GET request to the /v5/pre-upgrade/execution/list endpoint. It demonstrates how to specify parameters like category, limit, execType, and symbol to retrieve specific execution records. ```HTTP GET /v5/pre-upgrade/execution/list?category=linear&limit=1&execType=Funding&symbol=BTCUSDT HTTP/1.1 ``` -------------------------------- ### GET /v5/spread/tickers Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/spread/market/tickers Example of an HTTP GET request to the /v5/spread/tickers endpoint to fetch ticker information for a specific symbol. ```http GET /v5/spread/tickers?symbol=SOLUSDT_SOL/USDT HTTP/1.1 ``` -------------------------------- ### Python SDK Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/new-crypto-loan/reduce-max-collateral-amt Shows how to use the pybit SDK to get the maximum allowed collateral reduction amount for a new crypto loan. Requires API key and secret for authentication. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_max_allowed_collateral_reduction_amount_new_crypto_loan( collateralCurrency="BTC", )) ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/user/subuid-list This is an example of an HTTP GET request to the /v5/user/query-sub-members endpoint. ```HTTP GET /v5/user/query-sub-members HTTP/1.1 ``` -------------------------------- ### GET /v5/spread/recent-trade Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/spread/market/recent-trade This snippet shows an example HTTP GET request to the /v5/spread/recent-trade endpoint. It includes query parameters for the symbol and the number of results per page. ```http GET /v5/spread/recent-trade?symbol=SOLUSDT_SOL/USDT&limit=2 HTTP/1.1 ``` -------------------------------- ### .Net Order Creation Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/order/create-order This .Net example shows how to place a market order for a linear perpetual contract. Replace the placeholder API key and secret with your actual credentials. ```csharp using bybit.net.api.ApiServiceImp; using bybit.net.api.Models.Trade; BybitTradeService tradeService = new(apiKey: "xxxxxxxxxxxxxx", apiSecret: "xxxxxxxxxxxxxxxxxxxxx"); var orderInfo = await tradeService.PlaceOrder(category: Category.LINEAR, symbol: "BLZUSDT", side: Side.BUY, orderType: OrderType.MARKET, qty: "15", timeInForce: TimeInForce.GTC); Console.WriteLine(orderInfo); ``` -------------------------------- ### GET /v5/spread/max-qty Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/spread/trade/max-qty Example of an HTTP GET request to query the maximum order quantity for a spread trading pair. Ensure you provide the correct symbol, side, and orderPrice. ```http GET /v5/spread/max-qty?symbol=SOLUSDT_SOL/USDT&side=1&orderPrice=50000 HTTP/1.1 ``` -------------------------------- ### Python WebSocket Client Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/websocket/private/wallet Example of how to connect to the WebSocket, subscribe to the wallet stream, and handle incoming messages using the `pybit` library. ```python from pybit.unified_trading import WebSocket from time import sleep ws = WebSocket( testnet=True, channel_type="private", api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) def handle_message(message): print(message) ws.wallet_stream(callback=handle_message) while True: sleep(1) ``` -------------------------------- ### Go SDK for Funding Rate History Source: https://bybit-exchange.github.io/docs/zh-TW/v5/market/history-fund-rate Illustrates fetching historical funding rates using the Bybit Go SDK. This example uses a map for parameters and requires context and the Bybit client initialization. ```Go import ( "context" "fmt" bybit "github.com/bybit-exchange/bybit.go.api" ) client := bybit.NewBybitHttpClient("", "", bybit.WithBaseURL(bybit.TESTNET)) params := map[string]interface{}{"category": "linear", "symbol": "BTCUSDT"} client.NewUtaBybitServiceWithParams(params).GetFundingRateHistory(context.Background()) ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/spot-margin-uta/coinstate Example of an HTTP GET request to the coin state endpoint. ```HTTP GET /v5/spot-margin-trade/coinstate HTTP/1.1 ``` -------------------------------- ### Node.js Order Creation Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/order/create-order Demonstrates creating a spot market order using the Bybit Node.js SDK. Ensure you have the SDK installed and replace the testnet, key, and secret placeholders. ```javascript const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .submitOrder({ category: 'spot', symbol: 'BTCUSDT', side: 'Buy', orderType: 'Market', qty: '0.1', price: '15600', timeInForce: 'PostOnly', orderLinkId: 'spot-test-postonly', isLeverage: 0, orderFilter: 'Order', }) .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/asset/sub-uid-list This is an example of the HTTP GET request to query the sub-account list. ```HTTP GET /v5/asset/transfer/query-sub-member-list HTTP/1.1 ``` -------------------------------- ### Upgrade to UTA PRO with .NET SDK Source: https://bybit-exchange.github.io/docs/zh-TW/v5/account/upgrade-unified-account This .NET code example shows how to use the Bybit SDK to upgrade your account to UTA PRO. Ensure your API key and secret are correctly provided. ```.NET using bybit.net.api; using bybit.net.api.ApiServiceImp; using bybit.net.api.Models; BybitAccountService accountService = new(apiKey: "xxxxxx", apiSecret: "xxxxx"); Console.WriteLine(await accountService.UpgradeAccount()); ``` -------------------------------- ### GET /v5/spread/orderbook Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/spread/market/orderbook Example of an HTTP GET request to retrieve the order book depth for a specific spread product. Ensure the 'symbol' and optional 'limit' parameters are correctly set. ```http GET /v5/spread/orderbook?symbol=SOLUSDT_SOL/USDT&limit=1 HTTP/1.1 ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/position/close-pnl Example of an HTTP GET request to retrieve closed PnL data. ```HTTP GET /v5/position/closed-pnl?category=linear&limit=1 HTTP/1.1 ``` -------------------------------- ### Python SDK Example for Borrowing Crypto Source: https://bybit-exchange.github.io/docs/zh-TW/v5/abandon/borrow Demonstrates how to borrow cryptocurrency using the Bybit Python SDK. Requires API key and secret for authentication. The session is configured for testnet. Parameters like loanCurrency, loanAmount, collateralCurrency, loanTerm, and collateralAmount are passed to the borrow_crypto_loan method. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.borrow_crypto_loan( loanCurrency="USDT", loanAmount="550", collateralCurrency="BTC", loanTerm=None, collateralAmount=None, )) ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/asset/fiat-convert/query-trade-history This is an example of an HTTP GET request to query the fiat trade history. ```http GET /v5/fiat/trade-query-history HTTP/1.1 ``` -------------------------------- ### Go Example for Server Time Source: https://bybit-exchange.github.io/docs/zh-TW/v5/market/time Shows how to fetch the server time using the official Go API client for Bybit. This example uses the testnet endpoint. ```Go import ( "context" "fmt" bybit "github.com/bybit-exchange/bybit.go.api" ) client := bybit.NewBybitHttpClient("", "", bybit.WithBaseURL(bybit.TESTNET)) client.NewUtaBybitServiceNoParams().GetServerTime(context.Background()) ``` -------------------------------- ### Node.js SDK for Product Information Source: https://bybit-exchange.github.io/docs/zh-TW/v5/otc/margin-product-info This Node.js example shows how to retrieve product information using the `bybit-api` library. It requires your API key and secret for authentication and can be configured for testnet environments. ```Node.js const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .getInstitutionalLendingProductInfo({ productId: '91', }) .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### GET /v5/broker/ip/changelog Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/broker/api-broker/ip-changelog Demonstrates a GET request to the IP changelog endpoint with a limit parameter. ```http GET /v5/broker/ip/changelog?limit=3 HTTP/1.1 ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/spot-margin-uta/max-borrowable Example of an HTTP GET request to query the maximum borrowable amount for BTC. ```HTTP GET /v5/spot-margin-trade/max-borrowable?currency=BTC HTTP/1.1 ``` -------------------------------- ### Java Example for Batch Moving Positions Source: https://bybit-exchange.github.io/docs/zh-TW/v5/position/move-position Shows how to batch move positions using the Bybit Java SDK. This example includes moving both spot and option positions. Ensure correct category and side types are used. ```Java import com.bybit.api.client.domain.*; import com.bybit.api.client.domain.position.*; import com.bybit.api.client.domain.position.request.*; import com.bybit.api.client.service.BybitApiClientFactory; var client = BybitApiClientFactory.newInstance().newAsyncPositionRestClient(); var movePositionsRequest = Arrays.asList(MovePositionDetailsRequest.builder().category(CategoryType.SPOT.getCategoryTypeId()).symbol("BTCUSDT").side(Side.SELL.getTransactionSide()).price("100").qty("0.01").build(), MovePositionDetailsRequest.builder().category(CategoryType.SPOT.getCategoryTypeId()).symbol("ETHUSDT").side(Side.SELL.getTransactionSide()).price("100").qty("0.01").build()); var batchMovePositionsRequest = BatchMovePositionRequest.builder().fromUid("123456").toUid("456789").list(movePositionsRequest).build(); System.out.println(client.batchMovePositions(batchMovePositionsRequest)); ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/spot-margin-uta/liability Example of an HTTP GET request to query liability information for a specific currency. ```HTTP GET /v5/spot-margin-trade/liability?currency=BTC HTTP/1.1 ``` -------------------------------- ### Python SDK Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/asset/transfer/transferable-coin Shows how to use the pybit Python SDK to get a list of transferable coins. Requires API key and secret for authentication. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_transferable_coin( fromAccountType="UNIFIED", toAccountType="CONTRACT", )) ``` -------------------------------- ### Batch Place Orders Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/order/batch-place Demonstrates how to place multiple limit orders for different symbols in a single request. Ensure correct parameters like symbol, side, order type, quantity, price, and time in force are provided. ```javascript const { OrderSide, OrderType, TimeInForce } = require('../../../bybit-api'); // Batch place orders (async () => { const order1 = { symbol: 'BTCUSDT', side: OrderSide.Buy, orderType: OrderType.Limit, isLeverage: 0, qty: '0.001', price: '30000', timeInForce: TimeInForce.GTC, orderLinkId: 'spot-btc-03' }; const order2 = { symbol: 'ATOMUSDT', side: OrderSide.Sell, orderType: OrderType.Limit, isLeverage: 0, qty: '2', price: '12', timeInForce: TimeInForce.GTC, orderLinkId: 'spot-atom-03' }; try { const response = await client.placeOrders([order1, order2]); console.log(response); } catch (error) { console.error(error); } })(); ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/zh-TW/v5/pre-upgrade/settlement Example of an HTTP GET request to query pre-upgrade USDC settlement records. ```HTTP GET /v5/pre-upgrade/asset/settlement-record?category=linear&symbol=ETHPERP&limit=1 HTTP/1.1 ```