GithubHelp home page GithubHelp logo

jaggedsoft / php-binance-api Goto Github PK

View Code? Open in Web Editor NEW
607.0 33.0 500.0 8.7 MB

PHP Binance API is an asynchronous PHP library for the Binance API designed to be easy to use. https://github.com/binance-exchange/php-binance-api

License: MIT License

PHP 100.00%
binance cryptocurrency-exchanges cryptocurrency php

php-binance-api's People

Contributors

afsharsafavi avatar ahmeti avatar alipjxhub avatar areebmajeed avatar artturik avatar bright-light-in-the-night avatar cfremgen avatar chikashi-kato avatar crazyboy49z avatar dmzoneill avatar dxjones avatar epascalc avatar hotsaucejake avatar jaggedsoft avatar jay04653 avatar johandev1 avatar jokaorgua avatar lanort avatar lucasnogueiracorp avatar mrsantran avatar mtb-pro avatar munvier avatar nilsenpaul avatar omar8792 avatar osteel avatar robsantini avatar sajadsholi avatar sohaibilyas avatar tinyhazeleyes avatar vovizzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-binance-api's Issues

error in buying and selling

Hello,
I use codes that you share. I do most of my work with this library.

The php-binance-api.php library is in its original state

I'm experimenting with trial.php

`$symbol = "XVGBTC";
$quantity = 1;
$price = 0.00001114;
$price = number_format($price,8,'.','');

$order = $api->buy($symbol, $quantity, $price);
print_r($order);`

the error message is as follows.
Array ( [code] => -1013 [msg] => Filter failure: MIN_NOTIONAL )

I am waiting for your help on how to solve this problem

Fatal error with method Binance::depositAddress()

Hi,
I'm getting an error when trying to use the depositAddress method

$depositAddress = $api->depositAddress("VEN");
print_r($depositAddress);

This is the error:

Fatal error: Uncaught Error: Call to undefined method Binance::depositAddress()
Stack trace:
#0 {main}

LOT_SIZE Error

Array
(
[code] => -1013
[msg] => Filter failure: LOT_SIZE
)

Error in placing Market Order
$order = $api->buy($pair, $quantity, 0, "MARKET");

PHP Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in ***/binance/vendor/jaggedsoft/php-binance-api/php-binance-api.php on line 132

Hello,

I tried to put a market buy with that code in a php file :

'<?php
require 'vendor/autoload.php';
$api = new Binance\API("","");

$quantity = 0.001;
$order = $api->marketBuy("BTCUSDT", $quantity);
?>'

And I get this code error :

PHP Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /binance/vendor/jaggedsoft/php-binance-api/php-binance-api.php on line 132
PHP Warning: file_get_contents(): Failed to enable crypto in /binance/vendor/jaggedsoft/php-binance-api/php-binance-api.php on line 132
PHP Warning: file_get_contents(https://api.binance.com/api/v3/order?symbol=BTCUSDT&side=BUY&type=MARKET&quantity=0.001&recvWindow=60000&timestamp=1516474442097&signature=
**): failed to open stream: operation failed in ****/binance/vendor/jaggedsoft/php-binance-api/php-binance-api.php on line 132

Do you have an idea to fix it ?
Thanks

Buy and Sell functions dont work

Hi!

When i try to buy or sell some ticker i've get an error:
Array
(
[code] => -1101
[msg] => Too many parameters; expected '6' and received '7'.
)

syntax error, did I do something wrong?

PHP Parse error: syntax error, unexpected '[' in /home/ec2-user/php-binance-api/examples/binance-api-single.php on line 18

