Current fetchOHLCV minute timestamp different for exchanges
See original GitHub issueIt 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:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@developing-coder this is being addressed here, and we will merge it shortly: https://github.com/ccxt/ccxt/pull/5520
It seems that you only fixed the issue for
1m
candles, but the issue is the same for5m
and1h
.