Bybit docs https://bybit-exchange.github.io/docs/linear/
All interface methods are initialized the same as those provided by Bybit. See details src/api
Exchanges It includes all of the following exchanges and is highly recommended.
If you don't find the exchange SDK you want, you can tell me and I'll join them.
composer require linwj/bybit
Support V5 More
$bybit=new BybitV5($key,$secret);
//You can set special needs
$bybit->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,
'headers'=>[
//X-Referer or Referer - 經紀商用戶專用的頭參數
//X-BAPI-RECV-WINDOW 默認值為5000
//cdn-request-id
'X-BAPI-RECV-WINDOW'=>'6000',
]
]);
try {
$result=$bybit->order()->postCreate([
'category'=>'spot',
'symbol'=>'BTCUSDT',
'side'=>'buy',
'orderType'=>'limit',
'qty'=>'1',
'price'=>'1000',
//'orderLinkId'=>'xxxxxxxxxxx',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->order()->getRealTime([
'category'=>'spot',
'symbol'=>'BTCUSDT',
'orderId'=>'xxxxxxxxxx',
//'orderLinkId'=>'xxxxxxxxxxx',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->order()->getSpotBorrowCheck([
'category'=>'spot',
'symbol'=>'BTCUSDT',
'side'=>'by'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
V1 Fails Support for more request Settings
$bybit=new BybitLinear();
//or new
//$bybit=new BybitInverse();
//You can set special needs
$bybit->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,
//If you are developing locally and need an agent, you can set this
//'proxy'=>true,
//More flexible Settings
/* 'proxy'=>[
'http' => 'http://127.0.0.1:12333',
'https' => 'http://127.0.0.1:12333',
'no' => ['.cn']
], */
//Close the certificate
//'verify'=>false,
]);
Market Data API More
$bybit=new BybitLinear();
try {
$result=$bybit->publics()->getOrderBookL2([
'symbol'=>'BTCUSDT'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->publics()->getKline([
'symbol'=>'BTCUSDT',
'interval'=>'15',
'from'=>time()-3600,
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->publics()->getTickers();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->publics()->getRecentTradingRecords([
'symbol'=>'BTCUSDT',
'limit'=>'5',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->publics()->getSymbols();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
Place Active Order API More
$bybit=new BybitLinear($key,$secret);
try {
$result=$bybit->privates()->postOrderCreate([
//'order_link_id'=>'xxxxxxxxxxxxxx',
'side'=>'Buy',
'symbol'=>'BTCUSDT',
'order_type'=>'Limit',
'qty'=>'1',
'price'=>'4000',
'time_in_force'=>'GoodTillCancel',
'reduce_only'=>'false',
'close_on_trigger'=>'false',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getOrderSearch([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSDT',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postOrderReplace([
'order_id'=>'xxxxxxxxxxxxx',
'symbol'=>'BTCUSDT',
'p_r_qty'=>'2',
'p_r_price'=>'4999'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postOrderCancel([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSDT',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getOrderList([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSDT',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
Place Conditional Order API More
$bybit=new BybitLinear($key,$secret);
try {
$result=$bybit->privates()->postStopOrderCreate([
//'order_link_id'=>'xxxxxxxxxxxxxx',
'side'=>'Buy',
'symbol'=>'BTCUSDT',
'order_type'=>'Limit',
'qty'=>'1',
'price'=>'4000',
'time_in_force'=>'GoodTillCancel',
'reduce_only'=>'false',
'close_on_trigger'=>'false',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getStopOrderSearch([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSDT',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postStopOrderReplace([
'order_id'=>'xxxxxxxxxxxxx',
'symbol'=>'BTCUSDT',
'p_r_qty'=>'2',
'p_r_price'=>'4999'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postStopOrderCancel([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSDT',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getStopOrderList([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSDT',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
My Position API More
$bybit=new BybitLinear($key,$secret);
try {
$result=$bybit->privates()->getPositionList([
'symbol'=>'BTCUSDT',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postChangePositionMargin([
'symbol'=>'BTCUSDT',
'margin'=>'1'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postPositionTradingStop([
'symbol'=>'BTCUSDT',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getUserLeverage();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postUserLeverageSave([
'symbol'=>'BTCUSDT',
'leverage'=>'1'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getExecutionList([
'symbol'=>'BTCUSDT',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
Market data API More
$bybit=new BybitInverse();
try {
$result=$bybit->publics()->getOrderBookL2([
'symbol'=>'BTCUSD'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->publics()->getKlineList([
'symbol'=>'BTCUSD',
'interval'=>'15',
'from'=>time()-3600,
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->publics()->getTickers();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->publics()->getTradingRecords([
'symbol'=>'BTCUSD',
'limit'=>'5',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->publics()->getSymbols();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
Place Active Order API More
$bybit=new BybitInverse($key,$secret);
try {
$result=$bybit->privates()->postOrderCreate([
//'order_link_id'=>'xxxxxxxxxxxxxx',
'side'=>'Buy',
'symbol'=>'BTCUSD',
'order_type'=>'Limit',
'qty'=>'1',
'price'=>'4000',
'time_in_force'=>'GoodTillCancel',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getOrder([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postOrderReplace([
'order_id'=>'xxxxxxxxxxxxx',
'symbol'=>'BTCUSD',
'p_r_qty'=>'2',
'p_r_price'=>'4999'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postOrderCancel([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getOrderList([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
Place Conditional Order API More
$bybit=new BybitInverse($key,$secret);
try {
$result=$bybit->privates()->postStopOrderCreate([
//'order_link_id'=>'xxxxxxxxxxxxxx',
'side'=>'Buy',
'symbol'=>'BTCUSD',
'order_type'=>'Limit',
'qty'=>'1',
'price'=>'4000',
'time_in_force'=>'GoodTillCancel',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getStopOrder([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postStopOrderReplace([
'order_id'=>'xxxxxxxxxxxxx',
'symbol'=>'BTCUSD',
'p_r_qty'=>'2',
'p_r_price'=>'4999'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postStopOrderCancel([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getStopOrderList([
'order_id'=>'xxxxxxxxxxxxx',
//'order_link_id'=>'xxxxxxxxxxxxxx',
'symbol'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
My Position Api More
$bybit=new BybitInverse($key,$secret);
try {
$result=$bybit->privates()->getPositionList([
'symbol'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postChangePositionMargin([
'symbol'=>'BTCUSD',
'margin'=>'1'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postPositionTradingStop([
'symbol'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getUserLeverage();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->postUserLeverageSave([
'symbol'=>'BTCUSD',
'leverage'=>'1'
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
try {
$result=$bybit->privates()->getExecutionList([
'symbol'=>'BTCUSD',
]);
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}