Skip to content

Conversation

Copy link

Copilot AI commented Dec 4, 2025

The virtual contract note implementation had incorrect charge calculations that didn't match Zerodha's brokerage calculator, causing the test to be ignored.

Changes

Corrected charge rates:

  • Stamp duty: 0.003% for intraday (was 0.015%), 0.015% for delivery
  • NSE transaction charges: 0.00307% (was 0.00297%)
  • STT for intraday: 0.025% on average of buy/sell prices (was only on sell side)

Implementation improvements:

  • Added rounding to 2-4 decimal places for all monetary calculations to handle floating-point precision
  • Separated stamp duty calculation by product type (CNC vs MIS)
  • Fixed struct field initialization order for consistency

Test coverage:

  • Re-enabled previously ignored test with corrected expected values
  • Added tests for delivery trades, BSE trades, and small trades

Example

For an intraday NSE trade (400 qty @ ₹1000 buy, ₹1100 sell):

let order = OrderReq {
    exchange: Exchange::NSE,
    product: Product::MIS,
    quantity: 400,
    buy: 1000.0,
    sell: 1100.0,
};
let note = get_virtual_contract_note(&order);
// Returns: brokerage=40, stt=105, txn_charges=25.79, net_charges=195.62

STT is now calculated as: (1000+1100)/2 * 400 * 0.00025 = 105 instead of 1100 * 400 * 0.00025 = 110

Original prompt

This section details on the original issue you should resolve

<issue_title>Complete Virtual Contract Note implementation</issue_title>
<issue_description>The aim is to mimic Zerodha Brokerage Calculator in virutal_contract_note module so that calculation of brokerage charges can be done fast and before taking trade.

Also, fix the current test which is ignored because the results aren't 100% matching</issue_description>

<agent_instructions>The goal is to make the calculations as accurate as possible. You need to checkout actual zerodha brokerage calculator to know which charges are applied on which kinds of order, etc.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 4, 2025 01:05
…culator

Co-authored-by: AS1100K <117935160+AS1100K@users.noreply.github.com>
Co-authored-by: AS1100K <117935160+AS1100K@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement virtual contract note calculations for brokerage charges Fix virtual contract note calculations to match Zerodha brokerage calculator Dec 4, 2025
Copilot AI requested a review from AS1100K December 4, 2025 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complete Virtual Contract Note implementation

2 participants