fetch_ohlcv returning strange results
See original GitHub issue*First of all i understand this is under development
i’m a little bit confused about how the fetch_ohlcv returns data. I have an algo that i drip feed bars every day (or hour etc). For example, every day i want to give a OHLCV daily bar to the algo to process, the algo stores a list of all previous daily candles.
So to clarify, i would have a timer that runs every day, pulls the last full closed daily bar up to the millisecond and feeds it to my algo.
I don’t want a bar in progress. I want the close of the bar to be the current price
- OS: Windows 10
- Programming Language: Python 3.5
- CCXT version: 1.10.413
- Exchange: bitmex
- Method: fetch_ohlcv
import ccxt
exchange = ccxt.bitmex()
exchange_markets = exchange.load_markets()
ticker = 'BTC/USD'
print('current exchange time')
print(exchange.iso8601(exchange.milliseconds()))
print()
#the latest close of the ticker - in the following lines i'm expecting the close price of the bar to be this value
print('latest close: ' + str(exchange.fetchTicker(symbol=ticker)['close']))
#this seems to get really old data, 2016 - I would expect the most recent 100 bars by default?
bars = exchange.fetch_ohlcv(ticker,'1d')
print('bars in array: ' + str(len(bars)))
print(bars[-1])
print(exchange.iso8601(bars[-1][0]))
print()
print('latest close: ' + str(exchange.fetchTicker(symbol=ticker)['close']))
#does this get the latet 1day closed bar?
bars = exchange.fetch_ohlcv(ticker,'1d', since=exchange.milliseconds())
print('bars in array: ' + str(len(bars)))
print('# the -open- is higher than the -high- ?')
print(bars[-1])
print(exchange.iso8601(bars[-1][0]))
print()
print('latest close: ' + str(exchange.fetchTicker(symbol=ticker)['close']))
#I would expect this to return one full day of ticks in the form of 1 day bar
bars = exchange.fetch_ohlcv(ticker,'1d', since=exchange.milliseconds() - (24 * 60 * 60 * 1000)) # 1 day
print('#returns two bars, but i only put since 1 day of milliseconds')
print('bars in array: ' + str(len(bars)))
print('second second bar in array')
print('is this a bar in progress or a closed bar?')
print(bars[1])
print('# the date is the 2017-12-26 - 1 day in the future, how is this possible')
print(exchange.iso8601(bars[1][0]))
print('first bar in array')
print(bars[0])
print(exchange.iso8601(bars[0][0]))
This is an example output
current exchange time
2017-12-25T04:54:04.260Z
latest close: 14161.0
bars in array: 100
[1451779200000, 435.99, 438, 429.25, 435, 729519]
2016-01-03T00:00:00.000Z
latest close: 14123.5
bars in array: 1
\# the -open- is higher than the -high- ?
[1514246400000, 14227.5, 14185.5, 14123.5, 14136.5, 368345]
2017-12-26T00:00:00.000Z
latest close: 14118.5
\#returns two bars, but i only put since 1 day of milliseconds
bars in array: 2
second second bar in array
is this a bar in progress or a closed bar?
[1514246400000, 14227.5, 14387, 13232, 14108.5, 225518513]
\# the date is the 2017-12-26 - 1 day in the future, how is this possible
2017-12-26T00:00:00.000Z
first bar in array
[1514160000000, 14719.5, 14788.5, 12521.5, 14227.5, 1662515600]
2017-12-26T00:00:00.000Z
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ftx fetchOhlcv returns inconsistent results · Issue #12855 · ccxt ...
the fetch_ohlcv request on ftx returns some strange, inconsistent resutls depending on parameters given. Depending on the time within the candle ...
Read more >Ccxt binance fetchOHLCV doesn't return last data
To calculate the sar indicator, I am using fetchOHLCV to get last last historical data but the problem is that some times data...
Read more >ccxt-dev/ccxt - Gitter
how do i know which one to use, TRUNCATE, ROUND , etc ? and DECIMAL_PLACES for each market ? Suppose the market allows...
Read more >Exchanges — ccxt 2.4.71 documentation
This is only populated when has['fetchOHLCV'] property is true. ... the exchange and returns an exchange-specific JSON result from the API as is,...
Read more >Anyone use backtrader to do live trading on Bitcoin exchange?
the data is then returned as part of notify_order and forward to a limit ... I noticed something strange with the ccxt fetchohlc()...
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
What about the first one?
↑ are you sure you’re doing it right? From the above it should be obvious.
@DaneEdwards thanks! We really appreciate it! I’m sure many people will find it useful! You might also want to take a look at our examples/py for built-in rate-limiting, async generators and other interesting use-cases.