### Installing ByBit PHP SDK via Composer Source: https://github.com/goodmagma/bybit-php-api/blob/develop/README.md This command demonstrates how to add the ByBit PHP SDK library to your project using the Composer dependency manager. ```Shell composer require goodmagma/bybit-php-api ``` -------------------------------- ### Creating Public ByBit API Client in PHP Source: https://github.com/goodmagma/bybit-php-api/blob/develop/README.md This snippet shows how to instantiate the ByBitApi class to interact with public ByBit API endpoints. It includes examples for both the default production environment and specifying a sandbox environment URL. ```PHP include '../vendor/autoload.php'; use ByBit\SDK\ByBitApi; //create public API on real environment $bybitApi = new ByBitApi(); //create public API on sandbox environment $bybitApi = new ByBitApi('', '', ByBitApi::PROD_API_URL); ``` -------------------------------- ### Getting Position Info using ByBit PHP SDK Source: https://github.com/goodmagma/bybit-php-api/blob/develop/README.md This example illustrates how to use the instantiated ByBit API client to call a specific method, `positionApi()->getPositionInfo`, with required parameters to retrieve position details for a given symbol and category. ```PHP // Get Position Info $params = ["category" => "linear", "symbol" => "BTCUSDT"]; $positions = $bybitApi->positionApi()->getPositionInfo($params); var_dump($positions); ``` -------------------------------- ### Migrating ByBitApi Initialization (PHP) Source: https://github.com/goodmagma/bybit-php-api/blob/develop/CHANGELOG.md This snippet provides an example of how to adapt existing code using the old boolean sandbox parameter to the new constructor which requires a host URL string. It uses a ternary operator to select the appropriate host URL based on the original sandbox flag. ```php $bybitApi = new ByBitApi($key, $secret, $sandbox ? ByBitApi::TESTNET_API_URL : ByBitApi::PROD_API_URL); ``` -------------------------------- ### Initializing ByBitApi - New Constructor (PHP) Source: https://github.com/goodmagma/bybit-php-api/blob/develop/CHANGELOG.md This snippet demonstrates the current method (from version 0.7.0 onwards) for initializing the ByBitApi class. The boolean sandbox parameter is replaced by a string parameter specifying the API host URL, allowing support for different environments like testnet, demo, and production. ```php $bybitApi = new ByBitApi($api_key, $api_secret, $host); ``` -------------------------------- ### Initializing ByBitApi - Old Constructor (PHP) Source: https://github.com/goodmagma/bybit-php-api/blob/develop/CHANGELOG.md This snippet shows the deprecated way to initialize the ByBitApi class prior to version 0.7.0. It required the API key, API secret, and a boolean flag indicating if the sandbox environment should be used. ```php $bybitApi = new ByBitApi($api_key, $api_secret, $sandbox); ``` -------------------------------- ### Creating Private ByBit API Client in PHP Source: https://github.com/goodmagma/bybit-php-api/blob/develop/README.md This code demonstrates how to create an instance of the ByBitApi class for accessing private API endpoints. It requires providing your API key, secret key, and the desired host URL (testnet, demo, or production). ```PHP include '../vendor/autoload.php'; use ByBit\SDK\ByBitApi; //Your API Key $api_key = 'XXXXXXXXXX'; //Your Secret Key $api_secret = 'XXXXXXXXXX'; //Your Host //$host = ByBit\SDK\ByBitApi::TESTNET_API_URL; //$host = ByBit\SDK\ByBitApi::DEMO_API_URL; $host = ByBit\SDK\ByBitApi::PROD_API_URL; //create private API $bybitApi = new ByBitApi($api_key, $api_secret, $host); ``` -------------------------------- ### Making Custom API Requests with ByBit PHP SDK Source: https://github.com/goodmagma/bybit-php-api/blob/develop/README.md This snippet demonstrates how to use the `customApi()->request()` method to interact with ByBit API endpoints that may not have dedicated methods in the SDK. It requires specifying the HTTP method, the endpoint URI, and any necessary parameters. ```PHP // Get Transferable Amount (Unified) $params = ['coinName' => $coin]; $uri = 'v5/account/withdrawal'; $method = \ByBit\SDK\ApiRequest::METHOD_GET; $transferableAmount = $bybitApi->customApi()->request($method, $uri, $params); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.