### Install Python Bitget Client Source: https://github.com/cuongitl/python-bitget/blob/master/docs/overview.md Installs the python-bitget library using pip. This is the first step to using the library for Bitget API interactions. ```bash pip install python-bitget ``` -------------------------------- ### Make REST API Call to Get Accounts Source: https://github.com/cuongitl/python-bitget/blob/master/docs/overview.md Example of making a REST API call to retrieve account information for a specific product type (e.g., UMCBL). Requires an initialized client object. ```python from bitget import Client api_key = "your-api-key" api_secret = "your-secret-key" api_passphrase = "your-api-passphrase" client = Client(api_key, api_secret, passphrase=api_passphrase) result = client.mix_get_accounts(productType='UMCBL') print(result) ``` -------------------------------- ### Get All Bitget Spot Trading Symbols (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Fetches a list of all available spot trading pairs and their specifications from the Bitget API. Requires an initialized client. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Get all available spot trading symbols data = client.spot_get_symbols() print(data) # Output: {'code': '00000', 'msg': 'success', 'data': [{'symbol': 'BTCUSDT', 'baseCoin': 'BTC', 'quoteCoin': 'USDT', ...}]} ``` -------------------------------- ### GET /api/spot/v1/market/time Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieve the current server time for synchronization purposes. ```APIDOC ## GET /api/spot/v1/market/time ### Description Retrieve the current server time from the Bitget exchange for synchronization purposes. ### Method GET ### Endpoint /api/spot/v1/market/time ### Response #### Success Response (200) - **code** (string) - API response code - **msg** (string) - Success message - **data** (string) - Server timestamp in milliseconds #### Response Example { "code": "00000", "msg": "success", "data": "1674875751521" } ``` -------------------------------- ### Connect and Subscribe to Bitget WebSocket Channels Source: https://github.com/cuongitl/python-bitget/blob/master/docs/websockets.md Demonstrates how to initialize a BitgetWsClient with authentication credentials and subscribe to various market data channels. It includes examples for both public ticker/candle data and private order channel subscriptions. ```python from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error from pybitget.enums import * from pybitget import logger def on_message(message): logger.info(message) api_key = "your-api-key" api_secret = "your-secret-key" api_passphrase = "your-api-passphrase" if __name__ == '__main__': client = BitgetWsClient(api_key=api_key, api_secret=api_secret, passphrase=api_passphrase, verbose=True) \ .error_listener(handel_error) \ .build() # Subscribe to Public Channels channels = [SubscribeReq("mc", "ticker", "BTCUSD"), SubscribeReq("SP", "candle1W", "BTCUSDT")] client.subscribe(channels, on_message) # Subscribe to Private Order Channel channels = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] client.subscribe(channels, on_message) ``` -------------------------------- ### Get Open Orders - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Fetches a list of all currently open (unfilled or partially filled) spot orders. Can be filtered by symbol. ```python data = client.spot_get_open_orders(self, symbol='') ``` -------------------------------- ### Initialize WebSocket Client and Subscribe to Channels Source: https://github.com/cuongitl/python-bitget/blob/master/README.md Shows how to set up a WebSocket client for real-time data streaming. It includes examples of subscribing to both public market channels and private order channels with a custom message handler. ```python from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error from pybitget.enums import * from pybitget import logger api_key = "your-api-key" api_secret = "your-api-secret" api_passphrase = "your-api-passphrase" def on_message(message): logger.info(message) client = BitgetWsClient(api_key=api_key, api_secret=api_secret, passphrase=api_passphrase, verbose=True) \ .error_listener(handel_error) \ .build() channels = [SubscribeReq("mc", "ticker", "BTCUSD"), SubscribeReq("SP", "candle1W", "BTCUSDT")] client.subscribe(channels, on_message) channels = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] client.subscribe(channels, on_message) ``` -------------------------------- ### GET /spot/public/time Source: https://github.com/cuongitl/python-bitget/blob/master/docs/index.md Retrieves the current server time from the Bitget Spot API. ```APIDOC ## GET /spot/public/time ### Description Fetches the current server time to synchronize client requests. ### Method GET ### Endpoint /api/spot/v1/public/time ### Parameters None ### Request Example GET /api/spot/v1/public/time ### Response #### Success Response (200) - **serverTime** (string) - The current server timestamp in milliseconds. #### Response Example { "code": "0", "msg": "success", "data": { "serverTime": "1674816745836" } } ``` -------------------------------- ### Get Positions Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieve current open positions, either all positions for a product type or a specific position for a symbol. ```APIDOC ## Get Positions ### Description Retrieve current open positions. ### Method GET ### Endpoint `/api/v1/mix/position/all-positions` (for all positions) `/api/v1/mix/position/position` (for a specific position) ### Parameters #### Query Parameters (for `/api/v1/mix/position/all-positions`) - **productType** (string) - Required - The product type (e.g., 'UMCBL'). - **marginCoin** (string) - Required - The margin coin (e.g., 'USDT'). #### Query Parameters (for `/api/v1/mix/position/position`) - **symbol** (string) - Required - The trading symbol (e.g., 'BTCUSDT_UMCBL'). - **marginCoin** (string) - Required - The margin coin (e.g., 'USDT'). ### Request Example (Get all positions) ```python client.mix_get_all_positions(productType='UMCBL', marginCoin='USDT') ``` ### Request Example (Get specific position) ```python client.mix_get_single_position(symbol="BTCUSDT_UMCBL", marginCoin="USDT") ``` ### Response (Success) ```json { "code": "00000", "msg": "success", "data": [ { "symbol": "BTCUSDT_UMCBL", "holdSide": "long", "total": "0.1", "available": "0.1", "averageOpenPrice": "22000", ... } ] } ``` ``` -------------------------------- ### Initialize WebSocket Client (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Demonstrates how to initialize both public and authenticated WebSocket clients using the `pybitget.stream` module. Public clients do not require authentication, while authenticated clients need API credentials for accessing private channels. Includes error handling setup. ```python from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error from pybitget.enums import CONTRACT_WS_URL from pybitget import logger def on_message(message): logger.info(f"Received: {message}") # Public WebSocket (no authentication required) public_client = BitgetWsClient() .error_listener(handel_error) .build() # Authenticated WebSocket (for private channels) api_key = "your-api-key" api_secret = "your-secret-key" api_passphrase = "your-api-passphrase" auth_client = BitgetWsClient( api_key=api_key, api_secret=api_secret, passphrase=api_passphrase, verbose=True ) .error_listener(handel_error) .build() ``` -------------------------------- ### Get Account Assets - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Fetches the assets held in the user's spot account. Can be filtered by a specific coin or retrieve all assets if no coin is specified. ```python data = client.spot_get_account_assets(self, coin=None) ``` -------------------------------- ### Get Bitget Spot Account Assets (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Fetches account balance and asset information for spot trading on Bitget. Can retrieve all assets or details for a specific coin. Requires an initialized client. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Get all account assets data = client.spot_get_account_assets() print(data) # Output: {'code': '00000', 'msg': 'success', 'data': [{'coinId': '1', 'coinName': 'BTC', 'available': '0.5', 'frozen': '0.1', ...}]} # Get specific coin assets btc_assets = client.spot_get_account_assets(coin="BTC") print(btc_assets) ``` -------------------------------- ### Get Plan Order List Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves a list of active or historical plan orders. Supports filtering by symbol and product type. ```python data = client.mix_get_plan_order_tpsl(symbol=None, productType=None, isPlan=None) data = client.mix_get_history_plan_orders(symbol, startTime, endTime, pageSize=100, lastEndId=None, isPre=False, isPlan=None) ``` -------------------------------- ### GET /mix/open-orders Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieves current open futures orders for a symbol or product type. ```APIDOC ## GET /mix/open-orders ### Description Retrieves current open futures orders for a symbol or product type. ### Method GET ### Parameters #### Query Parameters - **symbol** (string) - Optional - The trading symbol - **productType** (string) - Optional - The product type - **marginCoin** (string) - Optional - The margin coin ### Response #### Success Response (200) - **data** (array) - List of open orders ``` -------------------------------- ### Get Coin List - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Fetches a list of all supported coins on the Bitget platform. This information can be used to validate coin symbols or display available trading pairs. ```python data = client.spot_get_coin_list() ``` -------------------------------- ### Get Bitget Spot Ticker Information (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieves ticker information for spot trading pairs on Bitget. Can fetch data for a single symbol or all symbols. Requires an initialized client. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Get single ticker data = client.spot_get_ticker(symbol="BTCUSDT_SPBL") print(data) # Output: {'code': '00000', 'msg': 'success', 'data': {'symbol': 'BTCUSDT', 'high24h': '23500', 'low24h': '22800', 'close': '23100', ...}} # Get all tickers all_tickers = client.spot_get_tickers() print(all_tickers) ``` -------------------------------- ### Get Order Details - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Retrieves detailed information about a specific spot order. Requires the symbol and order ID. Can optionally filter by client order ID. ```python data = client.spot_get_order_details(self, symbol, orderId, clientOrderId=None) ``` -------------------------------- ### Get Bitget Spot Trading Server Time (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieves the current server time from the Bitget API, useful for timestamp synchronization. Requires client initialization with API credentials. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Get server timestamp data = client.spot_get_server_time() print(data) # Output: {'code': '00000', 'msg': 'success', 'data': '1674875751521'} ``` -------------------------------- ### Get Sub-Account Spot Assets - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Retrieves the spot account assets for a sub-account. This allows managing and monitoring funds across different sub-accounts. ```python data = client.spot_get_sub_account_assets() ``` -------------------------------- ### Get Deposit List - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Retrieves a history of deposit records. Supports filtering by coin, time range, and pagination parameters. Useful for tracking incoming funds. ```python data = client.spot_get_depositList(self, coin, startTime, endTime, pageSize=20, pageNo=1) ``` -------------------------------- ### Get Plan Order (TPSL) List Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves a list of plan orders, including those with Take Profit and Stop Loss (TPSL) settings. ```APIDOC ## GET /api/v1/mix/order/get-plan-tpsl ### Description Retrieves a list of plan orders with TPSL settings. ### Method GET ### Endpoint /api/v1/mix/order/get-plan-tpsl ### Parameters #### Query Parameters - **symbol** (string) - Optional - The trading symbol. - **productType** (string) - Optional - The type of product. - **isPlan** (string) - Optional - Filter by plan status. ``` -------------------------------- ### Get Bitget Spot Candle Data (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieves candlestick (kline) data for spot trading pairs on Bitget, suitable for technical analysis. Supports various time periods and date ranges. Requires an initialized client. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Get candle data # period options: 1min, 5min, 15min, 30min, 1h, 4h, 12h, 1day, 1week data = client.spot_get_candle_data( symbol="BTCUSDT_SPBL", period="1h", after='1674800000000', # Start time in milliseconds before='1674900000000', # End time in milliseconds limit=100 ) print(data) # Output: {'code': '00000', 'msg': 'success', 'data': [['1674800000000', '23000', '23200', '22900', '23100', '1500.5'], ...] } ``` -------------------------------- ### Get Symbols - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Retrieves a list of all available trading symbols on Bitget. This is essential for identifying valid trading pairs and their associated market information. ```python data = client.spot_get_symbols() ``` -------------------------------- ### CopyTrade - Get Trader History Profit Summary (by settlement currency) Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves historical profit summaries for traders, grouped by settlement currency. ```APIDOC ## GET /api/v1/copytrade/get-trader-profit-settle-margin-coin ### Description Retrieves historical profit summaries for traders, grouped by settlement currency. ### Method GET ### Endpoint /api/v1/copytrade/get-trader-profit-settle-margin-coin ``` -------------------------------- ### Get Bitget Spot Market Depth (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Fetches the order book depth data for a specified spot trading pair on Bitget. Allows customization of limit and merge type for the depth data. Requires an initialized client. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Get depth data with limit and merge type # type options: step0 (default), step1, step2, step3, step4, step5 data = client.spot_get_depth(symbol="BTCUSDT_SPBL", limit='50', type='step0') print(data) # Output: {'code': '00000', 'msg': 'success', 'data': {'asks': [['23100.5', '0.5'], ...], 'bids': [['23099.5', '0.8'], ...], 'timestamp': '1674875751521'}} ``` -------------------------------- ### Get Order History - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Retrieves the history of past spot orders. Supports filtering by symbol, time range, and limit. Useful for reviewing past trades. ```python data = client.spot_get_order_history(self, symbol, after='', before='', limit=100) ``` -------------------------------- ### Get API Key Info - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Retrieves information about the currently used API key, such as permissions and creation date. Useful for verifying API key configuration. ```python data = client.spot_get_ApiKeyInfo() ``` -------------------------------- ### Get Market Data - Python Bitget API Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Fetches various market data points for Bitget futures, including symbols, depth, tickers, candles, funding rates, and open interest. Requires a symbol and potentially other parameters like granularity or time ranges. ```python data = client.mix_get_symbols_info(productType) ``` ```python data = client.mix_get_depth(symbol, limit=100) ``` ```python data = client.mix_get_single_symbol_ticker(symbol) ``` ```python data = client.mix_get_all_symbol_ticker(productType) ``` ```python # Get recent trades. data = client.mix_get_fills(symbol, limit=100) ``` ```python data = client.mix_get_candles(symbol, granularity, startTime, endTime) ``` ```python data = client.mix_get_symbol_index_price(symbol) ``` ```python data = client.mix_get_symbol_next_funding(symbol) ``` ```python data = client.mix_get_history_fund_rate(symbol, pageSize=20, pageNo=1, nextPage=False) ``` ```python data = client.mix_get_current_fund_rate(symbol) ``` ```python data = client.mix_get_open_interest(symbol) ``` ```python data = client.mix_get_market_price(symbol) ``` ```python data = client.mix_get_leverage(symbol) ``` -------------------------------- ### Retrieve Trader Profit Summary (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Fetches profit summaries for copy trading. It includes functions to get the overall profit summary, profit broken down by settlement currency, and profit grouped by date. Requires API credentials. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Get trader profit summary profit_summary = client.mix_get_cp_profit_summary() print(profit_summary) # Get profit by settlement currency profit_by_coin = client.mix_get_cp_profit_settle_margin_coin() print(profit_by_coin) # Get profit grouped by date profit_by_date = client.mix_get_cp_profit_date_group(pageSize=20, pageNo=1) print(profit_by_date) ``` -------------------------------- ### Get History Plan Orders - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Fetches the history of past plan orders. Supports filtering by symbol, time range, and pagination. Useful for reviewing executed or cancelled plan orders. ```python data = client.spot_get_history_plan_orders(self, symbol, startTime, endTime, pageSize=20, lastEndId='') ``` -------------------------------- ### Get Futures Account Information Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieves futures account information and balances for a given product type or a specific symbol and margin coin. This helps in understanding available funds and margin status. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Get account list for product type accounts = client.mix_get_accounts(productType='UMCBL') print(accounts) # Get single account account = client.mix_get_account( symbol="BTCUSDT_UMCBL", marginCoin="USDT" ) print(account) ``` -------------------------------- ### Initialize Bitget REST API Client (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Initializes the Bitget REST API client using API credentials. It demonstrates how to set up the client and optionally sync server time. Includes a test to fetch account list for a specific product type. ```python from pybitget import Client api_key = "your-api-key" api_secret = "your-secret-key" api_passphrase = "your-api-passphrase" # Initialize client with optional server time sync client = Client(api_key, api_secret, passphrase=api_passphrase, use_server_time=False) # Test connection by getting account list result = client.mix_get_accounts(productType='UMCBL') print(result) # Output: {'code': '00000', 'msg': 'success', 'data': [...]} ``` -------------------------------- ### GET /mix/copy-trading-orders Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieves copy trading orders for traders and followers. ```APIDOC ## GET /mix/copy-trading-orders ### Description Retrieves copy trading orders for traders and followers. ### Method GET ### Parameters #### Query Parameters - **symbol** (string) - Required - Trading symbol - **productType** (string) - Required - Product type ### Response #### Success Response (200) - **data** (array) - List of copy trade orders ``` -------------------------------- ### GET /api/spot/v1/market/symbols Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieve all available spot trading pairs and their specifications. ```APIDOC ## GET /api/spot/v1/market/symbols ### Description Retrieve a list of all available spot trading pairs and their associated specifications. ### Method GET ### Endpoint /api/spot/v1/market/symbols ### Response #### Success Response (200) - **data** (array) - List of trading symbols #### Response Example { "code": "00000", "msg": "success", "data": [{"symbol": "BTCUSDT", "baseCoin": "BTC", "quoteCoin": "USDT"}] } ``` -------------------------------- ### Connect and Subscribe to Bitget WebSocket Streams Source: https://github.com/cuongitl/python-bitget/blob/master/docs/overview.md Demonstrates how to establish a WebSocket connection to Bitget and subscribe to various public and private channels, such as tickers, candles, and order updates. Includes error handling. ```python from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error from pybitget.enums import * from pybitget import logger def on_message(message): logger.info(message) api_key = "your-api-key" api_secret = "your-secret-key" api_passphrase = "your-api-passphrase" if __name__ == '__main__': # Un-auth subscribe # client = BitgetWsClient() \ # .error_listener(handel_error) \ # .build() # Auth subscribe client = BitgetWsClient(api_key=api_key, api_secret=api_secret, passphrase=api_passphrase, verbose=True) \ .error_listener(handel_error) \ .build() # multi subscribe - Public Channels channels = [SubscribeReq("mc", "ticker", "BTCUSD"), SubscribeReq("SP", "candle1W", "BTCUSDT")] client.subscribe(channels, on_message) # single subscribe - # multi subscribe Public Channels # channels = [SubscribeReq("mc", "ticker", "BTCUSD")] # client.subscribe(channels, on_message) # single subscribe - Order Channel - Private Channels channels = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] client.subscribe(channels, on_message) ``` -------------------------------- ### CopyTrade - Get CopyTrade Symbols Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves a list of symbols available for CopyTrade. ```APIDOC ## GET /api/v1/copytrade/get-symbols ### Description Retrieves a list of symbols available for CopyTrade. ### Method GET ### Endpoint /api/v1/copytrade/get-symbols ``` -------------------------------- ### Initialize REST API Client Source: https://github.com/cuongitl/python-bitget/blob/master/README.md Demonstrates how to authenticate and initialize the Bitget REST client to perform account-related operations. It requires valid API credentials including key, secret, and passphrase. ```python from pybitget import Client api_key = "your-api-key" api_secret = "your-api-secret" api_passphrase = "your-api-passphrase" client = Client(api_key, api_secret, passphrase=api_passphrase) result = client.mix_get_accounts(productType='UMCBL') print(result) ``` -------------------------------- ### Place a Spot Order on Bitget (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Places a spot order (limit or market) on Bitget. Supports specifying symbol, quantity, side, order type, price, and client order ID. Requires an initialized client. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Place a limit buy order data = client.spot_place_order( symbol="BTCUSDT_SPBL", quantity="0.001", side="buy", # buy or sell orderType="limit", # limit or market force="normal", # normal, postOnly, ioc, fok price="22000", clientOrderId="my_order_001" ) print(data) # Output: {'code': '00000', 'msg': 'success', 'data': {'orderId': '1003067092170850306', 'clientOrderId': 'my_order_001'}} ``` -------------------------------- ### Get Historical Funding Rates Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieve historical funding rates for a specified symbol. ```APIDOC ## Get Historical Funding Rates ### Description Retrieve historical funding rates. ### Method GET ### Endpoint `/api/v1/mix/funding-rate/history` ### Parameters #### Query Parameters - **symbol** (string) - Required - The trading symbol (e.g., 'BTCUSDT_UMCBL'). - **pageSize** (integer) - Optional - The number of results per page (default 20). - **pageNo** (integer) - Optional - The page number (default 1). ### Request Example ```python client.mix_get_history_fund_rate(symbol="BTCUSDT_UMCBL", pageSize=20, pageNo=1) ``` ### Response (Success) ```json { "code": "00000", "msg": "success", "data": [ { "symbol": "BTCUSDT_UMCBL", "fundingRate": "0.00005", "fundingTime": "1678886400000" }, ... ] } ``` ``` -------------------------------- ### Bitget WebSocket Client Connection and Subscription Source: https://github.com/cuongitl/python-bitget/blob/master/docs/websockets.md This snippet demonstrates how to initialize the Bitget WebSocket client, handle authentication, and subscribe to various public and private channels. ```APIDOC ## Bitget WebSocket API Connection and Subscription ### Description This section provides an example of how to connect to the Bitget WebSocket API using the `BitgetWsClient`. It covers initializing the client with API credentials for authenticated access and subscribing to both public and private data streams, such as market tickers, candles, and order updates. ### Method N/A (Client-side connection) ### Endpoint N/A (WebSocket endpoint is handled internally by the client) ### Parameters #### API Credentials (for authenticated subscriptions) - **api_key** (string) - Required - Your Bitget API key. - **api_secret** (string) - Required - Your Bitget API secret. - **passphrase** (string) - Required - Your Bitget API passphrase. #### Subscription Requests - **channels** (list of SubscribeReq objects) - Required - A list of subscription requests, each specifying the channel type, topic, and instrument ID. - **on_message** (function) - Required - A callback function to process incoming messages. ### Request Example ```python from pybitget.stream import BitgetWsClient, SubscribeReq from pybitget.enums import * from pybitget import logger def on_message(message): logger.info(message) api_key = "your-api-key" api_secret = "your-secret-key" api_passphrase = "your-api-passphrase" # Authenticated subscribe client = BitgetWsClient(api_key=api_key, api_secret=api_secret, passphrase=api_passphrase, verbose=True) # Multi subscribe - Public Channels (Ticker and Candle) public_channels = [SubscribeReq("mc", "ticker", "BTCUSD"), SubscribeReq("SP", "candle1W", "BTCUSDT")] client.subscribe(public_channels, on_message) # Single subscribe - Order Channel - Private Channels private_channels = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] client.subscribe(private_channels, on_message) ``` ### Response #### Success Response Messages are received asynchronously via the `on_message` callback function. The structure of the message depends on the subscribed channel. #### Response Example ```json { "action": "subscribe", "data": { "channel": "mc|ticker|BTCUSD", "last": "30000.50", "bestBid": "30000.00", "bestAsk": "30001.00" } } ``` ### Error Handling Errors can be handled by passing an error listener function during client initialization using `.error_listener(handel_error)`. ``` -------------------------------- ### CopyTrade - Get Trader Profit Summary Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves a summary of profit for traders in the CopyTrade system. ```APIDOC ## GET /api/v1/copytrade/get-trader-profit-summary ### Description Retrieves a summary of profit for traders in the CopyTrade system. ### Method GET ### Endpoint /api/v1/copytrade/get-trader-profit-summary ``` -------------------------------- ### CopyTrade - Get Follower Open Orders Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves open orders placed by followers in the CopyTrade system. ```APIDOC ## GET /api/v1/copytrade/get-follower-open-orders ### Description Retrieves open orders placed by followers in the CopyTrade system. ### Method GET ### Endpoint /api/v1/copytrade/get-follower-open-orders ### Parameters #### Query Parameters - **symbol** (string) - Required - The trading symbol. - **productType** (string) - Required - The type of product. - **pageSize** (integer) - Optional - The number of records per page (default: 20). - **pageNo** (integer) - Optional - The page number (default: 1). ``` -------------------------------- ### Initialize Bitget Client Source: https://github.com/cuongitl/python-bitget/blob/master/docs/overview.md Initializes the Bitget client with API credentials. This client object is used to make authenticated calls to the Bitget API. ```python from bitget import Client api_key = "your-api-key" api_secret = "your-secret-key" api_passphrase = "your-api-passphrase" client = Client(api_key, api_secret, api_passphrase, use_server_time=False) ``` -------------------------------- ### CopyTrade - Get Trader Open Orders Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves open orders placed by a trader in the CopyTrade system. ```APIDOC ## GET /api/v1/copytrade/get-trader-open-order ### Description Retrieves open orders placed by a trader in the CopyTrade system. ### Method GET ### Endpoint /api/v1/copytrade/get-trader-open-order ### Parameters #### Query Parameters - **symbol** (string) - Required - The trading symbol. - **productType** (string) - Required - The type of product. - **pageSize** (integer) - Optional - The number of records per page (default: 20). - **pageNo** (integer) - Optional - The page number (default: 1). ``` -------------------------------- ### Subscribe to WebSocket Channels Source: https://context7.com/cuongitl/python-bitget/llms.txt Demonstrates how to subscribe to private account, order, and position channels using the Bitget WebSocket client. It requires defining the channel request objects and providing a callback function for updates. ```python account_channel = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ACCOUNT_CHANNEL, WS_CHANNEL_INSTID)] client.subscribe(account_channel, on_account_update) orders_channel = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] client.subscribe(orders_channel, on_order_update) positions_channel = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_POSITIONS_CHANNEL, WS_CHANNEL_INSTID)] client.subscribe(positions_channel, on_position_update) plan_channel = [SubscribeReq(WS_CHANNEL_INSTTYPE, WS_PRIVATE_PLAN_ORDERS_CHANNEL, WS_CHANNEL_INSTID)] client.subscribe(plan_channel, on_order_update) ``` -------------------------------- ### Unsubscribe from WebSocket Channels Source: https://context7.com/cuongitl/python-bitget/llms.txt Shows the process of initializing the Bitget WebSocket client and unsubscribing from active channels. This is useful for cleaning up resources when specific data streams are no longer needed. ```python from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error client = BitgetWsClient() \ .error_listener(handel_error) \ .build() channels = [SubscribeReq("mc", "ticker", "BTCUSD")] client.subscribe(channels, lambda msg: print(msg)) client.unsubscribe(channels) ``` -------------------------------- ### CopyTrade - Get Trader Profits Details Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves detailed profit information for traders, including pending profits. ```APIDOC ## GET /api/v1/copytrade/get-trader-wait-profit-detail ### Description Retrieves detailed profit information for traders, including pending profits. ### Method GET ### Endpoint /api/v1/copytrade/get-trader-wait-profit-detail ### Parameters #### Query Parameters - **pageSize** (integer) - Optional - The number of records per page (default: 20). - **pageNo** (integer) - Optional - The page number (default: 1). ``` -------------------------------- ### Get Futures Account Information Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieve futures account information and balances for a specified product type or a specific symbol. ```APIDOC ## Get Futures Account ### Description Retrieve futures account information and balances. ### Method GET ### Endpoint `/api/v1/mix/account/accounts` (for all accounts) `/api/v1/mix/account/account` (for a single account) ### Parameters #### Query Parameters (for `/api/v1/mix/account/accounts`) - **productType** (string) - Required - The product type (e.g., 'UMCBL'). #### Query Parameters (for `/api/v1/mix/account/account`) - **symbol** (string) - Required - The trading symbol (e.g., 'BTCUSDT_UMCBL'). - **marginCoin** (string) - Required - The margin coin (e.g., 'USDT'). ### Request Example (Get all accounts) ```python client.mix_get_accounts(productType='UMCBL') ``` ### Request Example (Get single account) ```python client.mix_get_account(symbol="BTCUSDT_UMCBL", marginCoin="USDT") ``` ### Response (Success) ```json { "code": "00000", "msg": "success", "data": [ { "marginCoin": "USDT", "locked": "0", "available": "1000", "equity": "1050", ... } ] } ``` ``` -------------------------------- ### Place Batch Orders - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Submits multiple spot orders simultaneously for the same symbol. Requires the symbol and a list of order details. Efficient for bulk order placement. ```python data = client.spot_place_batch_orders(self, symbol, orderList) ``` -------------------------------- ### Get Futures Funding Rates Source: https://context7.com/cuongitl/python-bitget/llms.txt Retrieves the current funding rate and the next scheduled funding time for a specific futures contract. ```python current_rate = client.mix_get_current_fund_rate(symbol="BTCUSDT_UMCBL") next_funding = client.mix_get_symbol_next_funding(symbol="BTCUSDT_UMCBL") ``` -------------------------------- ### Place Spot Order - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Submits a new spot trading order. Requires symbol, quantity, side (buy/sell), order type, and force parameter. Optional parameters include price and client order ID. ```python data = client.spot_place_order(self, symbol, quantity, side, orderType, force, price='', clientOrderId=None) ``` -------------------------------- ### Get Server Time - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Retrieves the current server time from the Bitget API. This is useful for timestamping requests or synchronizing with the exchange. ```python data = client.spot_get_server_time() ``` -------------------------------- ### CopyTrade - Get Trader History Profit Detail Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves detailed historical profit information for traders, filtered by settlement currency and date. ```APIDOC ## GET /api/v1/copytrade/get-trader-profit-date-detail ### Description Retrieves detailed historical profit information for traders. ### Method GET ### Endpoint /api/v1/copytrade/get-trader-profit-date-detail ### Parameters #### Query Parameters - **marginCoin** (string) - Required - The settlement currency. - **date** (string) - Required - The date for the profit details (format: YYYY-MM-DD). - **pageSize** (integer) - Optional - The number of records per page (default: 20). - **pageNo** (integer) - Optional - The page number (default: 1). ``` -------------------------------- ### Get Current Plan Orders - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Retrieves a list of all currently active (pending) plan orders. Supports filtering by symbol and pagination. ```python data = client.spot_get_plan_orders(self, symbol, pageSize=20, lastEndId='') ``` -------------------------------- ### CopyTrade - Get Traders History Orders Source: https://github.com/cuongitl/python-bitget/blob/master/docs/mix.md Retrieves the historical orders placed by traders in the CopyTrade system within a specified time range. ```APIDOC ## GET /api/v1/copytrade/get-trader-history-orders ### Description Retrieves historical orders placed by traders in the CopyTrade system. ### Method GET ### Endpoint /api/v1/copytrade/get-trader-history-orders ### Parameters #### Query Parameters - **startTime** (string) - Required - The start time for the query (Unix timestamp). - **endTime** (string) - Required - The end time for the query (Unix timestamp). - **pageSize** (integer) - Optional - The number of records per page (default: 20). - **pageNo** (integer) - Optional - The page number (default: 1). ``` -------------------------------- ### Get Deposit Address - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Retrieves the deposit address for a specific coin and blockchain. Essential for users to deposit funds into their Bitget account. ```python data = client.spot_get_depositAddress(self, coin, chain) ``` -------------------------------- ### POST /spot/trade/order Source: https://github.com/cuongitl/python-bitget/blob/master/docs/index.md Places a new order on the Bitget Spot market. ```APIDOC ## POST /spot/trade/order ### Description Creates a new buy or sell order for a specific trading pair. ### Method POST ### Endpoint /api/spot/v1/trade/orders ### Parameters #### Request Body - **symbol** (string) - Required - Trading pair (e.g., BTCUSDT) - **side** (string) - Required - Order side: buy or sell - **orderType** (string) - Required - Order type: limit or market - **price** (string) - Optional - Order price for limit orders - **size** (string) - Required - Order quantity ### Request Example { "symbol": "BTCUSDT", "side": "buy", "orderType": "limit", "price": "20000", "size": "0.1" } ### Response #### Success Response (200) - **orderId** (string) - Unique identifier for the created order. #### Response Example { "code": "0", "data": { "orderId": "123456789" } } ``` -------------------------------- ### Manage Sub-Account API Keys (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Facilitates the creation and management of API keys for sub-accounts. This includes creating new API keys with specified permissions, listing existing API keys for a sub-account, and modifying existing API key details like remarks and IP whitelists. Requires API credentials. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Create sub account API key api_key_data = client.broker_sub_create_api( subUid="123456789", passphrase="sub_passphrase", remark="Trading API", ip="", # IP whitelist (empty for all) perm="readonly" # readonly, trade ) print(api_key_data) # Get sub account API key list api_list = client.broker_get_sub_api_list(subUid="123456789") print(api_list) # Modify sub account API key modified = client.broker_sub_modify_api( subUid="123456789", apikey="sub_api_key", remark="Updated remark", ip="192.168.1.1", perm="trade" ) print(modified) ``` -------------------------------- ### Get All Tickers - Python Source: https://github.com/cuongitl/python-bitget/blob/master/docs/spot.md Fetches the latest ticker information for all trading symbols. This provides a quick overview of the market prices across all available pairs. ```python data = client.spot_get_tickers() ``` -------------------------------- ### Subscribe to Public WebSocket Channels (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Shows how to subscribe to various public market data channels via WebSocket, including tickers, candlesticks, order books, and trades. It utilizes the `BitgetWsClient` and `SubscribeReq` objects to specify the instrument type, channel, and instrument ID. Requires an initialized public WebSocket client. ```python from pybitget.stream import BitgetWsClient, SubscribeReq, handel_error from pybitget import logger def on_message(message): logger.info(f"Market data: {message}") # Create unauthenticated client client = BitgetWsClient() .error_listener(handel_error) .build() # Subscribe to ticker channel # SubscribeReq(instType, channel, instId) # instType: mc (coin futures), SP (spot), umcbl (USDT futures) ticker_channels = [ SubscribeReq("mc", "ticker", "BTCUSD"), SubscribeReq("SP", "ticker", "BTCUSDT") ] client.subscribe(ticker_channels, on_message) # Subscribe to candlestick channel candle_channels = [ SubscribeReq("mc", "candle1H", "BTCUSD"), SubscribeReq("SP", "candle1W", "BTCUSDT") ] client.subscribe(candle_channels, on_message) # Subscribe to order book channel books_channels = [SubscribeReq("mc", "books", "BTCUSD")] client.subscribe(books_channels, on_message) # Subscribe to trades channel trades_channels = [SubscribeReq("mc", "trade", "BTCUSD")] client.subscribe(trades_channels, on_message) ``` -------------------------------- ### Manage Broker Sub-Accounts (Python) Source: https://context7.com/cuongitl/python-bitget/llms.txt Enables the creation and management of sub-accounts for broker functionality. This includes retrieving broker information, creating new sub-accounts, listing existing sub-accounts, and fetching their spot and future assets. Requires API credentials. ```python from pybitget import Client client = Client(api_key, api_secret, passphrase=api_passphrase) # Get broker info broker_info = client.broker_get_info() print(broker_info) # Create sub account new_sub = client.broker_sub_create( subName="sub_account_001", remark="Trading sub account" ) print(new_sub) # Get sub account list sub_list = client.broker_get_sub_list(pageSize=10) print(sub_list) # Get sub account spot assets sub_assets = client.broker_get_sub_spot_assets(subUid="123456789") print(sub_assets) # Get sub account future assets sub_future_assets = client.broker_get_sub_future_assets( subUid="123456789", productType="UMCBL" ) print(sub_future_assets) ```