-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
Properly configuring the bybit-php library is essential for connecting to the Bybit API. This guide covers the configuration for both standalone PHP projects and Laravel applications.
For projects that do not use Laravel, you can instantiate the BybitClient class directly. The constructor accepts your API key, secret, and other configuration options.
use Tigusigalpa\ByBit\BybitClient;
$apiKey = 'your-api-key';
$apiSecret = 'your-api-secret';
$client = new BybitClient(
apiKey: $apiKey,
apiSecret: $apiSecret,
testnet: true // Use the testnet
);| Parameter | Type | Default | Description |
|---|---|---|---|
apiKey |
string |
Your Bybit API key. | |
apiSecret |
?string |
null |
Your Bybit API secret. |
testnet |
bool |
false |
Set to true to use the testnet environment. |
demoTrading |
bool |
false |
Set to true to use the demo trading environment. |
region |
string |
global |
The regional endpoint to use. |
recvWindow |
int |
5000 |
The request receive window in milliseconds. |
signature |
string |
hmac |
The signature method (hmac or rsa). |
rsaPrivateKey |
?string |
null |
Your RSA private key if using RSA signature. |
For Laravel applications, the recommended way to configure the library is by using environment variables.
If you haven't already, publish the configuration file:
php artisan vendor:publish --tag=bybit-configThis creates the config/bybit.php file, which reads the settings from your .env file.
Add your Bybit API credentials and other settings to your .env file:
BYBIT_API_KEY=your_api_key_here
BYBIT_API_SECRET=your_api_secret_here
BYBIT_TESTNET=true
BYBIT_REGION=global
BYBIT_SIGNATURE=hmacThe library will automatically use these settings when you use the Bybit facade or inject the client through the service container.
With the library configured, you are now ready to start making API calls. Proceed to the Quick Start guide for a hands-on example.