zhouaini528 / bybit-php Goto Github PK
View Code? Open in Web Editor NEWBybit API Like the official document interface, Support for arbitrary extension.
License: MIT License
Bybit API Like the official document interface, Support for arbitrary extension.
License: MIT License
您好,不好意思,请问能提供postman吗,或者能麻烦您教学如何在您的project里call api吗?麻烦您了,非常感谢
<?php
/**
* @author lin <[email protected]>
* */
use \Lin\Bybit\BybitSpot;
require __DIR__ .'../../../vendor/autoload.php';
include __DIR__ .'../../../vendor/key_secret.php';
$bybit=new BybitSpot($key,$secret);
//You can set special needs
$bybit->setOptions([
//Set the request timeout to 60 seconds by default
'timeout'=>10,
]);
try {
$result=$bybit->privates()->getAccount();
print_r($result);
}catch (\Exception $e){
print_r($e->getMessage());
}
I get error {"_message":"Client error: GET https:\/\/api.bybit.com\/spot\/v1\/account?
resulted in a 429 Too Many Requests
response","_httpcode":429}
An "error sign" error when there is a cursor in data.
It works correctly if you remove urldecode.
Hello
I'm using $bybit->privates()->postOrderCreate with necessary parameters
[body] => {"0":{"side":"Sell","symbol":"ETHUSDT","qty":0.2,"price":1261.15},"api_key":"...","timestamp":16730...,"sign":"..."}
but getting the answer:
[ret_msg] => body not json
Help plese
Thank you
Can you implement this in the current code?
https://bybit-exchange.github.io/docs/inverse/#t-websocket
I am working with your API and things generally seem to work well. GET requests I had no problem with (getPositionList, getTradingRecords, getWalletBalance, etc.). However, postOrderCreate always returns this:
"ret_code" => 10004 "ret_msg" => "error sign! origin_string[api_key=xxxxxxxxxxxxxx&order_type=Market&qty=1&reduce_only=true&side=Sell&symbol=BTCUSD&time_in_force=GoodTillCancel×tamp=1609525189785]" "ext_code" => "" "ext_info" => "" "result" => null "time_now" => "1609525190.137879"
At first I thought that it might be a problem with POST requests, but postOrderCancel() passes the sign check (it returns an error because I'm supplying an invalid order-id but the signature check passes OK) ...
For the postOrderCreate request which fails, the params passed to your API are:
"side" => "Sell" "symbol" => "BTCUSD" "order_type" => "Market" "qty" => 1 "reduce_only" => true "time_in_force" => "GoodTillCancel"
and the full request which is sent to bybit is this:
"body" => "{"api_key":"xxxxxxxxxxxxxx","order_type":"Market","qty":1,"reduce_only":true,"side":"Sell","symbol":"BTCUSD","time_in_force":"GoodTillCancel","timestamp":1609525189785,"sign":"7c12c29a413c401e8c8bdf9a740c40d3974e699c07c22bd05b8eee1d2d7d5878"}
As the signature is constructed in Request.php in a generic manner, I'm not sure what could be causing this. Can you offer any suggestions?
Hey looks like this function does not exist anymore or it has different name and parameters now?
Hi i kept getting this error. Synching my comp time didn't help or helped for short time.
To solve this problem i've modified \vendor\linwj\bybit\src\RequestV5.php
There you will find function called nonce()
It need to be changed to this:
protected function nonce() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://api.bybit.com/v5/market/time');
$output = curl_exec($ch);
curl_close($ch);
$data = json_decode($output, true);
$this->nonce=$data['time'];
}
Now i always have server time in my request, so this error never appeared ever again.
P.S. hope this will be fixed in further updates.
How to connect private proxies like ip:port@login:pass ?
Your script is great and I use it quite a lot in my PHP applications!
I was wondering if it is possible to return the API Rate limits, which are documented here:
https://bybit-exchange.github.io/docs/copy-trade/rate-limit
Thank you!
The Inverse Perpetual replace order url is wrong..
it must change from "/open-api/order/replace" to "/v2/private/order/replace"
I have fixed it on my side.
I apologize for a silly question, but how do I set up a test host (https://api-testnet.bybit.com
) for a client? From the code samples it is not quite clear.
Hi, I'm trying to connect to testnet api but it doesn't work. Also I've tried to setOptions testnet => true, but no success
$bybit = new BybitLinear($user_api->api_key,$user_api->api_secret,'https://api.bybit.com'); $bybit->setOptions( ['testnet' => true] );
Do you have any suggestion ?
Thanks
when you pass a real boolean value into an endpoint which expects one, the resulting signature is incorrect and generates an "error sign!" result from the ByBit API
example:
$bybit->privates()->postPositionSwitchIsolated([
'symbol' => $symbol,
'is_isolated' => false,
'buy_leverage' => $leverage,
'sell_leverage' => $leverage
]);
however, if you pass the boolean value as a string instead, everything works correctly:
$bybit->privates()->postPositionSwitchIsolated([
'symbol' => $symbol,
'is_isolated' => 'false',
'buy_leverage' => $leverage,
'sell_leverage' => $leverage
]);
I think this should be either documented somewhere or fixed, as it took me a while to realize what's going on and why my valid requests come back with an invalid signature error.
Hello i currently cloned the repo and ran composer require linwj/bybit
in my VPS when i go to run the test to see even public data endpoints i get errors. This is how i load in my URL
myurl.com/bybit-php/tests/inverse/publics.php
`
Route::get('/bybit', function () {
$key = env('BYBIT_KEY');
$secret = env('BYBIT_SECRET');
$bybit = new \Lin\Bybit\BybitLinear($key, $secret);
// dd($bybit);
try {
$result = $bybit->privates()->getPositionList([
'symbol' => 'BTCUSDT',
]);
// $result = $bybit->privates()->postOrderCreate([
// //'order_link_id'=>'xxxxxxxxxxxxxx',
// 'side' => 'Buy',
// 'symbol' => 'BTCUSDT',
// 'order_type' => 'Limit',
// 'qty' => '1',
// 'price' => '49000',
// 'time_in_force' => 'GoodTillCancel',
// 'reduce_only' => 'false',
// 'close_on_trigger' => 'false',
// ]);
dump($result);
} catch (\Exception $e) {
dd($e->getMessage());
}
});
`
why am i getting rate limited, is there something wrong with what im doing?
try {
$result=$bybit->privates()->postOrderCreate([
//'order_link_id'=>'xxxxxxxxxxxxxx',
'side'=>'Buy',
'symbol'=>'DOGEUSDT',
'order_type'=>'Market',
'qty'=>'250',
'time_in_force'=>'GoodTillCancel',
'reduce_only'=>false,
'close_on_trigger'=>false,
'position_idx'=>0
]);
}catch (\Exception $e){
print_r($e->getMessage());
}
Error I get
[ret_code] => 10004
[ret_msg] => error sign!
without position idx it works but only in hedge-mode, one way needs position idx 0
I am trying to fetch the BTCUSD data but it returns the following:
(
[ret_code] => 10001
[ret_msg] => Param validation for 'symbol' failed on the 'linear_symbol' tag
[ext_code] =>
[ext_info] =>
[result] =>
[time_now] => 1612508984.802319
[token] =>
)
The code I am using is:
$bybit = new BybitLinear();
$pair = 'BTCUSD';
$interbal_in_action = '1d';
$result = $bybit->publics()->getKline( [
'symbol' => $pair,
'interval' => $interval_in_action,
'limit' => 10,
'from' => $from,
] );
print_r($result);
Update
It seems that BybitAPI Does support for BTCUSD but in Inverse but your API does not support it
https://bybit-exchange.github.io/docs/inverse/?php#t-querykline
Hi!
I'll try post order on Spot, my code:
$key = 'xxxx';
$secret = 'xxxx';
$bybit = new \Lin\Bybit\BybitSpot($key, $secret);
$result=$bybit->privates()->postOrder([
'side'=>'Buy',
'symbol'=>'BTCUSDT',
'type'=>'MARKET',
'qty'=>0.1,
]);
print_r($result);
But i get error
Array ( [ret_code] => -1001 [ret_msg] => Internal error. [ext_code] => [ext_info] => [result] => )
could you tell me please what the mistake is?
Thanks :)
Seems like the method for the Instrument Info is missing.
https://bybit-exchange.github.io/docs/inverse/#t-websocketinstrumentinfo
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.