-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
This guide provides a quick overview of how to start using the bybit-php library. We will cover making your first API call in both a standalone PHP project and a Laravel application.
In a non-Laravel project, you can use the library by instantiating the BybitClient directly.
<?php
require_once __DIR__ .
use Tigusigalpa\ByBit\BybitClient;
$apiKey =
$apiSecret =
$client = new BybitClient(
apiKey: $apiKey,
apiSecret: $apiSecret,
testnet: true
);
// Get the server time
$serverTime = $client->getServerTime();
// Get the tickers for the BTC-USDT linear contract
$tickers = $client->getTickers([
]);In a Laravel application, you can use the Bybit facade or dependency injection for a more convenient and testable approach.
The facade provides a simple, static-like interface to the BybitClient.
use Tigusigalpa\ByBit\Facades\Bybit;
// Get the server time
$time = Bybit::getServerTime();
// Get the tickers for the BTC-USDT linear contract
$tickers = Bybit::getTickers([
]);For better code organization and testability, you can inject the BybitClient into your controllers or services.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Tigusigalpa\ByBit\BybitClient;
class TradingController extends Controller
{
private BybitClient $bybit;
public function __construct(BybitClient $bybit)
{
$this->bybit = $bybit;
}
public function getTickers()
{
$tickers = $this->bybit->getTickers([
]);
return response()->json($tickers);
}
}Now that you have made your first API call, you are ready to explore the full capabilities of the library. Dive into the API Methods for a complete overview of all available methods.