Iceberg order execution error

akhilesh_singla
I'm trying to execute iceberg orders via Google App Script using Rest APIs:
 { 
exchange: 'NFO',
variety: 'iceberg',
iceberg_legs: 2,
iceberg_quantity: 1200,
tradingsymbol: 'NIFTY25APR23800PE',
transaction_type: 'SELL',
order_type: 'MARKET',
quantity: 2475,
product: 'MIS'
}
Error received:
"The order quantity 2475 (33 lots) is higher than the maximum quantity of 1800 (24 lots) allowed by the exchanges".

"quantity" key is total quantity as suggested on other forum threads:
1. https://github.com/zerodha/javakiteconnect/blob/master/sample/src/Examples.java#L134
2. https://github.com/zerodha/kiteconnectjs/blob/9c34f728ec026b786427c927c4360f5000071410/examples/connect.js#L268


Should "quantity" be same as "iceberg_quantity"?
  • akhilesh_singla
    I tried using iceberg_quantity in quantity but it executed only 1st leg of the iceberg. Lost 1k in just testing this buggy iceberg API with unclear documentation.
  • Sravanthi_bh
    You may refer to the similar discussion here.
  • akhilesh_singla
    akhilesh_singla edited 7:55AM
    @Sravanthi_bh Thanks for your input. Before posting this thread, I had gone through the shared post and many other posts on icebergs on the forum. The shared link's conclusion is still vague to me. Does it mean I need to modify as below?

    freezeQuantity = 1800;
    iceberg_legs = Math.ceil(quantity / freezeQuantity);
    {
    exchange: 'NFO',
    variety: 'iceberg',
    iceberg_legs: 2,
    iceberg_quantity: (quantity/iceberg_legs),
    tradingsymbol: 'NIFTY25APR23800PE',
    transaction_type: 'SELL',
    order_type: 'MARKET',
    quantity: quantity,
    product: 'MIS'
    }
  • sujith
    sujith edited 10:32AM
    It should be
    s = quantity / Max(legCount, 2)
    iceberg_qty = (s/lotSize).ceil() * lotSize
  • akhilesh_singla
    @sujith Is legCount same as iceberg_legs? I used slicing as suggested and got the same error.
    icebergLegs = Math.ceil(quantity / freezeQuantity);
    const slice = quantity / icebergLegs;
    icebergQuantity = Math.ceil((slice / lotSize)) * lotSize;

    {
    exchange: 'NFO',
    tradingsymbol: 'NIFTY25APR22700PE',
    transaction_type: 'BUY',
    order_type: 'MARKET',
    quantity: 3750,
    product: 'MIS',
    variety: 'iceberg',
    iceberg_legs: 3,
    iceberg_quantity: 1275
    }
    Error:
    "The order quantity 3750 (50 lots) is higher than the maximum quantity of 1800 (24 lots) allowed by the exchanges"
  • sujith
    The iceberg quantity is 450 according to your values. What is the url you are placing order with?
  • akhilesh_singla
    akhilesh_singla edited 11:52AM
    @sujith URL: https://api.kite.trade/orders/regular
    Above URL and my complete code works for qty lower than freeze qty. Just stuck on iceberg orders.

    According to my values, iceberg_quantity should be 1275. Please see below calculation:
    quantity = 3750;
    freezeQuantity = 1800;
    icebergLegs = Math.ceil(quantity / freezeQuantity); // ceil(3750/1800) => ceil(2.08) => 3
    const slice = quantity / icebergLegs; // (3750/3) => 1250
    icebergQuantity = Math.ceil((slice / lotSize)) * lotSize; // ceil(1250/75) * 75 => 17 * 75 => 1275
  • sujith
    You are sending the request to the wrong endpoint. It should have variety iceberg and not regular in the URL.
  • akhilesh_singla
    Thanks for pointing out the mistake! Modified my code accordingly. Will check tomorrow during market hours and revert back here.
Sign In or Register to comment.