Package: pybitcs
pybitOfficial Python3 API connector for Bybit's HTTP and WebSockets APIs.Table of ContentsAboutDevelopmentInstallationBasic UsageMarket Data EndpointsAdvanced DataAccount Data EndpointsActive OrdersConditional OrdersPositionMarket Maker ProtectionRisk LimitFundingAPI Key InfoLCP InfoWallet Data EndpointsAPI Data EndpointsAccount Asset EndpointsWebSocketFuturesPublic TopicsPrivate TopicsSpotPublic Topics V1Public Topics V2Private TopicsContactContributorsDonationsAboutPut simply,pybit(Python + Bybit) is the official lightweight one-stop-shop module for the Bybit HTTP and WebSocket APIs. Originally created byVerata Veritatis, it's now maintained by Bybit employees - however, you're still welcome to contribute!It was designed with the following vision in mind:I was personally never a fan of auto-generated connectors that used a mosh-pit of various modules you didn't want (sorry,bravado) and wanted to build my own Python3-dedicated connector with very little external resources. The goal of the connector is to provide traders and developers with an easy-to-use high-performing module that has an active issue and discussion board leading to consistent improvements.Developmentpybitis being actively developed, and new Bybit API changes should arrive onpybitvery quickly.pybitusesrequestsandwebsocket-clientfor its methods, alongside other built-in modules. Anyone is welcome to branch/fork the repository and add their own upgrades. If you think you've made substantial improvements to the module, submit a pull request and we'll gladly take a look.Installationpybitrequires Python 3.6.1 or higher. The module can be installed manually or viaPyPIwithpip:pip install pybitBasic UsageYou can retrieve a specific market like so:frompybitimportinverse_perpetualCreate an HTTP session and connect via WebSocket for Inverse on mainnet:session=inverse_perpetual.HTTP(endpoint='https://api.bybit.com',api_key='...',api_secret='...')ws=inverse_perpetual.WebSocket(test=False,api_key="...",api_secret="...")Information can be sent to, or retrieved from, the Bybit APIs:# Get orderbook.session.orderbook(symbol='BTCUSD')# Create five long orders.orders=[{"symbol":"BTCUSD","order_type":"Limit","side":"Buy","qty":100,"price":i,"time_in_force":"GoodTillCancel"}foriin[5000,5500,6000,6500,7000]]# Submit the orders in bulk.session.place_active_order_bulk(orders)# Check on your order and position through WebSocket.defhandle_orderbook(message):print(message)defhandle_position(message):print(message)ws.orderbook_25_stream(handle_orderbook,"BTCUSD")ws.position_stream(handle_position)whileTrue:# Run your main trading strategy herepass# To avoid CPU utilisation, use time.sleep(1)Check out the example python files or the list of endpoints below for more information on available
endpoints and methods. Usage examples on theHTTPmethods can
be found at:https://github.com/bybit-exchange/pybit/blob/master/examples/http_example.pyUsage examples on theWebSocketmethods can be found at:https://github.com/bybit-exchange/pybit/blob/master/examples/websocket_example.pyMarket Data EndpointsEndpointMethodOrderbookorderbook()Query Klinequery_kline()Latest Information for Symbollatest_information_for_symbol()Public Trading Recordspublic_trading_records()Query Symbolquery_symbol()Liquidated Ordersliquidated_orders()Query Mark Price Klinequery_mark_price_kline()Open Interestopen_interest()Delivery Price (USDC)delivery_price()Last 500 Trades (USDC)last_500_trades()Advanced DataEndpointMethodQuery Klinequery_kline()Latest Big Deallatest_big_deal()Long Short Ratiolong_short_ratio()Account Data EndpointsActive OrdersEndpointMethodPlace Active Orderplace_active_order()Get Active Orderget_active_order()Cancel Active Ordercancel_active_order()Cancel All Active Orderscancel_all_active_orders()Replace Active Orderreplace_active_order()Query Active Orderquery_active_order()Batch Place Active Orders (USDC)batch_place_active_orders()Fast Cancel Active Order (Spot)fast_cancel_active_order()Batch Cancel Active Order (Spot, USDC)batch_cancel_active_order()Batch Fast Cancel Active Order (Spot)batch_fast_cancel_active_order()Batch Cancel Active Order By IDs (Spot)batch_cancel_active_order_by_ids()Batch Replace Active Orders (USDC)batch_replace_active_orders()Conditional OrdersEndpointMethodPlace Conditional Orderplace_conditional_order()Get Conditional Orderget_conditional_order()Cancel Conditional Ordercancel_conditional_order()Cancel All Conditional Orderscancel_all_conditional_orders()Replace Conditional Orderreplace_conditional_order()Query Conditional Orderquery_conditional_order()PositionEndpointMethodMy Positionmy_position()Set Auto Add Margin (Linear)set_auto_add_margin()Cross/Isolated Margin Switch (Linear)cross_isolated_margin_switch()Full/Partial Position SL/TP Switchfull_partial_position_tp_sl_switchAdd/Reduce Margin (Linear)add_reduce_margin()Set Trading-Stopset_trading_stop()Set Leverageset_leverage()User Leverage (deprecated)user_leverage()User Trade Recordsuser_trade_records()Closed Profit and Lossclosed_profit_and_loss()Query Trading Fee Ratequery_trading_fee_rate()Query Delivery History (USDC)query_delivery_history()Query Position Expiration Date (USDC)query_position_expiration_date()Market Maker ProtectionOnly available for the USDC API.EndpointMethodQuery MMPquery_mmp()Modify MMPmodify_mmp()Reset MMPreset_mmp()Risk LimitEndpointMethodGet Risk Limitmy_position()Set Risk Limit (Inverse)set_auto_add_margin()FundingEndpointMethodGet the Last Funding Rateget_the_last_funding_rate()My Last Funding Feemy_last_funding_fee()Predicted Funding Rate and My Funding Feepredicted_funding_rate()API Key InfoEndpointMethodAPI Key Infoapi_key_info()LCP InfoEndpointMethodLCP Infolcp_info()Wallet Data EndpointsEndpointMethodGet Wallet Balanceget_wallet_balance()Wallet Fund Recordswallet_fund_records()Withdraw Recordswithdraw_records()Asset Exchange Recordsasset_exchange_records()Get Asset Info (USDC)get_asset_info()Get Margin Mode (USDC)get_margin_mode()API Data EndpointsEndpointMethodServer Timeserver_time()Announcementannouncement()Account Asset EndpointsEndpointMethodCreate Internal Transfercreate_internal_transfer()Create Subaccount Transfercreate_subaccount_transfer()Query Transfer Listquery_transfer_list()Query Subaccount Transfer Listquery_subaccount_transfer_list()Query Subaccount Listquery_subaccount_list()Query Supported Deposit Listquery_supported_deposit_list()Query Deposit Recordsquery_deposit_records()Query Withdraw Recordsquery_withdraw_records()Query Coin Infoquery_coin_info()Query Asset Infoquery_asset_info()Withdrawwithdraw()Cancel Withdrawalcancel_withdrawal()Query Deposit Addressquery_deposit_address()pybit Custom EndpointsEndpointMethodPlace Active Order (Bulk)place_active_order_bulk()Cancel Active Order (Bulk)cancel_active_order_bulk()Place Conditional Order (Bulk)place_conditional_order_bulk()Cancel Conditional Order (Bulk)cancel_conditional_order_bulk()Close Positionclose_position()WebSocketTo see comprehensive examples of how to subscribe to the futures and spot websockets, check theexamples file.ContactYou can reach out for support on theBybitAPI Telegramgroup chat.ContributorsThanks goes to these wonderful people (emoji key):verata-veritatis💻📖APF20💻Cameron Harder-Hutton💻Tom Rumpf💻Todd Conley🤔This project follows theall-contributorsspecification. Contributions of any kind welcome!