PHP code example of carpenstar / bybitapi-sdk-core
1. Go to this page and download the library: Download carpenstar/bybitapi-sdk-core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
carpenstar / bybitapi-sdk-core example snippets
use Carpenstar\ByBitAPI\BybitAPI;
$sdk = new BybitAPI();
// Setting the host for the next call to the exchange API
$sdk->setHost('https://api-testnet.bybit.com');
// Setting an API key that will be applied the next time you access the exchange API (optional, since the parameter is ameters with one call
$sdk->setCredentials('https://api-testnet.bybit.com', 'apiKey', 'apiSecret')
// The function is used to access endpoints that do not
// The function is used to access endpoints that do not taining request parameters'>);
// The function is used to access endpoints that
use Carpenstar\ByBitAPI\BybitAPI;
use Carpenstar\ByBitAPI\Derivatives\MarketData\TickerInfo\Request\TickerInfoRequest;
use Carpenstar\ByBitAPI\Derivatives\MarketData\TickerInfo\TickerInfo;
// Here we set only the host, because we don’t need authorization
$sdk = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com');
// Prepare the endpoint for the request:
$endpoint = $sdk->publicEndpoint(TickerInfo::class, (new TickerInfoRequest())->setSymbol('BTCUSDT'));
// Start execution of the request:
$sdk->execute();
namespace Carpenstar\ByBitAPI\Core\Interfaces;
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
interface IResponseInterface
{
public function getReturnCode(): int; // Request completion code. If successful, it will always be 0
public function getReturnMessage(): string; // Return message, usually 'OK'
public function getExtendedInfo(): array; // Extended information
public function getResult(): AbstractResponse; // Endpoint-specific DTO object containing the response from the exchange API
}
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\TickerInfo\Interfaces;
interface ITickerInfoResponseInterface
{
/**
* @return ITickerInfoResponseItemInterface
*/
public function getTickerInfo(): ITickerInfoResponseItemInterface;
}
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\TickerInfo\Interfaces;
interface ITickerInfoResponseItemInterface
{
/**
* Symbol name
* @return string
*/
public function getSymbol(): string;
/**
* Best bid price
* @return float
*/
public function getBidPrice(): float;
/**
* Best ask price
* @return float
*/
public function getAskPrice(): float;
/**
* Last transaction price
* @return float
*/
public function getLastPrice(): float;
/**
* Direction of price change
* @return string
*/
public function getLastTickDirection(): string;
/**
* Price of 24 hours ago
* @return float
*/
public function getPrevPrice24h(): float;
/**
* Percentage change of market price relative to 24h
* @return float
*/
public function getPrice24hPcnt(): float;
/**
* The highest price in the last 24 hours
* @return float
*/
public function getHighPrice24h(): float;
/**
* Lowest price in the last 24 hours
* @return float
*/
public function getLowPrice24h(): float;
/**
* Hourly market price an hour ago
* @return float
*/
public function getPrevPrice1h(): float;
/**
* Mark price
* @return float
*/
public function getMarkPrice(): float;
/**
* Index price
* @return float
*/
public function getIndexPrice(): float;
/**
* Open interest
* @return float
*/
public function getOpenInterests(): float;
/**
* Turnover in the last 24 hours
* @return float
*/
public function getTurnover24h(): float;
/**
* Trading volume in the last 24 hours
* @return float
*/
public function getVolume24h(): float;
/**
* Funding rate
* @return float
*/
public function getFundingRate(): float;
/**
* Next timestamp for funding to settle
* @return \DateTime
*/
public function getNextFundingTime(): \DateTime;
/**
* Predicted delivery price. It has value when 30 min before delivery
* @return float
*/
public function getPredictedDeliveryPrice(): float;
/**
* Basis rate for futures
* @return float
*/
public function getBasisRate(): float;
/**
* Delivery fee rate
* @return float
*/
public function getDeliveryFeeRate(): float;
/**
* Delivery timestamp
* @return \DateTime
*/
public function getDeliveryTime(): \DateTime;
/**
* Open interest value
* @return float
*/
public function getOpenInterestValue(): float;
}