Historical Data not working (PHP)

prabhucse17
Hi Team,,

Please find the Screenshot and code as follows.
When i fetch the Last day data (06th oct) OHCL value in daily time frame,for 50 stockFUT,i am getting few response as blank and when i retry then again i am getting few more symbols data and few symbols as blank.It happening randomly.

I have paid for the Historical data api also..Still facing issue.Please look at the code and let me know if any mistake,ASAP.


<?php
require("../db.php");

$q=mysqli_query($con,"SELECT * FROM instruments ORDER BY id DESC LIMIT 50 ");
$APP_KEY = "99jdt8gpqukeq0gp";
$API_SECRET_KEY = "XXXXXXXXX";
$ACCESS_TOKEN = "YYYYYYYYYY";

while($r=mysqli_fetch_assoc($q)){
// var_dump($r);

$url = "https://api.kite.trade/instruments/historical/".$r['instrument']."/day?from=2017-10-06&to=2017-10-06&api_key=$APP_KEY&access_token=$ACCESS_TOKEN";
// var_dump($url);
$history = file_get_contents($url);
$history_data[$r['symbol']]=$history;
}

?>

<?php print_r($history_data); ?>

  • tonystark
    Hi @prabhucse17,

    Since you are fetching the API inside a while loop this crosses our API rate limit of 3 requests per second. Because of that requests are blocked with HTTP 429 status response. I would suggest you add 300ms delay between requests or get data as batches. And you can also store this locally to avoid multiple requests.
  • prabhucse17
    What will be scenario if i need to fetch the 5 mins candle for all the symbols of current day..? my idea is to display the all stock in table format and to fetch and update the OHLC value based on 5 mins candle on the table columns.so in this way if i fetch 3 stocks per time then wont there be a big delay .?? im new to programming bay be you can give some better idea also.
  • prabhucse17


    Seeing Same issue,even for just 2 symbols withe delay up to 30 sec added in loop.
    Not sure what is the issue from api end,it is just the basic requirement if historical data API.

    Really frustrating experience.Please help.

  • tonystark
    Hi @prabhucse17,

    Please collect the error information from the API response and post it here. For that instead of file_get_contents, you will have to use CURL library.
Sign In or Register to comment.