I had notices some errors which i dont know how to handle/fix
Binance if you fetch order which doesnt exist:
Notice: Use of undefined constant key - assumed 'key' in /home/httpd/trade/ccxt/php/Exchange.php on line 2390
Fatal error: Class '\ccxt\OrderNotFound' not found in /home/httpd/trade/ccxt/php/binance.php on line 1341
Poloniex if you fethc executed order or order which doesnt exist:
Notice: Use of undefined constant key - assumed 'key' in /home/httpd/trade/ccxt/php/Exchange.php on line 2390
Fatal error: Class 'ccxt\OrderNotCached' not found in /home/httpd/trade/ccxt/php/poloniex.php on line 864
@Showgofar thx for reporting! I've uploaded a fix for it, let me know if you have any further difficulties with it after upgrading to version 1.18.1166 in 15 minutes.
ok now its only this error left
Class 'ccxt\OrderNotFound' not found in /home/httpd/trade/ccxt/php/binance.php on line 1341
Class 'ccxt\OrderNotCached' not found in /home/httpd/trade/ccxt/php/poloniex.php on line 864
@Showgofar this one I cannot reproduce for some reason... what's your version of PHP ?
mbp:ccxt igorkroitor$ php -f examples/php/cli.php poloniex fetchOrder 123
poloniex->fetchOrder (123)
ccxt\OrderNotCached: poloniex order $id 123 is not in "open" state and not found in cache
mbp:ccxt igorkroitor$ php -f examples/php/cli.php binance fetchOrder 123 ETH/BTC
binance->fetchOrder (123, ETH/BTC)
ccxt\OrderNotFound: binance {"code":-2013,"msg":"Order does not exist."}
mbp:ccxt igorkroitor$ php -v
PHP 7.3.2 (cli) (built: Feb 5 2019 22:21:47) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.2, Copyright (c) 1999-2018, by Zend Technologies
mbp:ccxt igorkroitor$
PHP Version 5.5.33
and also
if you try nonexistent pair for example BNB on poloniex
Fatal error: Class 'ccxt\BadSymbol' not found in /home/httpd/trade/ccxt/php/Exchange.php on line 2326
@Showgofar Does this happen with PHP 7.2? Unfortunately, PHP 5.5 is too old, and we need at least PHP > 7.
@Showgofar how do you include/require it in your project btw?
require 'ccxt/ccxt.php';
@Showgofar can you try it with a newer version of PHP?
PHP 7.2
Fatal error: Uncaught Error: Class 'ccxt\OrderNotFound' not found in /home/httpd/trade/ccxt/php/binance.php:1341 Stack trace:
#0 /home/httpd/trade/ccxt/php/Exchange.php(1348): ccxt\binance->handle_errors(400, '', 'https://api.bin...', 'GET', Array, '{"code":-2013,"...', Array, Array, NULL)
#1 /home/httpd/trade/ccxt/php/Exchange.php(1155): ccxt\Exchange->fetch('https://api.bin...', 'GET', Array, NULL)
#2 /home/httpd/trade/ccxt/php/binance.php(1354): ccxt\Exchange->fetch2('order', 'private', 'GET', Array, NULL, NULL)
#3 [internal function]: ccxt\binance->request('order', 'private', 'GET', Array)
#4 /home/httpd/trade/ccxt/php/Exchange.php(2350): call_user_func_array(Array, Array)
#5 /home/httpd/trade/ccxt/php/binance.php(789): ccxt\Exchange->__call('privateGetOrder', Array)
#6 /home/httpd/trade/markets.php(432): ccxt\binance->fetch_order('111', 'ZRX/BTC')
#7 {main} thrown in /home/httpd/trade/ccxt/php/binance.php on line 1341
btw
same script same order but diffrent PHP versions
5.5
"symbol": "ZRX\/BTC",
"type": "limit",
"side": "sell",
"price": 0.00019979,
"amount": 10,
"cost": -1.0e-8,
7.2
"symbol": "ZRX\/BTC",
"type": "limit",
"side": "sell",
"price": 0.00019979000000000000990089954466810695521417073905467987060546875,
"amount": 10,
"cost": -1.0000000000000000209225608301284726753266340892878361046314239501953125e-8,
@Showgofar does the same error (class not found) happen with composer as well?
mkdir test-project && cd test-project
composer init
composer require ccxt
include_once 'vendor/autoload.php'
// ccxt code
?
On the numbers – i'm trying to reproduce that on my side now, but they seem to be parsed properly:
...
...
[cost] => 0
[average] =>
[filled] => 0
[remaining] => 1.147
[status] => canceled
[fee] =>
[trades] =>
)
[499] => Array
(
[info] => Array
(
[symbol] => ETHBTC
[orderId] => 441770949
[orderListId] => -1
[clientOrderId] => web_f3abd565819c47a1bac9a4d5ba24aa8d
[price] => 0.02216900
[origQty] => 1.13600000
[executedQty] => 1.13600000
[cummulativeQuoteQty] => 0.02518398
[status] => FILLED
[timeInForce] => GTC
[type] => LIMIT
[side] => BUY
[stopPrice] => 0.00000000
[icebergQty] => 0.00000000
[time] => 1564175222051
[updateTime] => 1564176027721
[isWorking] => 1
)
[id] => 441770949
[timestamp] => 1564175222051
[datetime] => 2019-07-26T21:07:02.051Z
[lastTradeTimestamp] =>
[symbol] => ETH/BTC
[type] => limit
[side] => buy
[price] => 0.022169
[amount] => 1.136
[cost] => 0.02518398
[average] => 0.022168996478873
[filled] => 1.136
[remaining] => 0
[status] => closed
[fee] =>
[trades] =>
)
)
mbp:ccxt igorkroitor$ php -f examples/php/cli.php binance fetchOrders ETH/BTC
Need your verbose output in order to resolve this thing with numbers.
@Showgofar if you dive into the ccxt
folder, and run
php -f examples/php/cli.php binance fetchOrder 111 ETH/BTC
you should see a regular ccxt\AuthenticationError
, that would indicate that those errors work from within the CCXT folder. Likewise, if you do
php -f examples/php/cli.php binance market FOO/BAR
you should see a ccxt\ExchangeError
(no such market).
If that is not the case, and you still see a _"class not found exception"_ then this may be some kind of issue with the SPL autoloading on this particular setup.
[apache@ ~]$ cd /trade/ccxt
[apache@ ccxt]$ php72 -f examples/php/cli.php binance market FOO/BAR
./keys.json
PHP Fatal error: Uncaught Error: Class 'ccxt\ExchangeError' not found in /home/httpd/trade/ccxt/php/Exchange.php:2353
Stack trace:
thrown in /home/httpd/trade/ccxt/php/Exchange.php on line 2353
Fatal error: Uncaught Error: Class 'ccxt\ExchangeError' not found in /home/httpd/trade/ccxt/php/Exchange.php:2353
Stack trace:
thrown in /home/httpd/trade/ccxt/php/Exchange.php on line 2353
[apache@ ccxt]$
and php 5.5
[apache@ ccxt]$ php -f examples/php/cli.php binance fetchOrder 111 ETH/BTC
./keys.json
PHP Fatal error: Class 'ccxt\ExchangeError' not found in /home/httpd/trade/ccxt/php/Exchange.php on line 2353
[apache@ ccxt]$
i had found problem.... sorry about that
file ccxt/ccxt.php wasnt updated
@Showgofar ok, glad to know you've figured it out! Thx for reporting back! Closing this for now, if you don't mind, feel free to reopen it, or just ask further questions if any.
Also i have find out that bcmath is required but not listed in requirements
And still cant find out problem with numbers on php 7.2
Also i have find out that bcmath is required but not listed in requirements
Make sure you have all files up to date:
And still cant find out problem with numbers on php 7.2
Does this fail with PHP 7.2 on your setup:
php -f php/test/decimal_to_precision.php
?
If it succeeds, there should be no output. If it fails, it should print out an error.
output is empty for both versions
@Showgofar can you post a short (but complete) snippet of code to reproduce it? 5-20 lines, including exchange instantiation (without your keys, of course).
....
if (httpRequest('fetch_orders'))
{
$response = $ccxt[$market]->fetchOpenOrders($symbol);
$timings->setTiming($markets[$market]['mrkt_title'] . ': fetch orders');
}
....
if (!empty($response))
{
$result = json_encode($response, JSON_PRETTY_PRINT);
}
....
Response:
[
{
"info": {
"id": "3748235158444328",
"createdAt": 1558779662000,
"account_type": 0,
"pair": "BIX_BTC",
"coin_symbol": "BIX",
"currency_symbol": "BTC",
"order_side": 2,
"order_type": 2,
"price": "0.00009922",
"deal_price": "0.00000000",
"amount": "100.0000",
"money": "0.00992200",
"deal_amount": "0.0000",
"deal_percent": "0.00%",
"deal_money": "0.00000000",
"status": 1,
"unexecuted": "100.0000",
"order_from": 6
},
"id": "3748235158444328",
"timestamp": 1558779662000,
"datetime": "2019-05-25T10:21:02.000Z",
"lastTradeTimestamp": null,
"symbol": "BIX\/BTC",
"type": "limit",
"side": "sell",
"price": 9.9220000000000002095788820266619723042822442948818206787109375e-5,
"amount": 100,
"cost": 0,
"average": 0,
"filled": 0,
"remaining": 100,
"status": "open",
"fee": null
},
@Showgofar will check on my side and will get back to you.
do u have any news about that? is there any specific function which make round?
@Showgofar we think we found what's causing it, and I hope to fix this as soon as I can. Pardon for the delays again, need some more time for testing to make sure we don't break anything else.
ok
thank you
@Showgofar plz check out the most recent version, we've added some edits to that section, let us know if you still have the same issue with it.
{
"info": {
"a": 53233175,
"p": "0.00225350",
"q": "12.74000000",
"f": 63301353,
"l": 63301353,
"T": 1571758101020,
"m": false,
"M": true
},
"timestamp": 1571758101020,
"datetime": "2019-10-22T15:28:21.020Z",
"symbol": "BNB\/BTC",
"id": "53233175",
"order": null,
"type": null,
"takerOrMaker": null,
"side": "buy",
"price": 0.0022534999999999998608612994388522565714083611965179443359375,
"amount": 12.7400000000000002131628207280300557613372802734375,
"cost": 0.028709590000000000109547926285813446156680583953857421875,
"fee": null
},
@Showgofar this is now a different method, fetchTrades
and parseTrade
in particular, we will add the logic to handle prices to precision in trades as well.
also at latest version on PHP 5.5
Parse error: syntax error, unexpected '.' in /home/httpd/trade/ccxt/php/base/Exchange.php on line 2764
at php 7 its OK
seems it wasnt solved
{
"info": {
"a": 56913718,
"p": "0.00190560",
"q": "0.93000000",
"f": 68050785,
"l": 68050785,
"T": 1579075611753,
"m": false,
"M": true
},
"timestamp": 1579075611753,
"datetime": "2020-01-15T08:06:51.753Z",
"symbol": "BNB\/BTC",
"id": "56913718",
"order": null,
"type": null,
"takerOrMaker": null,
"side": "buy",
"price": 0.0019055999999999999154620677899174552294425666332244873046875,
"amount": 0.93000000000000004884981308350688777863979339599609375,
"cost": 0.001772207999999999943063766494333322043530642986297607421875,
"fee": null
},
@Showgofar i will look into it again and will get back to you shortly, thx!
any news?)
@Showgofar tbh, i didn't have the time to work on this issue yet. It would really help a lot and we could get it resolved quicker, if you could paste a minimal reproducible snippet of PHP code here, including instantiation code, but without your keys, as described in these guidelines:
Make sure that your version of CCXT is up to date.
hi) But I already post the code
if (httpRequest('fetch_orders'))
{
$response = $ccxt[$market]->fetchOpenOrders($symbol);
$timings->setTiming($markets[$market]['mrkt_title'] . ': fetch orders');
}
....
if (!empty($response))
{
$result = json_encode($response, JSON_PRETTY_PRINT);
}
....
Its pretty simple and it works fine at php 5.6
and here is result
{
"info": {
"symbol": "BNBBTC",
"orderId": 34183457,
"orderListId": -1,
"clientOrderId": "LC3lvPttPmkuToBbOzcY4Y",
"price": "0.00145040",
"origQty": "2.00000000",
"executedQty": "2.00000000",
"cummulativeQuoteQty": "0.00289400",
"status": "FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"stopPrice": "0.00000000",
"icebergQty": "0.00000000",
"time": 1522053303388,
"updateTime": 1522053303388,
"isWorking": true,
"origQuoteOrderQty": "0.00000000"
},
"id": "34183457",
"timestamp": 1522053303388,
"datetime": "2018-03-26T08:35:03.388Z",
"lastTradeTimestamp": null,
"symbol": "BNB\/BTC",
"type": "limit",
"side": "buy",
"price": 0.00145039999999999990980270592189071976463310420513153076171875,
"amount": 2,
"cost": 0.002893999999999999871158617992250583483837544918060302734375,
"average": 0.0014469999999999999355793089961252917419187724590301513671875,
"filled": 2,
"remaining": 0,
"status": "closed",
"fee": null,
"trades": null
},
@Showgofar that snippet does not include your exchange instantiation code unfortunately, can you paste it as well (without the keys, but with all the other params)?
@Showgofar in particular, do you have the parseOrderToPrecision
option enabled? (it is a binance-specific option atm)
It doesnt matter what exchange
Here is poloniex fetch trades
I dont use parseOrderToPrecision
Response:
[
{
"id": "441984536",
"info": {
"globalTradeID": 441984536,
"tradeID": 1971815,
"date": "2020-01-29 13:18:02",
"type": "sell",
"rate": "0.00002453",
"amount": "49.87500000",
"total": "0.00122343",
"orderNumber": 83184245679
},
"timestamp": 1580321882000,
"datetime": "2020-01-29T18:18:02.000Z",
"symbol": "ZRX\/BTC",
"order": "83184245679",
"type": "limit",
"side": "sell",
"takerOrMaker": null,
"price": 2.453000000000000061580081311962686640981701202690601348876953125e-5,
"amount": 49.875,
"cost": 0.00122342999999999996023347659246383045683614909648895263671875,
"fee": null
},
And the same response at PHP 5.6
Response:
[
{
"id": "441984536",
"info": {
"globalTradeID": 441984536,
"tradeID": 1971815,
"date": "2020-01-29 13:18:02",
"type": "sell",
"rate": "0.00002453",
"amount": "49.87500000",
"total": "0.00122343",
"orderNumber": 83184245679
},
"timestamp": 1580321882000,
"datetime": "2020-01-29T18:18:02.000Z",
"symbol": "ZRX\/BTC",
"order": "83184245679",
"type": "limit",
"side": "sell",
"takerOrMaker": null,
"price": 2.453e-5,
"amount": 49.875,
"cost": 0.00122343,
"fee": null
},
It doesnt matter what exchange
It does, since this is not supported for all exchanges. In general float formatting to desired precision is something the user can do on the user side, therefore we don't include it into the lib (not everyone wants it at a cost of performance). However, we have a specific option for Binance that does that formatting, yet the user has to enable it, it will not format floats by default.
I dont use parseOrderToPrecision
It will not format floats without that option. It will only work with Binance (which is the exchange mentioned in the beginning of the issue), but it will not work with Poloniex.
The option can be enabled like so:
$exchange = new \ccxt\binance(array(
'enableRateLimit' => true,
'apiKey' => 'YOUR_API_KEY',
'secret' => 'YOUR_SECRET',
'options' => array(
'parseOrderToPrecision' => true, // ←----------- HERE (inside "options")
),
));
Let me know if that does not answer the question.
@Showgofar exchange-specific options are explained here:
\It will not format floats without that option.
But thats works fine at older PHP version
Ok according your logic i had updated
'parseOrderToPrecision' => true, // force amounts and costs in parseOrder to precision
at binance.php
but nothing changed
Response:
[
{
"info": {
"a": 11991821,
"p": "0.00002414",
"q": "22.00000000",
"f": 13810446,
"l": 13810446,
"T": 1580371903269,
"m": false,
"M": true
},
"timestamp": 1580371903269,
"datetime": "2020-01-30T08:11:43.269Z",
"symbol": "ZRX\/BTC",
"id": "11991821",
"order": null,
"type": null,
"takerOrMaker": null,
"side": "buy",
"price": 2.413999999999999926760842205997192877475754357874393463134765625e-5,
"amount": 22,
"cost": 0.00053107999999999996355859455121617429540492594242095947265625,
"fee": null
},
Ok according your logic i had updated
'parseOrderToPrecision' => true, // force amounts and costs in parseOrder to precision
at binance.php
You should not really do that. Instead, you should override the exchange option upon instantiation:
$exchange = new \ccxt\binance(array(
'enableRateLimit' => true,
'apiKey' => 'YOUR_API_KEY',
'secret' => 'YOUR_SECRET',
'options' => array(
'parseOrderToPrecision' => true, // ←----------- HERE (inside "options")
),
));
$orders = $exchange->fetch_open_orders('ZRX/BTC');
var_dump($orders);
↑ Does this work if you edit it for your keys with minimal other edits? If it does work – does var_dump
output those numbers in price
, amount
and cost
inside orders to precision with this snippet?
@Showgofar also, you seem to be confusing orders with trades... The output pasted here is definitely not from binance.php's fetchOpenOrders
: https://github.com/ccxt/ccxt/issues/5836#issuecomment-580250504
It's from fetchTrades
or fetchMyTrades
which is a whole different story – you can't change methods and exchanges in question on the fly – since we have to be very specific ))) The rules for different methods are different, obviously.
Most of my comments above refer to binance's orders only. The difference between orders and trades is explained here:
Fetch open orders php 7
Response:
[
{
"info": {
"symbol": "ZRXBTC",
"orderId": 26730892,
"orderListId": -1,
"clientOrderId": "21SnU2qeQtLfQGjPSeFy3K",
"price": "0.00019979",
"origQty": "10.00000000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "-0.00000001",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"icebergQty": "0.00000000",
"time": 1527662925930,
"updateTime": 1527662925930,
"isWorking": true,
"origQuoteOrderQty": "0.00000000"
},
"id": "26730892",
"timestamp": 1527662925930,
"datetime": "2018-05-30T06:48:45.930Z",
"lastTradeTimestamp": null,
"symbol": "ZRX\/BTC",
"type": "limit",
"side": "sell",
"price": 0.00019979000000000000990089954466810695521417073905467987060546875,
"amount": 10,
"cost": -1.0000000000000000209225608301284726753266340892878361046314239501953125e-8,
"average": null,
"filled": 0,
"remaining": 10,
"status": "open",
"fee": null,
"trades": null
},
PHP 5
Response:
[
{
"info": {
"symbol": "ZRXBTC",
"orderId": 26730892,
"orderListId": -1,
"clientOrderId": "21SnU2qeQtLfQGjPSeFy3K",
"price": "0.00019979",
"origQty": "10.00000000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "-0.00000001",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"icebergQty": "0.00000000",
"time": 1527662925930,
"updateTime": 1527662925930,
"isWorking": true,
"origQuoteOrderQty": "0.00000000"
},
"id": "26730892",
"timestamp": 1527662925930,
"datetime": "2018-05-30T06:48:45.930Z",
"lastTradeTimestamp": null,
"symbol": "ZRX\/BTC",
"type": "limit",
"side": "sell",
"price": 0.00019979,
"amount": 10,
"cost": -1.0e-8,
"average": null,
"filled": 0,
"remaining": 10,
"status": "open",
"fee": null,
"trades": null
},
and it doesnt matter if its fetching orders or trades and what exchange is used
@Showgofar do you have the parseOrderToPrecision
enabled in PHP7? It will not format those values without it. With it the values will be formatted for Binance orders, but not trades nor the other exchanges.
I had changed 'parseOrderToPrecision' => true, at binance.php at php 7 so it should return correct values but it dont ))
also i had added option
'parseOrderToPrecision' => true, to params
I had changed 'parseOrderToPrecision' => true, at binance.php at php 7 so it should return correct values but it dont ))
Can you plz paste your code with that option enabled? (The instantiation code including all the constructor config params, but without your keys)
also i had added option
'parseOrderToPrecision' => true, to params
You shouldn't do that - won't work that way. You should only do that via exchange options.