amandris / arbitrage-trading-bot

Bot to automate trading orders between Bitcoin exchanges to make some profit.
MIT License
42 stars 30 forks source link

Invalid datetime format #5

Closed sweepglass closed 5 years ago

sweepglass commented 5 years ago

Might be related to #4

`test1@test1-VirtualBox:~/arbitrage-trading-bot$ bin/console bot:trade 30/04/2019 02:59:24 bitstamp Ask:5,148.31 Bid:5,148.30 cexio Ask:5,264.50 Bid:5,257.70 30/04/2019 02:59:30 bitstamp Ask:5,148.31 Bid:5,148.30 cexio Ask:5,264.90 Bid:5,257.60 30/04/2019 02:59:36 bitstamp Ask:5,148.31 Bid:5,148.30 cexio Ask:5,264.90 Bid:5,259.50

In AbstractMySQLDriver.php line 106:

An exception occurred while executing 'INSERT INTO order_pair (buy_order_id, sell_order_id, buy_order_exchange, sell_order
_exchange, sell_order_open, buy_order_open, buy_order_amount_btc, sell_order_amount_btc, buy_order_amount_usd, sellorder
amount_usd, buy_order_price, sell_order_price, buy_order_created, sell_order_created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?
, ?, ?, ?, ?)' with params ["3202411249", "8756065699", "bitstamp", "cexio", 1, 1, 0.003, 0.003, 15.453930000000001, 15.76
95, 5151.31, 5256.5, "2019-04-30 00:59:35", "51296-03-30 10:16:50"]:

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '51296-03-30 10:16:50' for column 'sell_order_cre
ated' at row 1

In PDOStatement.php line 119:

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '51296-03-30 10:16:50' for column 'sell_order_cre
ated' at row 1
`

amandris commented 5 years ago

It's not the same issue. Your problem is related to the way the CEX.IO api returns the timestamp value when retrieving open orders. If you take a look to the api documentation https://cex.io/rest-api#open-orders, the timestamp should be returned in seconds, not milliseconds but the value your error trace shows is in milliseconds (tries to insert a datetime with year 51296).

I'm not sure to fix this issue in my code if CEX.IO doesn't update its api docs, but you can fix it locally just dividing by 1000 the $openOrder['time']value on the $timestamp->setTimestamp($openOrder['time']); lines in CexioService.php file.

sweepglass commented 5 years ago

Thank You for quick reply :) This did the trick for me: line 53: $timestamp->setTimestamp(($responseJson->timestamp)/1000); line 128: $timestamp->setTimestamp(($order['time'])/1000); line 156: $timestamp->setTimestamp(($openOrder['time'])/1000);