question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Current fetchOHLCV minute timestamp different for exchanges

See original GitHub issue

It seems that some exchanges take the ending minute as timestamp and some exchanges the beginning of the minute (imho the standard). The following little script illustrates the issue:

# !/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-

from datetime import datetime, timedelta
import sys
import time

import ccxt

exchange_id = sys.argv[1] if len(sys.argv) > 1 else 'binance'
symbol = sys.argv[2] if len(sys.argv) > 2 else 'BTC/USDT'

exchange = eval ('ccxt.%s ()' % exchange_id)

while True:
    fromdate = datetime.utcnow() - timedelta(minutes=1)
    since = int((fromdate - datetime(1970, 1, 1)).total_seconds() * 1000)
    ohlcvs = exchange.fetch_ohlcv(symbol, '1m', since=since, limit=3)
    if not ohlcvs:
        continue

    ohlcv = ohlcvs[-1]

    print(datetime.utcfromtimestamp(ohlcv[0]/1000), ohlcv[1], ohlcv[2],
          ohlcv[3], ohlcv[4], ohlcv[5])

    time.sleep(1)

So for example with binance (python script.py) the timestamp is the beginning of the current minute and with bitmex (python script.py bitmex BTC/USD) the timestamp is in the future, i.e. the ending of the current minute. Would be nice if this could be unified to a standard.

Also, I had to put a limit of larger then 1 for bitmex. The following returns an empty list:

bitmex = ccxt.bitmex()
bitmex.fetch_ohlcv('BTC/USD', '1m', since=int(((datetime.utcnow() - timedelta(minutes=1)) - datetime(1970, 1, 1)).total_seconds() * 1000), limit=1)
  • OS: Ubuntu 16.04.4 LTS
  • Programming Language version: Python 2.7.12
  • CCXT version: 1.11.62
  • Exchange: binance, bitmex
  • Method: fetch_ohlcv

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kroitorcommented, Aug 6, 2019

@developing-coder this is being addressed here, and we will merge it shortly: https://github.com/ccxt/ccxt/pull/5520

1reaction
FiV0commented, Mar 28, 2018

It seems that you only fixed the issue for 1m candles, but the issue is the same for 5m and 1h.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exchanges — ccxt 2.4.71 documentation
The CCXT library currently supports the following 104 cryptocurrency exchange markets and trading APIs: Besides making basic market and limit orders, some ...
Read more >
How to get ohlcv data for your exchange with ccxt library?
The since argument is an integer UTC timestamp in milliseconds. If since is not specified fetchOHLCV method it will return the time range...
Read more >
CCXT fetch_ohlcv returns too much data when inside for loop
I have a function that takes data of the given minute and ... def getBTC_data_from_binance(date): exchange = ccxt.binance() timestamp ...
Read more >
ccxt-dev/ccxt - Gitter
and with bitmex (python script.py bitmex BTC/USD) the timestamp is in the future, i.e. the ending of the current minute. will add a...
Read more >
CCXT - Cryptocurrency Exchange Trading Library Tutorial
Like the video? Support the channel by visiting Interactive Brokers: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found