Bybit Guide

How to Create and Set Up a Bybit API Key

Intermediate
Bybit Guide
2023年6月14日

Trading APIs have been widely used for their versatility and flexibility for customization. The integration of a trading API is especially helpful for automation that enables traders to manage their portfolios, analyze market trends or implement sophisticated trading strategies. As the crypto market continues to evolve, more product upgrades and features are being integrated to meet the increased demand, including the rollout of Bybit APIs. 

In this guide, you’ll learn how to integrate Bybit API with other automated trading applications. 

Key Takeaways:

  • API and API keys work hand-in-hand, allowing the software applications to interact with one another. 

  • Bybit offers many APIs, ranging from WebSocket API and REST API to the historical market API. 

  • Users can benefit from these APIs by customizing their user interface and preferences and automating their strategies for copy trading to increase their trading speed and accuracy. 

What Is Bybit API?

Bybit API is a set of application programming interfaces (APIs) that allow developers to interact with the Bybit platform programmatically. Bybit is a best-in-class cryptocurrency derivatives exchange that provides trading options for various digital assets. With APIs, developers can access market data, manage orders, execute trades and subscribe to data streams. 

The API has multiple versions that cater to different products and features. For instance, the V3 API supports Spot Trading, USDC Perpetual and Options Contracts, while V2 API supports Inverse Perpetual and Futures Contracts. To maximize security, Bybit API uses HMAC encryption for authentication. Developers can use a range of tools and languages, including Python, Node.js and WebSocket to integrate with Bybit API.

Understanding API vs. API Keys 

API refers to a communication protocol using a different set of rules and languages, allowing software applications to interact with one another. For example, the web API uses HTTP protocols, allowing developers to access web-based resources via commonly used data formats such as JSON and XML

API keys, meanwhile, can appear in the form of public or private keys. They function as authentication keys or access tokens, using a string of unique characters that serve as a form of authentication when requesting access to the API function. These authentication keys are generated by the provider of the API primarily to track the usage of the API by different clients or applications. 

Bybit V3 vs. V5 API: The Differences

Bybit V3 API is the previous version of Bybit's API. It supports linear and inverse contracts for both regular and unified accounts. On the other hand, Bybit V5 API is the latest version, upgraded to support Spot, Derivatives and Options Contracts for Bybit Unified Accounts.

Here are some of the differences between V3 and V5 API:

  • Bybit V3 API covers only specific trading products, with other products having their own set of APIs. In contrast, V5 API combines the APIs of various trading products into one, allowing users to trade Spot, Derivatives and Options contracts through a single API.

  • Unlike V3, the Bybit V5 API allows users to upgrade their accounts to a Unified Trading Account, enabling fund sharing and cross-utilization across different contract types.

  • V5 API supports borrowing across a Unified Trading Account mode, using multiple assets as collateral to obtain margin for trading across different products.

  • V5 API also enables combined margins between USDT Perpetual, USDC Perpetual, USDC Futures and Options contracts for Unified Trading Accounts.

The Bybit V5 API is built upon V3 API, making it easy for users to upgrade simply by adjusting the URL and interface fields.

Learn more: Bybit API documentation (API docs)

How to Create an API Key on Bybit

To use Bybit with third-party applications, you must first create an API key on the Bybit platform. But before you do, it's essential to understand the IP rate limit.

Understanding the IP Rate Limit

The IP rate limit regulates network traffic, based on the IP addresses of incoming requests, and prevents users from repeating actions too frequently within a specific time frame. Bybit has different rate limits for different requests, such as public data, private data and order placement. 

If you exceed the rate limit for a certain request type, you'll receive an error code, and your request will be rejected. To avoid this, you must monitor your request frequency and adjust accordingly. Additionally, consider using WebSocket API instead of REST API for some requests, since WebSocket requests aren’t counted against the rate limit.

Step-By-Step Instructions for Connecting Your API

To use Bybit's API with an application or platform, first, create an API key on Bybit and then connect it to your desired platform. Proceed with the following steps:

  1. Log in to your Bybit account or Sign Up for a Bybit account.

  2. Click on your account icon at the top right corner of the screen, and select API from the drop-down menu.

  3. Navigate to the API Management tab and click on Create New Key.

  4. Select either System-generated API Keys or Self-generated API Keys.

  5. Select Connect to Third-Party Applications, select the third-party application from the drop-down menu, and name the API key.

  6. Set the permissions for the API key (e.g., account information, order placement, position information) and click on Submit.

  7. Copy the API key and secret, and save them somewhere safe.

  8. Log in to the third-party application and link the saved API. 

How to Connect 3Commas API on Bybit

If you want to use the 3Commas crypto trading platform with Bybit, first, connect it using an API key. Here are the steps to follow:

  1. Log in to your Bybit account or Sign Up for a Bybit account.

  2. Click on your account icon in the top right corner of the screen, and select API from the drop-down menu.

  3. Navigate to the API Management tab and click on Create New Key.

  4. Choose System-generated API Keys.

  5. Change to Connect to Third-Party Applications, and choose 3Commas from the application name drop-down.

  6. Select the permissions for the API key: account information, order placement, position information, etc. (You may also select Read-Only if you only want to view your account data on 3Commas.)

  7. Click on Submit to generate the API key. You’ll see your API key and secret key on the screen. You can copy them to your clipboard or download them as a file.

  8. Log in to your 3Commas account or create a new one.

  9. Go to the My Exchanges page and click on Add Exchange.

  10. Select Bybit from the list of supported exchanges, and enter your API key and secret key that you generated on Bybit. You also need to enter your customer ID, which you can find on Bybit's Change Password page.

  11. Click on Connect to link your Bybit account to 3Commas.

Once you’ve completed these steps, you can use 3Commas with Bybit and access various trading tools and features. If you need to update or delete your API key, you can do so from the API management page on Bybit, or the My Exchanges page on 3Commas.

How to Connect Insilico API on Bybit

Insilico is a trading platform for cryptocurrency that offers a range of tools and features, such as interactive charts, order books, trades, instruments, activity, orders, positions, settings, configuration, execution panels and side panels. 

Here’s how to link your Bybit account to Insilico:

  1. Log in to your Bybit account and click on the Account icon in the top right corner of the screen.

  2. Click on your Account icon in the top right corner of the screen, and select API from the drop-down menu.

  3. Navigate to the API Management tab and click on Create New Key.

  4. Choose System-generated API Keys.

  5. Change to Connect to Third-Party Applications and select Insilico Terminal from the drop-down menu. This ensures that the key is locked to Insilico's server IP range.

  6. Select permissions for the API key: Account information, order placement and position information. You can also choose Read-Only to view account data only on Insilico.

  7. Click on Submit to generate the API key. You'll see both the key and secret key on the screen. If you wish, you may also copy or download them as a file.

  8. Log in to your Insilico account (or create a new one).

  9. Go to the Settings page and click on Add Exchange.

  10. Choose Bybit from the list of supported exchanges, and enter the API and secret keys generated on Bybit. You also need to enter your customer ID, which you can find on Bybit's Change Password page.

  11. Click on Connect to link your Bybit account to Insilico.

Can I Use the Bybit Testing Environment for API Testing?

Yes. You may use the Bybit testing environment for API testing as long as you want, but the data and transactions aren’t real and may not reflect actual market conditions. The Bybit testing environment, also known as the testnet, is a virtual trading platform that allows you to test your API strategies and codes without risking actual funds. It provides access to Bybit's API services, such as REST API, WebSocket API and historical market data.

Types of Bybit APIs

Bybit API has three types of interfaces. 

REST API 

REST API is an interface that lets you send requests and receive responses using HTTP methods, such as GET, POST, PUT and DELETE. You can use REST API to perform various actions on Bybit's platform: Querying market data, placing orders, modifying orders and checking positions. REST API is ideal for low-frequency and high-latency requests.

WebSocket API

This interface allows you to establish a persistent connection with Bybit's server, and to receive real-time updates using the WebSocket protocol. You can use WebSocket API, equipped with the WebSocket data, to subscribe to various markets and private data topics, such as order book, K-line, trades, funding rate, order status and position status. WebSocket API is best suited to high-frequency and low-latency requests.

Explore: Subscribe to the WebSocket API.

Historical Market Data

You may download historical public market data in CSV format and use this data to backtest your strategies and analyze market trends. Historical market data includes order book snapshots, K-line data, trade data and funding rate data.

Learn more: Download the Bybit Market Data API here.

How Can You Benefit From Bybit API?

Bybit API is a powerful tool that can help improve your trading experience and performance. Here are some of the ways in which you can benefit:

  • Automate your trading strategies with speed and accuracy. Bybit API allows you to create and run trading bots that can place, modify and cancel orders, and manage positions based on your predefined logic and parameters. The API also lets you integrate with third-party trading tools and features.

  • Access real-time and historical market data. Subscribe to various market data topics, and receive real-time updates using WebSocket API. You may also download historical public market data in CSV format to analyze market trends, identify trading opportunities and backtest your strategies.

  • Customize your user interface and preferences. Create your own user interface and dashboard to display information and functions tailored to your needs. You can adjust your settings and configurations, such as margin mode, leverage level and risk limit.

Is Bybit API Free?

The Bybit API is free to use for Bybit users, without any additional fees or charges. However, regular trading and funding fees still apply to your transactions on the platform.

The Bottom Line

Bybit API gives developers useful tools and interfaces so they can interact with the Bybit platform through code. These tools allow you to automate trading strategies, access real-time market data and customize your user interface. 

Follow the above steps to set up an API key on Bybit and connect it to third-party apps like 3Commas or Insilico. It's important to note the differences between Bybit V3 and V5 API versions and to stay within the IP rate limits for seamless trading.