### Get Transaction Log Request Examples Source: https://bybit-exchange.github.io/docs/v5/account/transaction-log Examples of how to query transaction logs using HTTP, Python, and Node.js. ```http GET /v5/account/transaction-log?accountType=UNIFIED&category=linear¤cy=USDT HTTP/1.1 ``` ```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", )) ``` ```javascript const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .getTransactionLog({ accountType: 'UNIFIED', category: 'linear', currency: 'USDT', }) .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Node.js Batch Order Creation Setup Source: https://bybit-exchange.github.io/docs/v5/order/batch-place Node.js example initializing the RestClientV5 for Bybit API interactions. This is a setup snippet and requires further code to place orders. ```javascript const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, ``` -------------------------------- ### Get Loan Orders Request Examples Source: https://bybit-exchange.github.io/docs/v5/otc/loan-info Examples for retrieving loan orders using HTTP, Python, and Node.js. ```http GET /v5/ins-loan/loan-order HTTP/1.1 ``` ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_loan_orders()) ``` ```javascript const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .getInstitutionalLendingLoanOrders({ limit: 10, }) .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Get Small Balance Coins Request Examples Source: https://bybit-exchange.github.io/docs/v5/asset/convert-small-balance/small-balanc-coins Examples for querying small-balance coins using HTTP and the Python SDK. ```http GET /v5/asset/covert/small-balance-list?fromCoin=XRP&accountType=eb_convert_uta HTTP/1.1 ``` ```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", )) ``` -------------------------------- ### HTTP Request Example for Querying Coin Balance Source: https://bybit-exchange.github.io/docs/v5/asset/balance/all-balance This example demonstrates how to make an HTTP GET request to query the coin balance for a specific account type and coin. ```http GET /v5/asset/transfer/query-account-coins-balance?accountType=FUND&coin=USDC HTTP/1.1 ``` -------------------------------- ### Node.js Example for Getting All Coins Balance Source: https://bybit-exchange.github.io/docs/v5/asset/balance/all-balance This Node.js example utilizes the bybit-api library to fetch all coin balances. It includes error handling for the API request. ```javascript const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .getAllCoinsBalance({ accountType: 'FUND', coin: 'USDC' }) .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Python Example for Getting All Coins Balance Source: https://bybit-exchange.github.io/docs/v5/asset/balance/all-balance Use this Python snippet with the pybit library to retrieve all coin balances for a specified account type and coin. 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_coins_balance( accountType="FUND", coin="USDC", )) ``` -------------------------------- ### Create Linear Order with Go SDK Source: https://bybit-exchange.github.io/docs/v5/order/create-order Demonstrates placing a linear limit order using the Bybit Go SDK. This example requires setting up the HTTP client with your API key and secret. ```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()) ``` -------------------------------- ### Get Margin Coin Info using Python SDK Source: https://bybit-exchange.github.io/docs/v5/otc/margin-coin-convert-info Use the Bybit Python SDK to fetch margin coin information. Ensure you have the SDK installed and provide your API key and secret for authentication. Testnet is enabled in this example. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_margin_coin_info()) ``` -------------------------------- ### Quick Repayment Request Examples Source: https://bybit-exchange.github.io/docs/v5/account/repay-liability Examples of how to initiate a quick repayment request using HTTP, Python, and Node.js. ```http POST /v5/account/quick-repayment HTTP/1.1 { "coin": "USDT" } ``` ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.repay_liability( coin="USDT" )) ``` ```javascript const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .repayLiability({ coin: 'USDT', }) .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### GET Request Example for Realtime Orders Source: https://bybit-exchange.github.io/docs/v5/guide Example of a GET request to retrieve realtime order data. Ensure to include necessary authentication headers. ```http GET /v5/order/realtime?category=option&symbol=BTC-29JUL22-25000-C HTTP/1.1 -H 'X-BAPI-SIGN: XXXXXXXXXX' \ -H 'X-BAPI-API-KEY: xxxxxxxxxxxxxxxxxx' \ -H 'X-BAPI-TIMESTAMP: 1658384431891' \ -H 'X-BAPI-RECV-WINDOW: 5000' ``` -------------------------------- ### Python SDK Example for Manual Repay Source: https://bybit-exchange.github.io/docs/v5/account/repay Shows how to use the pybit unified_trading library to perform a manual repayment via the HTTP client. Ensure your API key and secret are correctly configured. ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.repay( coin="BTC", amount="0.01" )) ``` -------------------------------- ### Response Example for Get UID Wallet Type Source: https://bybit-exchange.github.io/docs/v5/user/wallet-type This is an example of a successful response from the get UID wallet type endpoint, showing user ID and their associated account types. ```JSON { "retCode": 0, "retMsg": "", "result": { "accounts": [ { "uid": "533285", "accountType": [ "UNIFIED", "FUND" ] } ] }, "retExtInfo": {}, "time": 1686884974151 } ``` -------------------------------- ### GET /v5/strategy/order-list Request Example Source: https://bybit-exchange.github.io/docs/v5/strategy/order-list This snippet shows an example HTTP GET request to retrieve a list of strategy orders. It includes parameters for strategy ID and page size. ```HTTP GET /v5/strategy/order-list?strategyId=119b6211-2611-461b-be5e-5ac557099e82&pageSize=2 HTTP/1.1 ``` -------------------------------- ### Bybit V5 SBE Integration Setup Source: https://bybit-exchange.github.io/docs/v5/sbe/trade/order-entry Sets up the necessary imports, constants, and logging for Bybit V5 SBE integration. Includes WebSocket URL, API credentials, schema details, and template IDs. ```python import hashlib import hmac import json import logging import struct import threading import time from typing import Any, Dict, Optional, Tuple import websocket logging.basicConfig( filename="logfile_order_entry.log", level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s", ) WS_URL = "wss://stream-testnet.bybits.org/v5/trade-sbe" API_KEY = "your_api_key" API_SECRET = "your_api_secret" RECV_WINDOW = 5000 SCHEMA_ID = 2 VERSION = 2 # Template IDs TMPL_AUTH_REQ = 1 TMPL_AUTH_RESP = 2 TMPL_PING_REQ = 3 TMPL_PONG_RESP = 4 TMPL_CREATE_REQ = 5 TMPL_CREATE_RESP = 6 TMPL_REPLACE_REQ = 7 TMPL_REPLACE_RESP = 8 TMPL_CANCEL_REQ = 9 TMPL_CANCEL_RESP = 10 TMPL_ERR_RESP = 17 # Enum values CATEGORY_LINEAR = 2 SIDE_BUY = 1 SIDE_SELL = 2 ORDER_TYPE_LIMIT = 2 ORDER_TYPE_MARKET = 1 TIF_GTC = 1 POSITION_ONE_WAY = 0 MARKET_UNIT_BASE = 1 BOOL_FALSE = 0 BOOL_TRUE = 1 SMP_NONE = 0 # Struct formats (little-endian, no padding) HDR_FMT = " str: global _req_counter _req_counter += 1 return f"req_{_req_counter:012d}" ``` -------------------------------- ### Repay Flexible Crypto Loan with Python SDK Source: https://bybit-exchange.github.io/docs/v5/new-crypto-loan/flexible/repay This Python example demonstrates how to use the Bybit SDK to repay a flexible crypto loan. Ensure you have the SDK 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.repay_flexible_crypto_loan( loanCurrency="BTC", loanAmount="0.005", )) ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/v5/market/open-interest Example of an HTTP GET request to retrieve open interest data. ```HTTP GET /v5/market/open-interest?limit=5&category=inverse&intervalTime=1d&symbol=BTCUSD HTTP/1.1 ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/v5/market/orderbook Example of an HTTP GET request to retrieve orderbook data for a spot market. ```http GET /v5/market/orderbook?category=spot&symbol=BTCUSDT HTTP/1.1 ``` -------------------------------- ### Query DCP Info API Examples Source: https://bybit-exchange.github.io/docs/v5/account/dcp-info Examples for querying DCP configuration using HTTP, Python, and Node.js. ```http GET /v5/account/query-dcp-info HTTP/1.1 ``` ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.query_dcp_info()) ``` ```javascript const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .getDCPInfo() .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Set Spot Margin Leverage Request Examples Source: https://bybit-exchange.github.io/docs/v5/spot-margin-uta/set-leverage Examples for configuring spot margin leverage using HTTP, Python, and Node.js clients. ```http POST /v5/spot-margin-trade/set-leverage HTTP/1.1 { "leverage": "4" } ``` ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.spot_margin_trade_set_leverage( leverage="4", )) ``` ```javascript const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .setSpotMarginLeverage('4') .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/v5/account/pay-info Example of an HTTP GET request to the /v5/account/pay-info endpoint with a specific coin parameter. ```http GET /v5/account/pay-info?coin=SOL HTTP/1.1 ``` -------------------------------- ### Python SDK Example for Pre Check Order Source: https://bybit-exchange.github.io/docs/v5/order/pre-check-order Demonstrates how to use the `pre_check_order` method from the `pybit.unified_trading.HTTP` client to check order parameters. Ensure you have the Bybit SDK 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.pre_check_order( category="spot", symbol="BTCUSDT", side="Buy", orderType="Limit", qty="0.1", price="28000", timeInForce="PostOnly", takeProfit="35000", stopLoss="27000", tpOrderType="Market", slOrderType="Market", )) ``` -------------------------------- ### API Path Structure Example Source: https://bybit-exchange.github.io/docs/v5/intro Illustrates the standardized API path structure for Bybit V5, which includes host, version, product, and module. ```string api.bybit.com/v5/market/recent-trade ``` -------------------------------- ### Get Delivery Record Request Examples Source: https://bybit-exchange.github.io/docs/v5/asset/delivery Examples of how to request delivery records using HTTP, Python, and Node.js. ```http GET /v5/asset/delivery-record?expDate=29DEC22&category=option HTTP/1.1 ``` ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_option_delivery_record( category="option", expDate="29DEC22", )) ``` ```javascript const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .getDeliveryRecord({ category: 'option', expDate: '29DEC22' }) .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Go Batch Order Creation Source: https://bybit-exchange.github.io/docs/v5/order/batch-place Go example for creating batch orders using the Bybit Go SDK. Uses testnet and requires API credentials. Note the specific parameters for option orders. ```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": "option", "request": []map[string]interface{}{ { "category": "option", "symbol": "BTC-10FEB23-24000-C", "orderType": "Limit", "side": "Buy", "qty": "0.1", "price": "5", "orderIv": "0.1", "timeInForce": "GTC", "orderLinkId": "9b381bb1-401", "mmp": false, "reduceOnly": false, }, { "category": "option", "symbol": "BTC-10FEB23-24000-C", "orderType": "Limit", "side": "Buy", "qty": "0.1", "price": "5", "orderIv": "0.1", "timeInForce": "GTC", "orderLinkId": "82ee86dd-001", "mmp": false, "reduceOnly": false, }, }, } client.NewUtaBybitServiceWithParams(params).PlaceBatchOrder(context.Background()) ``` -------------------------------- ### Create Spot Order with Python SDK Source: https://bybit-exchange.github.io/docs/v5/order/create-order Shows how to place a spot 'PostOnly' limit order using the `pybit` Python SDK. Ensure you have the SDK 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.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", )) ``` -------------------------------- ### Get Collateral Info HTTP Request Source: https://bybit-exchange.github.io/docs/v5/account/collateral-info Example of an HTTP GET request to retrieve collateral information for a specific currency. ```http GET /v5/account/collateral-info?currency=BTC HTTP/1.1 ``` -------------------------------- ### Get Position Tiers Request Examples Source: https://bybit-exchange.github.io/docs/v5/spot-margin-uta/position-tiers Examples of how to request position tier data using HTTP and the Python SDK. ```http GET /v5/spot-margin-trade/position-tiers?currency=BTC HTTP/1.1 ``` ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.spot_margin_trade_get_position_tiers( currency="BTC" )) ``` -------------------------------- ### Spot Order Examples Source: https://bybit-exchange.github.io/docs/v5/order/create-order Demonstrates creating various spot orders, including limit orders with market or limit take profit/stop loss, post-only orders, TP/SL orders, margin orders, and market buy orders. ```json {"category": "spot","symbol": "BTCUSDT","side": "Buy","orderType": "Limit","qty": "0.01","price": "28000","timeInForce": "PostOnly","takeProfit": "35000","stopLoss": "27000","tpOrderType": "Market","slOrderType": "Market"} ``` ```json {"category": "spot","symbol": "BTCUSDT","side": "Buy","orderType": "Limit","qty": "0.01","price": "28000","timeInForce": "PostOnly","takeProfit": "35000","stopLoss": "27000","tpLimitPrice": "36000","slLimitPrice": "27500","tpOrderType": "Limit","slOrderType": "Limit"} ``` ```json {"category":"spot","symbol":"BTCUSDT","side":"Buy","orderType":"Limit","qty":"0.1","price":"15600","timeInForce":"PostOnly","orderLinkId":"spot-test-01","isLeverage":0,"orderFilter":"Order"} ``` ```json {"category":"spot","symbol":"BTCUSDT","side":"Buy","orderType":"Limit","qty":"0.1","price":"15600","triggerPrice": "15000", "timeInForce":"Limit","orderLinkId":"spot-test-02","isLeverage":0,"orderFilter":"tpslOrder"} ``` ```json {"category":"spot","symbol":"BTCUSDT","side":"Buy","orderType":"Limit","qty":"0.1","price":"15600","timeInForce":"GTC","orderLinkId":"spot-test-limit","isLeverage":1,"orderFilter":"Order"} ``` ```json {"category":"spot","symbol":"BTCUSDT","side":"Buy","orderType":"Market","qty":"200","timeInForce":"IOC","orderLinkId":"spot-test-04","isLeverage":0,"orderFilter":"Order"} ``` -------------------------------- ### Get Auto Repay Mode Request Examples Source: https://bybit-exchange.github.io/docs/v5/spot-margin-uta/get-auto-repay-mode Examples for querying the auto-repay mode using HTTP, Python, and Node.js. ```http GET /v5/spot-margin-trade/get-auto-repay-mode?currency=ETH HTTP/1.1 ``` ```python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_auto_repay_mode( currency="ETH" )) ``` ```javascript ``` -------------------------------- ### Repay Collateral with Python SDK Source: https://bybit-exchange.github.io/docs/v5/new-crypto-loan/flexible/repay-collateral This Python example demonstrates how to use the Bybit unified trading SDK to repay collateral for flexible crypto loans. Remember to set `testnet=True` for testing and replace placeholders with your actual API key and secret. ```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", )) ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/v5/position/batch-lvg Example of an HTTP GET request to query symbol information and leverage settings for a specific symbol. ```http GET /v5/position/symbol-info?category=linear&symbol=BTCUSDT HTTP/1.1 ``` -------------------------------- ### Python Request Example Source: https://bybit-exchange.github.io/docs/v5/bybit-card/point/cashback-detail Shows how to make a POST request using the Python `requests` library to fetch cashback details. Includes necessary headers and parameters. The `X-BAPI-API-KEY`, `X-BAPI-SIGN`, and `X-BAPI-TIMESTAMP` headers are crucial for authentication and request validation. ```Python import requests url = "https://api-testnet.bybit.com/v5/card/reward/point/cashback/detail" headers = { "X-BAPI-API-KEY": "xxxxxxxxxxxxxxxxxx", "X-BAPI-SIGN": "XXXXX", "X-BAPI-TIMESTAMP": "1672211918471", "X-BAPI-RECV-WINDOW": "5000" } params = { "bizTxnId": "TXN20230101001" } response = requests.post(url, headers=headers, params=params) print(response.json()) ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/v5/otc/coin-delta-amount Example of an HTTP GET request to query the coin delta amount for a specific coin (BTC). ```HTTP GET /v5/ins-loan/coin-delta-amount?coin=BTC HTTP/1.1 ``` -------------------------------- ### Get Borrow Quota Request Examples Source: https://bybit-exchange.github.io/docs/v5/order/spot-borrow-quota Examples for querying the spot borrow quota across different protocols and languages. ```HTTP GET /v5/order/spot-borrow-check?category=spot&symbol=BTCUSDT&side=Buy HTTP/1.1 ``` ```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", )) ``` ```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)); ``` ```Node.js const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, key: 'xxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', }); client .getSpotBorrowCheck('BTCUSDT', 'Buy') .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Go SDK for Open Interest Source: https://bybit-exchange.github.io/docs/v5/market/open-interest Example of using the Bybit Go API client to fetch open interest. This snippet demonstrates setting up the client and making the request. ```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).GetOpenInterests(context.Background()) ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/v5/new-crypto-loan/fixed/supply-contract%20copy Example of an HTTP GET request to retrieve supply contract information, filtering by supply currency. ```HTTP GET /v5/crypto-loan-fixed/supply-contract-info?supplyCurrency=USDT HTTP/1.1 ``` -------------------------------- ### Get Index Price Kline Response Example Source: https://bybit-exchange.github.io/docs/v5/market/index-kline Example JSON response structure for the index price kline request. ```JSON { "retCode": 0, "retMsg": "OK", "result": { "symbol": "BTCUSDZ22", "category": "inverse", "list": [ [ "1670608800000", "17167.00", "17167.00", "17161.90", "17163.07" ], [ "1670608740000", "17166.54", "17167.69", "17165.42", "17167.00" ] ] }, "retExtInfo": {}, "time": 1672026471128 } ``` -------------------------------- ### Create Linear Order with C# SDK Source: https://bybit-exchange.github.io/docs/v5/order/create-order Demonstrates placing a linear market order using the Bybit .NET SDK. This example requires initializing the trade service with API keys. ```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 Delivery Price Request Examples Source: https://bybit-exchange.github.io/docs/v5/market/delivery-price Examples of how to request delivery price data across different programming languages. ```HTTP GET /v5/market/delivery-price?category=option&symbol=ETH-26DEC22-1400-C HTTP/1.1 ``` ```Python from pybit.unified_trading import HTTP session = HTTP() print(session.get_option_delivery_price( category="option", symbol="ETH-26DEC22-1400-C", )) ``` ```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": "ETH-26DEC22-1400-C"} client.NewUtaBybitServiceWithParams(params).GetDeliveryPrice(context.Background()) ``` ```Java import com.bybit.api.client.domain.CategoryType; import com.bybit.api.client.domain.market.request.MarketDataRequest; import com.bybit.api.client.service.BybitApiClientFactory; var client = BybitApiClientFactory.newInstance().newAsyncMarketDataRestClient(); var deliveryPriceRequest = MarketDataRequest.builder().category(CategoryType.OPTION).baseCoin("BTC").limit(10).build(); client.getDeliveryPrice(deliveryPriceRequest, System.out::println); ``` ```Node.js const { RestClientV5 } = require('bybit-api'); const client = new RestClientV5({ testnet: true, }); client .getDeliveryPrice({ category: 'option', symbol: 'ETH-26DEC22-1400-C' }) .then((response) => { console.log(response); }) .catch((error) => { console.error(error); }); ``` -------------------------------- ### Response Example Source: https://bybit-exchange.github.io/docs/v5/alpha/lp/order-list This snippet demonstrates a successful response from the /v5/alpha/lp/order-list endpoint, detailing a single LP order. ```JSON { "retCode": 0, "retMsg": "OK", "result": { "total": 1, "pageIndex": 1, "orders": [ { "orderType": 1, "orderNo": "LP_ORD_20240101_001", "orderStatus": 2, "poolAddress": "0x1234567890abcdef", "poolName": "ETH-USDC Pool", "positionId": 12345, "tokenCode": "CEX_1", "tokenSymbol": "USDT", "tokenIconUrlDay": "", "tokenIconUrlNight": "", "amount": "1000", "chainCode": "", "chainIconUrl": "", "gasTokenSymbol": "", "gasOnchain": "", "gasUsd": null, "platformFee": "", "platformFeeUsd": null, "createTime": 1704067200, "executionTime": 1704067230, "failureReason": "", "dercRatio": "" } ] }, "retExtInfo": {}, "time": 1704067300000 } ``` -------------------------------- ### Python: Get Product Info with API Key Source: https://bybit-exchange.github.io/docs/v5/otc/margin-product-info This Python snippet demonstrates how to use the pybit library to fetch product information. Ensure you have your API key and secret configured. This example queries for a specific productId. ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.get_product_info(productId="91")) ``` -------------------------------- ### Manual Borrow Request Examples Source: https://bybit-exchange.github.io/docs/v5/account/borrow Examples for initiating a manual borrow request using HTTP, Python, and Node.js. ```HTTP POST /v5/account/borrow HTTP/1.1 { "coin":"BTC", "amount":"0.01" } ``` ```Python from pybit.unified_trading import HTTP session = HTTP( testnet=True, api_key="xxxxxxxxxxxxxxxxxx", api_secret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ) print(session.borrow( coin="BTC", amount="0.01" )) ``` -------------------------------- ### HTTP GET Request for Borrow History Source: https://bybit-exchange.github.io/docs/v5/account/borrow-history Example of an HTTP GET request to retrieve borrow history with specified currency and limit. ```HTTP GET /v5/account/borrow-history?currency=BTC&limit=1 HTTP/1.1 ``` -------------------------------- ### HTTP Request Example Source: https://bybit-exchange.github.io/docs/v5/new-crypto-loan/flexible/unpaid-loan-order Example of an HTTP GET request to retrieve ongoing flexible crypto loans, specifying the loan currency. ```HTTP GET /v5/crypto-loan-flexible/ongoing-coin?loanCurrency=BTC HTTP/1.1 ``` -------------------------------- ### Create Strategy Request Example Source: https://bybit-exchange.github.io/docs/v5/strategy/create-strategy Example of a POST request to create a strategy. Ensure all required parameters like 'side', 'symbol', 'category', 'size' or 'duration', and 'strategyType' are included. ```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" } ```