The code is as following.

        public function cancel($symbol, $orderid) {
                return $this->signedRequest("v3/order",["symbol"=>$symbol, "orderId"=>$orderid], "DELETE");

LOT_SIZE of pair?

Hi, thanks for a great code.

I am having trouble with LOT_SIZE, which is "minimum" rounded amount I need to send as request to Binance. Actually LOT is different for each pair (for most of them it is rounded to 2 decimal numbers), can I somehow pull the list of available LOT numbers?

I did not however managed to find the whole lot size list, the best it would be to pull it directly from binance servers

https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#lot_size

Any way I can pull the data? Thanks a lot.

LOT_SIZE error can't resolve..:(

I am new to binance API, placing a buy order but can't resolve the error of LOT_SIZE
My values are within limits of minQty and MIN_notional
Below are my values for example,
//Asset = CDTBTC

`0.00000001 Min Price
100000.00000000 Max Price
1.00000000 Min Quantity
90000000.00000000 MaxQty
1.00000000 Step Size
0.00200000 MiNotional

Quantity of CDTBTC to be traded: 2.98786828`

$api->buy($symbol, $quantity, $price)

missing endpoint: POST api/v3/order/test

This implementation is missing the "order/test" endpoint.

It would be helpful to implement this as public functions:
$api->buy_test()
$api->sell_test()
which could call a new private function order_test(), ... similar to order(), but with the different endpoint.

getting ServerTime option when using aJax to call api

I have the api and key save in database. when I click on the button save..
it run the ajax and connect to api and connect data, but it throw back this error and I have already set the time option:

$api = new Binance\API($api, $apiSecret, ['useServerTime' => true]);

Error:
balanceData error: Please make sure your system time is synchronized, or pass the useServerTime option.

HTTP/1.1 400 Bad Request

I got an error when try to place order.

         $api = new API($apiKey,$apiSecret);
         $quantity = 1;
         $price = 0.0005;
         $order = $api->buy("BNBBTC", $quantity, $price);
PHP Warning – yii\base\ErrorException
file_get_contents(https://api.binance.com/api/v3/order?symbol=BNBBTC
&amp;side=BUY&amp;type=LIMIT&amp;quantity=1&amp;recvWindow=60000
&amp;price=0.0005&amp;timeInForce=GTC
&amp;timestamp=1513645254232
&amp;signature=*******): 
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

Sell Limit doesn't work

Code:

require 'vendor/autoload.php';
$api = new Binance\API("XJapikeyWZ","ysecretZ");
$quantity = 20;
$price = 0.00105;
$order = $api->sell("XRPETH", $quantity, $price);

It returns:
signedRequest error: {"code":-1021,"msg":"Timestamp for this request was 1000ms ahead of the server's time."}

What should I do?

balances not returning

Hi,
balances not returning. Notice: Undefined index: balances in C:\wamp\www\btc\php-binance-api.php on line 178

'Name' parameter is required for withdrawals

Hello,

It seems that the name parameter, showed non mandatory on api doc, is in fact mandatory for withdrawals. When I try one I get the following error message : Name is empty.

For those who are trying to do withdrawals and having the same issue, replace the public function withdraw in php-binance-api.php line 65 with that one :

public function withdraw($asset, $address, $amount, $addressTag = false, $name) {           
$options = ["asset"=>$asset, "address"=>$address, "amount"=>$amount, "name"=>$name, "wapi"=>true];
                if ( $addressTag ) $options['addressTag'] = $addressTag;
                return $this->signedRequest("v3/withdraw.html", $options, "POST");
        }

And to initiate the withdrawal, just add the name parameter like this :

$asset = "BTC";
$address = "1C5gqLRs96Xq4V2ZZAR1347yUCpHie7sa";
$amount = 0.2;
$name = "whatever";
$response = $api->withdraw($asset, $address, $amount, $name);
print_r($response);

It save the destination address in your withdrawal dashboard with a name...

Bye !

Autoload not working in Lumen

Hi,

I am tried to install your package in lumen, but somehow the class not autoloaded. I have check its autoloaded fine if I use simple php + composer though.

Manditory timeInForce missing on STOP_LOSS_LIMIT order

Hi,

I get the following error

signedRequest error: {"code":-1102,"msg":"Mandatory parameter 'timeInForce' was not sent, was empty/null, or malformed."}

When I try and do a stop loss order.

$order = $api->sell($pair, $newleftbalance, $stop, "STOP_LOSS_LIMIT", ["stopPrice"=>$stopprice]);

Any suggestions?

Thanks Steve

Websocket

I can't get any of the websocket functions to work?

even the ones in the example page don't work for me. Can you give me any guidance?

POST operations fail because parameters passed in URL but not in content

Most Binance API endpoints use the GET method. These work correctly, with parameters passed as a query appended to the URL.

However, these Binance API endpoints require the POST method:
/api/v3/order
/api/v3/order/test

The current implementation of $api->signedRequest fails to pass the parameters as POST data and therefore Binance.com rejects the API request.

$opt = [ "http" => [
"method" => $method,
...
"content" => $query // <-- this line needs to be added
] ];

The following example illustrates how query parameters should be passed as http "content" in the stream_context passed to file_get_contents().

https://stackoverflow.com/questions/2445276/how-to-post-data-in-php-using-file-get-contents

[HELP] Am I doing this right?

$CryptoCoins = array();

$api->ticker(false, function($api, $symbol, $ticker) use($CryptoCoins) {

echo '<pre>';
$CryptoSymbol = $ticker['symbol'];

if ( array_key_exists($CryptoSymbol, $CryptoCoins) )  {
  // Update Price
    //$newtest[$ticker['symbol']] = array('percentChange' => $ticker['percentChange']);
    echo 'exist';
} else {
    $CryptoCoins[$CryptoSymbol] = array('percentChange' => $ticker['percentChange'] );
    echo 'ADD: ' . $CryptoSymbol;
}
print_r($CryptoCoins);

echo '';
});

HTTP request failed! HTTP/1.1 400 Bad Request

Today this problem started.

       $api = new Binance\API("xxx", "yyy");

	$quantity = 1;

	$price = 0.0006;

	$api->sell("ARKBTC", $quantity, $price);`

Gives the below error code:

Message: 'file_get_contents(https://api.binance.com/api/v3/order?symbol=ARKBTC&side=SELL&type=LIMIT&quantity=1&recvWindow=60000&price=0,0006&timeInForce=GTC&timestamp=1516659076390&signature=283e234a746f283e47fd6c283ca82734628734d6283746a2f8d374f627a8346e272c3): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request '

What format is openTime

I am trying to figure out what format is returned for $api->prevDay with openTime and closeTime.. It doesn't appear to be epoch...

Low prices are giving error. + FIX

small numers like 0.000098 will be formatted like this: &price=9.82E-5
Raising the following error: Illegal characters found in parameter 'price'; legal range is '^([0-9]{1,20})(.[0-9]{1,20})?$'.

Fix:
file: php-binance-api.php
line: 129 add following code:
if(isset($params['price']))
{
$params['price'] = number_format($params['price'], 8, '.', '');
}
Binance useses 8 precision for all its coins.

I am sorry, I am not that familiar with forking and updating the code. maybe the creator can add this? ;)
Cheers

bookprinces bids last 100

$bookPrices = $api->bookPrices();
echo "Bid price of ETH: {$bookprices['ETHBTC']['bid]}".PHP_EOL;
OK

as it would be for the list of the last 100?
echo "Bid price of ETH: {$bookprices['ETHBTC']['bids']['100']}".PHP_EOL;

Timestamps & useServerTime option

I am getting a lot of -1021 "Timestamp for this request was 1000ms ahead of the server's time." errors when performing a signed request. According to the API, it is possible to send a useServerTime parameter (it is mentioned in the PHP API as well: "balanceData error: Please make sure your system time is synchronized, or pass the useServerTime option."). With the PHP API it doesn't look like it is possible to use the useServerTime option tho?

Issues

Hi,

I am running your examples and I am getting the following errors when I make this call
$balances = $api->balances($ticker);

Among other errors.

PHP Notice: Undefined index: balances in /root/php-binance-api/php-binance-api.php on line 178
PHP Warning: Invalid argument supplied for foreach() in /root/php-binance-api/php-binance-api.php on line 178
PHP Notice: Undefined index: BTC in /root/php-binance-api/examples/example2.php on line 11
PHP Notice: Undefined index: ETH in /root/php-binance-api/examples/example2.php on line 12

balanceData error: Please make sure your system time is synchronized, or pass the useServerTime option.

Trying to use this in Symfony 4. Works perfectly through a controller and displaying results on a page. However if I try to use the balances in a command when running the cli command I get:

signedRequest error: {"code":-1022,"msg":"Signature for this request is not valid."}
balanceData error: Please make sure your system time is synchronized, or pass the useServerTime option.

Saw this ticket:
#35

I think I need to use useServerTime but it isn't implemented yet?

I echoed out the $endpoint from the call and it looks like (signature modified for obscurification):

https://api.binance.com/api/v3/account?timestamp=1516900612521&signature=df5a4338fa3421f8ff79afbdbe3df1cb8c87a288512c9e648f6260ee75114446

Missing test orders

There are any endpoints to create test orders with the api installed via composer.

I think it's very important to create a test order endpoint

Opentime gets corrupted

The putting the opentime as they array key does not work. The value gets corrupted when trying to read the associative array using foreach($res as $key => $val)

Suggestion to add opentime as a value on the object instead

Websocket trades() multi symbol

As I've seen in the code, the trades() method allows multiple symbols:

// Trades WebSocket Endpoint
public function trades($symbols, $callback) {
	foreach ( $symbols as $symbol ) {
            ...

But in the end it seems to be connected only to the stream of first symbol passed in the array and I'm not able to retrieve information about the other ones. My call:

$api->trades(['TRXETH', 'ADAETH'], function($api, $symbol, $trades) {...

What am I doing wrong?

invalid float parsing

I encountered this error with PHP:

Array
(
    [code] => -1100
    [msg] => Illegal characters found in parameter 'price'; legal range is '^([0-9]{1,20})(\.[0-9]{1,20})?$'.
)

I was using

$order = $api->sell($symbol."BTC", $spend, $price_desired, "LIMIT", $flags);

$price_desired was float.

This is what fixed it:

$order = $api->sell($symbol."BTC", $spend, number_format($price_desired,8,'.',''), "LIMIT", $flags);

its because PHP treats that float as: float(1.1E-5) instead of 0.00011

please fix this in order function

Fatal Error

I have the composer version now... but can't get this to work either.... :-(

I'm just trying with your examples

Fatal error: Uncaught Error: Class 'React\EventLoop\Factory' not found in C:\xampp\htdocs\BinanceComposer\examples\php-binance-api.php:536 Stack trace: #0 C:\xampp\htdocs\BinanceComposer\examples\example.php(89): Binance\API->trades(Array, Object(Closure)) #1 {main} thrown in C:\xampp\htdocs\BinanceComposer\examples\php-binance-api.php on line 536

WebSocket API returning error

Hi,
I'm getting an error when trying to use the WebSocket example:

$api->chart(["BNBBTC"], "15m", function($api, $symbol, $chart) {
echo "{$symbol} chart update\n";
print_r($chart);
});

Notice: Undefined variable: symbol in php-binance-api.php on line 619

Notice: Undefined variable: interval in php-binance-api.php on line 619
chart(,)) Could not connect: DNS query for stream.binance.com failed: too many retries

Setting a buy order

Hi

How do i set a buy order for once the coin reaches a certain amount.

Say bitcoin is at 8470 and i want to set it to buy if it reaches 8510?

Which one would i use?
STOP_LOSS (market)
STOP_LOSS_LIMIT
TAKE_PROFIT (market)
TAKE_PROFIT_LIMIT

Balance check: Misschien BTC values/totals

When checking my balance it seems the BTC value for every alt is missing, like this one but also for alts which have a total value of over 1 btc.

`$balances = $api->balances("BTC");
print_r($balances);

Result:
[XVG] => Array
(
[available] => 0.66500000
[onOrder] => 0.00000000
[btcValue] => 0
[btcTotal] => 0
)`

Very slow compared to Node.js lib

I don't know if this is a real issue or not, but I don't know where to put it. Is this lib (very) slow compared to the Node.js API lib located here https://github.com/jaggedsoft/node-binance-api

I am trying to do analysis where every part of a second counts. To make it clear, my questions is; is this library suitable for this? Or should I move to another solution? I don't know what makes it slow. Are the endpoints just slow or can I do something on my side to make if faster?

Feature request : Getting current withdrawal fees

Hello !

I would like to know if there is a way to get the withdrawal fees from the api ? Because if I want to make a withdrawal with a specific amount and I don't know what are the current withdrawal fees it will never be exactly as I asked...

Thank you !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.