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.

fetch_ohlcv should be useable without endTime for this usecase

See original GitHub issue

Recent changes made to fetch_ohlcv on binance.php prevent us from using fetch_ohlcv to grab the oldest OHLCVs for a pair, due to an enforced use of endTime parameter. I used to be able to call fetch_ohlcv with 0 startTime in previous versions to grab the oldest OHLCV from Binance, because endTime was not used.

I propose the following change to this code block in binance.php to allow use of startTime without endTime in fetch_ohlcv requests, if called with $since => null.

if ($since !== null) {
      $request['startTime'] = $since;
      $endTime = $this->sum($since, $limit * $duration * 1000 - 1);
      $now = $this->milliseconds();
      $request['endTime'] = min ($now, $endTime);
} 

to:

if ($since !== null) {
      $request['startTime'] = $since;
      $endTime = $this->sum($since, $limit * $duration * 1000 - 1);
      $now = $this->milliseconds();
      $request['endTime'] = min ($now, $endTime);
} elseif($since === null) {
      $request['startTime'] = 0;
}

This way, if you call the function with null, it defaults to 0 startTime and no endTime, which brings the oldest candles for that pair from Binance. Then if you’d want to use startTime with endTime, I can always provide 0 to $since parameter.

Eitherway, if you see a better way to do this, please propose it here. I don’t think endTime should be enforced for this specific usecase.

If approved, I’ll submit a PR.

  • OS: Ubuntu 20.04
  • Programming Language version: PHP 7.4
  • CCXT version: 1.4.61

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kroitorcommented, Feb 5, 2021

@yazeed thx for your feedback!

1reaction
yazeedcommented, Feb 5, 2021

Thank you, my bad, it works now. Apologies. Have a great day or evening wherever you are!

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Bitmex json api - Caritas Castellaneta
(Most of the times the temp ban expires before 60 minutes, but in some cases it can take up to 24 hours). json...
Read more >
Ccxt python documentation. ago. API Resources and Support ...
I'm not sure why thought because I'm pretty sure binance supports trailing stop loss orders (it says so in its own API documentation)....
Read more >
How to get ohlcv data for your exchange with ccxt library?
How to use ccxt library to obtain OHLCV data from crypto exchange ... If since is not specified fetchOHLCV method it will return...
Read more >
Cricket data usage limit - urbangame.eu
Of course, playing a game online will use data. ... fetchOHLCV (symbol, timeframe='1m', since=undefined, limit=undefined, params= {}) This is the example in ...
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