Too many requests ++ when trying to placeOrder

pannet1
hi,

AA) i have a loginController that handles the login flow and stores the kite object and access token in respective session variables.

BB) then i have controller that has the following code


if ($f3->exists('SESSION.oKite')) {
$this->kite = $f3->get('SESSION.oKite');

try {
$this->kite->setAccessToken($f3->get('SESSION.user_access_token'));
} catch (Exception $e) {
echo "Authentication failed: ".$e->getMessage();
throw $e;
}

// some code that fetches $quotes from db are left out for brevity

try {
$oQuote = $this->kite->getQuote($quotes);
//print_r($oQuote);
} catch (Exception $e) {
echo "exception while trying to get quote :-( ".$e->getMessage();
throw $e;
}

}

CC) then i have orderController with following code


class orderController extends Controller
{
protected $Kite;

public function __construct()
{
parent::__construct();
}

if ($f3->exists('SESSION.oKite')) {
$this->Kite = $f3->get('SESSION.oKite');

try {
$this->kite->setAccessToken($f3->get('SESSION.user_access_token'));
} catch (Exception $e) {
echo "Authentication failed: ".$e->getMessage();
throw $e;
}

}



public function processOrder($order)
{
$o = $this->Kite->placeOrder( "regular",[
"tradingsymbol" => $order['tradingsymbol'],
"exchange" => $order['exchange'],
"quantity" => $order['quantity'],
"transaction_type" => $transaction_type,
"order_type" => $order['order_type'],
"product" => "MIS",
"trigger_price" => $trigger_price,
"price" => $price,
"validity" => 'DAY',
]);
}
$order_id = $o->order_id;
return $order_id;

}


Whenever i access the route controlled by orderController, i am getting Too many requests (from the controller). It is necessary that we access the changing price every now and then and this may be immediatly followed by an orderPlace. So how could we avoid the "Too many requests" exception.
  • trade_then
    trade_then edited March 2018
    error 429
    describes it as rate-limiting. are you crossing the current limit of 5 orders per second. check limits.

    if so, you will have to pass your orders through a scheduler at your end that wont let fire more than the prescribed number of orders in prescribed time range .( which is currently in measure of orders per second ).

    Thanks
    Regards
  • pannet1
    @trade_then, @sujith and others,

    i am requesting the quote to refresh on every new page request (1/sec). i am only trying to process one order. is there a combined limit like if i request a quote, i am not supposed to send an order (1/sec). actually i am getting the problem only when i try to process an order. (see code above)

    should i renewAccessToken on subsequent requests.
  • trade_then
    Questions
    Answers
    i am requesting the quote to
    refresh on every new page request (1/sec).
     I dont think this would result in rate - limit 
    i am only trying to process one order.
    i am not supposed to send an order (1/sec)
     You can try what is allowed. 
    should i renewAccessToken on subsequent requests.  Not required. 
    is there a combined limit like if i request a quote,  I am not sure. for @sujith  

    Thanks
    Regards
  • pannet1
    @Kailash @sujith @vivek

    bumping this again. almost one month of subscription is going to get over tomorrow. i have not even used it once for my original purpose. appreciate your help in this regard.

    thanks.
  • sujith
    @pannet1,
    You can check out latest API rate limits here.
  • sujith
    There are no combined limits.
  • pannet1
    @sujith
    thank you. in that case, can anyone please fix the problem with my above code.
  • mrkaran
    @pannet1 What's the length of the array of orders which you're passing in processOrder ? The issue is you're most likely sending more than 5 orders/second.
    You can try putting a sleep() after every iteration of orders array to overcome this.
  • pannet1
    dear @mrkaran

    its very kind of you to reply to this issue.

    i dont have any more strength or time to troubleshoot this. i may move to the competition. however, as promised i will post my code to github, so its useful to someone.
Sign In or Register to comment.