Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchTrades returns GMT as localized timestamp in JS #325

Closed
D-Nice opened this issue Oct 17, 2017 · 6 comments
Closed

fetchTrades returns GMT as localized timestamp in JS #325

D-Nice opened this issue Oct 17, 2017 · 6 comments
Assignees

Comments

@D-Nice
Copy link

D-Nice commented Oct 17, 2017

Only tested with Poloniex and fetchTrades, but the converted timestamp is wrong. The library appears to assume that the time Poloniex is returning is my local timezone, and not GMT. The time fetched (which is already GMT) is converted to GMT, and makes orders appear as though they happened in the future.

@kroitor kroitor self-assigned this Oct 17, 2017
@kroitor
Copy link
Member

kroitor commented Oct 17, 2017

Hi, @D-Nice! What's your programming language version of ccxt?

@kroitor
Copy link
Member

kroitor commented Oct 17, 2017

Please note, that all timestamps and datetimes are UTC!

import ccxt
poloniex = ccxt.poloniex()
trades = poloniex.fetchTrades('BTC/USDT')
print('Current UTC time:', poloniex.iso8601(poloniex.milliseconds()))
print('Last trade was on UTC time:', trades[0]['datetime'])

The little python test above should show your system's UTC datetime, and will show the UTC datetime of the last trade on Poloniex, so those two datetime values should be very close to each other.

mbp:ccxt igorkroitor$ python
Python 2.7.13 (default, Jun  5 2017, 10:04:07) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ccxt
>>> poloniex = ccxt.poloniex()
>>> trades = poloniex.fetchTrades('BTC/USDT')
>>> print('Current UTC time:', poloniex.iso8601(poloniex.milliseconds()))
('Current UTC time:', '2017-10-17T00:34:40.000Z')
>>> print('Last trade was on UTC time:', trades[0]['datetime'])
('Last trade was on UTC time:', '2017-10-17T00:34:20.000Z')
>>> 

@D-Nice
Copy link
Author

D-Nice commented Oct 17, 2017

I'm using node. I did try your test, but the python version appears to have issues working at all. Regardless, node is my personal preference anyways.

I've cloned your test script for node 8+:

const ccxt = require('ccxt')

const polo = new ccxt['poloniex']()

console.log(polo.iso8601(polo.milliseconds()))

;(async() => {
  console.log((await polo.fetchTrades('BTC/USDT'))[0].datetime)
})()

here's the output

2017-10-17T02:11:02.877Z
2017-10-17T06:11:02.000Z

And the issue I am talking about.

Thanks for your time and help!

@kroitor
Copy link
Member

kroitor commented Oct 17, 2017

@D-Nice thx a lot for the snippet!

Can you please try the same for Bitfinex now?

const ccxt = require('ccxt')
const ex = new ccxt.bitfinex()
console.log(ex.iso8601(ex.milliseconds()))
;(async() => { console.log(ex.id, (await ex.fetchTrades('BTC/USD'))[0].datetime) })()

Looks like a Polo issue to me... A difference of 3 hours, where the same functions return no difference for Bitfinex UTC time... For Kraken it seems to be 1 hour. If that is the case, we will have to add some corrections for that. Should be UTC, really. Or there may be a bug inside the library, will test for that as well.

I did try your test, but the python version appears to have issues working at all.

If you could post an error log or something, it would be awesome. I tried that test by copying it and pasting into launched python interpreter shell inside the library directory and it worked for me. If it doesn't work for you, then, maybe we should do some debugging on that as well, we would appreciate your help.

@kroitor
Copy link
Member

kroitor commented Oct 17, 2017

Ok, never mind, I did a few more tests and it looks like a bug in parse8601 implementation in JS, but I'll fix it quickly. Thx for your report!

@kroitor kroitor changed the title fetchTrades returns GMT unix timestamp as localized timestamp fetchTrades returns GMT as localized timestamp in JS Oct 17, 2017
kroitor added a commit that referenced this issue Oct 17, 2017
@kroitor
Copy link
Member

kroitor commented Oct 17, 2017

Ok, this issue has been fixed as of CCXT version 1.9.156+. Thx for your feedback once again! Let us know if you find any other inconsistencies! Cheers!

academe-01 pushed a commit to academe-01/ccxt that referenced this issue Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants